diff --git a/include/h.h b/include/h.h index 7cee49fae..dc64b49ea 100644 --- a/include/h.h +++ b/include/h.h @@ -1392,6 +1392,7 @@ extern void url_start_async(const char *url, HttpMethod http_method, const char extern void url_init(void); extern void url_cancel_handle_by_callback_data(void *ptr); extern EVENT(url_socket_timeout); +extern int downloads_in_progress(void); /* end of url stuff */ extern char *collapse(char *pattern); extern void clear_scache_hash_table(void); diff --git a/src/modules/spamreport.c b/src/modules/spamreport.c index 6e360eecc..a69144690 100644 --- a/src/modules/spamreport.c +++ b/src/modules/spamreport.c @@ -320,6 +320,17 @@ int _spamreport(Client *client, const char *ip, NameValuePrioList *details, cons char *url = NULL; char *body = NULL; NameValuePrioList *headers = NULL; + int num; + + num = downloads_in_progress(); + if (num > 100) + { + // TODO: throttle this error + unreal_log(ULOG_WARNING, "spamreport", "SPAMREPORT_TOO_MANY_CONCURRENT_REQUESTS", NULL, + "Already $num_requests HTTP(S) requests in progress, new spamreport requests ignored.", + log_data_integer("num_requests", num)); + return 0; + } if (!spamreport_block) { diff --git a/src/url_curl.c b/src/url_curl.c index d73ba78fe..88b9d5ea4 100644 --- a/src/url_curl.c +++ b/src/url_curl.c @@ -453,3 +453,16 @@ char *urlencode(const char *s, char *wbuf, int wlen) strlcpy(wbuf, ret, wlen); return wbuf; } + +int downloads_in_progress(void) +{ + Download *d; + int count = 0; + + /* Bit stupid to do it this slow way, can't we maintain a counter? Needs to be accurate though */ + + for (d = downloads; d; d = d->next); + count++; + + return count; +} diff --git a/src/url_unreal.c b/src/url_unreal.c index 6ec552122..83cc3b258 100644 --- a/src/url_unreal.c +++ b/src/url_unreal.c @@ -1226,3 +1226,16 @@ char *urlencode(const char *s, char *wbuf, int wlen) return wbuf; } + +int downloads_in_progress(void) +{ + Download *d; + int count = 0; + + /* Bit stupid to do it this slow way, can't we maintain a counter? Needs to be accurate though */ + + for (d = downloads; d; d = d->next); + count++; + + return count; +}