[TD-3113] <fix>: remove curl from TDengine. cleanup.
This commit is contained in:
parent
d88c2970bd
commit
3eaaf27dc9
|
@ -1508,156 +1508,6 @@ static void printfQuerySystemInfo(TAOS * taos) {
|
|||
|
||||
}
|
||||
|
||||
|
||||
#ifdef TD_LOWA_CURL
|
||||
#if 0
|
||||
static size_t responseCallback(void *contents, size_t size, size_t nmemb, void *userp)
|
||||
{
|
||||
size_t realsize = size * nmemb;
|
||||
curlMemInfo* mem = (curlMemInfo*)userp;
|
||||
|
||||
char *ptr = realloc(mem->buf, mem->sizeleft + realsize + 1);
|
||||
if(ptr == NULL) {
|
||||
/* out of memory! */
|
||||
printf("not enough memory (realloc returned NULL)\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
mem->buf = ptr;
|
||||
memcpy(&(mem->buf[mem->sizeleft]), contents, realsize);
|
||||
mem->sizeleft += realsize;
|
||||
mem->buf[mem->sizeleft] = 0;
|
||||
|
||||
//printf("result:%s\n\n", mem->buf);
|
||||
|
||||
return realsize;
|
||||
}
|
||||
|
||||
void curlProceLogin(void)
|
||||
{
|
||||
CURL *curl_handle;
|
||||
CURLcode res;
|
||||
|
||||
curlMemInfo chunk;
|
||||
|
||||
chunk.buf = malloc(1); /* will be grown as needed by the realloc above */
|
||||
chunk.sizeleft = 0; /* no data at this point */
|
||||
|
||||
//curl_global_init(CURL_GLOBAL_ALL);
|
||||
|
||||
/* init the curl session */
|
||||
curl_handle = curl_easy_init();
|
||||
|
||||
curl_easy_setopt(curl_handle,CURLOPT_POSTFIELDS,"");
|
||||
curl_easy_setopt(curl_handle, CURLOPT_POST, 1);
|
||||
|
||||
char dstUrl[128] = {0};
|
||||
snprintf(dstUrl, 128, "http://%s:6041/rest/login/root/taosdata", g_Dbs.host);
|
||||
|
||||
/* specify URL to get */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_URL, dstUrl);
|
||||
|
||||
/* send all data to this function */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, responseCallback);
|
||||
|
||||
/* we pass our 'chunk' struct to the callback function */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
|
||||
|
||||
/* do it! */
|
||||
res = curl_easy_perform(curl_handle);
|
||||
|
||||
/* check for errors */
|
||||
if(res != CURLE_OK) {
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
|
||||
}
|
||||
else {
|
||||
//printf("response len:%lu, content: %s \n", (unsigned long)chunk.sizeleft, chunk.buf);
|
||||
;
|
||||
}
|
||||
|
||||
/* cleanup curl stuff */
|
||||
curl_easy_cleanup(curl_handle);
|
||||
|
||||
free(chunk.buf);
|
||||
|
||||
/* we're done with libcurl, so clean it up */
|
||||
//curl_global_cleanup();
|
||||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
int curlProceSql(char* host, uint16_t port, char* sqlstr, CURL *curl_handle)
|
||||
{
|
||||
//curlProceLogin();
|
||||
|
||||
//CURL *curl_handle;
|
||||
CURLcode res;
|
||||
|
||||
curlMemInfo chunk;
|
||||
|
||||
chunk.buf = malloc(1); /* will be grown as needed by the realloc above */
|
||||
chunk.sizeleft = 0; /* no data at this point */
|
||||
|
||||
|
||||
char dstUrl[128] = {0};
|
||||
snprintf(dstUrl, 128, "http://%s:%u/rest/sql", host, port+TSDB_PORT_HTTP);
|
||||
|
||||
//curl_global_init(CURL_GLOBAL_ALL);
|
||||
|
||||
/* init the curl session */
|
||||
//curl_handle = curl_easy_init();
|
||||
|
||||
//curl_easy_setopt(curl_handle,CURLOPT_POSTFIELDS,"");
|
||||
curl_easy_setopt(curl_handle, CURLOPT_POST, 1L);
|
||||
|
||||
/* specify URL to get */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_URL, dstUrl);
|
||||
|
||||
/* enable TCP keep-alive for this transfer */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_TCP_KEEPALIVE, 1L);
|
||||
/* keep-alive idle time to 120 seconds */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_TCP_KEEPIDLE, 120L);
|
||||
/* interval time between keep-alive probes: 60 seconds */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_TCP_KEEPINTVL, 60L);
|
||||
|
||||
/* send all data to this function */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, responseCallback);
|
||||
|
||||
/* we pass our 'chunk' struct to the callback function */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
|
||||
|
||||
struct curl_slist *list = NULL;
|
||||
list = curl_slist_append(list, "Authorization: Basic cm9vdDp0YW9zZGF0YQ==");
|
||||
curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, list);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, list);
|
||||
|
||||
/* Set the expected upload size. */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)strlen(sqlstr));
|
||||
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, sqlstr);
|
||||
|
||||
/* get it! */
|
||||
res = curl_easy_perform(curl_handle);
|
||||
|
||||
/* check for errors */
|
||||
if(res != CURLE_OK) {
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
/* curl_easy_perform() block end and return result */
|
||||
//printf("[%32.32s] sql response len:%lu, content: %s \n\n", sqlstr, (unsigned long)chunk.sizeleft, chunk.buf);
|
||||
;
|
||||
}
|
||||
|
||||
curl_slist_free_all(list); /* free the list again */
|
||||
|
||||
free(chunk.buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define REQ_EXTRA_BUF_LEN 1024
|
||||
#define RESP_BUF_LEN 4096
|
||||
|
||||
|
|
Loading…
Reference in New Issue