-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathurl.h
420 lines (334 loc) · 10.8 KB
/
url.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
/*
* url.h
*
* 2006 Copyright (c)
* Robert Iakobashvili, <[email protected]>
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef URL_H
#define URL_H
#include <stddef.h>
#include <curl/curl.h>
#define URL_SHORT_NAME_LEN 12
#define URL_AUTH_STR_LEN 64
#define URL_RESPONSE_STATUS_ERRORS_TABLE_SIZE 600
/*
Application types of URLs.
*/
typedef enum url_appl_type
{
URL_APPL_UNDEF = 0, /* set by calloc */
URL_APPL_HTTP,
URL_APPL_HTTPS,
URL_APPL_FTP,
URL_APPL_FTPS,
URL_APPL_SFTP,
URL_APPL_TELNET,
}url_appl_type;
typedef enum authentication_method
{
AUTHENTICATION_NO = CURLAUTH_NONE, /* set by calloc */
AUTHENTICATION_BASIC = CURLAUTH_BASIC,
AUTHENTICATION_DIGEST = CURLAUTH_DIGEST,
AUTHENTICATION_GSS_NEGOTIATE = CURLAUTH_GSSNEGOTIATE,
AUTHENTICATION_NTLM = CURLAUTH_NTLM,
AUTHENTICATION_ANY = CURLAUTH_ANY,
} authentication_method;
/*
* Currently, we are using mainly username and password, but up to 16
* tokens/records are available.
*/
#define FORM_RECORDS_MAX_TOKENS_NUM 16
#define FORM_RECORDS_TOKEN_MAX_LEN 64
#define FORM_RECORDS_SEQ_NUM_LEN 7 /* Up to 10 000 000 clients */
typedef struct form_records_cdata
{
/*
On access test, that the form_tokens have been allocated.
*/
char* form_tokens[FORM_RECORDS_MAX_TOKENS_NUM];
} form_records_cdata;
/*
GF
Structures for storing a set of URLs built from an URL_TEMPLATE such as
http://www.abc.com/group/%s/user/%s/account
Each URL is built by replacing the %s's with a token from a file specified
by URL_TOKEN_FILE, or from an URL_TOKEN obtained in a prior server response.
This allows each virtual client to make a unique request.
The token file may also specify a cookie to accompany the request.
*/
typedef struct urle
{
char* string;
char* cookie;
} urle;
typedef struct url_set
{
int n_urles;
urle* urles;
int index;
} url_set;
/*
The URL_TEMPLATE is stored here, for both URL_TOKEN and URL_TOKEN_FILE cases,
although both cannot be used together.
*/
typedef struct
{
char* string; /* template string, eg http://www.abc.com/group/%s/user/%s/account */
int n_cents; /* number of %s's in the template */
int n_tokens; /* number of URL_TOKENS parsed so far */
char** names; /* URL_TOKEN names */
char** values; /* scratch space for collecting token values */
} url_template;
/*
This url has this many RESPONSE_TOKENS that we must scan for
*/
typedef struct
{
int n_tokens;
}url_response;
/*
url_context - structure, that concentrates our knowledge
about the url to fetch (download, upload, etc).
*/
typedef struct url_context
{
/* URL buffer, string containing the url */
char* url_str;
/* URL buffer length*/
size_t url_str_len;
/* The short-cut URL name to be used in Load Status GUI. */
char url_short_name [URL_SHORT_NAME_LEN + 1];
/*
The flag can be set instead of URL string provisioning. If true,
the current url will be used.
Useful e.g. when POST-ing to the form, obtained by the previous
GET fetching. Cannot be used for the first URL, because there is
no any "currect" url with CURL handle till at least a single fetch
has been done.
*/
int url_use_current;
/*
If true, such url is done only once and not cycled.
Useful for a single login/logoff operation. A url with such flag to be
fetched only, when all previous cycling URLs have been accomplished.
*/
int url_dont_cycle;
/*
Number of custom HTTP headers in array.
*/
size_t custom_http_hdrs_num;
/*
The list of custom HTTP headers.
*/
struct curl_slist *custom_http_hdrs;
/*
Request type/method. Used currently for HTTP only and can be:
REQ_TYPE_GET_AND_POST, REQ_TYPE_POST, REQ_TYPE_GET
*/
size_t req_type;
/*
The username to be used to access a URL by filling the POST
form or in GET url.
*/
char username[URL_AUTH_STR_LEN];
/*
The password to be used to access a URL by filling the POST form or
in GET url.
*/
char password[URL_AUTH_STR_LEN];
/*
The type of <form_str>. Valid types are:
FORM_USAGETYPE_UNIQUE_USERS_AND_PASSWORDS
- like "user=%s%d&password=%s%d";
FORM_USAGETYPE_UNIQUE_USERS_SAME_PASSWORD
- like "user=%s%d&password=%s";
FORM_USAGETYPE_SINGLE_USER - like "user=%s&password=%s";
FORM_USAGETYPE_RECORDS_FROM_FILE
Record file enables up to 16 record tokens to be used. Thus, an appropriate
form to include up to 16 form names with "=%s" to be filled by the record tokens
from a file:
"form1=%s&form2=%s&form3=%s.... &form16=%s", which for user and password form could look like:
"user=%s&password=%s
FORM_USAGETYPE_AS_IS - use the string provided AS IS;
*/
int form_usage_type;
/*
The string to be used as the base for login post message
*/
char* form_str;
/*
The file with strings like "user:password", where separator may be
',', ';', ':', '@', '/' and ' ' (space). The file may be created as a dump of DB tables
of users and passwords.
*/
char* form_records_file;
/*
The array of form records with clients data (cdata).
form_records_array[N] is for client number N and contains cdata tokens
to be used e.g. in POST-ing forms
*/
form_records_cdata* form_records_array;
/*
Number of records in the above array of form records, containing client
data (cdata).
Normally, to be the same size as the number of clients, but it can
be larger as well.
*/
size_t form_records_num;
/* The limit of records, passed by configuration. If no limit set and the field is
zero, we are taking number of clients as the possible maximum */
size_t form_records_file_max_num;
/*
If 1 set, records are used in a random fashion and not "bound"
to each client using index (index of client == index of record).
*/
size_t form_records_random;
/*
Name of the file (with a path, if required) to upload.
*/
char* upload_file;
/* Size of the file to upload in bytes. */
off_t upload_file_size;
/* File pointer to the open upload file */
FILE* upload_file_ptr;
/* Structures for multipart/formdata HTTP POST (rfc1867-style posts) */
struct curl_httppost* mpart_form_post;
struct curl_httppost* mpart_form_last;
/* Web authentication method. If 0 - no Web authentication */
authentication_method web_auth_method;
/*
Username:password. If NULL, username and password are
combined to make it.
*/
char* web_auth_credentials;
/* Proxy authentication method. If 0 - no proxy authentication */
authentication_method proxy_auth_method;
/*
Username:password. If NULL, username and password are
combined to make it.
*/
char* proxy_auth_credentials;
/*
When true, an existing connection will be closed and connection
will be re-established (attempted).
*/
long fresh_connect;
/*
Maximum time to establish TCP connection with a server (including resolving).
If zero, the global connect_timeout default is taken.
*/
long connect_timeout;
/*
Time to accomplish fetching of a url.
*/
unsigned long timer_url_completion_lrange;
unsigned long timer_url_completion_hrange;
/*
Time to relax/sleep after fetching this url (msec). The timeout
actually emulates user behavior. A user normally needs time to
read the page retrived prior to making another click.
*/
unsigned long timer_after_url_sleep_lrange;
unsigned long timer_after_url_sleep_hrange;
/* When positive, means ftp-active. The default is ftp-passive. */
int ftp_active;
/* Logs headers of HTTP responses to files, when true. */
int log_resp_headers;
/* Logs bodies of HTTP responses to files, when true. */
int log_resp_bodies;
/*
Upper limit for download/upload rate in
bytes/sec.
*/
curl_off_t transfer_limit_rate;
/*
Percent probability, that a client will fetch the url.
Should be from 0 up to 100%, where zero means 100% probability.
*/
int fetch_probability;
/*
Client should make the decision "to fetch or not to fetch" a url
only once (at the first cycle), remember the decision and to
follow the once-made decision at all next cycles.
*/
int fetch_probability_once;
/************* Assisting Elements *************/
/* Application type of url, e.g. HTTP, HTTPS, FTP, etc */
url_appl_type url_appl_type;
/*
Our index in the url array
*/
long url_ind;
/*
Directory name to be used for logfiles of responses
(headers and bodies).
*/
char* dir_log;
/*
An optional table of response status errors. If a response status is 404,
when resp_status_errors_tbl[404] is true, and the response is considered
as an error.
By default 4xx responses without 401 and 407 and all 5xx responses are
considered as errors.
*/
unsigned char *resp_status_errors_tbl;
/*GF */
url_set set;
url_template template;
url_response response;
/*
Keep a separate upload-file offset for each client
Replaces the single upload_file_ptr.
*/
/* file descriptor for open upload file */
int upload_descriptor;
/* allocated, one for each client */
off_t* upload_offsets;
/*
Allows form records to be used sequentially as clients cycle.
See form_records_array above.
*/
int form_records_cycle;
size_t form_records_index;
/*
Governs how urls are chosen from the url_set, not implemented yet
*/
int url_cycling;
/*
Ignore the content length of the response. The server would normally
close the connection.
*/
int ignore_content_length;
/*
Randomize a part of the url specified by a token
*/
int random_lrange;
int random_hrange;
char* random_token;
} url_context;
/* GF */
#define is_template(url) (url->template.string != 0)
int
current_url_completion_timeout (unsigned long *timeout,
url_context* url,
unsigned long now);
int
current_url_sleeping_timeout (unsigned long *timeout,
url_context* url,
unsigned long now);
#endif /* URL_H */