- remove unused bits
[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 $ifdefs = array(
32 'COOKIELIST' => '7,14,1'
33 );
34 $exclude = array(
35 'PRIVATE', 'LASTSOCKET', 'FTP_ENTRY_PATH'
36 );
37 $translate = array(
38 'HTTP_CONNECTCODE' => "connect_code"
39 );
40
41 $templates = array(
42 'STRING' =>
43 ' if (CURLE_OK == curl_easy_getinfo(request->ch, %s, &c)) {
44 add_assoc_string_ex(&array, "%s", sizeof("%2$s"), c ? c : "", 1);
45 }
46 ',
47 'DOUBLE' =>
48 ' if (CURLE_OK == curl_easy_getinfo(request->ch, %s, &d)) {
49 add_assoc_double_ex(&array, "%s", sizeof("%2$s"), d);
50 }
51 ',
52 'LONG' =>
53 ' if (CURLE_OK == curl_easy_getinfo(request->ch, %s, &l)) {
54 add_assoc_long_ex(&array, "%s", sizeof("%2$s"), l);
55 }
56 ',
57 'SLIST' =>
58 ' if (CURLE_OK == curl_easy_getinfo(request->ch, %s, &s)) {
59 MAKE_STD_ZVAL(subarray);
60 array_init(subarray);
61 for (p = s; p; p = p->next) {
62 add_next_index_string(subarray, p->data, 1);
63 }
64 add_assoc_zval_ex(&array, "%s", sizeof("%2$s"), subarray);
65 curl_slist_free_all(s);
66 }
67 '
68 );
69
70 $infos = file_re('curl.h', '/^\s*(CURLINFO_(\w+))\s*=\s*CURLINFO_(STRING|LONG|DOUBLE|SLIST)\s*\+\s*\d+\s*,?\s*$/m');
71
72 ob_start();
73 foreach ($infos as $info) {
74 list(, $full, $short, $type) = $info;
75 if (in_array($short, $exclude)) continue;
76 if (isset($ifdefs[$short])) printf("#if HTTP_CURL_VERSION(%s)\n", $ifdefs[$short]);
77 if (isset($translate[$short])) $short = $translate[$short];
78 printf($templates[$type], $full, strtolower($short));
79 if (isset($ifdefs[$short])) printf("#endif\n");
80 }
81
82 file_put_contents("http_request_info.c",
83 preg_replace('/(\/\* BEGIN \*\/\n).*(\/\* END \*\/)/s', '$1'. ob_get_contents() .'$2',
84 file_get_contents("http_request_info.c")));
85
86 ?>