cvs: php4 /ext/ircg ircg.c ircg_common.c php_ircg_private.h

From: Date: Tue, 22 Apr 2003 05:30:47 +0000
Subject: cvs: php4 /ext/ircg ircg.c ircg_common.c php_ircg_private.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-20427@lists.php.net to get a copy of this message
sas Tue Apr 22 01:30:47 2003 EDT Modified files: /php4/ext/ircg ircg.c ircg_common.c php_ircg_private.h Log: First try at providing compatibility for existing PHP 4.2 deployments which lack certain SAPI functions. Index: php4/ext/ircg/ircg.c diff -u php4/ext/ircg/ircg.c:1.171 php4/ext/ircg/ircg.c:1.172 --- php4/ext/ircg/ircg.c:1.171 Sun Apr 20 03:22:08 2003 +++ php4/ext/ircg/ircg.c Tue Apr 22 01:30:47 2003 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: ircg.c,v 1.171 2003/04/20 07:22:08 sas Exp $ */ +/* $Id: ircg.c,v 1.172 2003/04/22 05:30:47 sas Exp $ */ /* {{{ includes */ @@ -2155,12 +2155,15 @@ static void setup(int stage); -static int initialized; - /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(ircg) { + uid_t uid; + gid_t gid; + char *user; + char buf[32]; + #if IRCG_API_VERSION >= 20010307 if (irc_sizeof_irconn() != sizeof(irconn_t)) { printf("FATAL: The size of the irconn_t structure has changed " @@ -2178,16 +2181,23 @@ #endif REGISTER_INI_ENTRIES(); + + sleep(10); + php_ircg_init_compat(); - if (initialized == 0) { - initialized = 1; #if IRCG_API_VERSION >= 20021127 - ircg_setup_global(IRCGG(work_dir), IRCGG(shared_mem_size), IRCGG(control_user), setup); + if (php_ircg_get_target_data(&uid, &gid)) { + user = IRCGG(control_user); + } else { + sprintf(buf, "%u", uid); + user = buf; + } + + ircg_setup_global(IRCGG(work_dir), IRCGG(shared_mem_size), user, setup); #else - setup(0); - setup(1); + setup(0); + setup(1); #endif - } ircg_hash_init(&php_ircg->h_fmt_msgs, 0, NULL, fmt_msgs_dtor, 1); #ifdef USE_FD2IRCONN Index: php4/ext/ircg/ircg_common.c diff -u php4/ext/ircg/ircg_common.c:1.2 php4/ext/ircg/ircg_common.c:1.3 --- php4/ext/ircg/ircg_common.c:1.2 Tue Dec 31 11:06:49 2002 +++ php4/ext/ircg/ircg_common.c Tue Apr 22 01:30:47 2003 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: ircg_common.c,v 1.2 2002/12/31 16:06:49 sebastian Exp $ */ +/* $Id: ircg_common.c,v 1.3 2003/04/22 05:30:47 sas Exp $ */ #include "php.h" @@ -25,8 +25,148 @@ return -1; } +#define PHP_IRCG_COMPATIBLE + +#ifdef PHP_IRCG_COMPATIBLE + +#include <dlfcn.h> + +static int (*php_ircg_sapi_get_fd)(int *fd TSRMLS_DC); +static int (*php_ircg_sapi_force_http_10)(TSRMLS_D); +static int (*php_ircg_sapi_get_target_uid)(uid_t * TSRMLS_DC); +static int (*php_ircg_sapi_get_target_gid)(gid_t * TSRMLS_DC); + +static int is_apache; + +static uid_t *php_ircg_ap_user_id; +static gid_t *php_ircg_ap_group_id; + +typedef struct { + int a; + unsigned char *b; + int c[3]; + void *d[2]; + int e; + void (*f)(void); + void *g; + long int h; + void *i; + + int fd; +} ircg_BUFF; + +typedef struct { + void *a[4]; + int b; + ircg_BUFF *client; +} ircg_conn_rec; + +typedef struct { + void *a; + + ircg_conn_rec *connection; + + void *b[5]; + int c; + enum { REALLY_NOTHING } d; + int e; + void *f; + + int proto_num; +} ircg_request_rec; + +#include "main/SAPI.h" + +static int php_ircg_force_http_10(TSRMLS_D) +{ + if (is_apache) { + ircg_request_rec *r = SG(server_context); + + /* ensure that we are not accidentially hitting something else */ + if (r->proto_num == 9 + || (r->proto_num >= 1000 && r->proto_num <= 2000)) { + r->proto_num = 1000; + return SUCCESS; + } + } + return FAILURE; +} + +static int php_ircg_get_fd(int *nfd TSRMLS_DC) +{ + if (is_apache) { + ircg_request_rec *r = SG(server_context); + int fd; + + fd = r->connection->client->fd; + + if (fd >= 0 && fd < 130000) { + *nfd = fd; + return SUCCESS; + } + } + + return FAILURE; +} + +static int php_ircg_get_target_uid(uid_t *obj TSRMLS_DC) +{ + if (is_apache) { + *obj = *php_ircg_ap_user_id; + return SUCCESS; + } + return FAILURE; +} + +static int php_ircg_get_target_gid(gid_t *obj TSRMLS_DC) +{ + if (is_apache) { + *obj = *php_ircg_ap_group_id; + return SUCCESS; + } + return FAILURE; +} + +#endif + +void php_ircg_init_compat(TSRMLS_D) +{ +#ifdef PHP_IRCG_COMPATIBLE + void *p; + + if (strcmp(sapi_module.name, "apache")) { + is_apache = 1; + php_ircg_ap_user_id = dlsym(NULL, "ap_user_id"); + php_ircg_ap_group_id = dlsym(NULL, "ap_group_id"); + } + + p = dlsym(NULL, "sapi_get_fd"); + php_ircg_sapi_get_fd = p ? p : php_ircg_get_fd; + + p = dlsym(NULL, "sapi_force_http_10"); + php_ircg_sapi_force_http_10 = p ? p : php_ircg_force_http_10; + + p = dlsym(NULL, "sapi_get_target_uid"); + php_ircg_sapi_get_target_uid = p ? p : php_ircg_get_target_uid; + + p = dlsym(NULL, "sapi_get_target_gid"); + php_ircg_sapi_get_target_gid = p ? p : php_ircg_get_target_gid; +#endif +} + +int php_ircg_get_target_data(uid_t *uid, gid_t *gid TSRMLS_DC) +{ + return php_ircg_sapi_get_target_uid(uid TSRMLS_DC) + || php_ircg_sapi_get_target_gid(gid TSRMLS_DC); +} + int php_ircg_register_with_sapi(int *fd TSRMLS_DC) { - sapi_force_http_10(TSRMLS_C); - return sapi_get_fd(fd TSRMLS_CC); +#ifdef PHP_IRCG_COMPATIBLE + return php_ircg_sapi_force_http_10(TSRMLS_C) + || php_ircg_sapi_get_fd(fd TSRMLS_CC); +#else + return sapi_force_http_10(TSRMLS_C); + || sapi_get_fd(fd TSRMLS_CC); +#endif } Index: php4/ext/ircg/php_ircg_private.h diff -u php4/ext/ircg/php_ircg_private.h:1.6 php4/ext/ircg/php_ircg_private.h:1.7 --- php4/ext/ircg/php_ircg_private.h:1.6 Sat Apr 19 14:03:47 2003 +++ php4/ext/ircg/php_ircg_private.h Tue Apr 22 01:30:47 2003 @@ -55,4 +55,6 @@ time_t php_ircg_now(void); +int php_ircg_get_target_data(uid_t *uid, gid_t *gid TSRMLS_DC); + #endif

« previous php.cvs (#20427) next »