我正在使用星號13.5.0。在utils的目錄,我創建稱爲curl_util與如下源代碼一個新的模塊:httpRequestPostcurl_easy_getinfo undefined symbol error
#include "asterisk/curl_utils.h"
HttpResponse * httpResponseNew()
{
HttpResponse * response = calloc(1, sizeof(HttpResponse));
return response;
error:
return NULL;
}
HttpResponse * httpRequestPost(char *url, char *post_body, size_t size)
{
struct MemoryStruct chunk;
CURL *curl = curl_easy_init();
chunk.memory = malloc(1);
chunk.size = 0;
HttpResponse *response = httpResponseNew();
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 0);
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_body);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, size);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HttpResponseMemoryWriter);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
response->res = curl_easy_perform(curl);
if (response->res != CURLE_OK)
{
response->OK = 0;
}
else
{
response->OK = 1;
response->size = chunk.size;
response->body = chunk.memory;
}
curl_easy_cleanup(curl);
return response;
error:
free(chunk.memory);
if (curl) curl_easy_cleanup(curl);
return response;
}
在chan_sip.c,我調用上述功能。 執行make並進行安裝即可。 但是,開始DAHDI和星號的時候,我得到了以下錯誤:
錯誤加載模塊chan_sip.so:未定義的符號:httpRequestPost
loader.c:模塊chan_sip.so無法加載。
您能否提供提示或建議來解決此錯誤? 預先感謝您。
也許它與模塊加載順序有關?請參閱[本書](http://www.asteriskdocs.org/en/3rd_Edition/asterisk-book-html-chunk/additional_configuration_tasks-modules-conf-file.html)獲取加載訂單信息 – QuickDanger
謝謝。對於我的情況,我猜想curl_util沒有鏈接make文件來構建它,儘管在Makefile中,curl_util的路徑已經包含了。所以,我試着將上面的源代碼移動到chan_sip.c,然後錯誤消失了。但是,我收到另一個錯誤:加載模塊chan_sip.so時出錯:未定義符號:curl_easy_getinfo。 loader.c:模塊chan_sip.so無法加載。 – Aloha
我不知道星號是否有一個函數可以解析類似於上述函數httpRequestPost()的URL中的xml內容。有人知道嗎? – Aloha