At 05:31 PM 2/17/2001 +0000, Sascha Schumann wrote:
>sas             Sat Feb 17 09:31:36 2001 EDT
>
>   Modified files:
>     /php4/ext/ircg      ircg.c
>   Log:
>   Add initial CTCP handling and fix a possible segfault in ircg_msg()
>
>
>Index: php4/ext/ircg/ircg.c
>diff -u php4/ext/ircg/ircg.c:1.25 php4/ext/ircg/ircg.c:1.26
>--- php4/ext/ircg/ircg.c:1.25   Sat Feb 17 00:30:10 2001
>+++ php4/ext/ircg/ircg.c        Sat Feb 17 09:31:36 2001
>@@ -16,7 +16,7 @@
>     +----------------------------------------------------------------------+
>   */
>
>-/* $Id: ircg.c,v 1.25 2001/02/17 08:30:10 sas Exp $ */
>+/* $Id: ircg.c,v 1.26 2001/02/17 17:31:36 sas Exp $ */
>
>  #include "php.h"
>  #include "php_ini.h"
>@@ -84,6 +84,7 @@
>         int irconn_id;
>         php_fmt_msgs_t *fmt_msgs;
>         irc_write_buf wb;
>+       HashTable ctcp_msgs;
>  } php_irconn_t;
>
>  static char *fmt_msgs_default[] = {
>@@ -157,6 +158,7 @@
>         conn->fd = -2;
>         zend_hash_index_del(&h_irconn, conn->irconn_id);
>
>+       zend_hash_destroy(&conn->ctcp_msgs);
>         zend_llist_destroy(&conn->buffer);
>         free(conn);
>  }
>@@ -271,14 +273,48 @@
>         zend_llist_apply_with_argument(&conn->buffer, msg_send_apply, conn);
>  }
>
>+
>+static void handle_ctcp(php_irconn_t *conn, const char *chan, const char 
>*from,
>+               smart_str *msg, smart_str *result)
>+{
>+       char *token_end;
>+       char *real_msg;
>+       char *real_msg_end;
>+
>+       for (token_end = msg->c + 1; *token_end; token_end++)
>+               if (!isalpha(*token_end)) break;
>+
>+       if (*token_end != '\001') {
>+               real_msg = token_end + 1;
>+
>+               real_msg_end = strchr(real_msg, '\001');
>+               if (real_msg_end) {
>+                       char *fmt_msg;
>+
>+                       *real_msg_end = '\0';
>+                       *token_end = '\0';
>+
>+                       if (zend_hash_find(&conn->ctcp_msgs, msg->c + 1, 
>token_end - msg->c - 1, (void **) &fmt_msg) != SUCCESS) {
>+                               return;
>+                       }
>+
>+                       format_msg(fmt_msg, chan, conn->conn.username, 
>from, real_msg,
>+                                       result);
>+               }
>+       }
>+}
>+
>+
>  static void msg_handler(irconn_t *ircc, const char *chan, const char *from,
>                 smart_str *msg, void *conn_data, void *chan_data)
>  {
>         php_irconn_t *conn = conn_data;
>         static smart_str m;
>
>-       m.len = 0;
>-       if (chan) {
>+       m.len = 0;
>+       if (msg->c[0] == '\001') {
>+               handle_ctcp(conn, chan, from, msg, &m);
>+       } else if (chan) {
>                 format_msg(MSG(conn, FMT_MSG_CHAN), chan, ircc->username, 
> from, msg->c,
>                                 &m);
>         } else {
>@@ -540,20 +576,43 @@
>         irc_register_hook(conn, IRCG_TOPIC, new_topic);
>  }
>
>+static int ircg_copy_ctcp_msgs(zval **array, php_irconn_t *conn)
>+{
>+       zval **val;
>+       char *str;
>+       ulong num;
>+
>+       zend_hash_internal_pointer_reset(Z_ARRVAL_PP(array));
>+
>+       while (zend_hash_get_current_key(Z_ARRVAL_PP(array), &str, &num, 
>0) == HASH_KEY_IS_STRING) {
>+               zend_hash_get_current_data(Z_ARRVAL_PP(array), (void **) 
>&val);
>+               convert_to_string_ex(val);
>+               zend_hash_add(&conn->ctcp_msgs, str, strlen(str), 
>Z_STRVAL_PP(val),
>+                               Z_STRLEN_PP(val) + 1, NULL);
>+
>+               zend_hash_move_forward(Z_ARRVAL_PP(array));
>+       }
>+
>+       return 0;
>+}
>+
>  PHP_FUNCTION(ircg_pconnect)
>  {
>-       zval **p1, **p2, **p3, **p4 = NULL;
>+       zval **p1, **p2, **p3, **p4 = NULL, **p5 = NULL;
>         const char *username;
>         const char *server = "0";
>         int port = 6667;
>         php_fmt_msgs_t *fmt_msgs = NULL;
>         php_irconn_t *conn;
>
>-       if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 4
>-                       || zend_get_parameters_ex(ZEND_NUM_ARGS(), &p1, 
>&p2, &p3, &p4) == FAILURE)
>+       if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 5
>+                       || zend_get_parameters_ex(ZEND_NUM_ARGS(), &p1, 
>&p2, &p3, &p4, &p5) == FAILURE)
>                 WRONG_PARAM_COUNT;
>
>         switch (ZEND_NUM_ARGS()) {
>+       case 5:
>+               if (Z_TYPE_PP(p5) != IS_ARRAY)
>+                       WRONG_PARAM_COUNT;
>         case 4:
>                 convert_to_string_ex(p4);
>                 fmt_msgs = lookup_fmt_msgs(p4);
>@@ -575,11 +634,15 @@
>         conn = malloc(sizeof(*conn));
>         conn->fd = -1;
>
>+       zend_hash_init(&conn->ctcp_msgs, 10, NULL, NULL, 1);
>         if (irc_connect(username, register_hooks,
>                         conn, server, port, &conn->conn)) {
>                 free(conn);
>                 RETURN_FALSE;
>         }
>+       if (p5) {
>+               ircg_copy_ctcp_msgs(p5, conn);
>+       }
>         conn->fmt_msgs = fmt_msgs;
>         irconn_id++;
>         conn->irconn_id = irconn_id;
>@@ -646,7 +709,6 @@
>
>         irc_msg(&conn->conn, Z_STRVAL_PP(recipient), Z_STRVAL_PP(msg));
>         smart_str_setl(&l, Z_STRVAL_PP(msg), Z_STRLEN_PP(msg));
>-       smart_str_0(&l);
>
>         switch (Z_STRVAL_PP(recipient)[0]) {
>         case '#':
>
>
>
>--
>PHP CVS Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to