You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

314 lines
8.6 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo: fix memory leaks and heap corruption Continuous leaks: - protocolParser: on package-pool overflow the oldest package was removed but never freed while the newest (still pooled) one was freed. Every packet a handler does not consume (e.g. other sensors on a shared bus) leaked once the pool was full. Free the removed package, free pooled packages in the destructor and getPackage(), use memmove for the overlapping buffer shifts. - SQLite_Connector::Query: loop only while sqlite3_step() returns SQLITE_ROW. Looping until SQLITE_DONE spun forever allocating rows on SQLITE_BUSY/ERROR. Set a busy timeout, close handles after a failed open, fix escapeBinary() writing into uninitialised buffers. - basicThread/basicDualThread: threads that ended by themselves were never joined, leaking their stacks on every stream drop/restart. Always join once (detach when called from the thread itself); check pthread_create result correctly. - curlRequest: free the header list; initialise m_pPostData and the content type; curlRequestsManager deletes requests it cannot queue. - kernelModuleModemManager: free the phonebook ID list on every reload. - deviceNodeFactory: do not append the same pending node every cycle. - streamHandler: free frames left in the encoding queue on destruction. Heap corruption: - kernelModuleFactory: module that failed to start was deleted twice. - mojoRemoteClient: basicRing::push() returns an ID (may be 0), not a bool; compare with -1. Fix packetExtractor and destructor leaks. - utilizeBasicEvent: payloads are malloc'ed, release with free(). - videoAVLIBSource: avoid sws context double free, NULL check order. - trim(): memmove for overlapping copy. Smaller leaks: dropSession duplicate query, LRF upload data, report backupper / fly hunter settings, Kafka consumer handle, BVMS uniq ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
la_mojo: fix memory leaks and heap corruption Continuous leaks: - protocolParser: on package-pool overflow the oldest package was removed but never freed while the newest (still pooled) one was freed. Every packet a handler does not consume (e.g. other sensors on a shared bus) leaked once the pool was full. Free the removed package, free pooled packages in the destructor and getPackage(), use memmove for the overlapping buffer shifts. - SQLite_Connector::Query: loop only while sqlite3_step() returns SQLITE_ROW. Looping until SQLITE_DONE spun forever allocating rows on SQLITE_BUSY/ERROR. Set a busy timeout, close handles after a failed open, fix escapeBinary() writing into uninitialised buffers. - basicThread/basicDualThread: threads that ended by themselves were never joined, leaking their stacks on every stream drop/restart. Always join once (detach when called from the thread itself); check pthread_create result correctly. - curlRequest: free the header list; initialise m_pPostData and the content type; curlRequestsManager deletes requests it cannot queue. - kernelModuleModemManager: free the phonebook ID list on every reload. - deviceNodeFactory: do not append the same pending node every cycle. - streamHandler: free frames left in the encoding queue on destruction. Heap corruption: - kernelModuleFactory: module that failed to start was deleted twice. - mojoRemoteClient: basicRing::push() returns an ID (may be 0), not a bool; compare with -1. Fix packetExtractor and destructor leaks. - utilizeBasicEvent: payloads are malloc'ed, release with free(). - videoAVLIBSource: avoid sws context double free, NULL check order. - trim(): memmove for overlapping copy. Smaller leaks: dropSession duplicate query, LRF upload data, report backupper / fly hunter settings, Kafka consumer handle, BVMS uniq ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo: fix memory leaks and heap corruption Continuous leaks: - protocolParser: on package-pool overflow the oldest package was removed but never freed while the newest (still pooled) one was freed. Every packet a handler does not consume (e.g. other sensors on a shared bus) leaked once the pool was full. Free the removed package, free pooled packages in the destructor and getPackage(), use memmove for the overlapping buffer shifts. - SQLite_Connector::Query: loop only while sqlite3_step() returns SQLITE_ROW. Looping until SQLITE_DONE spun forever allocating rows on SQLITE_BUSY/ERROR. Set a busy timeout, close handles after a failed open, fix escapeBinary() writing into uninitialised buffers. - basicThread/basicDualThread: threads that ended by themselves were never joined, leaking their stacks on every stream drop/restart. Always join once (detach when called from the thread itself); check pthread_create result correctly. - curlRequest: free the header list; initialise m_pPostData and the content type; curlRequestsManager deletes requests it cannot queue. - kernelModuleModemManager: free the phonebook ID list on every reload. - deviceNodeFactory: do not append the same pending node every cycle. - streamHandler: free frames left in the encoding queue on destruction. Heap corruption: - kernelModuleFactory: module that failed to start was deleted twice. - mojoRemoteClient: basicRing::push() returns an ID (may be 0), not a bool; compare with -1. Fix packetExtractor and destructor leaks. - utilizeBasicEvent: payloads are malloc'ed, release with free(). - videoAVLIBSource: avoid sws context double free, NULL check order. - trim(): memmove for overlapping copy. Smaller leaks: dropSession duplicate query, LRF upload data, report backupper / fly hunter settings, Kafka consumer handle, BVMS uniq ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
la_mojo: fix memory leaks and heap corruption Continuous leaks: - protocolParser: on package-pool overflow the oldest package was removed but never freed while the newest (still pooled) one was freed. Every packet a handler does not consume (e.g. other sensors on a shared bus) leaked once the pool was full. Free the removed package, free pooled packages in the destructor and getPackage(), use memmove for the overlapping buffer shifts. - SQLite_Connector::Query: loop only while sqlite3_step() returns SQLITE_ROW. Looping until SQLITE_DONE spun forever allocating rows on SQLITE_BUSY/ERROR. Set a busy timeout, close handles after a failed open, fix escapeBinary() writing into uninitialised buffers. - basicThread/basicDualThread: threads that ended by themselves were never joined, leaking their stacks on every stream drop/restart. Always join once (detach when called from the thread itself); check pthread_create result correctly. - curlRequest: free the header list; initialise m_pPostData and the content type; curlRequestsManager deletes requests it cannot queue. - kernelModuleModemManager: free the phonebook ID list on every reload. - deviceNodeFactory: do not append the same pending node every cycle. - streamHandler: free frames left in the encoding queue on destruction. Heap corruption: - kernelModuleFactory: module that failed to start was deleted twice. - mojoRemoteClient: basicRing::push() returns an ID (may be 0), not a bool; compare with -1. Fix packetExtractor and destructor leaks. - utilizeBasicEvent: payloads are malloc'ed, release with free(). - videoAVLIBSource: avoid sws context double free, NULL check order. - trim(): memmove for overlapping copy. Smaller leaks: dropSession duplicate query, LRF upload data, report backupper / fly hunter settings, Kafka consumer handle, BVMS uniq ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
la_mojo: fix memory leaks and heap corruption Continuous leaks: - protocolParser: on package-pool overflow the oldest package was removed but never freed while the newest (still pooled) one was freed. Every packet a handler does not consume (e.g. other sensors on a shared bus) leaked once the pool was full. Free the removed package, free pooled packages in the destructor and getPackage(), use memmove for the overlapping buffer shifts. - SQLite_Connector::Query: loop only while sqlite3_step() returns SQLITE_ROW. Looping until SQLITE_DONE spun forever allocating rows on SQLITE_BUSY/ERROR. Set a busy timeout, close handles after a failed open, fix escapeBinary() writing into uninitialised buffers. - basicThread/basicDualThread: threads that ended by themselves were never joined, leaking their stacks on every stream drop/restart. Always join once (detach when called from the thread itself); check pthread_create result correctly. - curlRequest: free the header list; initialise m_pPostData and the content type; curlRequestsManager deletes requests it cannot queue. - kernelModuleModemManager: free the phonebook ID list on every reload. - deviceNodeFactory: do not append the same pending node every cycle. - streamHandler: free frames left in the encoding queue on destruction. Heap corruption: - kernelModuleFactory: module that failed to start was deleted twice. - mojoRemoteClient: basicRing::push() returns an ID (may be 0), not a bool; compare with -1. Fix packetExtractor and destructor leaks. - utilizeBasicEvent: payloads are malloc'ed, release with free(). - videoAVLIBSource: avoid sws context double free, NULL check order. - trim(): memmove for overlapping copy. Smaller leaks: dropSession duplicate query, LRF upload data, report backupper / fly hunter settings, Kafka consumer handle, BVMS uniq ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
7 years ago
​
​
​
la_mojo: fix memory leaks and heap corruption Continuous leaks: - protocolParser: on package-pool overflow the oldest package was removed but never freed while the newest (still pooled) one was freed. Every packet a handler does not consume (e.g. other sensors on a shared bus) leaked once the pool was full. Free the removed package, free pooled packages in the destructor and getPackage(), use memmove for the overlapping buffer shifts. - SQLite_Connector::Query: loop only while sqlite3_step() returns SQLITE_ROW. Looping until SQLITE_DONE spun forever allocating rows on SQLITE_BUSY/ERROR. Set a busy timeout, close handles after a failed open, fix escapeBinary() writing into uninitialised buffers. - basicThread/basicDualThread: threads that ended by themselves were never joined, leaking their stacks on every stream drop/restart. Always join once (detach when called from the thread itself); check pthread_create result correctly. - curlRequest: free the header list; initialise m_pPostData and the content type; curlRequestsManager deletes requests it cannot queue. - kernelModuleModemManager: free the phonebook ID list on every reload. - deviceNodeFactory: do not append the same pending node every cycle. - streamHandler: free frames left in the encoding queue on destruction. Heap corruption: - kernelModuleFactory: module that failed to start was deleted twice. - mojoRemoteClient: basicRing::push() returns an ID (may be 0), not a bool; compare with -1. Fix packetExtractor and destructor leaks. - utilizeBasicEvent: payloads are malloc'ed, release with free(). - videoAVLIBSource: avoid sws context double free, NULL check order. - trim(): memmove for overlapping copy. Smaller leaks: dropSession duplicate query, LRF upload data, report backupper / fly hunter settings, Kafka consumer handle, BVMS uniq ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo: fix memory leaks and heap corruption Continuous leaks: - protocolParser: on package-pool overflow the oldest package was removed but never freed while the newest (still pooled) one was freed. Every packet a handler does not consume (e.g. other sensors on a shared bus) leaked once the pool was full. Free the removed package, free pooled packages in the destructor and getPackage(), use memmove for the overlapping buffer shifts. - SQLite_Connector::Query: loop only while sqlite3_step() returns SQLITE_ROW. Looping until SQLITE_DONE spun forever allocating rows on SQLITE_BUSY/ERROR. Set a busy timeout, close handles after a failed open, fix escapeBinary() writing into uninitialised buffers. - basicThread/basicDualThread: threads that ended by themselves were never joined, leaking their stacks on every stream drop/restart. Always join once (detach when called from the thread itself); check pthread_create result correctly. - curlRequest: free the header list; initialise m_pPostData and the content type; curlRequestsManager deletes requests it cannot queue. - kernelModuleModemManager: free the phonebook ID list on every reload. - deviceNodeFactory: do not append the same pending node every cycle. - streamHandler: free frames left in the encoding queue on destruction. Heap corruption: - kernelModuleFactory: module that failed to start was deleted twice. - mojoRemoteClient: basicRing::push() returns an ID (may be 0), not a bool; compare with -1. Fix packetExtractor and destructor leaks. - utilizeBasicEvent: payloads are malloc'ed, release with free(). - videoAVLIBSource: avoid sws context double free, NULL check order. - trim(): memmove for overlapping copy. Smaller leaks: dropSession duplicate query, LRF upload data, report backupper / fly hunter settings, Kafka consumer handle, BVMS uniq ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo: fix memory leaks and heap corruption Continuous leaks: - protocolParser: on package-pool overflow the oldest package was removed but never freed while the newest (still pooled) one was freed. Every packet a handler does not consume (e.g. other sensors on a shared bus) leaked once the pool was full. Free the removed package, free pooled packages in the destructor and getPackage(), use memmove for the overlapping buffer shifts. - SQLite_Connector::Query: loop only while sqlite3_step() returns SQLITE_ROW. Looping until SQLITE_DONE spun forever allocating rows on SQLITE_BUSY/ERROR. Set a busy timeout, close handles after a failed open, fix escapeBinary() writing into uninitialised buffers. - basicThread/basicDualThread: threads that ended by themselves were never joined, leaking their stacks on every stream drop/restart. Always join once (detach when called from the thread itself); check pthread_create result correctly. - curlRequest: free the header list; initialise m_pPostData and the content type; curlRequestsManager deletes requests it cannot queue. - kernelModuleModemManager: free the phonebook ID list on every reload. - deviceNodeFactory: do not append the same pending node every cycle. - streamHandler: free frames left in the encoding queue on destruction. Heap corruption: - kernelModuleFactory: module that failed to start was deleted twice. - mojoRemoteClient: basicRing::push() returns an ID (may be 0), not a bool; compare with -1. Fix packetExtractor and destructor leaks. - utilizeBasicEvent: payloads are malloc'ed, release with free(). - videoAVLIBSource: avoid sws context double free, NULL check order. - trim(): memmove for overlapping copy. Smaller leaks: dropSession duplicate query, LRF upload data, report backupper / fly hunter settings, Kafka consumer handle, BVMS uniq ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
7 years ago
​
7 years ago
7 years ago
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
7 years ago
7 years ago
​
​
​
7 years ago
​
​
​
7 years ago
7 years ago
​
​
​
  1. #include "curlRequest.h"
  2. //#define DEBUG_EXTRA
  3. #define LOG(X) m_pLog->Log("curlRequest", this, X)
  4. #define LOG_ERROR(X) m_pLog->Log("curlRequest", this, _LOG_ERROR, X)
  5. // Thread Logging
  6. #define SLOG(X) basicLogCollection::getInstance()->Log("curlRequest_T", NULL, X)
  7. #define SLOG_ERROR(X) basicLogCollection::getInstance()->Log("curlRequest_T", NULL, _LOG_ERROR, X)
  8. curlRequest::curlRequest(CSTR URL, CSTR cntType)
  9. {
  10. m_pLog = basicLogCollection::getInstance();
  11. m_pCURL = NULL;
  12. m_pBaseObject = NULL;
  13. m_pBaseParam = NULL;
  14. m_pPostData = NULL;
  15. m_pSignalFunc = NULL;
  16. m_pMemoryBuffer = NULL;
  17. m_HeaderList = NULL;
  18. m_nMemorySize = 0;
  19. m_bRequestComplete = false;
  20. m_pURL = (CSTR) malloc(strlen(URL) + 1);
  21. m_cContentType[0] = (char) 0;
  22. if (cntType != NULL)
  23. {
  24. snprintf(m_cContentType, sizeof(m_cContentType), "Content-Type: %s", cntType);
  25. }
  26. if (m_pURL)
  27. {
  28. sprintf(m_pURL, "%s", URL);
  29. #ifdef DEBUG_EXTRA
  30. LOG(m_pURL);
  31. #endif
  32. init_CURL();
  33. };
  34. }
  35. curlRequest::curlRequest(CSTR Host, CSTR Path, CSTR cntType)
  36. {
  37. m_pLog = basicLogCollection::getInstance();
  38. m_pCURL = NULL;
  39. m_pBaseObject = NULL;
  40. m_pBaseParam = NULL;
  41. m_pSignalFunc = NULL;
  42. m_pPostData = NULL; // was uninitialised: destructor freed a garbage pointer
  43. m_pMemoryBuffer = NULL;
  44. m_HeaderList = NULL;
  45. m_nMemorySize = 0;
  46. m_bRequestComplete = false;
  47. m_cContentType[0] = (char) 0;
  48. if (cntType != NULL)
  49. {
  50. snprintf(m_cContentType, sizeof(m_cContentType), "Content-Type: %s", cntType);
  51. }
  52. m_pURL = (CSTR) malloc(strlen(Host) + 1 + strlen(Path));
  53. if (m_pURL)
  54. {
  55. sprintf(m_pURL, "%s%s", Host, Path);
  56. #ifdef DEBUG_EXTRA
  57. LOG(m_pURL);
  58. #endif
  59. init_CURL();
  60. };
  61. }
  62. curlRequest::~curlRequest()
  63. {
  64. #ifdef DEBUG
  65. #endif
  66. if (m_pCURL)
  67. {
  68. curl_easy_cleanup(m_pCURL);
  69. m_pCURL = NULL;
  70. }
  71. // The header list is not owned by the easy handle - it must be freed explicitly
  72. if (m_HeaderList)
  73. {
  74. curl_slist_free_all(m_HeaderList);
  75. m_HeaderList = NULL;
  76. }
  77. if (m_pURL)
  78. {
  79. free(m_pURL);
  80. }
  81. if (m_pPostData)
  82. {
  83. free(m_pPostData);
  84. }
  85. if (m_pMemoryBuffer)
  86. {
  87. free(m_pMemoryBuffer);
  88. }
  89. }
  90. #ifdef DEBUG_EXTRA
  91. int curlRequest::debug_callback(CURL * handle, curl_infotype type, char * data, size_t size, void * userptr)
  92. {
  93. FILE * tdFD = fopen("CURL_DEBUG.TXT", "ab+");
  94. if (tdFD)
  95. {
  96. switch (type)
  97. {
  98. case CURLINFO_TEXT: fprintf(tdFD, "== Info: %s\n", data); break;
  99. case CURLINFO_HEADER_IN:
  100. fprintf(tdFD, "<= Recpt header\n");
  101. fwrite(data, 1, size, tdFD);
  102. fprintf(tdFD, "\n");
  103. break;
  104. case CURLINFO_HEADER_OUT:
  105. fprintf(tdFD, "=> Send header\n");
  106. fwrite(data, 1, size, tdFD);
  107. fprintf(tdFD, "\n");
  108. break;
  109. case CURLINFO_DATA_IN:
  110. fprintf(tdFD, "<= Recpt Data\n");
  111. fwrite(data, 1, size, tdFD);
  112. fprintf(tdFD, "\n");
  113. break;
  114. case CURLINFO_DATA_OUT:
  115. fprintf(tdFD, "=> Send Data\n");
  116. fwrite(data, 1, size, tdFD);
  117. fprintf(tdFD, "\n");
  118. break;
  119. case CURLINFO_SSL_DATA_IN:
  120. fprintf(tdFD, "<= Recpt SSL Data\n");
  121. fwrite(data, 1, size, tdFD);
  122. fprintf(tdFD, "\n");
  123. break;
  124. case CURLINFO_SSL_DATA_OUT:
  125. fprintf(tdFD, "=> Send SSL Data\n");
  126. fwrite(data, 1, size, tdFD);
  127. fprintf(tdFD, "\n");
  128. break;
  129. case CURLINFO_END: fprintf(tdFD, "End\n~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); break;
  130. default : fprintf(tdFD, "~~~~~~~~~ UNKNOWN ~~~~~~~~~~~~\n%s\n", data);
  131. };
  132. fclose(tdFD);
  133. };
  134. return 0;
  135. }
  136. #endif
  137. void curlRequest::init_CURL()
  138. {
  139. m_pCURL = curl_easy_init();
  140. if (m_pCURL != NULL)
  141. {
  142. if (m_cContentType[0])
  143. {
  144. m_HeaderList = curl_slist_append(m_HeaderList, m_cContentType);
  145. }
  146. //m_HeaderList = curl_slist_append( m_HeaderList, "Connection: Keep-Alive" );
  147. m_HeaderList = curl_slist_append( m_HeaderList, "accept: application/json" );
  148. // m_HeaderList = curl_slist_append( m_HeaderList, "Connection: Close" );
  149. curl_easy_setopt(m_pCURL, CURLOPT_HTTPHEADER, m_HeaderList);
  150. curl_easy_setopt(m_pCURL, CURLOPT_CONNECTTIMEOUT, 20);
  151. curl_easy_setopt(m_pCURL, CURLOPT_TIMEOUT, 20);
  152. curl_easy_setopt(m_pCURL, CURLOPT_SSL_VERIFYPEER, 0);
  153. curl_easy_setopt(m_pCURL, CURLOPT_SSL_VERIFYHOST, 0);
  154. #ifdef DEBUG_EXTRA
  155. curl_easy_setopt(m_pCURL, CURLOPT_VERBOSE, 1);
  156. curl_easy_setopt(m_pCURL, CURLOPT_DEBUGFUNCTION, debug_callback);
  157. curl_easy_setopt(m_pCURL, CURLOPT_DEBUGDATA, this);
  158. #else
  159. curl_easy_setopt(m_pCURL, CURLOPT_VERBOSE, 0);
  160. #endif
  161. #ifdef __linux__
  162. #if LIBCURL_VERSION_NUM >= 0x073C00 // 7.60
  163. curl_easy_setopt(m_pCURL, CURLOPT_TCP_FASTOPEN, 1);
  164. curl_easy_setopt(m_pCURL, CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS, 0);
  165. #endif
  166. #endif
  167. curl_easy_setopt(m_pCURL, CURLOPT_NOPROGRESS, 1);
  168. curl_easy_setopt(m_pCURL, CURLOPT_TCP_NODELAY, 1);
  169. curl_easy_setopt(m_pCURL, CURLOPT_NOSIGNAL, 1);
  170. curl_easy_setopt(m_pCURL, CURLOPT_URL, m_pURL);
  171. curl_easy_setopt(m_pCURL, CURLOPT_WRITEFUNCTION, m_fWriteMemoryHandler);
  172. curl_easy_setopt(m_pCURL, CURLOPT_WRITEDATA, this);
  173. curl_easy_setopt(m_pCURL, CURLOPT_USERAGENT, "Mozilla/5.0 (PC; U; Intel; Linux; en) AppleWebKit/420+ (KHTML, like Gecko)");
  174. };
  175. }
  176. void curlRequest::setCredentials(CSTR user, CSTR password, uint8_t AuthMode){
  177. if (! strlen(user) || ! strlen(password)){
  178. return;
  179. }
  180. sprintf( m_cUserPassword, "%s:%s", user, password );
  181. curl_easy_setopt( m_pCURL, CURLOPT_USERPWD, m_cUserPassword);
  182. switch (AuthMode){
  183. case 1: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); break;
  184. case 2: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST_IE); break;
  185. case 3: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_BEARER ); break; //Does not works on 3D
  186. case 4: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_NEGOTIATE); break;
  187. case 5: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_NTLM); break;
  188. case 6: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_NTLM_WB); break;
  189. case 7: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_ANY); break;
  190. case 8: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE); break;
  191. case 9: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_ONLY); break;
  192. //case 10:curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_AWS_SIGV4 ); break;
  193. default:
  194. curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  195. };
  196. }
  197. static char * EmptyExpectConstant = (CSTR) "Expect:";
  198. static char * EmptyAcceptConstant = (CSTR) "Accept: */*";
  199. //static char * AcceptEncoding = (CSTR) "Accept-Encoding: gzip, deflate";
  200. void curlRequest::setPOST(CSTR postDATA, int size)
  201. {
  202. if (m_pCURL != NULL)
  203. {
  204. if (! postDATA)
  205. {
  206. #ifdef DEBUG
  207. LOG_ERROR("No Post Data Supplied In Post Request!");
  208. #endif
  209. return;
  210. };
  211. if (! size)
  212. {
  213. size = strlen(postDATA);
  214. }
  215. if (m_pPostData)
  216. {
  217. free(m_pPostData);
  218. }
  219. m_pPostData = (CSTR) malloc(size + 1);
  220. if (! m_pPostData)
  221. {
  222. LOG_ERROR("Memory Allocation Error!");
  223. return;
  224. };
  225. memcpy(m_pPostData, postDATA, size);
  226. m_pPostData[size] = (char) 0;
  227. sprintf(m_cContentLength, "Content-Length: %d", size);
  228. m_HeaderList = curl_slist_append(m_HeaderList, EmptyExpectConstant);
  229. m_HeaderList = curl_slist_append(m_HeaderList, EmptyAcceptConstant);
  230. // m_HeaderList = curl_slist_append( m_HeaderList, AcceptEncoding );
  231. m_HeaderList = curl_slist_append(m_HeaderList, m_cContentLength);
  232. curl_easy_setopt(m_pCURL, CURLOPT_HTTPHEADER, m_HeaderList);
  233. curl_easy_setopt(m_pCURL, CURLOPT_POST, 1);
  234. curl_easy_setopt(m_pCURL, CURLOPT_POSTFIELDS, m_pPostData);
  235. }
  236. else
  237. {
  238. LOG_ERROR("Wrong CURL handle!");
  239. }
  240. }
  241. void curlRequest::setHandler(void * baseObject, void * (*start_routine)(void *, void *), void * ptr)
  242. {
  243. #ifdef DEBUG_EXTRA
  244. LOG("Set Handler");
  245. #endif
  246. m_pBaseObject = baseObject;
  247. m_pSignalFunc = start_routine;
  248. m_pBaseParam = ptr;
  249. }
  250. BYTE * curlRequest::getBuffer(void)
  251. {
  252. return m_pMemoryBuffer;
  253. }
  254. size_t curlRequest::m_fWriteMemoryHandler(void * ptr, size_t nsize, size_t nmemb, void * data)
  255. {
  256. size_t realsize = nsize * nmemb;
  257. curlRequest * me = (curlRequest *) data;
  258. #ifdef DEBUG_EXTRA
  259. SLOG("*<-D");
  260. #endif
  261. BYTE * tMB = (BYTE *) realloc(me->m_pMemoryBuffer, me->m_nMemorySize + realsize + 1); // +1 to transfer String terminator
  262. if (tMB)
  263. {
  264. me->m_pMemoryBuffer = tMB;
  265. }
  266. else
  267. {
  268. // free(me->m_pMemoryBuffer);
  269. // me->m_pMemoryBuffer = NULL;
  270. // Well be Fried at destruction;
  271. SLOG_ERROR("Out Of Memory!");
  272. return -1;
  273. };
  274. memcpy(&(me->m_pMemoryBuffer[me->m_nMemorySize]), ptr, realsize);
  275. me->m_nMemorySize += realsize;
  276. me->m_pMemoryBuffer[me->m_nMemorySize] = 0;
  277. return realsize;
  278. }
  279. void curlRequest::issue(void)
  280. {
  281. if (m_pCURL)
  282. {
  283. m_bRequestComplete = true;
  284. if (m_pSignalFunc != NULL)
  285. {
  286. (*m_pSignalFunc)(m_pBaseObject, m_pBaseParam);
  287. }
  288. };
  289. }
  290. #undef LOG
  291. #undef LOG_ERROR
  292. #undef SLOG
  293. #undef SLOG_ERROR
  294. //#undef DEBUG_EXTRA