1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-05 02:53:13 +02:00

New URL API (not really a unrealircd module api tho) - work in progress.

No longer url_start_async(a,b,c,d,e,f,g,...) but usings structs so
simply url_start_async(tehstruct);
makes it easy to add fields later without forcing all modules to
change the prototype.

Work in progress....
This commit is contained in:
Bram Matthys
2023-11-24 11:27:39 +01:00
parent c9abf0709a
commit 3548b7e2af
8 changed files with 203 additions and 161 deletions
+21 -6
View File
@@ -980,6 +980,7 @@ void cbl_mdata_free(ModData *m)
void send_request_for_pending_clients(void)
{
Client *client, *next;
OutgoingWebRequest *w;
json_t *j, *requests;
NameValuePrioList *headers = NULL;
int num;
@@ -1030,9 +1031,16 @@ void send_request_for_pending_clients(void)
add_nvplist(&headers, 0, "Content-Type", "application/json; charset=utf-8");
add_nvplist(&headers, 0, "X-API-Key", cfg.api_key);
c = add_cbl_transfer(clientlist);
url_start_async(cfg.url, HTTP_METHOD_POST, json_serialized, headers, 0, 0, cbl_download_complete, c, cfg.url, 1);
safe_free(json_serialized);
safe_free_nvplist(headers);
/* Do the web request */
w = safe_alloc(sizeof(OutgoingWebRequest));
safe_strdup(w->url, cfg.url);
w->http_method = HTTP_METHOD_POST;
w->body = json_serialized;
w->headers = headers;
w->max_redirects = 1;
w->callback = cbl_download_complete;
w->callback_data = c;
url_start_async(w);
}
int cbl_any_pending_clients(void)
@@ -1082,6 +1090,7 @@ CMD_OVERRIDE_FUNC(cbl_override_spamreport_gather)
void cbl_spamreport(Client *from, Client *client)
{
json_t *j, *requests, *data, *cmds, *item;
OutgoingWebRequest *w;
NameValuePrioList *headers = NULL;
int num;
char *json_serialized;
@@ -1145,9 +1154,15 @@ void cbl_spamreport(Client *from, Client *client)
json_decref(j);
add_nvplist(&headers, 0, "Content-Type", "application/json; charset=utf-8");
add_nvplist(&headers, 0, "X-API-Key", cfg.api_key);
url_start_async(cfg.spamreport_url, HTTP_METHOD_POST, json_serialized, headers, 0, 0, download_complete_dontcare, NULL, cfg.spamreport_url, 1);
safe_free(json_serialized);
safe_free_nvplist(headers);
/* Do the web request */
w = safe_alloc(sizeof(OutgoingWebRequest));
safe_strdup(w->url, cfg.spamreport_url);
w->http_method = HTTP_METHOD_POST;
w->body = json_serialized;
w->headers = headers;
w->max_redirects = 1;
w->callback = download_complete_dontcare;
url_start_async(w);
}
CMD_OVERRIDE_FUNC(cbl_override_spamreport_cmd)
+10 -2
View File
@@ -393,6 +393,7 @@ int spamfilter_block_rate_limited(Spamreport *spamreport)
int _spamreport(Client *client, const char *ip, NameValuePrioList *details, const char *spamreport_block)
{
Spamreport *s;
OutgoingWebRequest *request;
char urlbuf[512];
char bodybuf[512];
char *url = NULL;
@@ -472,8 +473,15 @@ int _spamreport(Client *client, const char *ip, NameValuePrioList *details, cons
log_data_string("url", url),
log_data_string("body", (body ? body : "")));
#endif
url_start_async(url, s->http_method, body, headers, 0, 0, download_complete_dontcare, NULL, url, 3);
safe_free_nvplist(headers);
/* Do the web request */
request = safe_alloc(sizeof(OutgoingWebRequest));
safe_strdup(request->url, url);
request->http_method = s->http_method;
safe_strdup(request->body, body);
request->headers = headers;
request->callback = download_complete_dontcare;
request->max_redirects = 3;
url_start_async(request);
return 1;
}