cvs: php4 /ext/ircg ircg.c
| From: | Sascha Schumann | Date: | Tue, 09 Jan 2001 08:00:24 +0000 |
| Subject: | cvs: php4 /ext/ircg ircg.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-3503@lists.php.net to get a copy of this message | ||
sas Tue Jan 9 00:00:24 2001 EDT
Modified files:
/php4/ext/ircg ircg.c
Log:
Handle the case that the IRC server kills our connection more gracefully
(i.e. without segfaulting the whole server).
Index: php4/ext/ircg/ircg.c
diff -u php4/ext/ircg/ircg.c:1.9 php4/ext/ircg/ircg.c:1.10
--- php4/ext/ircg/ircg.c:1.9 Mon Jan 8 18:58:56 2001
+++ php4/ext/ircg/ircg.c Tue Jan 9 00:00:23 2001
@@ -68,6 +68,7 @@
const char *channel;
zend_llist buffer;
int fd;
+ int irconn_id;
char *fmt_msgs[NO_FMTS];
} php_irconn_t;
@@ -98,14 +99,8 @@
static void irconn_dtor(void *dummy)
{
php_irconn_t **conn = dummy;
- int i;
-
- for (i = 0; i < NO_FMTS; i++) {
- if ((*conn)->fmt_msgs[i] && (*conn)->fmt_msgs[i] != fmt_msgs_default[i])
free((*conn)->fmt_msgs[i]);
- }
irc_disconnect(&(*conn)->conn, "Browser connection closed");
- free((char *) (*conn)->username);
}
static void buffer_dtor(void *dummy)
@@ -114,11 +109,20 @@
smart_str_free_ex(msg, 1);
}
-
static void quit_handler(irconn_t *c, void *dummy)
{
php_irconn_t *conn = dummy;
+ int i;
+
+ if (conn->fd != -1)
+ zend_hash_index_del(&h_fd2irconn, conn->fd);
+ zend_hash_index_del(&h_irconn, conn->irconn_id);
+ for (i = 0; i < NO_FMTS; i++) {
+ if (conn->fmt_msgs[i] && conn->fmt_msgs[i] != fmt_msgs_default[i])
free(conn->fmt_msgs[i]);
+ }
+ free((char *) conn->username);
+
zend_llist_destroy(&conn->buffer);
free(conn);
}
@@ -379,13 +383,15 @@
static void http_closed_connection(int fd)
{
- int *id;
-
+ int *id, stored_id;
+
if (zend_hash_index_find(&h_fd2irconn, fd, (void **) &id) == FAILURE)
return;
+ stored_id = *id;
+
zend_hash_index_del(&h_fd2irconn, fd);
- zend_hash_index_del(&h_irconn, *id);
+ zend_hash_index_del(&h_irconn, stored_id);
}
PHP_FUNCTION(ircg_set_current)
@@ -507,6 +513,10 @@
username = Z_STRVAL_PP(p1);
}
+ /*
+ * conn must be able to live longer than the hash entry in h_irconn,
+ * so we have to allocate it ourselves.
+ */
conn = malloc(sizeof(*conn));
conn->username = strdup(username);
conn->channel = NULL,
@@ -528,6 +538,7 @@
memset(conn->fmt_msgs, 0, sizeof(conn->fmt_msgs));
}
irconn_id++;
+ conn->irconn_id = irconn_id;
zend_hash_index_update(&h_irconn, irconn_id, &conn, sizeof(conn), NULL);
zend_llist_init(&conn->buffer, sizeof(smart_str), buffer_dtor, 1);
irc_connect(username, NULL, msg_handler, quit_handler, error_handler,