void DisplayStage(char s, char *msg, int error) { char *p; char buf[MAXLEN]; if(msg!=NULL && *msg!=0) { if(error) snprintf(DeferMSG,MAXLEN,"<font color=red>错误:%s</font>",msg); else snprintf(DeferMSG,MAXLEN,"信息:%s",msg); } p = user_agent(); if ( (s<'0') || (s>'2') ) s='0'; if( HtmlHeadOut==0 ) { HtmlHead(); } if( p && (strstr(p,"Mobile")) ) { #ifdef DEBUG snprintf(buf,MAXLEN,"/var/www/html/mstage%c.1.html",s); #else snprintf(buf,MAXLEN,"/var/www/html/mstage%c.html",s); #endif } else { #ifdef DEBUG snprintf(buf,MAXLEN,"/var/www/html/stage%c.1.html",s); #else snprintf(buf,MAXLEN,"/var/www/html/stage%c.html",s); #endif } PrintFile(buf); if ( mysql ) mysql_close(mysql); exit(0); }
/* * requests_get_headers - Performs GET request (same as above) but allows * custom headers. * * Returns the CURLcode return code provided from curl_easy_perform. CURLE_OK * is returned on success. * * @curl: libcurl handle * @req: request struct * @url: url to send request to * @custom_hdrv: char* array of custom headers * @custom_hdrc: length of `custom_hdrv` */ CURLcode requests_get_headers(CURL *curl, req_t *req, char *url, char **custom_hdrv, int custom_hdrc) { CURLcode rc; struct curl_slist *slist = NULL; char *ua = user_agent(); req->url = url; long code; /* headers */ if (custom_hdrv != NULL) { rc = process_custom_headers(&slist, req, custom_hdrv, custom_hdrc); if (rc != CURLE_OK) return rc; curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist); } common_opt(curl, req); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, resp_callback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, req); curl_easy_setopt(curl, CURLOPT_USERAGENT, ua); rc = curl_easy_perform(curl); if (rc != CURLE_OK) return rc; curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code); req->code = code; if (slist != NULL) curl_slist_free_all(slist); req->ok = check_ok(code); curl_easy_cleanup(curl); free(ua); return rc; }
static void x_SetupUserAgent(SConnNetInfo* net_info) { CNcbiApplication* theApp = CNcbiApplication::Instance(); if (theApp) { string user_agent("User-Agent: "); user_agent += theApp->GetProgramDisplayName(); ConnNetInfo_ExtendUserHeader(net_info, user_agent.c_str()); } }
/* * requests_pt - Performs POST or PUT request using supplied data and populates * req struct text member with request response, code with response code, and * size with size of response. To submit no data, use NULL for data, and 0 for * data_size. * * Returns CURLcode provided from curl_easy_perform. CURLE_OK is returned on * success. -1 returned if there are issues with libcurl's internal linked list * append. * * Typically this function isn't used directly, use requests_post() or * requests_put() instead. * * @curl: libcurl handle * @req: request struct * @url: url to send request to * @data: url encoded data to send in request body * @custom_hdrv: char* array of custom headers * @custom_hdrc: length of `custom_hdrv` * @put_flag: if not zero, sends PUT request, otherwise uses POST */ static CURLcode requests_pt(CURL *curl, req_t *req, char *url, char *data, char **custom_hdrv, int custom_hdrc, int put_flag) { CURLcode rc; struct curl_slist *slist = NULL; req->url = url; /* body data */ if (data != NULL) { curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data); } else { /* content length header defaults to -1, which causes request to fail sometimes, so we need to manually set it to 0 */ char *cl_header = "Content-Length: 0"; slist = curl_slist_append(slist, cl_header); if (slist == NULL) return -1; if (custom_hdrv == NULL) curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist); hdrv_append(&req->req_hdrv, &req->req_hdrc, cl_header); } /* headers */ if (custom_hdrv != NULL) { rc = process_custom_headers(&slist, req, custom_hdrv, custom_hdrc); if (rc != CURLE_OK) return rc; curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist); } common_opt(curl, req); if (put_flag) /* use custom request instead of dedicated PUT, because dedicated PUT doesn't work with arbitrary request body data */ curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); else curl_easy_setopt(curl, CURLOPT_POST, 1); char *ua = user_agent(); curl_easy_setopt(curl, CURLOPT_USERAGENT, ua); rc = curl_easy_perform(curl); if (rc != CURLE_OK) return rc; long code; curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code); req->code = code; req->ok = check_ok(code); if (slist != NULL) curl_slist_free_all(slist); free(ua); curl_easy_cleanup(curl); return rc; }
int post_url(char *path) { int result; HttpClient http(client); http.setHttpWaitForDataDelay(200); http.setHttpResponseTimeout(HTTP_TIMEOUT); http.beginRequest(); log("POST ", path); wdog.feed(); result = handle_response(http.post(acsettings.servername, acsettings.port, path, user_agent()), http); http.stop(); log(result); return result; }
/* * requests_get - Performs GET request and populates req struct text member * with request response, code with response code, and size with size of * response. * * Returns the CURLcode return code provided from curl_easy_perform. CURLE_OK * is returned on success. * * @curl: libcurl handle * @req: request struct * @url: url to send request to */ CURLcode requests_get(CURL *curl, req_t *req, char *url) { CURLcode rc; char *ua = user_agent(); req->url = url; long code; common_opt(curl, req); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, resp_callback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, req); curl_easy_setopt(curl, CURLOPT_USERAGENT, ua); rc = curl_easy_perform(curl); if (rc != CURLE_OK) return rc; curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code); req->code = code; req->ok = check_ok(code); curl_easy_cleanup(curl); free(ua); return rc; }
static int winhttp_connect( winhttp_subtransport *t) { wchar_t *wide_host; int32_t port; wchar_t *wide_ua; git_buf ua = GIT_BUF_INIT; int error = -1; int default_timeout = TIMEOUT_INFINITE; int default_connect_timeout = DEFAULT_CONNECT_TIMEOUT; t->session = NULL; t->connection = NULL; /* Prepare port */ if (git__strtol32(&port, t->connection_data.port, NULL, 10) < 0) return -1; /* Prepare host */ if (git__utf8_to_16_alloc(&wide_host, t->connection_data.host) < 0) { giterr_set(GITERR_OS, "unable to convert host to wide characters"); return -1; } if ((error = user_agent(&ua)) < 0) { git__free(wide_host); return error; } if (git__utf8_to_16_alloc(&wide_ua, git_buf_cstr(&ua)) < 0) { giterr_set(GITERR_OS, "unable to convert host to wide characters"); git__free(wide_host); git_buf_free(&ua); return -1; } git_buf_free(&ua); /* Establish session */ t->session = WinHttpOpen( wide_ua, WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0); if (!t->session) { giterr_set(GITERR_OS, "failed to init WinHTTP"); goto on_error; } if (!WinHttpSetTimeouts(t->session, default_timeout, default_connect_timeout, default_timeout, default_timeout)) { giterr_set(GITERR_OS, "failed to set timeouts for WinHTTP"); goto on_error; } /* Establish connection */ t->connection = WinHttpConnect( t->session, wide_host, (INTERNET_PORT) port, 0); if (!t->connection) { giterr_set(GITERR_OS, "failed to connect to host"); goto on_error; } if (WinHttpSetStatusCallback(t->connection, winhttp_status, WINHTTP_CALLBACK_FLAG_SECURE_FAILURE, 0) == WINHTTP_INVALID_STATUS_CALLBACK) { giterr_set(GITERR_OS, "failed to set status callback"); goto on_error; } error = 0; on_error: if (error < 0) winhttp_close_connection(t); git__free(wide_host); git__free(wide_ua); return error; }