doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lib508.c
Go to the documentation of this file.
1 #include "test.h"
2 
3 static char data[]="this is what we post to the silly web server\n";
4 
5 struct WriteThis {
6  char *readptr;
7  size_t sizeleft;
8 };
9 
10 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
11 {
12  struct WriteThis *pooh = (struct WriteThis *)userp;
13 
14  if(size*nmemb < 1)
15  return 0;
16 
17  if(pooh->sizeleft) {
18  *(char *)ptr = pooh->readptr[0]; /* copy one single byte */
19  pooh->readptr++; /* advance pointer */
20  pooh->sizeleft--; /* less data left */
21  return 1; /* we return 1 byte at a time! */
22  }
23 
24  return -1; /* no more data left to deliver */
25 }
26 
27 int test(char *URL)
28 {
29  CURL *curl;
31 
32  struct WriteThis pooh;
33 
34  pooh.readptr = data;
35  pooh.sizeleft = strlen(data);
36 
37  curl = curl_easy_init();
38  if(curl) {
39  /* First set the URL that is about to receive our POST. */
40  curl_easy_setopt(curl, CURLOPT_URL, URL);
41 
42  /* Now specify we want to POST data */
43  curl_easy_setopt(curl, CURLOPT_POST, TRUE);
44 
45  /* Set the expected POST size */
46  curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)pooh.sizeleft);
47 
48  /* we want to use our own read function */
49  curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
50 
51  /* pointer to pass to our read function */
52  curl_easy_setopt(curl, CURLOPT_INFILE, &pooh);
53 
54  /* get verbose debug output please */
55  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
56 
57  /* include headers in the output */
58  curl_easy_setopt(curl, CURLOPT_HEADER, TRUE);
59 
60  /* Perform the request, res will get the return code */
61  res = curl_easy_perform(curl);
62 
63  /* always cleanup */
64  curl_easy_cleanup(curl);
65  }
66  return res;
67 }
int test(char *URL)
Definition: lib508.c:27
CURLcode curl_easy_perform(CURL *curl)
Definition: easy.c:260
CURLcode
Definition: curl.h:209
char * readptr
Definition: post-callback.c:21
CURLcode curl_easy_setopt(CURL *curl, CURLoption option,...)
Definition: easy.c:217
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:2853
size_t sizeleft
Definition: lib508.c:7
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
void CURL
Definition: types.h:25
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