RTS API Documentation  1.10.11
Macros | Typedefs | Functions | Variables
switch_curl.h File Reference
#include <curl/curl.h>
+ Include dependency graph for switch_curl.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define HAVE_SWITCH_CURL_MIME
 
#define switch_curl_easy_setopt   curl_easy_setopt
 

Typedefs

typedef struct curl_slist switch_curl_slist_t
 
typedef int switch_CURLINFO
 
typedef int switch_CURLcode
 
typedef int switch_CURLoption
 
typedef void switch_curl_mime
 

Functions

switch_CURLswitch_curl_easy_init (void)
 
switch_CURLcode switch_curl_easy_perform (switch_CURL *handle)
 
switch_CURLcode switch_curl_easy_getinfo (switch_CURL *curl, switch_CURLINFO info,...)
 
void switch_curl_easy_cleanup (switch_CURL *handle)
 
switch_curl_slist_tswitch_curl_slist_append (switch_curl_slist_t *list, const char *string)
 
void switch_curl_slist_free_all (switch_curl_slist_t *list)
 
switch_CURLcode switch_curl_easy_setopt (CURL *handle, switch_CURLoption option,...)
 
const char * switch_curl_easy_strerror (switch_CURLcode errornum)
 
void switch_curl_init (void)
 
void switch_curl_destroy (void)
 
switch_status_t switch_curl_process_mime (switch_event_t *event, switch_CURL *curl_handle, switch_curl_mime **mimep)
 
void switch_curl_mime_free (switch_curl_mime **mimep)
 
switch_CURLcode switch_curl_easy_setopt_mime (switch_CURL *curl_handle, switch_curl_mime *mime)
 

Variables

SWITCH_BEGIN_EXTERN_C typedef void switch_CURL
 

Macro Definition Documentation

◆ HAVE_SWITCH_CURL_MIME

#define HAVE_SWITCH_CURL_MIME

Definition at line 43 of file switch_curl.h.

◆ switch_curl_easy_setopt

#define switch_curl_easy_setopt   curl_easy_setopt

Definition at line 59 of file switch_curl.h.

Typedef Documentation

◆ switch_curl_mime

typedef void switch_curl_mime

Definition at line 44 of file switch_curl.h.

◆ switch_curl_slist_t

typedef struct curl_slist switch_curl_slist_t

Definition at line 38 of file switch_curl.h.

◆ switch_CURLcode

typedef int switch_CURLcode

Definition at line 40 of file switch_curl.h.

◆ switch_CURLINFO

typedef int switch_CURLINFO

Definition at line 39 of file switch_curl.h.

◆ switch_CURLoption

typedef int switch_CURLoption

Definition at line 41 of file switch_curl.h.

Function Documentation

◆ switch_curl_destroy()

void switch_curl_destroy ( void  )

Definition at line 56 of file switch_curl.c.

Referenced by switch_core_destroy().

57 {
58  curl_global_cleanup();
59 }

◆ switch_curl_easy_cleanup()

void switch_curl_easy_cleanup ( switch_CURL handle)

Definition at line 28 of file switch_curl.c.

Referenced by xswitch_http_request().

29 {
30  curl_easy_cleanup((CURL *)handle);
31 }

◆ switch_curl_easy_getinfo()

switch_CURLcode switch_curl_easy_getinfo ( switch_CURL curl,
switch_CURLINFO  info,
  ... 
)

Definition at line 16 of file switch_curl.c.

Referenced by xswitch_http_request().

17 {
18  va_list ap;
19  switch_CURLcode code;
20 
21  va_start(ap, info);
22  code = curl_easy_getinfo(curl, info, va_arg(ap, void *));
23  va_end(ap);
24 
25  return code;
26 }
int switch_CURLcode
Definition: switch_curl.h:40

◆ switch_curl_easy_init()

switch_CURL* switch_curl_easy_init ( void  )

Definition at line 5 of file switch_curl.c.

Referenced by xswitch_http_request().

6 {
7  return curl_easy_init();
8 }

◆ switch_curl_easy_perform()

switch_CURLcode switch_curl_easy_perform ( switch_CURL handle)

Definition at line 10 of file switch_curl.c.

Referenced by xswitch_http_request().

11 {
12  return curl_easy_perform((CURL *)handle);
13 }

◆ switch_curl_easy_setopt()

switch_CURLcode switch_curl_easy_setopt ( CURL *  handle,
switch_CURLoption  option,
  ... 
)

Referenced by xswitch_http_request().

◆ switch_curl_easy_setopt_mime()

switch_CURLcode switch_curl_easy_setopt_mime ( switch_CURL curl_handle,
switch_curl_mime mime 
)

Definition at line 183 of file switch_curl.c.

184 {
185 #if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800)
186  return curl_easy_setopt(curl_handle, CURLOPT_MIMEPOST, mime);
187 #else
188  return curl_easy_setopt(curl_handle, CURLOPT_HTTPPOST, mime);
189 #endif
190 }

◆ switch_curl_easy_strerror()

const char* switch_curl_easy_strerror ( switch_CURLcode  errornum)

Definition at line 46 of file switch_curl.c.

Referenced by switch_curl_process_mime().

47 {
48  return curl_easy_strerror(errornum);
49 }

◆ switch_curl_init()

