void append_char(string *s, char c) { if(s->buf) { s->buf[s->i++]=c; } else { *s=init_string(); append_char(s, c); } char *nbuf=s->buf; if(s->i>=s->l) { if(s->i) s->l=s->i*2; else s->l=80; nbuf=(char *)realloc(s->buf, s->l); } if(nbuf) { s->buf=nbuf; s->buf[s->i]=0; } else { free(s->buf); *s=init_string(); } }
/** First information such as permissions is gathered for each directory entry. * All entries are then sorted. */ static struct directory_entry * get_smb_directory_entries(int dir, struct string *prefix) { struct directory_entry *entries = NULL; int size = 0; struct smbc_dirent *entry; while ((entry = smbc_readdir(dir))) { struct stat st, *stp; struct directory_entry *new_entries; struct string attrib; struct string name; if (!strcmp(entry->name, ".")) continue; new_entries = mem_realloc(entries, (size + 2) * sizeof(*new_entries)); if (!new_entries) continue; entries = new_entries; if (!init_string(&attrib)) { continue; } if (!init_string(&name)) { done_string(&attrib); continue; } add_string_to_string(&name, prefix); add_to_string(&name, entry->name); stp = (smbc_stat(name.source, &st)) ? NULL : &st; stat_type(&attrib, stp); stat_mode(&attrib, stp); stat_links(&attrib, stp); stat_user(&attrib, stp); stat_group(&attrib, stp); stat_size(&attrib, stp); stat_date(&attrib, stp); entries[size].name = stracpy(entry->name); entries[size].attrib = attrib.source; done_string(&name); size++; } smbc_closedir(dir); if (!size) { /* We may have allocated space for entries but added none. */ mem_free_if(entries); return NULL; } qsort(entries, size, sizeof(*entries), compare_dir_entries); memset(&entries[size], 0, sizeof(*entries)); return entries; }
void init_twins (char *dev_A, char *log_A, char *dev_B, char *log_B) { static log_s LogA; static log_s LogB; init_log( &LogA, log_A, dev_A); init_log( &LogB, log_B, dev_B); init_string( &TreeA, &LogA); init_string( &TreeB, &LogB); blazy(TreeA.t_dev); }
int poll_read(int fd, char* readbuf, uint8_t bytes_num){ int pollret; char tmpstring[100]; init_string(tmpstring); read_pollfd.fd = fd; read_pollfd.events = POLLIN; pollret = poll(&read_pollfd, 1, 10000); if ((pollret == 1)&&(read_pollfd.revents == POLLIN)){ read(fd, readbuf, bytes_num); //printf("%s ", readbuf);//debug only if ((readbuf[0] != '+')&&(readbuf[0] != 'A')) return 0; // successful while(strstr(readbuf, "\r\n\r\n") == NULL){ strcat(tmpstring, readbuf); if (strstr(tmpstring, "\r\n\r\n") != NULL) { strcpy(readbuf, tmpstring); break; } read(fd, readbuf, bytes_num); } strcat(tmpstring, readbuf); strcpy(readbuf, tmpstring); return 0; } return -1;// something wrong }
int ATZ(int fd) //wifi模块重启 { char cmdbuf[100]="AT+Z\r"; char readbuf[100]; char tmp[50]; int pollret; wflag = write(fd, cmdbuf, strlen((char*)cmdbuf)); usleep(10000); pollret = poll_read(fd, readbuf, 50); if (pollret == -1) return -1;//something must be wrong //read(fd,readbuf,50); //printf("1 %d\n", strlen((char *)readbuf)); strncpy(tmp, (char *)readbuf, (strlen((char *)readbuf))); //printf("1 %d\n", strlen(tmp)); //printf("2 %d\n", strlen(para)); printf("ATZ%s\n", tmp); init_string(readbuf); return 0; if(wflag > 0) { //printf("%d\n", strlen((char*)cmdbuf)); printf("WIFI SET: %s\n",cmdbuf); } //usleep(7000000);//手册说明重启需要6s }
static unsigned char * get_auth_entry_info(struct listbox_item *item, struct terminal *term) { struct auth_entry *auth_entry = (struct auth_entry *)item->udata; struct string info; if (item->type == BI_FOLDER) return NULL; if (!init_string(&info)) return NULL; add_format_to_string(&info, "%s: ", _("URL", term)); add_uri_to_string(&info, auth_entry->uri, URI_HTTP_AUTH); add_format_to_string(&info, "\n%s: ", _("Realm", term)); if (auth_entry->realm) { int len = strlen((const char *)auth_entry->realm); int maxlen = 512; /* Max. number of chars displayed for realm. */ if (len < maxlen) add_bytes_to_string(&info, auth_entry->realm, len); else { add_bytes_to_string(&info, auth_entry->realm, maxlen); add_to_string(&info, (const unsigned char *)"..."); } } else { add_to_string(&info, _("none", term)); } add_format_to_string(&info, "\n%s: %s\n", _("State", term), auth_entry->valid ? _("valid", term) : _("invalid", term)); return info.source; }
void run() { Performance p; printf("Allocating buffers\n"); text_buf = alloc_shared_buffer<char> (LENGTH_OF_TEXT, &text_c); pattern_buf= alloc_shared_buffer<char> (LENGTH_OF_PATTERN, &pattern_c); result_buf= alloc_shared_buffer<char> (1, &result_c); result_c[0] = 0; init_string( text_c, pattern_c ); printf("Initializing kernels\n"); size_t task_dim = 1; clKernelSet kernel_set (device, context, program); // kernel_set.addKernel ("text_processor", 1, &task_dim, text_buf, LENGTH_OF_TEXT); // kernel_set.addKernel ("word_processor", 1, &task_dim); kernel_set.addKernel ("word_processor", 1, &task_dim, text_buf, LENGTH_OF_TEXT); kernel_set.addKernel ("matching", 1, &task_dim, pattern_buf, LENGTH_OF_PATTERN, result_buf); printf("Launching the kernel...\n"); p.start(); kernel_set.launch(); printf(" start waiting.... \n"); kernel_set.finish(); p.stop(); printf(" done Execution (OpenCL Channel) time = (%u,%u), result = %d\n", p.report_sec(), p.report_usec(),result_c[0]); test_in_cpu( text_c, pattern_c ); return; }
struct string ip_address() { CURL *curl; CURLcode response; struct string url_data; curl = curl_easy_init(); if (curl) { init_string(&url_data); curl_easy_setopt(curl, CURLOPT_URL, my_ip_url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, callback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &url_data); response = curl_easy_perform(curl); if (response != CURLE_OK) { printf("something went wrong with curl..."); exit(EXIT_FAILURE); } curl_easy_cleanup(curl); } return url_data; }
int main (int argc, char *argv[]) { char *dev_name = ".btree"; #if DEVELOPMENT debugon(); fdebugon(); #else debugoff(); fdebugoff(); #endif FN; if (argc > 1) { dev_name = argv[1]; } #if DEVELOPMENT unlink(dev); /* Development only */ #endif binit(20); Dev = bopen(dev_name); if (!Dev) eprintf("Couldn't open %s:", dev_name); blazy(Dev); init_string(Dev); init_shell(quit_callback); init_cmd(); return shell(); }
char* request_post(char* user_agent, char* url, char* post) // Based on an example from curl.haxx.se { char* response = "value"; CURL *curl; CURLcode res; curl = curl_easy_init(); if(curl) { struct string s; init_string(&s); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); curl_easy_setopt(curl, CURLOPT_USERAGENT, user_agent); curl_easy_setopt(curl, CURLOPT_POST, 1); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); res = curl_easy_perform(curl); if(res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); else { response = s.ptr; free(s.ptr); } curl_easy_cleanup(curl); } return response; }
static int set_python_search_path(void) { struct string new_python_path; unsigned char *old_python_path; int result = -1; if (!init_string(&new_python_path)) return result; if (elinks_home && !add_format_to_string(&new_python_path, "%s%c", elinks_home, DELIM)) goto end; if (!add_to_string(&new_python_path, CONFDIR)) goto end; old_python_path = (unsigned char *) getenv("PYTHONPATH"); if (old_python_path && !add_format_to_string(&new_python_path, "%c%s", DELIM, old_python_path)) goto end; result = env_set("PYTHONPATH", new_python_path.source, -1); end: done_string(&new_python_path); return result; }
int query(const char* query, char* received_data) { int result = SEND_SUCCESS; struct string response_message; if (!check_URL(query)) { return 0; } if (!prepare_query(query)) { return 0; } init_string(&response_message); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_write); curl_easy_setopt(curl, CURLOPT_WRITEDATA, response_message); CURLcode response = curl_easy_perform(curl); if (response != CURLE_OK) { result = SEND_FAILED; const char *error_msg = curl_easy_strerror(response); log_error("query(const char*, char*) %s", error_msg); } received_data = (char*) realloc (received_data, response_message.len); received_data = response_message.ptr; curl_easy_reset(curl); return result; }
static struct uri * proxy_uri(struct uri *uri, unsigned char *proxy, struct connection_state *error_state) { struct string string; if (init_string(&string) && string_concat(&string, "proxy://", proxy, "/", (unsigned char *) NULL) && add_uri_to_string(&string, uri, URI_BASE)) { /* There is no need to use URI_BASE when calling get_uri() * because URI_BASE should not add any fragments in the first * place. */ uri = get_uri(string.source, 0); /* XXX: Assume the problem is due to @proxy having bad format. * This is a lot faster easier than checking the format. */ if (!uri) *error_state = connection_state(S_PROXY_ERROR); } else { uri = NULL; *error_state = connection_state(S_OUT_OF_MEM); } done_string(&string); return uri; }
int main(){ String s; char* str; init_string( &s ); copy_str( s, "Hello world..." ); print_string( s ); putchar( '\n' ); concat_str( s, " my name is Blur." ); print_string( s ); putchar( '\n' ); copy_str( s, "Hi" ); print_string( s ); putchar( '\n' ); printf( "Is it equal to hi? %d\n", compare_str( s, "hi" ) ); printf( "Is it equal to Hi? %d\n", compare_str( s, "Hi" ) ); printf( "Is it equal to hello? %d\n", compare_str( s, "hello" ) ); printf( "Is it equal to Hello? %d\n", compare_str( s, "Hello" ) ); str = to_c_str( s ); printf( "%s\n", str ); free( str ); clear_string( &s ); return 0; }
char* query(char *json, char *service){ CURL *curl; CURLcode res; struct curl_slist *hl = NULL; struct string s; curl = curl_easy_init(); init_string(&s); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, service); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json); hl = curl_slist_append(hl, "Content-type: CONTENT_TYPE"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, hl); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); res = curl_easy_perform(curl); if(res != 0){ mexErrMsgTxt(curl_easy_strerror(res)); } curl_easy_cleanup(curl); curl_slist_free_all (hl); } return s.ptr; }
LH_HttpResponse* http_execute_request(const char* url, LH_Dict* headers, uint8_t method, const char* request_body) { CURL *curl = curl_easy_init(); if (curl) { CURLcode res; LH_List* keys_of_headers = lh_dict_get_keys(headers); struct string s; init_string(&s); int j; struct curl_slist *header_list = NULL; for (j = 0; j < headers->size; j++) { char* header_key = lh_list_get(keys_of_headers, j); char* header_value = (char*) lh_dict_get(headers, header_key); uint16_t header_len = strlen(header_key) + strlen(header_value) + 3; // +3 because we will add ": " and the null terminating byte. char* header_text = malloc(header_len * sizeof header_text); header_text[0] = 0; strcat(header_text, header_key); strcat(header_text, ": "); strcat(header_text, header_value); header_list = curl_slist_append(header_list, header_text); free(header_text); } lh_list_free(keys_of_headers); curl_easy_setopt(curl, CURLOPT_URL, url); if (method == PERFORM_POST) { curl_easy_setopt(curl, CURLOPT_POST, 1); if (request_body != NULL) curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request_body); } if (method == PERFORM_PUT) { curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); if (request_body != NULL) curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request_body); } curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header_list); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); res = curl_easy_perform(curl); if (res != CURLE_OK) { char* message_template = "Request to url %s failed. CURLcode %d."; char* message = malloc((strlen(url) + strlen(message_template) + 15) * sizeof message); sprintf(message, message_template, url, res); log_error(message); free(message); } long http_response_code_long; uint16_t* http_response_code = malloc(sizeof http_response_code); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_response_code_long); *http_response_code = (uint16_t) http_response_code_long; LH_HttpResponse* response = malloc(sizeof *response); response->http_code = http_response_code; response->response_body = s.ptr; curl_slist_free_all(header_list); curl_easy_cleanup(curl); return response; } return NULL; }
/* TODO: Store cookie in data arg. --jonas*/ void accept_cookie_dialog(struct session *ses, void *data) { /* [gettext_accelerator_context(accept_cookie_dialog)] */ struct cookie *cookie = (struct cookie *)cookie_queries.next; struct string string; assert(ses); if (list_empty(cookie_queries) || !init_string(&string)) return; del_from_list(cookie); add_format_to_string(&string, (const char *)_("Do you want to accept a cookie from %s?", ses->tab->term), cookie->server->host); add_to_string(&string, (const unsigned char *)"\n\n"); add_cookie_info_to_string(&string, cookie, ses->tab->term); msg_box(ses->tab->term, NULL, MSGBOX_FREE_TEXT, N_("Accept cookie?"), ALIGN_LEFT, string.source, cookie, 2, MSG_BOX_BUTTON(N_("~Accept"), accept_cookie_in_msg_box, B_ENTER), MSG_BOX_BUTTON(N_("~Reject"), reject_cookie_in_msg_box, B_ESC)); }
datum_t uuid_out(PG_FUNC_ARGS) { pg_uuid_t *uuid = ARG_UUID_P(0); static const char hex_chars[] = "0123456789abcdef"; struct string buf; int i; init_string(&buf); for (i = 0; i < UUID_LEN; i++) { int hi; int lo; /* * We print uuid values as a string of 8, 4, 4, 4, and then 12 * hexadecimal characters, with each group is separated by a * hyphen ("-"). Therefore, add the hyphens at the appropriate * places here. */ if (i == 4 || i == 6 || i == 8 || i == 10) append_cstring(&buf, '-'); hi = uuid->data[i] >> 4; lo = uuid->data[i] & 0x0F; append_cstring(&buf, hex_chars[hi]); append_cstring(&buf, hex_chars[lo]); } RET_CSTRING(buf.data); }
unsigned char *get_auth_entry_info( struct listbox_item *item, struct terminal *term ) { int eax; int ecx; int edx; struct string info; if ( item->type != BI_FOLDER && init_string( &info ) ) { add_format_to_string( &info, "%s: " ); add_uri_to_string( &info, &item->udata[3], URI_HTTP_AUTH ); add_format_to_string( &info, "\n%s: " ); if ( item->udata[4] ) { if ( strlen( &item->udata[4] ) <= 511 ) add_bytes_to_string__( &info, &item->udata[4], strlen( &item->udata[4] ) ); else { add_bytes_to_string__( &info, &item->udata[4], 512 ); add_to_string( &info, "..." ); } } else { add_to_string( &info, _( "none", term ) ); } add_format_to_string( &info, "\n%s: %s\n" ); return info.source; } else { } }
static void error_reporter(JSContext *ctx, const char *message, JSErrorReport *report) { unsigned char *strict, *exception, *warning, *error; struct string msg; if (!init_string(&msg)) goto reported; strict = JSREPORT_IS_STRICT(report->flags) ? " strict" : ""; exception = JSREPORT_IS_EXCEPTION(report->flags) ? " exception" : ""; warning = JSREPORT_IS_WARNING(report->flags) ? " warning" : ""; error = !report->flags ? " error" : ""; add_format_to_string(&msg, "A client script raised the following%s%s%s%s", strict, exception, warning, error); add_to_string(&msg, ":\n\n"); add_to_string(&msg, message); if (report->linebuf && report->tokenptr) { int pos = report->tokenptr - report->linebuf; add_format_to_string(&msg, "\n\n%s\n.%*s^%*s.", report->linebuf, pos - 2, " ", strlen(report->linebuf) - pos - 1, " "); } alert_smjs_error(msg.source); done_string(&msg); reported: JS_ClearPendingException(ctx); }
unsigned char * get_ssl_connection_cipher(struct socket *socket) { ssl_t *ssl = socket->ssl; struct string str; if (!init_string(&str)) return NULL; #ifdef USE_OPENSSL add_format_to_string(&str, "%ld-bit %s %s", SSL_get_cipher_bits(ssl, NULL), SSL_get_cipher_version(ssl), SSL_get_cipher_name(ssl)); #elif defined(CONFIG_GNUTLS) /* XXX: How to get other relevant parameters? */ add_format_to_string(&str, "%s - %s - %s - %s - %s (compr: %s)", gnutls_protocol_get_name(gnutls_protocol_get_version(*ssl)), gnutls_kx_get_name(gnutls_kx_get(*ssl)), gnutls_cipher_get_name(gnutls_cipher_get(*ssl)), gnutls_mac_get_name(gnutls_mac_get(*ssl)), gnutls_certificate_type_get_name(gnutls_certificate_type_get(*ssl)), gnutls_compression_get_name(gnutls_compression_get(*ssl))); #endif return str.source; }
void report_scripting_error(struct module *module, struct session *ses, unsigned char *msg) { struct terminal *term; struct string string; if (!ses) { if (list_empty(terminals)) { usrerror("[%s error] %s", module->name, msg); return; } term = terminals.next; } else { term = ses->tab->term; } if (!init_string(&string)) return; add_format_to_string(&string, _("An error occurred while running a %s script", term), module->name); add_format_to_string(&string, ":\n\n%s", msg); info_box(term, MSGBOX_NO_TEXT_INTL | MSGBOX_FREE_TEXT, N_("Browser scripting error"), ALIGN_LEFT, string.source); }
int WMODE(int fd, char *para)//3 //wifi模块设置为STA模式 { char cmdbuf[100]="AT+WMODE"; //STA\r"; char ret = '\r'; //char ok[] = "+ok"; char readbuf[100]; char *pchar; int pollret; char *tmpstring; init_string(readbuf); wflag = write(fd, cmdbuf, strlen((char*)cmdbuf)); wflag = write(fd, &ret, 1); usleep(10000); pollret = poll_read(fd, readbuf, 50); if (pollret == -1) return -1;//something must be wrong //printf("readbuf lenth is %d \n",strlen(readbuf)); tmpstring = strchr(readbuf, '\r'); *tmpstring = '\0'; //printf("readbuf lenth is %d \n",strlen(readbuf)); printf("%s\n", readbuf); pchar = strstr((char *)readbuf, para); if (pchar != NULL) return 1; // network parameter unchanged init_string(readbuf); strcat(cmdbuf,"="); strcat(cmdbuf,para); strcat(cmdbuf,"\r"); wflag = write(fd, cmdbuf, strlen((char*)cmdbuf) + 1); usleep(10000); pollret = poll_read(fd, readbuf, 50); if (pollret == -1) return -1;//something must be wrong tmpstring = strchr(readbuf, '\r'); *tmpstring = '\0'; printf("%s\n", readbuf); //init_string(readbuf); return 0; /* pchar = strstr((char *)readbuf, ok); if (pchar != NULL){ printf("%s\n", ok); return 0; } if(wflag > 0) { printf("WIFI SET: %s\n",cmdbuf); } */ }
string email_receive_message (string& error) { #ifdef CLIENT_PREPARED error = "Not implemented with embedded http library"; return ""; #else CURL *curl; CURLcode res = CURLE_OK; struct cstring s; init_string (&s); curl = curl_easy_init (); curl_easy_setopt (curl, CURLOPT_USERNAME, Database_Config_General::getMailStorageUsername ().c_str()); curl_easy_setopt (curl, CURLOPT_PASSWORD, Database_Config_General::getMailStoragePassword ().c_str()); string message_url = url () + "/1"; curl_easy_setopt (curl, CURLOPT_URL, message_url.c_str()); curl_easy_setopt (curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL); curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0); curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 0); curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, writefunc); curl_easy_setopt (curl, CURLOPT_WRITEDATA, &s); // Some servers need this validation. curl_easy_setopt (curl, CURLOPT_USERAGENT, "libcurl-agent/1.0"); filter_url_curl_set_timeout (curl); res = curl_easy_perform (curl); string body; if (res == CURLE_OK) { body = (char *) s.ptr; } else { error = curl_easy_strerror (res); } // Set the DELE command. curl_easy_setopt (curl, CURLOPT_CUSTOMREQUEST, "DELE"); // Do not perform a transfer as DELE returns no data. curl_easy_setopt (curl, CURLOPT_NOBODY, 1L); // Perform the custom request. res = curl_easy_perform(curl); if (s.ptr) free (s.ptr); curl_easy_cleanup (curl); return body; #endif }
/* create error message */ char *pool_error_message(char *message) { String *str; str = init_string(""); string_append_char(str,message); return str->data; }
// Returns how many emails are waiting in the mail storage host's POP3 email inbox. int email_receive_count (string& error, bool verbose) { #ifdef CLIENT_PREPARED error = "Not implemented with embedded http library"; if (verbose) {} return 0; #else CURL *curl; CURLcode res = CURLE_OK; struct cstring s; init_string (&s); curl = curl_easy_init (); curl_easy_setopt (curl, CURLOPT_USERNAME, Database_Config_General::getMailStorageUsername ().c_str()); curl_easy_setopt (curl, CURLOPT_PASSWORD, Database_Config_General::getMailStoragePassword ().c_str()); curl_easy_setopt (curl, CURLOPT_URL, url ().c_str()); curl_easy_setopt (curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL); curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0); curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 0); curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, writefunc); curl_easy_setopt (curl, CURLOPT_WRITEDATA, &s); if (verbose) { curl_easy_setopt (curl, CURLOPT_DEBUGFUNCTION, filter_url_curl_debug_callback); curl_easy_setopt (curl, CURLOPT_VERBOSE, 1L); } // Some servers need this validation. curl_easy_setopt (curl, CURLOPT_USERAGENT, "libcurl-agent/1.0"); filter_url_curl_set_timeout (curl); res = curl_easy_perform (curl); int mailcount = 0; if (res == CURLE_OK) { string response = (char *) s.ptr; response = filter_string_trim (response); mailcount = filter_string_explode (response, '\n').size(); } else { error = curl_easy_strerror (res); } if (s.ptr) free (s.ptr); curl_easy_cleanup (curl); return mailcount; #endif }
int main (int argc, char *argv[]) { // debugoff(); debugon(); fdebugon(); FN; init_string(); init_shell(NULL); init_cmd(); return shell(); }
void HttpClient::SendMessage(const std::string& message, std::string& result) throw (JsonRpcException) { CURL* curl = curl_easy_init(); if (!curl) { throw JsonRpcException(Errors::ERROR_CLIENT_CONNECTOR, ": libcurl initialization error"); } curl_easy_setopt(curl, CURLOPT_URL, this->url.c_str()); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); CURLcode res; struct string s; init_string(&s); struct curl_slist * headers = NULL; //Maybe to restrictive //headers = curl_slist_append(headers, "Accept: application/json"); for (std::map<std::string, std::string>::iterator header = this->headers.begin(); header != this->headers.end(); ++header) { headers = curl_slist_append(headers, (header->first + ": " + header->second).c_str()); } headers = curl_slist_append(headers, "Content-Type: application/json"); headers = curl_slist_append(headers, "charsets: utf-8"); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, message.c_str()); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); res = curl_easy_perform(curl); result = s.ptr; free(s.ptr); curl_slist_free_all(headers); if (res != CURLE_OK) { stringstream str; if(res == 7) { str << ": Could not connect to " << this->url; } else { str << ": libcurl error: " << res; } throw JsonRpcException(Errors::ERROR_CLIENT_CONNECTOR, str.str()); } if (curl) { curl_easy_cleanup(curl); } }
static unsigned char * get_nntp_title(struct connection *conn) { struct nntp_connection_info *nntp = conn->info; struct string title; if (!init_string(&title)) return NULL; switch (nntp->target) { case NNTP_TARGET_ARTICLE_RANGE: add_format_to_string(&title, "Articles in the range %ld to %ld", nntp->current_article, nntp->end_article); break; case NNTP_TARGET_ARTICLE_NUMBER: case NNTP_TARGET_MESSAGE_ID: case NNTP_TARGET_GROUP_MESSAGE_ID: { unsigned char *subject; subject = parse_header(conn->cached->head, "Subject", NULL); if (subject) { add_to_string(&title, subject); mem_free(subject); break; } add_format_to_string(&title, "Article "), add_string_to_string(&title, &nntp->message); if (nntp->target == NNTP_TARGET_MESSAGE_ID) break; add_format_to_string(&title, " in "); add_string_to_string(&title, &nntp->group); break; } case NNTP_TARGET_GROUP: add_format_to_string(&title, "Articles in "), add_string_to_string(&title, &nntp->group); break; case NNTP_TARGET_GROUPS: add_format_to_string(&title, "Newsgroups on "), add_uri_to_string(&title, conn->uri, URI_PUBLIC); break; case NNTP_TARGET_QUIT: break; } return title.source; }
static unsigned char * str_rd(struct option *opt, unsigned char **file, int *line) { unsigned char *str = *file; struct string str2; if (!init_string(&str2)) return NULL; /* We're getting used in some parser functions in conf.c as well, and * that's w/ opt == NULL; so don't rely on opt to point anywhere. */ if (!commandline) { if (!isquote(*str)) { done_string(&str2); return NULL; } str++; } while (*str && (commandline || !isquote(*str))) { if (*str == '\\') { /* FIXME: This won't work on crlf systems. */ if (str[1] == '\n') { str[1] = ' '; str++; (*line)++; } /* When there's quote char, we will just move on there, * thus we will never test for it in while () condition * and we will treat it just as '"', ignoring the * backslash itself. */ else if (isquote(str[1])) str++; /* \\ means \. */ else if (str[1] == '\\') str++; } if (*str == '\n') (*line)++; add_char_to_string(&str2, *str); str++; } if (!commandline && !*str) { done_string(&str2); *file = str; return NULL; } str++; /* Skip the quote. */ if (!commandline) *file = str; if (opt && opt->max && str2.length >= opt->max) { done_string(&str2); return NULL; } return str2.source; }