/** * Print EDonkey 2000 url for given file to a stream. * * @param out the stream where to print url to * @param filename the file name * @param filesize the file size * @param sums the file hash sums */ static void fprint_ed2k_url(FILE* out, struct file_info *info, int print_type) { const char *filename = get_basename(file_info_get_utf8_print_path(info)); int upper_case = (print_type & PRINT_FLAG_UPPERCASE ? RHPR_UPPERCASE : 0); int len = urlencode(NULL, filename) + int_len(info->size) + (info->sums_flags & RHASH_AICH ? 84 : 49); char* buf = (char*)rsh_malloc( len + 1 ); char* dst = buf; assert(info->sums_flags & (RHASH_ED2K|RHASH_AICH)); assert(info->rctx); strcpy(dst, "ed2k://|file|"); dst += 13; dst += urlencode(dst, filename); *dst++ = '|'; sprintI64(dst, info->size, 0); dst += strlen(dst); *dst++ = '|'; rhash_print(dst, info->rctx, RHASH_ED2K, upper_case); dst += 32; if((info->sums_flags & RHASH_AICH) != 0) { strcpy(dst, "|h="); rhash_print(dst += 3, info->rctx, RHASH_AICH, RHPR_BASE32 | upper_case); dst += 32; } strcpy(dst, "|/"); fprintf(out, "%s", buf); free(buf); }
/*++ * @method: oAuth::buildOAuthRawDataKeyValPairs * * @description: this method prepares key-value pairs from the data part of the URL * or from the URL post fields data, as required by OAuth header * and signature generation. * * @input: rawData - Raw data either from the URL itself or from post fields. * Should already be url encoded. * urlencodeData - If true, string will be urlencoded before converting * to key value pairs. * * @output: rawDataKeyValuePairs - Map in which key-value pairs are populated * * @remarks: internal method * *--*/ void oAuth::buildOAuthRawDataKeyValPairs( const std::string& rawData, bool urlencodeData, oAuthKeyValuePairs& rawDataKeyValuePairs ) { /* Raw data if it's present. Data should already be urlencoded once */ if( rawData.empty() ) { return; } size_t nSep = std::string::npos; size_t nPos = std::string::npos; std::string dataKeyVal; std::string dataKey; std::string dataVal; /* This raw data part can contain many key value pairs: key1=value1&key2=value2&key3=value3 */ std::string dataPart = rawData; while( std::string::npos != ( nSep = dataPart.find_first_of("&") ) ) { /* Extract first key=value pair */ dataKeyVal = dataPart.substr( 0, nSep ); /* Split them */ nPos = dataKeyVal.find_first_of( "=" ); if( std::string::npos != nPos ) { dataKey = dataKeyVal.substr( 0, nPos ); dataVal = dataKeyVal.substr( nPos + 1 ); /* Put this key=value pair in map */ rawDataKeyValuePairs[dataKey] = urlencodeData ? urlencode( dataVal ) : dataVal; } dataPart = dataPart.substr( nSep + 1 ); } /* For the last key=value */ dataKeyVal = dataPart.substr( 0, nSep ); /* Split them */ nPos = dataKeyVal.find_first_of( "=" ); if( std::string::npos != nPos ) { dataKey = dataKeyVal.substr( 0, nPos ); dataVal = dataKeyVal.substr( nPos + 1 ); /* Put this key=value pair in map */ rawDataKeyValuePairs[dataKey] = urlencodeData ? urlencode( dataVal ) : dataVal; //std::cout << "URLENCODE: " << urlencode( dataVal ) << " NOENCODE: " << dataVal << " KEY: " << dataKey << std::endl; //std::cout << rawDataKeyValuePairs[dataKey] << std::endl; } }
int main(int argc, char *argv[]) { char *buf = malloc(512); if (argv[1]) urlencode(argv[1]); else while (fgets(buf, 512, stdin) > 0) { urlencode(buf); } free(buf); return 0; }
static char *plurk_encode_kv(char *buf, const char *key, const char *value) { int rc; rc = urlencode(buf, key); buf += rc; memcpy(buf, "=", 2); ++buf; rc = urlencode(buf, value); buf += rc; return buf; }
int main(int argc,char* argv[]) { int i; for (i=1; i<argc; ++i) { urlencode(argv[i]); } if (argc<2) { char src[1024]; int len=read(0,src,sizeof(src)-1); if (len==-1) return(1); src[len]=0; urlencode(src); } return 0; }
int btTracker::BuildBaseRequest() { char ih_buf[20 * 3 + 1], pi_buf[20 * 3 + 1], *tmppath, *tmpreq = (char *)0; if( !(tmppath = new char[strlen(m_spec->request) + 1]) || !(tmpreq = new char[strlen(m_spec->request) + 256]) ){ errno = ENOMEM; CONSOLE.Warning(1, "Error building tracker request: %s", strerror(errno)); if( tmppath ) delete []tmppath; return -1; } strcpy(tmppath, m_spec->request); delete []m_spec->request; sprintf(tmpreq, "GET %s%cinfo_hash=%s&peer_id=%s&key=%s", tmppath, strchr(tmppath, '?') ? '&' : '?', urlencode(ih_buf, BTCONTENT.GetInfoHash(), 20), urlencode(pi_buf, BTCONTENT.GetPeerId(), PEER_ID_LEN), m_key); if( *cfg_listen_port > 0 ){ strcat(tmpreq, "&port="); sprintf(tmpreq + strlen(tmpreq), "%d", (int)*cfg_listen_port); } cfg_public_ip.Lock(); if( *cfg_public_ip ){ strcat(tmpreq, "&ip="); strcat(tmpreq, *cfg_public_ip); }else{ struct sockaddr_in addr; Self.GetAddress(&addr); if( !IsPrivateAddress(addr.sin_addr.s_addr) ){ strcat(tmpreq, "&ip="); strcat(tmpreq, inet_ntoa(addr.sin_addr)); } } if( !(m_spec->request = new char[strlen(tmpreq) + 1]) ){ errno = ENOMEM; CONSOLE.Warning(1, "Error building tracker request: %s", strerror(errno)); delete []tmpreq; return -1; } strcpy(m_spec->request, tmpreq); delete []tmpreq; return 0; }
shared_ptr<HttpSession> WebGetter::getFile(const string &url, function<void(const File&)> callback) { string u = url; auto target = make_shared<File>(cacheDir + "/" + urlencode(url, ":/\\?;")); lock_guard<mutex>{m}; auto s = make_shared<HttpSession>(url); if(target->exists() && target->getSize() > 0) { callback(*target); return s; } sessions.push_back(s); s->connect(); if(s->getState() == HttpSession::ERROR) { callback(File::NO_FILE); sessions.erase(sessions.end()-1); return s; } s->stream([=](HttpSession &session, const vector<uint8_t> &v) { target->write(v); if(session.done()) { auto finalUrl = session.getUrl(); target->close(); if(session.returnCode() != 200) { target->remove(); utils::schedule_callback([=]() { callback(File::NO_FILE); }); } else if(finalUrl != url) { auto finalTarget = make_shared<File>(cacheDir + "/" + urlencode(finalUrl, ":/\\?;")); rename(target->getName().c_str(), finalTarget->getName().c_str()); #ifdef _WIN32 // TODO: Some way to simulate symlinks? File::copy(finalTarget->getName(), target->getName()); #else symlink(finalTarget->getName().c_str(), target->getName().c_str()); #endif //callback(*finalTarget); utils::schedule_callback([=]() { callback(*finalTarget); }); } else utils::schedule_callback([=]() { callback(*target); }); //callback(*target); } }); return s; }
char *make_request_header(char *logbookname,char *glob_boundary,int which) { glob_boundary = boundary; char request[REQUESTSIZE]; char *p = request; char boun_buf[BOUNSIZE]; char host_name[50]; char *url_enc = urlencode(logbookname); if(gethostname(host_name,sizeof(host_name)) == -1) { perror("gethostname"); exit(EXIT_FAILURE); } sprintf(boun_buf,"%s",boundary); if(which){ PRINTINFO(MSGQUERY,debug); } strncpy(request,POSTREQ,sizeof(POSTREQ)); sprintf(request + strlen(request), "%s/",url_enc); strcat(request,HTTPVER); sprintf(request + strlen(request), "Content-Type: multipart/form-data; boundary=%s\r\n",glob_boundary); sprintf(request + strlen(request), "Host: %s\r\n", host_name); sprintf(request + strlen(request), "User-Agent: ELOG\r\n"); sprintf(request + strlen(request), "Authorization: Basic %s\r\n",encuserandpass); sprintf(request + strlen(request), "Content-Length: %d\r\n\r\n", content_length); bzero(encoded_url,sizeof(encoded_url)); return(p); }
/*++ * @method: twitCurl::performPost * * @description: method to send http POST request. this is an internal method. * twitcurl users should not use this method. * * @input: postUrl - url, * dataStr - data to be posted * * @output: none * * @remarks: internal method * *--*/ bool twitCurl::performPost( const std::string& postUrl, std::string dataStr ) { std::string oAuthHttpHeader( "" ); struct curl_slist* pOAuthHeaderList = NULL; /* Prepare standard params */ prepareStandardParams(); /* urlencode data */ if( dataStr.length() > 0 ) { /* Data should already be urlencoded once */ std::string dataKey( "" ); std::string dataValue( "" ); size_t nPos = dataStr.find_first_of( "=" ); if( std::string::npos != nPos ) { dataKey = dataStr.substr( 0, nPos ); dataValue = dataStr.substr( nPos + 1 ); dataValue = urlencode( dataValue ); dataStr.assign( dataKey ); dataStr.append( "=" ); dataStr.append( dataValue ); } } /* Set OAuth header */ m_oAuth.getOAuthHeader( eOAuthHttpPost, postUrl, dataStr, oAuthHttpHeader ); if( oAuthHttpHeader.length() > 0 ) { pOAuthHeaderList = curl_slist_append( pOAuthHeaderList, oAuthHttpHeader.c_str() ); if( pOAuthHeaderList ) { curl_easy_setopt( m_curlHandle, CURLOPT_HTTPHEADER, pOAuthHeaderList ); } } /* Set http request, url and data */ curl_easy_setopt( m_curlHandle, CURLOPT_POST, 1 ); curl_easy_setopt( m_curlHandle, CURLOPT_URL, postUrl.c_str() ); if( dataStr.length() ) { curl_easy_setopt( m_curlHandle, CURLOPT_COPYPOSTFIELDS, dataStr.c_str() ); } /* Send http request */ if( CURLE_OK == curl_easy_perform( m_curlHandle ) ) { if( pOAuthHeaderList ) { curl_slist_free_all( pOAuthHeaderList ); } return true; } if( pOAuthHeaderList ) { curl_slist_free_all( pOAuthHeaderList ); } return false; }
struct http_connection_t *net_http_connection_new(const char *url) { char **domain = NULL; struct http_connection_t *conn = (struct http_connection_t*)calloc(1, sizeof(struct http_connection_t)); if (!conn) return NULL; conn->urlcopy = urlencode(url); if (!conn->urlcopy) goto error; if (strncmp(url, "http://", strlen("http://")) != 0) goto error; conn->scan = conn->urlcopy + strlen("http://"); domain = &conn->domain; *domain = conn->scan; return conn; error: if (conn->urlcopy) free(conn->urlcopy); conn->urlcopy = NULL; free(conn); return NULL; }
void WebGetter::update() { lock_guard<mutex>{m}; Connection::run(); auto it = sessions.begin(); while(it != sessions.end()) { auto s = *it; if(s->gotHeaders() && s->isRedirect()) { auto location = s->getHeader("Location"); if(!startsWith(location, "http://")) { location = format("http://%s:%d%s", s->getHost(), s->getPort(), urlencode(location, ":\\?;+ ")); } LOGD("Redirecting to '%s'", location); auto callback = s->getCallback(); it = sessions.erase(it); auto s = make_shared<HttpSession>(location); sessions.push_back(s); s->connect(); s->stream(callback); it = sessions.end(); continue; } if(s->error()) { errorCallback(0, ""); } if(s->done()) { it = sessions.erase(it); LOGD("Session done"); } else it++; } }
byte* buildAuthRequest(std::string username, int &byteLen,std::string APIKEY, std::string SECRETKEY) { std::string timeStamp = getODataUTCDateFilter(); std::string params; params.append("apiKey"); params.append(APIKEY); params.append("timeStamp"); params.append(timeStamp); params.append("user"); params.append(username); params.append("version1.5"); unsigned char hmac_digest[20]; memset(hmac_digest, 0, 20); CHMAC_SHA1 hmac_sha1; hmac_sha1.HMAC_SHA1((unsigned char *)params.c_str(),params.length(), (unsigned char *)SECRETKEY.c_str(), SECRETKEY.length(),hmac_digest); std::string hmac = urlencode(base64_encode(hmac_digest, 20)); cJSON *payloadJSON; payloadJSON = cJSON_CreateObject(); cJSON_AddStringToObject(payloadJSON,"apiKey", APIKEY.c_str()); cJSON_AddStringToObject(payloadJSON,"version", "1.5"); cJSON_AddStringToObject(payloadJSON,"timeStamp", timeStamp.c_str()); cJSON_AddStringToObject(payloadJSON,"user", username.c_str()); cJSON_AddStringToObject(payloadJSON,"signature", hmac.c_str()); cJSON_AddNumberToObject(payloadJSON, "keepalive", WARP_KEEP_ALIVE_TIME_INTERVAL);//recoverytime cJSON_AddNumberToObject(payloadJSON, "recoverytime", RECOVERY_ALLOWANCE_TIME); char* cRet = cJSON_PrintUnformatted(payloadJSON); std::string payload = cRet; free(cRet); cJSON_Delete(payloadJSON); return buildWarpRequest(RequestType::auth, payload, byteLen); }
void session_interface::set_session_cookie(int64_t age,string const &data,string const &key) { if(data.empty()) age=-1; string cookie_name=worker.app.config.sval("session.cookies_prefix","cppcms_session"); if(!key.empty()) { cookie_name+="_"; cookie_name+=key; } if(age < 0) { cookie cook(cookie_name,"","", worker.app.config.sval("session.cookies_domain",""), 0, worker.app.config.sval("session.cookies_path","/"), worker.app.config.ival("session.cookies_secure",0)); cook.remove(); ostringstream out; out<<cook; worker.add_header(out.str()); } else { cgicc::HTTPCookie cook( cookie_name, // name (age >= 0 ? urlencode(data) : ""), // value "", // comment worker.app.config.sval("session.cookies_domain",""), // domain ( age < 0 ? 0 : age ), worker.app.config.sval("session.cookies_path","/"), worker.app.config.ival("session.cookies_secure",0)); worker.set_cookie(cook); } }
// @todo use Collection::getQueryString string Curl::createQueryString(const list<rcp::Parameter*>& queryParams) { string qs; list<rcp::Parameter*>::const_iterator it = queryParams.begin(); while(it != queryParams.end()) { qs.append(urlencode((*it)->getName())); qs.append("="); qs.append(urlencode((*it)->getStringValue())); ++it; if(it != queryParams.end()) { qs.append("&"); } } return qs; }
/*++ * \fn OAuth::buildOAuthRawDataKeyValPairs * * \brief this method prepares key-value pairs from the data part of the URL * or from the URL post fields data, as required by OAuth header * and signature generation. * * \param rawData - Raw data either from the URL itself or from post fields. * Should already be url encoded. * urlencodeData - If true, string will be urlencoded before converting * to key value pairs. * * \return rawDataKeyValuePairs - Map in which key-value pairs are populated * * @remarks: internal method * *--*/ std::map<std::string, std::string> OAuth::buildOAuthRawDataKeyValPairs( const std::string& rawData, bool urlencodeData ) { std::map<std::string, std::string> rawDataKeyValuePairs; /* Raw data if it's present. Data should already be urlencoded once */ if( rawData.length() ) { size_t nSep = std::string::npos; size_t nPos = std::string::npos; std::string dataKeyVal; std::string dataKey; std::string dataVal; /* This raw data part can contain many key value pairs: key1=value1&key2=value2&key3=value3 */ std::string dataPart = rawData; while( std::string::npos != ( nSep = dataPart.find_first_of("&") ) ) { /* Extract first key=value pair */ dataKeyVal = dataPart.substr( 0, nSep ); /* Split them */ nPos = dataKeyVal.find_first_of( "=" ); if( std::string::npos != nPos ) { dataKey = dataKeyVal.substr( 0, nPos ); dataVal = dataKeyVal.substr( nPos + 1 ); /* Put this key=value pair in map */ rawDataKeyValuePairs[dataKey] = urlencodeData ? urlencode( dataVal ) : dataVal; } dataPart = dataPart.substr( nSep + 1 ); } /* For the last key=value */ dataKeyVal = dataPart.substr( 0, nSep ); /* Split them */ nPos = dataKeyVal.find_first_of( "=" ); if( std::string::npos != nPos ) { dataKey = dataKeyVal.substr( 0, nPos ); dataVal = dataKeyVal.substr( nPos + 1 ); /* Put this key=value pair in map */ rawDataKeyValuePairs[dataKey] = urlencodeData ? urlencode( dataVal ) : dataVal; } } return rawDataKeyValuePairs; }
static char *wget_urlencode_strcpy(char *dest, const char *src) { int len = strlen(src); int d_len; d_len = urlencode_len(src, len); urlencode(src, len, dest, &d_len); return dest + d_len; }
bool CurlProcess::add_GET_parameter( const std::string& key, const std::string& value ) { if ( key.size() > 0 ) { _GET_data[key] = urlencode(value); return true; } else { return false; } }
static QByteArray encodePostData(const QMap<QByteArray, QByteArray>& params) { QByteArray data; QMap<QByteArray, QByteArray>::const_iterator it = params.begin(); QMap<QByteArray, QByteArray>::const_iterator ie = params.end(); for (; it != ie; ++it) { data.append(urlencode(it.key())); data.append('='); data.append(urlencode(it.value())); data.append('&'); } if (!data.isEmpty()) { data.resize(data.length() - 1); } return data; }
void Recaptcha::check_impl() { std::string challenge = value_text(challenge_field_).toUTF8(); std::string response = value_text(response_field_).toUTF8(); const std::string& remoteip = wApp->environment().clientAddress(); Http::Message m; m.setHeader("Content-Type", "application/x-www-form-urlencoded"); m.addBodyText("privatekey=" + private_key_ + "&"); m.addBodyText("remoteip=" + remoteip + "&"); m.addBodyText("challenge=" + urlencode(challenge) + "&"); m.addBodyText("response=" + urlencode(response) + "&"); #ifdef WT_WITH_SSL std::string schema = "https"; #else std::string schema = "http"; #endif if (!http_->post(schema + "://www.google.com/recaptcha/api/verify", m)) { mistake(tr("wc.captcha.Internal_error")); } }
/*++ * @method: oAuth::getOAuthHeader * * @description: this method builds OAuth header that should be used in HTTP requests to twitter * * @input: eType - HTTP request type * rawUrl - raw url of the HTTP request * rawData - HTTP data * includeOAuthVerifierPin - flag to indicate whether or not oauth_verifier needs to included * in OAuth header * * @output: oAuthHttpHeader - OAuth header * *--*/ bool oAuth::getOAuthHeader( const eOAuthHttpRequestType eType, const std::string& rawUrl, const std::string& rawData, std::string& oAuthHttpHeader, const bool includeOAuthVerifierPin ) { oAuthKeyValuePairs rawKeyValuePairs; std::string rawParams( "" ); std::string oauthSignature( "" ); std::string paramsSeperator( "" ); std::string pureUrl( rawUrl ); /* Clear header string initially */ oAuthHttpHeader.assign( "" ); rawKeyValuePairs.clear(); /* If URL itself contains ?key=value, then extract and put them in map */ size_t nPos = rawUrl.find_first_of( "?" ); if( std::string::npos != nPos ) { /* Get only URL */ pureUrl = rawUrl.substr( 0, nPos ); /* Get only key=value data part */ std::string dataPart = rawUrl.substr( nPos + 1 ); size_t nPos2 = dataPart.find_first_of( "=" ); if( std::string::npos != nPos2 ) { std::string dataKey = dataPart.substr( 0, nPos2 ); std::string dataVal = dataPart.substr( nPos2 + 1 ); /* Put this key=value pair in map */ rawKeyValuePairs[dataKey] = urlencode( dataVal ); } } /* Build key-value pairs needed for OAuth request token, without signature */ buildOAuthTokenKeyValuePairs( includeOAuthVerifierPin, rawData, std::string( "" ), rawKeyValuePairs ); /* Get url encoded base64 signature using request type, url and parameters */ getSignature( eType, pureUrl, rawKeyValuePairs, oauthSignature ); /* Now, again build key-value pairs with signature this time */ buildOAuthTokenKeyValuePairs( includeOAuthVerifierPin, std::string( "" ), oauthSignature, rawKeyValuePairs ); /* Get OAuth header in string format */ paramsSeperator = ","; getStringFromOAuthKeyValuePairs( rawKeyValuePairs, rawParams, paramsSeperator ); /* Build authorization header */ oAuthHttpHeader.assign( oAuthLibDefaults::OAUTHLIB_AUTHHEADER_STRING.c_str() ); oAuthHttpHeader.append( rawParams.c_str() ); return ( oAuthHttpHeader.length() > 0 ) ? true : false; }
std::string Gaem::getErrorPost() { std::stringstream ss, s2, s3; s2 << _exception.getLine(); std::map<std::string, std::string> params; params["message"] = _exception.getMessage(); params["file"] = _exception.getFilename(); params["line"] = s2.str(); params["user"] = _user->getUsername(); for ( std::map<std::string, std::string>::iterator iter = params.begin(); iter != params.end(); ++iter ) { ss << urlencode((*iter).first); ss << "="; ss << urlencode((*iter).second); ss << "&"; } return ss.str(); }
bool CurlProcess::add_POST_parameter( const std::string& key, const std::string& value ) { if ( key.size() > 0 ) { _POST_data[key] = urlencode(value); curl_easy_setopt( _curl, CURLOPT_POST, 1 ); return true; } else { return false; } }
/* * URL: ^F*D&S^s~09d * ENC: %5EF%2AD%26S%5Es%7E09d * DH.org: %5EF%2AD%26S%5Es%7E09d * * For details, see http://hn.org/hnRFC10.txt */ int main(void) { char url[] = "^F*D&S^s~09d"; char buf[3 * sizeof(url)]; printf("URL : %s\n", url); printf("ENC : %s\n", urlencode(url, strlen(url))); printf("ENC2 : %s\n", urlencode2(url, buf, sizeof(buf))); printf("DH.org: %%5EF%%2AD%%26S%%5Es%%7E09d\n"); return 0; }
static int altlog_writexfer_w3c(const int upload, const char * const filename, const off_t size, const double duration) { /* * <date> <time> <ip> "[]sent" <file> "226" <user> * date time c-ip cs-method cs-uri-stem sc-status cs-username */ struct tm *tm; struct tm gmt; const char *host_ = *host != 0 ? host : "-"; const char *account_ = *account != 0 ? account : "-"; char *alloca_line; char *quoted_filename; time_t now; size_t line_size; (void) duration; if ((now = time(NULL)) == (time_t) -1 || (tm = localtime(&now)) == NULL || tm->tm_mon > 11 || tm->tm_mon < 0) { return -1; } gmt = *gmtime(&now); if ((quoted_filename = urlencode(filename)) == NULL) { return -1; } line_size = (sizeof "13-04-1975 12:34:56 " - 1U) + strlen(host_) + 1U + (sizeof "[]created" - 1U) + 1U + strlen(quoted_filename) + 1U + (sizeof "226" - 1U) + strlen(account_) + 1U + 42U + 1U /* \n */ + 1U; if ((alloca_line = ALLOCA(line_size)) == NULL) { return -1; } if (!SNCHECK(snprintf(alloca_line, line_size, "%d-%02d-%02d %02d:%02d:%02d %s []%s %s 226 %s %llu\n", gmt.tm_year + 1900, gmt.tm_mon + 1, gmt.tm_mday, gmt.tm_hour, gmt.tm_min, gmt.tm_sec, host_, (upload != 0 ? "created" : "sent"), quoted_filename, account, (unsigned long long) size), line_size)) { altlog_write(alloca_line); } if (quoted_filename != filename) { free(quoted_filename); } ALLOCA_FREE(alloca_line); return 0; }
void sendAnnounce(std::string action, const std::vector<std::string> & clients_names, double uptime, u32 game_time, float lag, std::string gameid, std::vector<ModSpec> mods) { Json::Value server; if (action.size()) server["action"] = action; server["port"] = g_settings->get("port"); server["address"] = g_settings->get("server_address"); if (action != "delete") { server["name"] = g_settings->get("server_name"); server["description"] = g_settings->get("server_description"); server["version"] = minetest_version_simple; server["url"] = g_settings->get("server_url"); server["creative"] = g_settings->get("creative_mode"); server["damage"] = g_settings->get("enable_damage"); server["password"] = g_settings->getBool("disallow_empty_password"); server["pvp"] = g_settings->getBool("enable_pvp"); server["clients"] = (int)clients_names.size(); server["clients_max"] = g_settings->get("max_users"); server["clients_list"] = Json::Value(Json::arrayValue); for(u32 i = 0; i < clients_names.size(); ++i) { server["clients_list"].append(clients_names[i]); } if (uptime >= 1) server["uptime"] = (int)uptime; if (gameid != "") server["gameid"] = gameid; if (game_time >= 1) server["game_time"] = game_time; } if(server["action"] == "start") { server["dedicated"] = g_settings->get("server_dedicated"); server["privs"] = g_settings->get("default_privs"); server["rollback"] = g_settings->getBool("enable_rollback_recording"); server["liquid_finite"] = g_settings->getBool("liquid_finite"); server["mapgen"] = g_settings->get("mg_name"); server["can_see_far_names"] = g_settings->getBool("unlimited_player_transfer_distance"); server["mods"] = Json::Value(Json::arrayValue); for(std::vector<ModSpec>::iterator m = mods.begin(); m != mods.end(); m++) { server["mods"].append(m->name); } actionstream << "announcing to " << g_settings->get("serverlist_url") << std::endl; } else { if (lag) server["lag"] = lag; } Json::FastWriter writer; HTTPFetchRequest fetchrequest; fetchrequest.url = g_settings->get("serverlist_url") + std::string("/announce"); std::string query = std::string("json=") + urlencode(writer.write(server)); if (query.size() < 1000) fetchrequest.url += "?" + query; else fetchrequest.post_fields = query; httpfetch_async(fetchrequest); }
/** * Set the requesting entity. * @param This the object-like instance. * @param reqEntity the requesting entity */ void cltTransaction_t_setReqRequestingEntity(cltTransaction_t *This, char *reqEntity) { char reqEntityEnc[MAX_BUF_SIZE_B]; char authHeaderValue[MAX_BUF_SIZE_B]; memset(reqEntityEnc, 0, MAX_BUF_SIZE_B); memset(authHeaderValue, 0, MAX_BUF_SIZE_B); urlencode(reqEntity, reqEntityEnc); reqEntityEnc[strlen(reqEntityEnc)] = ':'; sprintf(authHeaderValue, "Basic "); rtl_base64_encode(authHeaderValue + 6 /* "Basic " */, reqEntityEnc, strlen(reqEntityEnc)); This->addReqHeader(This, HEADER_AUTHORIZATION, authHeaderValue); }
void HttpSession::sendRequest(const string &path, const string &host) { string req = utils::format("GET %s HTTP/1.1\r\nHost: %s\r\n\r\n", urlencode(path, "&#()!*[]:;\\;+'\" "), host); LOGD("REQ %p:\n%s", this, req); LOGD("%d", impl->data.size()); impl->c.write(req); impl->state = CONNECT; asio::async_read_until(impl->c.getSocket(), impl->data, "\r\n\r\n", [=](const asio::error_code &e, size_t n) { //LOGD("Read %d bytes", n); parseHeader(); impl->state = HEADERS; //if(impl->code == 200) readContent(); //else // impl->state = ERROR; }); }
void procdodir(struct connstruct *cn) { struct dirent *dp; char buf[MAXREQUESTLENGTH]; char encbuf[1024]; char *file; do { buf[0] = 0; if ((dp = readdir(cn->dirp)) == NULL) { snprintf(buf, sizeof(buf), "</body></html>\n"); special_write(cn, buf, strlen(buf)); removeconnection(cn); closedir(cn->dirp); return; } file = dp->d_name; /* if no index file, don't display the ".." directory */ if (cn->filereq[0] == '/' && cn->filereq[1] == '\0' && strcmp(file, "..") == 0) continue; /* don't display files beginning with "." */ if (file[0] == '.' && file[1] != '.') continue; /* make sure a '/' is at the end of a directory */ if (cn->filereq[strlen(cn->filereq) - 1] != '/') strcat(cn->filereq, "/"); /* see if the dir + file is another directory */ snprintf(buf, sizeof(buf), "%s%s", cn->actualfile, file); if (isdir(buf)) strcat(file, "/"); urlencode((uint8_t *)file, encbuf); snprintf(buf, sizeof(buf), "<a href=\"%s%s\">%s</a><br />\n", cn->filereq, encbuf, file); } while (special_write(cn, buf, strlen(buf))); }
void make_spy_header(char *hostname,short port, char *buf,char *logbook) { char *url_enc = urlencode(logbook); bzero(buf,sizeof(buf)); strncpy(buf,GETREQ,sizeof(GETREQ)); sprintf(buf + strlen(buf), "%s/",url_enc); sprintf(buf + strlen(buf), "%s",GETREQCMD); strcat (buf, HTTPVER); sprintf(buf + strlen(buf), "Host: %s:%d\r\n", hostname,port); sprintf(buf + strlen(buf), "User-Agent: ELOG\r\n"); sprintf(buf + strlen(buf), "Accept-Language: en-us,en;q=0.5\r\n"); sprintf(buf + strlen(buf), "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n"); sprintf(buf + strlen(buf), "Accept-Encoding: gzip,deflate\r\n"); sprintf(buf + strlen(buf), "Keep-Alive: 300\r\n"); sprintf(buf + strlen(buf), "Connection: keep-alive\r\n"); sprintf(buf + strlen(buf), "Authorization: Basic %s\r\n\r\n",encuserandpass); }
static int persist_load_torrent(FILE *fp) { ot_hash hash; ot_peerlist peer_list; #ifdef _DEBUG_PERSIST char log_buf[512]; #endif /* _DEBUG_PERSIST */ /* load torrent hash */ if (fread(&hash, sizeof(ot_hash), 1, fp) != 1) goto rerr; #ifdef _DEBUG_PERSIST if (urlencode((const char *)&hash, sizeof(ot_hash), log_buf, 512) <= 0) { LOG_ERR("urlencode failed\n"); assert(0); } LOG_ERR("%s\n", log_buf); #endif /* _DEBUG_PERSIST */ /* * load peer_list data: * * struct ot_peerlist { * ot_time base; * size_t seed_count; * size_t peer_count; * size_t down_count; * ot_vector peers; * } * */ if (fread(&peer_list.base, sizeof(ot_time), 1, fp) != 1) goto rerr; if (fread(&peer_list.seed_count, sizeof(size_t), 1, fp) != 1) goto rerr; if (fread(&peer_list.peer_count, sizeof(size_t), 1, fp) != 1) goto rerr; if (fread(&peer_list.down_count, sizeof(size_t), 1, fp) != 1) goto rerr; if (persist_load_peers(fp, &hash, &peer_list) < 0) goto rerr; return 0; rerr: LOG_ERR("%s\n", strerror(errno)); return -1; }