我使用星号13.5.0版本。在utils目录中,我创建了一个名为curl_util的新模块,其源代码如下:
#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中,我调用上面提到的httpRequestPost函数。执行make和make install是可以的。但是,当启动dahdi和星号时,我得到了以下错误:
加载模块chan_sip错误。http prequestpost
loader.c: module chan_sip. c因此无法加载
你能给点提示或建议来修复这个错误吗?
不需要编辑makefile。您只需要使用ASTLDFLAGS编译器选项,如:
./configure
make ASTLDFLAGS="-lcurl"
make install
make samples
make config
我通过以下操作修复了这个错误:
删除libcurl4-openssl-dev
从http://curl.haxx.se/下载CURL,解压缩,运行命令。/configure, make, make install
编辑星号的Makefile,为编译标记添加-lcurl