Revision 2d0a8d58

View differences:

ALTOclient/ALTOclient.c
293 293
       libCURL-based POST code
294 294
  ==================================*/
295 295

  
296
// libcurl is now obsolete!
297 296
#ifdef USE_CURL
298 297

  
299 298
// this function will be registered with curl as a handler, which
......
324 323
	curl = curl_easy_init();
325 324
	assertCheck(curl, "Couldn't get a handle from curl_easy_init(). abort.");
326 325

  
327
//	printf("Will send HTTP POST to %s\nwith form data:\n\n%s\n", alto_server_url, ALTO_XML_query);
326
	//printf("Will send HTTP POST to %s\nwith form data:\n\n%s\n", alto_server_url, ALTO_XML_query);
328 327

  
329 328
	// prepare the buffer to be send
330 329
	xmlChar*  doctxt;
331 330
	int       doclen;
332 331
	xmlDocDumpFormatMemoryEnc(doc,&doctxt,&doclen,"utf-8",1);
333 332

  
333
	#ifdef USE_DEBUG_OUTPUT
334
	printf(stderr, "[ALTOclientCURL] Will send HTTP POST to %s\nwith XML data:\n\n%s\n", alto_server_url, doctxt);
335
	#endif
336

  
334 337
	// URL that receives this POST
335 338
	curl_easy_setopt(curl, CURLOPT_URL, ALTO_server_URL);
339
//	curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1);
340
//	curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 1);
341
	curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
336 342

  
337 343
	// add form data
338 344
	curl_formadd(&formpost,
339 345
				 &lastptr,
340 346
				 CURLFORM_COPYNAME, "alto_xml_request",
341 347
//				 CURLFORM_COPYCONTENTS, ALTO_XML_query,
342
				 CURLFORM_COPYCONTENTS, doctxt,
348
				 CURLFORM_COPYCONTENTS, doctxt,		// PTRCONTENTS?
343 349
				 CURLFORM_END);
344 350

  
345 351
	curl_formadd(&formpost,
......
364 370
	// then cleanup the form post chain
365 371
	curl_formfree(formpost);
366 372

  
367
//  printf("result of curl_easy_perform() is: %i\n", res);
368
//  printf("received %i octetts. the buffer is:\n\n%s\nthat's all. bye.\n",alto_rep_buf.fill,alto_rep_buf.buffer);
373
	#ifdef USE_DEBUG_OUTPUT
374
	//printf("result of curl_easy_perform() is: %i\n", res);
375
	fprintf(stderr, "[ALTOclientCURL] received %i octets. the buffer is:\n\n%s\nthat's all. bye.\n", alto_rep_buf.fill, alto_rep_buf.buffer);
376
	#endif
369 377

  
370 378

  
371 379
	// and last but nor least, transform it into an XML doc
372
	ALTO_XML_response = xmlRecoverMemory(alto_rep_buf.buffer,sizeof(alto_rep_buf.buffer));		// <- for getting XML from memory
380
	ALTO_XML_response = xmlRecoverMemory(alto_rep_buf.buffer, sizeof(alto_rep_buf.buffer));		// <- for getting XML from memory
373 381

  
374 382
	return ALTO_XML_response;
375 383
}
......
1104 1112
	// prepare the XML environment
1105 1113
	LIBXML_TEST_VERSION;
1106 1114

  
1115
#ifdef USE_CURL
1116
	// prepare CURL
1117
	// ---------------------------------------------------------------------------------
1118
	// XXX: NOTE:
1119
	// "This function is NOT THREAD SAFE. You must not call it when any other thread 
1120
	// in the program (i.e. a thread sharing the same memory) is running. This doesn't 
1121
	// just mean no other thread that is using libcurl. Because curl_global_init() calls 
1122
	// functions of other libraries that are similarly thread unsafe, it could conflict 
1123
	// with any other thread that uses these other libraries."
1124
	// ---------------------------------------------------------------------------------
1125

  
1126
	curl_global_init(CURL_GLOBAL_ALL);
1127
#endif
1128

  
1107 1129
	// and Initialize the XMLs
1108 1130
    ALTO_XML_req = NULL;
1109 1131
    ALTO_XML_res = NULL;
1110

  
1111

  
1112 1132
}
1113 1133

  
1114 1134

  
......
1127 1147
    if (ALTO_XML_res) { xmlFreeDoc(ALTO_XML_res); ALTO_XML_res = NULL; }
1128 1148

  
1129 1149
	xmlCleanupParser();
1150

  
1151
#ifdef USE_CURL
1152
	// shutdown  libCurl
1153
	// XXX: NOTE: same thread un-safety warning applies!
1154
	curl_global_cleanup();
1155
#endif
1130 1156
}
1131 1157

  
1132 1158

  
ALTOclient/Makefile
5 5
LDFLAGS += -L$(XMLLIB)
6 6
LDLIBS += -lxml2 -lpthread
7 7

  
8
# libcurl is now obsolete
9
#LDLIBS += -lcurl
8
ifdef CURL
9
LDLIBS += -lcurl
10
CPPFLAGS += -DUSE_CURL
11
endif
10 12

  
11 13
all: main lib
12 14

  

Also available in: Unified diff