5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2006 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
21 #include "silchttpphp.h"
23 /* Executes PHP code and returns result */
25 SilcBuffer silc_http_php(char *php_data)
30 /* Write the PHP data to temporary file */
32 name = _mktemp("silchttpphpXXXXXX");
36 memset(tmp, 0, sizeof(tmp));
37 silc_snprintf(tmp, sizeof(tmp) - 1, "/tmp/silchttpphpXXXXXX");
38 if (mkstemp(tmp) == -1)
41 #endif /* SILC_WIN32 */
43 silc_file_writefile_mode(name, php_data, strlen(php_data), 0600);
46 ret = silc_http_php_file(name);
52 #endif /* SILC_WIN32 */
57 /* Loads PHP file and executes the PHP code and returns the result */
59 SilcBuffer silc_http_php_file(const char *filename)
61 SilcBuffer ret = NULL;
62 unsigned char tmp[8192];
66 SILC_LOG_DEBUG(("Executing PHP"));
68 memset(tmp, 0, sizeof(tmp));
69 silc_snprintf(tmp, sizeof(tmp) - 1, "php -f %s", filename);
72 fd = _popen(tmp, "r");
75 #endif /* SILC_WIN32 */
81 len = fread(tmp, 1, sizeof(tmp), fd);
83 silc_buffer_free(ret);
90 ret = silc_buffer_alloc(0);
97 silc_buffer_format(ret,
99 SILC_STR_DATA(tmp, len),
105 silc_buffer_format(ret,
107 SILC_STR_DATA('\0', 1),
109 silc_buffer_push(ret, silc_buffer_truelen(ret));