~ubuntu-branches/ubuntu/jaunty/cmake/jaunty-security

« back to all changes in this revision

Viewing changes to Source/CTest/Curl/Testing/postit2.c

  • Committer: Bazaar Package Importer
  • Author(s): A. Maitland Bottoms
  • Date: 2006-06-18 16:34:11 UTC
  • mfrom: (1.4.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060618163411-pi234s3v6jwlcmof
Tags: 2.4.2-1
* New upstream release (Closes: #338324)
* Put cmake .vim files into /usr/share/vim/addons/plugin/
  where they can be used. (Closes: #366663)
* Install cmake-mode.el so it can be used. (Closes: #366664)
* Ensure cmake FindKDE locates KDE libraries on Debian
  based distributions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 *                                  _   _ ____  _     
 
3
 *  Project                     ___| | | |  _ \| |    
 
4
 *                             / __| | | | |_) | |    
 
5
 *                            | (__| |_| |  _ <| |___ 
 
6
 *                             \___|\___/|_| \_\_____|
 
7
 *
 
8
 * $Id: postit2.c,v 1.1 2003/01/07 02:17:48 andy Exp $
 
9
 *
 
10
 * Example code that uploads a file name 'foo' to a remote script that accepts
 
11
 * "HTML form based" (as described in RFC1738) uploads using HTTP POST.
 
12
 *
 
13
 * The imaginary form we'll fill in looks like:
 
14
 *
 
15
 * <form method="post" enctype="multipart/form-data" action="examplepost.cgi">
 
16
 * Enter file: <input type="file" name="sendfile" size="40">
 
17
 * Enter file name: <input type="text" name="filename" size="30">
 
18
 * <input type="submit" value="send" name="submit">
 
19
 * </form>
 
20
 *
 
21
 * This exact source code has not been verified to work.
 
22
 */
 
23
 
 
24
/* to make this work under windows, use the win32-functions from the
 
25
   win32socket.c file as well */
 
26
 
 
27
#include <stdio.h>
 
28
#include <string.h>
 
29
 
 
30
#include <curl/curl.h>
 
31
#include <curl/types.h>
 
32
#include <curl/easy.h>
 
33
 
 
34
#if LIBCURL_VERSION_NUM < 0x070900
 
35
#error "curl_formadd() is not introduced until libcurl 7.9 and later"
 
36
#endif
 
37
 
 
38
int main(int argc, char *argv[])
 
39
{
 
40
  CURL *curl;
 
41
  CURLcode res;
 
42
 
 
43
  struct HttpPost *formpost=NULL;
 
44
  struct HttpPost *lastptr=NULL;
 
45
  struct curl_slist *headerlist=NULL;
 
46
  char buf[] = "Expect:";
 
47
 
 
48
  /* Fill in the file upload field */
 
49
  curl_formadd(&formpost,
 
50
               &lastptr,
 
51
               CURLFORM_COPYNAME, "sendfile",
 
52
               CURLFORM_FILE, "postit2.c",
 
53
               CURLFORM_END);
 
54
 
 
55
  /* Fill in the filename field */
 
56
  curl_formadd(&formpost,
 
57
               &lastptr,
 
58
               CURLFORM_COPYNAME, "filename",
 
59
               CURLFORM_COPYCONTENTS, "postit2.c",
 
60
               CURLFORM_END);
 
61
  
 
62
 
 
63
  /* Fill in the submit field too, even if this is rarely needed */
 
64
  curl_formadd(&formpost,
 
65
               &lastptr,
 
66
               CURLFORM_COPYNAME, "submit",
 
67
               CURLFORM_COPYCONTENTS, "send",
 
68
               CURLFORM_END);
 
69
 
 
70
  curl = curl_easy_init();
 
71
  /* initalize custom header list (stating that Expect: 100-continue is not
 
72
     wanted */
 
73
  headerlist = curl_slist_append(headerlist, buf);
 
74
  if(curl) {
 
75
    /* what URL that receives this POST */
 
76
    curl_easy_setopt(curl, CURLOPT_URL, "http://curl.haxx.se/examplepost.cgi");
 
77
    if ( (argc == 2) && (!strcmp(argv[1], "noexpectheader")) )
 
78
      /* only disable 100-continue header if explicitly requested */
 
79
      curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
 
80
    curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
 
81
    res = curl_easy_perform(curl);
 
82
 
 
83
    /* always cleanup */
 
84
    curl_easy_cleanup(curl);
 
85
 
 
86
    /* then cleanup the formpost chain */
 
87
    curl_formfree(formpost);
 
88
    /* free slist */
 
89
    curl_slist_free_all (headerlist);
 
90
  }
 
91
  return 0;
 
92
}