Example #1
0
static void *ctw_exec(void *thread_args) {
	struct _ctw *common = thread_args; 

	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, 0);
	common->easy_handle = curl_easy_init();
	common->multi_handle = curl_multi_init();
	if (common->easy_handle == NULL) {
		MYERROR("Cannot init curl.");
	} else {
		struct curl_slist *slist = NULL;
		struct _memory_struct out_memory;
		struct _memory_struct in_memory;
		FILE *fp; 
		fp = ctw_prepare(common, slist, &out_memory, &in_memory);
		ctw_thread_perform(common);
		ctw_output(common, &out_memory, fp);
		string_free(common->complete_url, &common->complete_url_len);
		string_free(common->parameters, &common->parameters_len);
		if (slist != NULL) {
			curl_slist_free_all(slist);
		}
		if (fp) {
			fclose(fp);
		}

	}
	common->locked = 0;
	return NULL;
}
Example #2
0
static void *rest_get_auth_token(void *const thread_args) {
	t_rest *const rest = thread_args;

	/* length + name=&password=*/
	rest->common.parameters = string_create(&rest->common.parameters_len, 
			rest->cookie.username_len + rest->cookie.password_len + 17);
	if (rest->common.parameters != NULL) {
		strcpy(rest->common.parameters, "name=");
		strcat(rest->common.parameters, rest->cookie.username);
		strcat(rest->common.parameters, "&password="******"POST");

	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, 0);
	rest->common.easy_handle = curl_easy_init();
	rest->common.multi_handle = curl_multi_init();
	if (rest->common.easy_handle == NULL) {
		MYERROR("Cannot init curl.");
		ctw_cleanup_request(&rest->common, NULL, NULL);
	} else {
		struct curl_slist *slist = NULL;
		struct _memory_struct out_content;
		struct _memory_struct out_header;
		FILE *fp = ctw_prepare(&rest->common, slist, &out_content, NULL);

		out_header.memory = getbytes(1);
		out_header.size = 0;

		struct _cb_val *cb_val = getbytes(sizeof(struct _cb_val));
		cb_val->mem = &out_header;
		cb_val->ctw = (struct _ctw *)rest;
		curl_easy_setopt(rest->common.easy_handle, CURLOPT_HEADERFUNCTION, ctw_write_mem_cb);
		curl_easy_setopt(rest->common.easy_handle, CURLOPT_WRITEHEADER, (void *)cb_val);
		ctw_thread_perform(&rest->common);
		rest_process_auth_data(rest, &out_header);
		string_free(out_header.memory, &out_header.size);
		string_free(out_content.memory, &out_content.size);
		ctw_cleanup_request(&rest->common, fp, slist);
	}
	return NULL;
}