release 2.6.0
[m6w6/ext-http] / scripts / gen_curlinfo.php
1 #!/usr/bin/env php
2 <?php
3 // $Id: gen_curlinfo.php 323304 2012-02-17 21:13:24Z mike $
4
5 error_reporting(0);
6
7 function failure() {
8 fprintf(STDERR, "FAILURE: %s\n", error_get_last()["message"]);
9 exit(-1);
10 }
11
12 function file_re($file, $pattern, $all = true) {
13 static $path;
14
15 $path or $path = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1].'/include/curl/' : "/usr/local/include/curl/";
16
17 if ($content = file_get_contents($path . $file)) {
18 if ($all) {
19 if (preg_match_all($pattern, $content, $matches, PREG_SET_ORDER)) {
20 return $matches;
21 }
22 } else {
23 if (preg_match($pattern, $content, $matches)) {
24 return $matches;
25 }
26 }
27 trigger_error("no match in $file for $pattern");
28 }
29 failure();
30 }
31
32 $ifdefs = array(
33 'PRIMARY_IP' => 'PHP_HTTP_CURL_VERSION(7,19,0)',
34 'APPCONNECT_TIME' => 'PHP_HTTP_CURL_VERSION(7,19,0)',
35 'CONDITION_UNMET' => 'PHP_HTTP_CURL_VERSION(7,19,4)',
36 'PRIMARY_PORT' => 'PHP_HTTP_CURL_VERSION(7,21,0)',
37 'LOCAL_PORT' => 'PHP_HTTP_CURL_VERSION(7,21,0)',
38 'LOCAL_IP' => 'PHP_HTTP_CURL_VERSION(7,21,0)',
39 'HTTP_VERSION' => 'PHP_HTTP_CURL_VERSION(7,50,0)'
40 );
41 $exclude = array(
42 'ACTIVESOCKET',
43 'CERTINFO',
44 'COOKIELIST',
45 'FTP_ENTRY_PATH',
46 'LASTSOCKET',
47 'PRIVATE',
48 'RTSP_CLIENT_CSEQ',
49 'RTSP_CSEQ_RECV',
50 'RTSP_SERVER_CSEQ',
51 'RTSP_SESSION_ID',
52 'TLS_SESSION',
53 'TLS_SSL_PTR',
54 );
55
56 $translate = array(
57 'HTTP_CONNECTCODE' => "connect_code",
58 'COOKIELIST' => 'cookies',
59 );
60
61 $templates = array(
62 'STRING' =>
63 ' if (CURLE_OK == curl_easy_getinfo(ch, %s, &c)) {
64 add_assoc_string_ex(&array, "%s", sizeof("%2$s"), c ? c : "", 1);
65 }
66 ',
67 'DOUBLE' =>
68 ' if (CURLE_OK == curl_easy_getinfo(ch, %s, &d)) {
69 add_assoc_double_ex(&array, "%s", sizeof("%2$s"), d);
70 }
71 ',
72 'LONG' =>
73 ' if (CURLE_OK == curl_easy_getinfo(ch, %s, &l)) {
74 add_assoc_long_ex(&array, "%s", sizeof("%2$s"), l);
75 }
76 ',
77 'SLIST' =>
78 ' if (CURLE_OK == curl_easy_getinfo(ch, %s, &s)) {
79 MAKE_STD_ZVAL(subarray);
80 array_init(subarray);
81 for (p = s; p; p = p->next) {
82 if (p->data) {
83 add_next_index_string(subarray, p->data, 1);
84 }
85 }
86 add_assoc_zval_ex(&array, "%s", sizeof("%2$s"), subarray);
87 curl_slist_free_all(s);
88 }
89 ',
90 );
91
92 $infos = file_re('curl.h', '/^\s*(CURLINFO_(\w+))\s*=\s*CURLINFO_(STRING|LONG|DOUBLE|SLIST)\s*\+\s*\d+\s*,?\s*$/m');
93
94 ob_start();
95 foreach ($infos as $info) {
96 list(, $full, $short, $type) = $info;
97 if (in_array($short, $exclude)) continue;
98 if (isset($ifdefs[$short])) printf("#if %s\n", $ifdefs[$short]);
99 printf($templates[$type], $full, strtolower((isset($translate[$short])) ? $translate[$short] : $short));
100 if (isset($ifdefs[$short])) printf("#endif\n");
101 }
102
103 file_put_contents("src/php_http_client_curl.c",
104 preg_replace('/(\/\* BEGIN::CURLINFO \*\/\n).*(\n\s*\/\* END::CURLINFO \*\/)/s', '$1'. ob_get_contents() .'$2',
105 file_get_contents("src/php_http_client_curl.c")));
106
107 ?>