doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lib510.c
Go to the documentation of this file.
1 #include "test.h"
2 
3 static const char *post[]={
4  "one",
5  "two",
6  "three",
7  "and a final longer crap: four",
8  NULL
9 };
10 
11 
12 struct WriteThis {
13  int counter;
14 };
15 
16 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
17 {
18  struct WriteThis *pooh = (struct WriteThis *)userp;
19  const char *data;
20 
21  if(size*nmemb < 1)
22  return 0;
23 
24  data = post[pooh->counter];
25 
26  if(data) {
27  size_t len = strlen(data);
28  memcpy(ptr, data, len);
29  pooh->counter++; /* advance pointer */
30  return len;
31  }
32  return 0; /* no more data left to deliver */
33 }
34 
35 int test(char *URL)
36 {
37  CURL *curl;
39  struct curl_slist *slist = NULL;
40 
41  struct WriteThis pooh;
42  pooh.counter = 0;
43 
44  slist = curl_slist_append(slist, "Transfer-Encoding: chunked");
45 
46  curl = curl_easy_init();
47  if(curl) {
48  /* First set the URL that is about to receive our POST. */
49  curl_easy_setopt(curl, CURLOPT_URL, URL);
50 
51  /* Now specify we want to POST data */
52  curl_easy_setopt(curl, CURLOPT_POST, TRUE);
53 
54  /* we want to use our own read function */
55  curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
56 
57  /* pointer to pass to our read function */
58  curl_easy_setopt(curl, CURLOPT_INFILE, &pooh);
59 
60  /* get verbose debug output please */
61  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
62 
63  /* include headers in the output */
64  curl_easy_setopt(curl, CURLOPT_HEADER, TRUE);
65 
66  /* enforce chunked transfer by setting the header */
67  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
68 
69  /* Perform the request, res will get the return code */
70  res = curl_easy_perform(curl);
71 
72  /* always cleanup */
73  curl_easy_cleanup(curl);
74 
75  /* clean up the headers list */
76  curl_slist_free_all(slist);
77 
78  }
79  return res;
80 }
CURLcode curl_easy_perform(CURL *curl)
Definition: easy.c:260
CURLcode
Definition: curl.h:209
GLenum GLsizei len
Definition: glext.h:3472
CURLcode curl_easy_setopt(CURL *curl, CURLoption option,...)
Definition: easy.c:217
#define NULL
Definition: Lib.h:88
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:2853
int test(char *URL)
Definition: lib510.c:35
Definition: curl.h:210
size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
Definition: httpput.c:24
GLsizeiptr size
Definition: glext.h:3112
struct curl_slist * curl_slist_append(struct curl_slist *, const char *)
Definition: sendf.c:82
void CURL
Definition: types.h:25
void curl_slist_free_all(struct curl_slist *)
Definition: sendf.c:108
int counter
Definition: lib510.c:13
GLuint res
Definition: glext.h:5385
#define TRUE
Definition: mprintf.c:69
void curl_easy_cleanup(CURL *curl)
Definition: easy.c:288
CURL * curl_easy_init(void)
Definition: easy.c:195