I am using asterisk version 13.5.0. In utils directory, I created a new module called curl_util with source code as below:
#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;
}
In chan_sip.c, I call above mentioned httpRequestPost function. Executing make and make install are OK. But, when starting dahdi and asterisk, I got the following error:
Error loading module chan_sip.so: undefined symbol: httpRequestPost
loader.c: module chan_sip.so could not be loaded.
Could you please give hints or advices to fix this error? Thank you in advance.