28 #include <sys/types.h>
29 #include <netinet/in.h>
31 #include <arpa/inet.h>
39 #include <curl/curl.h>
40 #include <curl/easy.h>
172 static int has_init = 0;
188 curl_global_init(CURL_GLOBAL_ALL);
216 if ((fp = fopen(
buf,
"r")) == NULL) {
220 while (fgets(
buf,
sizeof(
buf), fp) != NULL) {
224 if ((cp = strrchr(
buf,
'\n')) != NULL)
233 if ((cp = strpbrk(
buf,
" \t")) != NULL) {
249 LOG(
llevError,
"metaserver2: Unknown value for metaserver2_notification: %s\n", cp);
258 LOG(
llevError,
"metaserver2: metaserver2_server must have a value.\n");
264 LOG(
llevError,
"metaserver2: localhostname must have a value.\n");
270 LOG(
llevError,
"metaserver2: portnumber must have a value.\n");
300 LOG(
llevError,
"metaserver2 file is set to do notification, but libcurl is not found.\n");
301 LOG(
llevError,
"Either fix your compilation, or turn off metaserver2 notification in \n");
331 LOG(
llevError,
"metaserver2_init: return code from pthread_create() is %d\n", ret);
353 size_t realsize = size*nmemb;
354 LOG(
llevError,
"Message from metaserver:\n%s\n", (
const char*)ptr);
359 static void metaserver2_build_form(
struct curl_httppost **formpost) {
360 struct curl_httppost *lastptr = NULL;
369 curl_formadd(formpost, &lastptr,
370 CURLFORM_COPYNAME,
"hostname",
375 curl_formadd(formpost, &lastptr,
376 CURLFORM_COPYNAME,
"port",
377 CURLFORM_COPYCONTENTS,
buf,
380 curl_formadd(formpost, &lastptr,
381 CURLFORM_COPYNAME,
"html_comment",
385 curl_formadd(formpost, &lastptr,
386 CURLFORM_COPYNAME,
"text_comment",
390 curl_formadd(formpost, &lastptr,
391 CURLFORM_COPYNAME,
"archbase",
395 curl_formadd(formpost, &lastptr,
396 CURLFORM_COPYNAME,
"mapbase",
400 curl_formadd(formpost, &lastptr,
401 CURLFORM_COPYNAME,
"codebase",
405 curl_formadd(formpost, &lastptr,
406 CURLFORM_COPYNAME,
"flags",
413 curl_formadd(formpost, &lastptr,
414 CURLFORM_COPYNAME,
"num_players",
415 CURLFORM_COPYCONTENTS,
buf,
419 curl_formadd(formpost, &lastptr,
420 CURLFORM_COPYNAME,
"in_bytes",
421 CURLFORM_COPYCONTENTS,
buf,
425 curl_formadd(formpost, &lastptr,
426 CURLFORM_COPYNAME,
"out_bytes",
427 CURLFORM_COPYCONTENTS,
buf,
431 curl_formadd(formpost, &lastptr,
432 CURLFORM_COPYNAME,
"uptime",
433 CURLFORM_COPYCONTENTS,
buf,
441 curl_formadd(formpost, &lastptr,
442 CURLFORM_COPYNAME,
"version",
447 curl_formadd(formpost, &lastptr,
448 CURLFORM_COPYNAME,
"sc_version",
449 CURLFORM_COPYCONTENTS,
buf,
453 curl_formadd(formpost, &lastptr,
454 CURLFORM_COPYNAME,
"cs_version",
455 CURLFORM_COPYCONTENTS,
buf,
467 struct curl_httppost *formpost = NULL;
468 metaserver2_build_form(&formpost);
471 CURL *curl = curl_easy_init();
474 curl_easy_setopt(curl, CURLOPT_URL, ms2->hostname);
475 curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
483 char errbuf[CURL_ERROR_SIZE];
484 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
486 CURLcode
res = curl_easy_perform(curl);
488 LOG(
llevError,
"metaserver update failed: %s\n", errbuf);
492 curl_easy_cleanup(curl);
494 LOG(
llevError,
"metaserver: could not initialize curl\n");
498 curl_formfree(formpost);