* Fixed bug in HttpRequestPool where a negative timeout was passed to select()
[m6w6/ext-http] / scripts / gen_curlinfo.php
1 <?php
2 // $Id$
3
4 error_reporting(0);
5
6 function failure() {
7 fprintf(STDERR, "FAILURE: %s\n", error_get_last());
8 exit(-1);
9 }
10
11 function file_re($file, $pattern, $all = true) {
12 static $path;
13
14 $path or $path = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1].'/include/curl/' : "/usr/local/include/curl/";
15
16 if ($content = file_get_contents($path . $file)) {
17 if ($all) {
18 if (preg_match_all($pattern, $content, $matches, PREG_SET_ORDER)) {
19 return $matches;
20 }
21 } else {
22 if (preg_match($pattern, $content, $matches)) {
23 return $matches;
24 }
25 }
26 trigger_error("no match in $file for $pattern");
27 }
28 failure();
29 }
30
31 function version($major, $minor, $pl) {
32 static $version;
33
34 $version or $version = file_re('curlver.h', '/^#\s*define\s+LIBCURL_VERSION\s+"(\d+)\.(\d+)\.(\d+)(?:-\w+)?"\s*$/m', false);
35
36 return $major <= $version[1] && $minor <= $version[2] && $pl <= $version[3];
37 }
38
39 $ifdefs = array(
40 'COOKIELIST' => '7,14,1'
41 );
42 $exclude = array(
43 'PRIVATE', 'LASTSOCKET', 'FTP_ENTRY_PATH'
44 );
45 $translate = array(
46 'HTTP_CONNECTCODE' => "connect_code"
47 );
48
49 $templates = array(
50 'STRING' =>
51 ' if (CURLE_OK == curl_easy_getinfo(request->ch, %s, &c)) {
52 add_assoc_string_ex(&array, "%s", sizeof("%2$s"), c ? c : "", 1);
53 }
54 ',
55 'DOUBLE' =>
56 ' if (CURLE_OK == curl_easy_getinfo(request->ch, %s, &d)) {
57 add_assoc_double_ex(&array, "%s", sizeof("%2$s"), d);
58 }
59 ',
60 'LONG' =>
61 ' if (CURLE_OK == curl_easy_getinfo(request->ch, %s, &l)) {
62 add_assoc_long_ex(&array, "%s", sizeof("%2$s"), l);
63 }
64 ',
65 'SLIST' =>
66 ' if (CURLE_OK == curl_easy_getinfo(request->ch, %s, &s)) {
67 MAKE_STD_ZVAL(subarray);
68 array_init(subarray);
69 for (p = s; p; p = p->next) {
70 add_next_index_string(subarray, p->data, 1);
71 }
72 add_assoc_zval_ex(&array, "%s", sizeof("%2$s"), subarray);
73 curl_slist_free_all(s);
74 }
75 '
76 );
77
78 $types = file_re('curl.h', '/^#\s*define\s+CURLINFO_(STRING|LONG|DOUBLE|SLIST|MASK|TYPEMASK)\s+(0x[0-9a-fA-F]+)\s*$/m');
79 $infos = file_re('curl.h', '/^\s*(CURLINFO_(\w+))\s*=\s*CURLINFO_(STRING|LONG|DOUBLE|SLIST)\s*\+\s*\d+\s*,?\s*$/m');
80
81 ob_start();
82 foreach ($infos as $info) {
83 list(, $full, $short, $type) = $info;
84 if (in_array($short, $exclude)) continue;
85 if (isset($ifdefs[$short])) printf("#if HTTP_CURL_VERSION(%s)\n", $ifdefs[$short]);
86 if (isset($translate[$short])) $short = $translate[$short];
87 printf($templates[$type], $full, strtolower($short));
88 if (isset($ifdefs[$short])) printf("#endif\n");
89 }
90
91 file_put_contents("http_request_info.c",
92 preg_replace('/(\/\* BEGIN \*\/\n).*(\/\* END \*\/)/s', '$1'. ob_get_contents() .'$2',
93 file_get_contents("http_request_info.c")));
94
95 ?>