doom3-gpl
Doom 3 GPL source release
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
neo
curl
src
writeout.c
Go to the documentation of this file.
1
/***************************************************************************
2
* _ _ ____ _
3
* Project ___| | | | _ \| |
4
* / __| | | | |_) | |
5
* | (__| |_| | _ <| |___
6
* \___|\___/|_| \_\_____|
7
*
8
* Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
9
*
10
* This software is licensed as described in the file COPYING, which
11
* you should have received as part of this distribution. The terms
12
* are also available at http://curl.haxx.se/docs/copyright.html.
13
*
14
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
* copies of the Software, and permit persons to whom the Software is
16
* furnished to do so, under the terms of the COPYING file.
17
*
18
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
* KIND, either express or implied.
20
*
21
* $Id: writeout.c,v 1.21 2004/02/25 15:41:36 bagder Exp $
22
***************************************************************************/
23
24
#include "
setup.h
"
25
26
#include <stdio.h>
27
#include <string.h>
28
29
#ifdef HAVE_SYS_TYPES_H
30
#include <sys/types.h>
31
#endif
32
#ifdef HAVE_SYS_SELECT_H
33
#include <sys/select.h>
34
#endif
35
36
#include <
curl/curl.h
>
37
38
#define _MPRINTF_REPLACE
/* we want curl-functions instead of native ones */
39
#include <
curl/mprintf.h
>
40
41
#include "
writeout.h
"
42
43
typedef
enum
{
44
VAR_NONE
,
/* must be the first */
45
VAR_TOTAL_TIME
,
46
VAR_NAMELOOKUP_TIME
,
47
VAR_CONNECT_TIME
,
48
VAR_PRETRANSFER_TIME
,
49
VAR_STARTTRANSFER_TIME
,
50
VAR_SIZE_DOWNLOAD
,
51
VAR_SIZE_UPLOAD
,
52
VAR_SPEED_DOWNLOAD
,
53
VAR_SPEED_UPLOAD
,
54
VAR_HTTP_CODE
,
55
VAR_HEADER_SIZE
,
56
VAR_REQUEST_SIZE
,
57
VAR_EFFECTIVE_URL
,
58
VAR_CONTENT_TYPE
,
59
VAR_NUM_OF_VARS
/* must be the last */
60
}
replaceid
;
61
62
struct
variable
{
63
const
char
*
name
;
64
replaceid
id
;
65
};
66
67
68
static
struct
variable
replacements[]={
69
{
"url_effective"
,
VAR_EFFECTIVE_URL
},
70
{
"http_code"
,
VAR_HTTP_CODE
},
71
{
"time_total"
,
VAR_TOTAL_TIME
},
72
{
"time_namelookup"
,
VAR_NAMELOOKUP_TIME
},
73
{
"time_connect"
,
VAR_CONNECT_TIME
},
74
{
"time_pretransfer"
,
VAR_PRETRANSFER_TIME
},
75
{
"time_starttransfer"
,
VAR_STARTTRANSFER_TIME
},
76
{
"size_header"
,
VAR_HEADER_SIZE
},
77
{
"size_request"
,
VAR_REQUEST_SIZE
},
78
{
"size_download"
,
VAR_SIZE_DOWNLOAD
},
79
{
"size_upload"
,
VAR_SIZE_UPLOAD
},
80
{
"speed_download"
,
VAR_SPEED_DOWNLOAD
},
81
{
"speed_upload"
,
VAR_SPEED_UPLOAD
},
82
{
"content_type"
,
VAR_CONTENT_TYPE
},
83
{
NULL
,
VAR_NONE
}
84
};
85
86
void
ourWriteOut
(
CURL
*curl,
char
*writeinfo)
87
{
88
FILE *stream = stdout;
89
char
*ptr=writeinfo;
90
char
*stringp;
91
long
longinfo;
92
double
doubleinfo;
93
94
while
(*ptr) {
95
if
(
'%'
== *ptr) {
96
if
(
'%'
== ptr[1]) {
97
/* an escaped %-letter */
98
fputc
(
'%'
, stream);
99
ptr+=2;
100
}
101
else
{
102
/* this is meant as a variable to output */
103
char
*
end
;
104
char
keepit;
105
int
i
;
106
if
((
'{'
== ptr[1]) && (end=strchr(ptr,
'}'
))) {
107
ptr+=2;
/* pass the % and the { */
108
keepit=*
end
;
109
*end=0;
/* zero terminate */
110
for
(i=0; replacements[
i
].
name
; i++) {
111
if
(
curl_strequal
(ptr, replacements[i].
name
)) {
112
switch
(replacements[i].
id
) {
113
case
VAR_EFFECTIVE_URL
:
114
if
((
CURLE_OK
==
115
curl_easy_getinfo
(curl,
CURLINFO_EFFECTIVE_URL
, &stringp))
116
&& stringp)
117
fputs(stringp, stream);
118
break
;
119
case
VAR_HTTP_CODE
:
120
if
(
CURLE_OK
==
121
curl_easy_getinfo
(curl,
CURLINFO_RESPONSE_CODE
, &longinfo))
122
fprintf(stream,
"%03ld"
, longinfo);
123
break
;
124
case
VAR_HEADER_SIZE
:
125
if
(
CURLE_OK
==
126
curl_easy_getinfo
(curl,
CURLINFO_HEADER_SIZE
, &longinfo))
127
fprintf(stream,
"%ld"
, longinfo);
128
break
;
129
case
VAR_REQUEST_SIZE
:
130
if
(
CURLE_OK
==
131
curl_easy_getinfo
(curl,
CURLINFO_REQUEST_SIZE
, &longinfo))
132
fprintf(stream,
"%ld"
, longinfo);
133
break
;
134
case
VAR_TOTAL_TIME
:
135
if
(
CURLE_OK
==
136
curl_easy_getinfo
(curl,
CURLINFO_TOTAL_TIME
, &doubleinfo))
137
fprintf(stream,
"%.3f"
, doubleinfo);
138
break
;
139
case
VAR_NAMELOOKUP_TIME
:
140
if
(
CURLE_OK
==
141
curl_easy_getinfo
(curl,
CURLINFO_NAMELOOKUP_TIME
,
142
&doubleinfo))
143
fprintf(stream,
"%.3f"
, doubleinfo);
144
break
;
145
case
VAR_CONNECT_TIME
:
146
if
(
CURLE_OK
==
147
curl_easy_getinfo
(curl,
CURLINFO_CONNECT_TIME
, &doubleinfo))
148
fprintf(stream,
"%.3f"
, doubleinfo);
149
break
;
150
case
VAR_PRETRANSFER_TIME
:
151
if
(
CURLE_OK
==
152
curl_easy_getinfo
(curl,
CURLINFO_PRETRANSFER_TIME
, &doubleinfo))
153
fprintf(stream,
"%.3f"
, doubleinfo);
154
break
;
155
case
VAR_STARTTRANSFER_TIME
:
156
if
(
CURLE_OK
==
157
curl_easy_getinfo
(curl,
CURLINFO_STARTTRANSFER_TIME
, &doubleinfo))
158
fprintf(stream,
"%.3f"
, doubleinfo);
159
break
;
160
case
VAR_SIZE_UPLOAD
:
161
if
(
CURLE_OK
==
162
curl_easy_getinfo
(curl,
CURLINFO_SIZE_UPLOAD
, &doubleinfo))
163
fprintf(stream,
"%.0f"
, doubleinfo);
164
break
;
165
case
VAR_SIZE_DOWNLOAD
:
166
if
(
CURLE_OK
==
167
curl_easy_getinfo
(curl,
CURLINFO_SIZE_DOWNLOAD
, &doubleinfo))
168
fprintf(stream,
"%.0f"
, doubleinfo);
169
break
;
170
case
VAR_SPEED_DOWNLOAD
:
171
if
(
CURLE_OK
==
172
curl_easy_getinfo
(curl,
CURLINFO_SPEED_DOWNLOAD
, &doubleinfo))
173
fprintf(stream,
"%.3f"
, doubleinfo);
174
break
;
175
case
VAR_SPEED_UPLOAD
:
176
if
(
CURLE_OK
==
177
curl_easy_getinfo
(curl,
CURLINFO_SPEED_UPLOAD
, &doubleinfo))
178
fprintf(stream,
"%.3f"
, doubleinfo);
179
break
;
180
case
VAR_CONTENT_TYPE
:
181
if
((
CURLE_OK
==
182
curl_easy_getinfo
(curl,
CURLINFO_CONTENT_TYPE
, &stringp))
183
&& stringp)
184
fputs(stringp, stream);
185
break
;
186
default
:
187
/* -Wunreachable-code wrongly complains on this */
188
break
;
189
}
190
break
;
191
}
192
}
193
ptr=end+1;
/* pass the end */
194
*end = keepit;
195
}
196
else
{
197
/* illegal syntax, then just output the characters that are used */
198
fputc
(
'%'
, stream);
199
fputc
(ptr[1], stream);
200
ptr+=2;
201
}
202
}
203
}
204
else
if
(
'\\'
== *ptr) {
205
switch
(ptr[1]) {
206
case
'r'
:
207
fputc
(
'\r'
, stream);
208
break
;
209
case
'n'
:
210
fputc
(
'\n'
, stream);
211
break
;
212
case
't'
:
213
fputc
(
'\t'
, stream);
214
break
;
215
default
:
216
/* unknown, just output this */
217
fputc
(*ptr, stream);
218
fputc
(ptr[1], stream);
219
break
;
220
}
221
ptr+=2;
222
}
223
else
{
224
fputc
(*ptr, stream);
225
ptr++;
226
}
227
}
228
229
}
replaceid
replaceid
Definition:
writeout.c:43
CURLINFO_SIZE_DOWNLOAD
Definition:
curl.h:1113
curl_easy_getinfo
CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info,...)
Definition:
easy.c:299
VAR_SPEED_DOWNLOAD
Definition:
writeout.c:52
CURLINFO_EFFECTIVE_URL
Definition:
curl.h:1106
VAR_SIZE_DOWNLOAD
Definition:
writeout.c:50
VAR_CONNECT_TIME
Definition:
writeout.c:47
VAR_TOTAL_TIME
Definition:
writeout.c:45
CURLINFO_SPEED_DOWNLOAD
Definition:
curl.h:1114
VAR_SIZE_UPLOAD
Definition:
writeout.c:51
CURLINFO_CONNECT_TIME
Definition:
curl.h:1110
CURLINFO_HEADER_SIZE
Definition:
curl.h:1116
CURLINFO_NAMELOOKUP_TIME
Definition:
curl.h:1109
variable::name
const char * name
Definition:
writeout.c:63
VAR_NONE
Definition:
writeout.c:44
curl.h
CURLINFO_RESPONSE_CODE
Definition:
curl.h:1107
process.i
int i
Definition:
process.py:33
VAR_NAMELOOKUP_TIME
Definition:
writeout.c:46
variable::id
replaceid id
Definition:
writeout.c:64
VAR_HEADER_SIZE
Definition:
writeout.c:55
CURLINFO_REQUEST_SIZE
Definition:
curl.h:1117
ourWriteOut
void ourWriteOut(CURL *curl, char *writeinfo)
Definition:
writeout.c:86
VAR_NUM_OF_VARS
Definition:
writeout.c:59
CURLINFO_CONTENT_TYPE
Definition:
curl.h:1123
end
GLuint GLuint end
Definition:
glext.h:2845
NULL
#define NULL
Definition:
Lib.h:88
mprintf.h
fputc
int fputc(int, FILE *)
CURLINFO_SIZE_UPLOAD
Definition:
curl.h:1112
VAR_CONTENT_TYPE
Definition:
writeout.c:58
writeout.h
CURLE_OK
Definition:
curl.h:210
VAR_STARTTRANSFER_TIME
Definition:
writeout.c:49
name
const GLcharARB * name
Definition:
glext.h:3629
VAR_EFFECTIVE_URL
Definition:
writeout.c:57
CURLINFO_SPEED_UPLOAD
Definition:
curl.h:1115
CURLINFO_PRETRANSFER_TIME
Definition:
curl.h:1111
VAR_PRETRANSFER_TIME
Definition:
writeout.c:48
VAR_HTTP_CODE
Definition:
writeout.c:54
CURL
void CURL
Definition:
types.h:25
CURLINFO_TOTAL_TIME
Definition:
curl.h:1108
setup.h
VAR_SPEED_UPLOAD
Definition:
writeout.c:53
curl_strequal
int() curl_strequal(const char *s1, const char *s2)
Definition:
strequal.c:37
CURLINFO_STARTTRANSFER_TIME
Definition:
curl.h:1122
VAR_REQUEST_SIZE
Definition:
writeout.c:56
variable
Definition:
writeout.c:62
This page is maintained by
Wladimir van der Laan
. Generated on Mon Nov 17 2014 12:23:15 for doom3-gpl by
1.8.6
.