~ubuntu-branches/ubuntu/vivid/curl/vivid

« back to all changes in this revision

Viewing changes to tests/libtest/lib552.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Schuldei
  • Date: 2009-04-02 23:35:45 UTC
  • mto: (1.2.1 upstream) (3.2.3 sid)
  • mto: This revision was merged to the branch mainline in revision 38.
  • Revision ID: james.westby@ubuntu.com-20090402233545-geixkwhe3izccjt7
Tags: upstream-7.19.4
ImportĀ upstreamĀ versionĀ 7.19.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *                            | (__| |_| |  _ <| |___
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
 
 * $Id: lib552.c,v 1.4 2008-05-22 21:49:53 danf Exp $
 
8
 * $Id: lib552.c,v 1.7 2008-09-20 04:26:57 yangtse Exp $
9
9
 *
10
10
 * argv1 = URL
11
11
 * argv2 = proxy with embedded user+password
13
13
 
14
14
#include "test.h"
15
15
 
 
16
#include "memdebug.h"
 
17
 
16
18
struct data {
17
19
  char trace_ascii; /* 1 or 0 */
18
20
};
106
108
 
107
109
 
108
110
static size_t current_offset = 0;
109
 
char data[70000]; /* MUST  be more than 64k OR MAX_INITIAL_POST_SIZE */
 
111
static char databuf[70000]; /* MUST be more than 64k OR MAX_INITIAL_POST_SIZE */
110
112
 
111
113
static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
112
114
{
113
115
  size_t  amount = nmemb * size; /* Total bytes curl wants */
114
 
  size_t  available = sizeof data - current_offset;  /* What we have to give */
 
116
  size_t  available = sizeof(databuf) - current_offset; /* What we have to give */
115
117
  size_t  given = amount < available ? amount : available; /* What is given */
116
118
  (void)stream;
117
 
  memcpy(ptr, data + current_offset, given);
 
119
  memcpy(ptr, databuf + current_offset, given);
118
120
  current_offset += given;
119
121
  return given;
120
122
}
146
148
int test(char *URL)
147
149
{
148
150
  CURL *curl;
149
 
  CURLcode res;
 
151
  CURLcode res = CURLE_OUT_OF_MEMORY;
150
152
  struct data config;
151
153
  size_t i;
152
 
  char fill[] = "test data";
 
154
  static const char fill[] = "test data";
153
155
 
154
156
  config.trace_ascii = 1; /* enable ascii tracing */
155
157
 
161
163
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
162
164
 
163
165
    /* setup repeated data string */
164
 
    for (i=0; i < sizeof data; ++i)
165
 
        data[i] = fill[i % sizeof fill];
 
166
    for (i=0; i < sizeof(databuf); ++i)
 
167
        databuf[i] = fill[i % sizeof fill];
166
168
 
167
169
    /* Post */
168
170
    curl_easy_setopt(curl, CURLOPT_POST, 1L);
169
171
 
170
172
    /* Setup read callback */
171
 
    curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) sizeof data);
 
173
    curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) sizeof(databuf));
172
174
    curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
173
175
 
174
176
    /* Write callback */
190
192
    /* always cleanup */
191
193
    curl_easy_cleanup(curl);
192
194
  }
193
 
  return 0;
 
195
  curl_global_cleanup();
 
196
  return (int)res;
194
197
}