f9d83f653128008479d4ece2febe7596fb51489a
[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 'COOKIELIST' => 'cookies',
40 );
41
42 $templates = array(
43 'STRING' =>
44 ' if (CURLE_OK == curl_easy_getinfo(request->ch, %s, &c)) {
45 add_assoc_string_ex(&array, "%s", sizeof("%2$s"), c ? c : "", 1);
46 }
47 ',
48 'DOUBLE' =>
49 ' if (CURLE_OK == curl_easy_getinfo(request->ch, %s, &d)) {
50 add_assoc_double_ex(&array, "%s", sizeof("%2$s"), d);
51 }
52 ',
53 'LONG' =>
54 ' if (CURLE_OK == curl_easy_getinfo(request->ch, %s, &l)) {
55 add_assoc_long_ex(&array, "%s", sizeof("%2$s"), l);
56 }
57 ',
58 'SLIST' =>
59 ' if (CURLE_OK == curl_easy_getinfo(request->ch, %s, &s)) {
60 MAKE_STD_ZVAL(subarray);
61 array_init(subarray);
62 for (p = s; p; p = p->next) {
63 add_next_index_string(subarray, p->data, 1);
64 }
65 add_assoc_zval_ex(&array, "%s", sizeof("%2$s"), subarray);
66 curl_slist_free_all(s);
67 }
68 '
69 );
70
71 $infos = file_re('curl.h', '/^\s*(CURLINFO_(\w+))\s*=\s*CURLINFO_(STRING|LONG|DOUBLE|SLIST)\s*\+\s*\d+\s*,?\s*$/m');
72
73 ob_start();
74 foreach ($infos as $info) {
75 list(, $full, $short, $type) = $info;
76 if (in_array($short, $exclude)) continue;
77 if (isset($ifdefs[$short])) printf("#if HTTP_CURL_VERSION(%s)\n", $ifdefs[$short]);
78 printf($templates[$type], $full, strtolower((isset($translate[$short])) ? $translate[$short] : $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 ?>