FreeSWITCH API Documentation  1.7.0
switch_curl.c
Go to the documentation of this file.
1 #include <switch.h>
2 #include "switch_curl.h"
3 #include <curl/curl.h>
4 
6 {
7  return curl_easy_init();
8 }
9 
11 {
12  return curl_easy_perform((CURL *)handle);
13 }
14 
15 
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 }
27 
29 {
30  curl_easy_cleanup((CURL *)handle);
31 }
32 
33 
34 
36 {
37  return (switch_curl_slist_t *) curl_slist_append((struct curl_slist *)list, string);
38 }
39 
40 
42 {
43  curl_slist_free_all((struct curl_slist *) list);
44 }
45 
47 {
48  return curl_easy_strerror(errornum);
49 }
50 
52 {
53  curl_global_init(CURL_GLOBAL_ALL);
54 }
55 
57 {
58  curl_global_cleanup();
59 }
60 
61 SWITCH_DECLARE(switch_status_t) switch_curl_process_form_post_params(switch_event_t *event, switch_CURL *curl_handle, struct curl_httppost **formpostp)
62 {
63 
64  struct curl_httppost *formpost=NULL;
65  struct curl_httppost *lastptr=NULL;
67  int go = 0;
68 
69  for (hp = event->headers; hp; hp = hp->next) {
70  if (!strncasecmp(hp->name, "attach_file:", 12)) {
71  go = 1;
72  break;
73  }
74  }
75 
76  if (!go) {
77  return SWITCH_STATUS_FALSE;
78  }
79 
80  for (hp = event->headers; hp; hp = hp->next) {
81 
82  if (!strncasecmp(hp->name, "attach_file:", 12)) {
83  char *pname = strdup(hp->name + 12);
84 
85  if (pname) {
86  char *fname = strchr(pname, ':');
87  if (fname) {
88  *fname++ = '\0';
89 
90  curl_formadd(&formpost,
91  &lastptr,
92  CURLFORM_COPYNAME, pname,
93  CURLFORM_FILENAME, fname,
94  CURLFORM_FILE, hp->value,
95  CURLFORM_END);
96  }
97  free(pname);
98  }
99  } else {
100  curl_formadd(&formpost,
101  &lastptr,
102  CURLFORM_COPYNAME, hp->name,
103  CURLFORM_COPYCONTENTS, hp->value,
104  CURLFORM_END);
105 
106  }
107  }
108 
109  *formpostp = formpost;
110 
111  return SWITCH_STATUS_SUCCESS;
112 
113 }
114 
115 /* For Emacs:
116  * Local Variables:
117  * mode:c
118  * indent-tabs-mode:t
119  * tab-width:4
120  * c-basic-offset:4
121  * End:
122  * For VIM:
123  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
124  */
void switch_curl_init(void)
Definition: switch_curl.c:51
void switch_curl_destroy(void)
Definition: switch_curl.c:56
Representation of an event.
Definition: switch_event.h:80
switch_curl_slist_t * switch_curl_slist_append(switch_curl_slist_t *list, const char *string)
Definition: switch_curl.c:35
switch_CURLcode switch_curl_easy_getinfo(switch_CURL *curl, switch_CURLINFO info,...)
Definition: switch_curl.c:16
An event Header.
Definition: switch_event.h:65
switch_CURLcode switch_curl_easy_perform(switch_CURL *handle)
Definition: switch_curl.c:10
switch_CURL * switch_curl_easy_init(void)
Definition: switch_curl.c:5
SWITCH_BEGIN_EXTERN_C typedef void switch_CURL
Definition: switch_curl.h:37
int switch_CURLcode
Definition: switch_curl.h:40
struct curl_slist switch_curl_slist_t
Definition: switch_curl.h:38
switch_status_t
Common return values.
struct switch_event_header * next
Definition: switch_event.h:76
Main Library Header.
switch_status_t switch_curl_process_form_post_params(switch_event_t *event, switch_CURL *curl_handle, struct curl_httppost **formpostp)
Definition: switch_curl.c:61
#define SWITCH_DECLARE(type)
void switch_curl_easy_cleanup(switch_CURL *handle)
Definition: switch_curl.c:28
const char * switch_curl_easy_strerror(switch_CURLcode errornum)
Definition: switch_curl.c:46
void switch_curl_slist_free_all(switch_curl_slist_t *list)
Definition: switch_curl.c:41
int switch_CURLINFO
Definition: switch_curl.h:39