9284272000-03-17Martin Nilsson // This is a roxen module. Copyright © 1999 - 2000, Roxen IS.
e658201999-09-29Francesco Chemolli #include <module.h> inherit "module"; constant thread_safe=1;
9b03652001-03-07Kenneth Johansson constant cvs_version="$Id: throttletags.pike,v 1.11 2001/03/07 13:40:47 kuntri Exp $";
e658201999-09-29Francesco Chemolli  #ifdef THROTTLING_DEBUG #undef THROTTLING_DEBUG
b3ef2d1999-12-18Martin Nilsson #define THROTTLING_DEBUG(X) werror("throttletags: "+X+"\n")
e658201999-09-29Francesco Chemolli #else #define THROTTLING_DEBUG(X) #endif #define THROW(X) throw( X+"\n" )
b3281f2000-09-10Martin Nilsson constant module_type = MODULE_TAG;
ad959c2000-02-12Martin Nilsson constant module_name = "Throttling control tags"; constant module_doc = "This module provides a <tt>&lt;THROTTLE&gt;</tt> tag " "that you can use to determine a request's allocated bandwidth";
2227c92000-05-15Francesco Chemolli constant module_unique = 1;
e658201999-09-29Francesco Chemolli 
920dcc1999-12-18Martin Nilsson TAGDOCUMENTATION; #ifdef manual
9b03652001-03-07Kenneth Johansson constant tagdoc=(["throttle":#"<desc tag='tag'><p><short> This tag determines a request's allocated bandwidth.</short></p> </desc>
c589a22000-04-15Per Hedbor 
9b03652001-03-07Kenneth Johansson <attr name='not'><p>
5ded5c2000-04-25Kenneth Johansson Disables all and any throttling for the current request. Implies the
9b03652001-03-07Kenneth Johansson 'final' arg.</p>
5ded5c2000-04-25Kenneth Johansson </attr>
c589a22000-04-15Per Hedbor 
9b03652001-03-07Kenneth Johansson <attr name='add' value='rate'><p> Adds 'rate' bytes/sec to the current rate for the current request.</p>
5ded5c2000-04-25Kenneth Johansson </attr>
9b03652001-03-07Kenneth Johansson <attr name='subtract' value='rate'><p>
5ded5c2000-04-25Kenneth Johansson Subtracts 'rate' bytes/sec from the current rate for the current
9b03652001-03-07Kenneth Johansson request.</p>
5ded5c2000-04-25Kenneth Johansson </attr>
9b03652001-03-07Kenneth Johansson <attr name='multiply' value='float'><p> Multiplies this requests' bandwidth by 'float'.</p>
5ded5c2000-04-25Kenneth Johansson </attr>
9b03652001-03-07Kenneth Johansson <attr name='divide' value='float'><p> Divides this requests' bandwidth by 'float'.</p>
5ded5c2000-04-25Kenneth Johansson </attr>
9b03652001-03-07Kenneth Johansson <attr name='rate' value='value'><p> Sets this request's bandwidth to 'value'.</p>
5ded5c2000-04-25Kenneth Johansson </attr>
9b03652001-03-07Kenneth Johansson <attr name='final' required><p>
5ded5c2000-04-25Kenneth Johansson No subsequent modifications will be done to this request's bandwidth
9b03652001-03-07Kenneth Johansson after the current one.</p>
c589a22000-04-15Per Hedbor </attr>",
5ded5c2000-04-25Kenneth Johansson  ]);
920dcc1999-12-18Martin Nilsson #endif
e658201999-09-29Francesco Chemolli 
920dcc1999-12-18Martin Nilsson string|int tag_throttle(string tag, mapping args, RequestID id) {
e658201999-09-29Francesco Chemolli  mapping t=id->throttle; string tmp; if (t->fixed) { THROTTLING_DEBUG("Fixed. returning"); return 0; } if (args->not) { THROTTLING_DEBUG("Don't want to throttle."); t->doit=0; t->fixed=1; return 0; } if (tmp=args->add) { t->rate+=(int)tmp; t->doit=1; THROTTLING_DEBUG("added "+tmp); } if (tmp=args->subtract) { t->rate-=(int)tmp; t->doit=1; THROTTLING_DEBUG("subtracted "+tmp); } if (tmp=args->multiply) { t->rate=(int)(t->rate*(float)tmp); t->doit=1; THROTTLING_DEBUG("multiplied by "+tmp); } if (tmp=args->divide) { t->rate=(int)(t->rate/(float)tmp); t->doit=1; THROTTLING_DEBUG("divided by "+tmp); } if (tmp=args->rate) { t->rate=(int)tmp; t->doit=1; THROTTLING_DEBUG("rate set to "+tmp); } if (args["final"]) { t->fixed=1; t->doit=1; THROTTLING_DEBUG("finalized setting"); } return ""; }