static void netplay_announce(void) { char buf [2048]; char url [2048] = "http://newlobby.libretro.com/add/"; char *username = NULL; char *corename = NULL; char *gamename = NULL; char *coreversion = NULL; char *frontend_ident = NULL; settings_t *settings = config_get_ptr(); rarch_system_info_t *system = runloop_get_system_info(); uint32_t content_crc = content_get_crc(); char frontend_architecture[PATH_MAX_LENGTH]; netplay_get_architecture(frontend_architecture, sizeof(frontend_architecture)); net_http_urlencode(&username, settings->paths.username); net_http_urlencode(&corename, system->info.library_name); net_http_urlencode(&gamename, !string_is_empty(path_basename(path_get(RARCH_PATH_BASENAME))) ? path_basename(path_get(RARCH_PATH_BASENAME)) : "N/A"); net_http_urlencode(&coreversion, system->info.library_version); net_http_urlencode(&frontend_ident, frontend_architecture); buf[0] = '\0'; snprintf(buf, sizeof(buf), "username=%s&core_name=%s&core_version=%s&" "game_name=%s&game_crc=%08X&port=%d&mitm_server=%s" "&has_password=%d&has_spectate_password=%d&force_mitm=%d&retroarch_version=%s&frontend=%s", username, corename, coreversion, gamename, content_crc, settings->uints.netplay_port, settings->arrays.netplay_mitm_server, *settings->paths.netplay_password ? 1 : 0, *settings->paths.netplay_spectate_password ? 1 : 0, settings->bools.netplay_use_mitm_server, PACKAGE_VERSION, frontend_architecture); #if 0 RARCH_LOG("[netplay] announcement URL: %s\n", buf); #endif task_push_http_post_transfer(url, buf, true, NULL, netplay_announce_cb, NULL); if (username) free(username); if (corename) free(corename); if (gamename) free(gamename); if (coreversion) free(coreversion); if (frontend_ident) free(frontend_ident); }
/* Re-encode a full URL */ void net_http_urlencode_full(char *dest, const char *source, size_t size) { char *tmp = NULL; char url_domain[PATH_MAX_LENGTH] = {0}; char url_path[PATH_MAX_LENGTH] = {0}; int count = 0; strlcpy (url_path, source, sizeof(url_path)); tmp = url_path; while (count < 3 && tmp[0] != '\0') { tmp = strchr(tmp, '/'); count++; tmp++; } strlcpy(url_domain, source, tmp - url_path); strlcpy(url_path, source + strlen(url_domain) + 1, strlen(tmp) + 1 ); tmp = NULL; net_http_urlencode(&tmp, url_path); snprintf(dest, size, "%s/%s", url_domain, tmp); free (tmp); }