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