doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lib505.c
Go to the documentation of this file.
1 /*****************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * $Id: lib505.c,v 1.4 2004/02/05 12:34:17 bagder Exp $
9  */
10 
11 #include "test.h"
12 
13 #ifdef HAVE_SYS_SOCKET_H
14 #include <sys/socket.h>
15 #endif
16 #ifdef HAVE_SYS_TYPES_
17 #include <sys/types.h>
18 #endif
19 #ifdef HAVE_SYS_STAT_H
20 #include <sys/stat.h>
21 #endif
22 #ifdef HAVE_FCNTL_H
23 #include <fcntl.h>
24 #endif
25 
26 #ifdef HAVE_UNISTD_H
27 #include <unistd.h>
28 #endif
29 
30 /*
31  * This example shows an FTP upload, with a rename of the file just after
32  * a successful upload.
33  *
34  * Example based on source code provided by Erick Nuwendam. Thanks!
35  */
36 
37 int test(char *URL)
38 {
39  CURL *curl;
40  CURLcode res;
41  FILE *hd_src ;
42  int hd ;
43  struct stat file_info;
44 
45  struct curl_slist *headerlist=NULL;
46  const char *buf_1 = "RNFR 505";
47  const char *buf_2 = "RNTO 505-forreal";
48 
49  /* get the file size of the local file */
50  hd = stat(arg2, &file_info);
51  if(hd == -1) {
52  /* can't open file, bail out */
53  return -1;
54  }
55 
56  if(! file_info.st_size) {
57  fprintf(stderr, "WARNING: file %s has no size!\n", arg2);
58  return -4;
59  }
60 
61  /* get a FILE * of the same file, could also be made with
62  fdopen() from the previous descriptor, but hey this is just
63  an example! */
64  hd_src = fopen(arg2, "rb");
65  if(NULL == hd_src) {
66  return -2; /* if this happens things are major weird */
67  }
68 
69  /* In windows, this will init the winsock stuff */
71 
72  /* get a curl handle */
73  curl = curl_easy_init();
74  if(curl) {
75  /* build a list of commands to pass to libcurl */
76  headerlist = curl_slist_append(headerlist, buf_1);
77  headerlist = curl_slist_append(headerlist, buf_2);
78 
79  /* enable uploading */
80  curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ;
81 
82  /* enable verbose */
83  curl_easy_setopt(curl, CURLOPT_VERBOSE, TRUE) ;
84 
85  /* specify target */
86  curl_easy_setopt(curl,CURLOPT_URL, URL);
87 
88  /* pass in that last of FTP commands to run after the transfer */
89  curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist);
90 
91  /* now specify which file to upload */
92  curl_easy_setopt(curl, CURLOPT_INFILE, hd_src);
93 
94  /* and give the size of the upload (optional) */
95  curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
96  file_info.st_size);
97 
98  /* Now run off and do what you've been told! */
99  res = curl_easy_perform(curl);
100 
101  /* clean up the FTP commands list */
102  curl_slist_free_all (headerlist);
103 
104  /* always cleanup */
105  curl_easy_cleanup(curl);
106  }
107  fclose(hd_src); /* close the local file */
108 
110  return res;
111 }
CURLcode curl_global_init(long flags)
Globally initializes cURL given a bitwise set of the different features to initialize.
Definition: easy.c:147
CURLcode curl_easy_perform(CURL *curl)
Definition: easy.c:260
CURLcode
Definition: curl.h:209
CURLcode curl_easy_setopt(CURL *curl, CURLoption option,...)
Definition: easy.c:217
GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg2
Definition: glext.h:5286
void curl_global_cleanup(void)
Globally cleanup cURL, uses the value of "init_flags" to determine what needs to be cleaned up and ...
Definition: easy.c:174
#define NULL
Definition: Lib.h:88
int test(char *URL)
Definition: lib505.c:37
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
GLuint res
Definition: glext.h:5385
#define TRUE
Definition: mprintf.c:69
#define CURL_GLOBAL_ALL
Definition: curl.h:1153
void curl_easy_cleanup(CURL *curl)
Definition: easy.c:288
CURL * curl_easy_init(void)
Definition: easy.c:195