void switch_curl_init ( void  )

Definition at line 51 of file switch_curl.c.

Referenced by switch_core_init().

52 {
53  curl_global_init(CURL_GLOBAL_ALL);
54 }

◆ switch_curl_mime_free()

void switch_curl_mime_free ( switch_curl_mime **  mimep)

Definition at line 171 of file switch_curl.c.

172 {
173  if (mimep && *mimep) {
174 #if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800)
175  curl_mime_free(*mimep);
176 #else
177  curl_formfree(*mimep);
178 #endif
179  mimep = NULL;
180  }
181 }

◆ switch_curl_process_mime()

switch_status_t switch_curl_process_mime ( switch_event_t event,
switch_CURL curl_handle,
switch_curl_mime **  mimep 
)

Definition at line 61 of file switch_curl.c.

References switch_event::headers, switch_event_header::name, switch_event_header::next, SWITCH_CHANNEL_LOG, switch_curl_easy_strerror(), SWITCH_LOG_DEBUG, switch_log_printf(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_event_header::value.

62 {
63 #if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800)
64  curl_mime *mime = NULL;
65  curl_mimepart *part = NULL;
66  uint8_t added = 0;
67  switch_CURLcode curl_code = CURLE_OK;
68 #else
69  struct curl_httppost *formpost=NULL;
70  struct curl_httppost *lastptr=NULL;
71 #endif
73  int go = 0;
74 
75  for (hp = event->headers; hp; hp = hp->next) {
76  if (!strncasecmp(hp->name, "attach_file:", 12)) {
77  go = 1;
78  break;
79  }
80  }
81 
82  if (!go) {
83  return SWITCH_STATUS_FALSE;
84  }
85 
86 #if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800)
87  mime = curl_mime_init(curl_handle);
88 #endif
89 
90  for (hp = event->headers; hp; hp = hp->next) {
91  if (!strncasecmp(hp->name, "attach_file:", 12)) {
92  char *pname = strdup(hp->name + 12);
93 
94  if (pname) {
95  char *fname = strchr(pname, ':');
96 
97  if (fname) {
98  *fname++ = '\0';
99 
100 #if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800)
101  part = curl_mime_addpart(mime);
102  if ((curl_code = curl_mime_name(part, pname))) {
103  free(pname);
104  goto error;
105  }
106 
107  if ((curl_code = curl_mime_filename(part, fname))) {
108  free(pname);
109  goto error;
110  }
111 
112  if ((curl_code = curl_mime_filedata(part, hp->value))) {
113  free(pname);
114  goto error;
115  }
116 
117  added++;
118 #else
119  curl_formadd(&formpost,
120  &lastptr,
121  CURLFORM_COPYNAME, pname,
122  CURLFORM_FILENAME, fname,
123  CURLFORM_FILE, hp->value,
124  CURLFORM_END);
125 #endif
126  }
127 
128  free(pname);
129  }
130  } else {
131 #if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800)
132  part = curl_mime_addpart(mime);
133  if ((curl_code = curl_mime_name(part, hp->name))) {
134  goto error;
135  }
136 
137  if ((curl_code = curl_mime_data(part, hp->value, CURL_ZERO_TERMINATED))) {
138  goto error;
139  }
140 
141  added++;
142 #else
143  curl_formadd(&formpost,
144  &lastptr,
145  CURLFORM_COPYNAME, hp->name,
146  CURLFORM_COPYCONTENTS, hp->value,
147  CURLFORM_END);
148 #endif
149  }
150  }
151 
152 #if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800)
153  error:
154  if (curl_code) {
155  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CURL error occured. Error code: %d Error msg: [%s]\n", curl_code, switch_curl_easy_strerror(curl_code));
156  }
157 
158  if (!added) {
159  curl_mime_free(mime);
160  mime = NULL;
161  }
162 
163  *mimep = mime;
164 #else
165  *mimep = formpost;
166 #endif
167 
168  return SWITCH_STATUS_SUCCESS;
169 }
#define SWITCH_CHANNEL_LOG
An event Header.
Definition: switch_event.h:65
Definition: cJSON.c:68
int switch_CURLcode
Definition: switch_curl.h:40
struct switch_event_header * next
Definition: switch_event.h:76
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
const char * switch_curl_easy_strerror(switch_CURLcode errornum)
Definition: switch_curl.c:46
switch_event_header_t * headers
Definition: switch_event.h:90

◆ switch_curl_slist_append()

switch_curl_slist_t* switch_curl_slist_append ( switch_curl_slist_t list,
const char *  string 
)

Definition at line 35 of file switch_curl.c.

Referenced by header_callback().

36 {
37  return (switch_curl_slist_t *) curl_slist_append((struct curl_slist *)list, string);
38 }
struct curl_slist switch_curl_slist_t
Definition: switch_curl.h:38

◆ switch_curl_slist_free_all()

void switch_curl_slist_free_all ( switch_curl_slist_t list)

Definition at line 41 of file switch_curl.c.

Referenced by xswitch_http_request().

42 {
43  curl_slist_free_all((struct curl_slist *) list);
44 }

Variable Documentation

◆ switch_CURL

SWITCH_BEGIN_EXTERN_C typedef void switch_CURL

Definition at line 37 of file switch_curl.h.

Referenced by xswitch_http_request().