sas             Thu Nov 14 20:55:27 2002 EDT

  Modified files:              
    /php4/ext/ircg      ircg.c 
  Log:
  Simplify handling of ctcp messages by improving %t.
  
  
Index: php4/ext/ircg/ircg.c
diff -u php4/ext/ircg/ircg.c:1.140 php4/ext/ircg/ircg.c:1.141
--- php4/ext/ircg/ircg.c:1.140  Wed Nov 13 20:09:45 2002
+++ php4/ext/ircg/ircg.c        Thu Nov 14 20:55:27 2002
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: ircg.c,v 1.140 2002/11/14 01:09:45 sas Exp $ */
+/* $Id: ircg.c,v 1.141 2002/11/15 01:55:27 sas Exp $ */
 
 /* {{{ includes */
 
@@ -825,7 +825,7 @@
 
 /* {{{ IRCG-handlers */
 static void handle_ctcp(php_irconn_t *conn, smart_str *chan, smart_str *from,
-               smart_str *msg, smart_str *result)
+               smart_str *to, smart_str *msg, smart_str *result)
 {
        char *token_end;
        char *real_msg;
@@ -851,8 +851,19 @@
                        }
 
                        smart_str_setl(&tmp, real_msg, real_msg_end - real_msg);
-                       smart_str_setl(&tmp2, conn->conn.username, 
conn->conn.username_len);
-                       format_msg(fmt_msg, chan, &tmp2, from, &tmp, result, 
conn->conn.username, conn->conn.username_len, &status);
+                       
+                       /*
+                        * If no `toŽ information was provided by the IRCG layer,
+                        * someone sent us a private CTCP message.
+                        * Otherwise, to will be the channel name or the nickname
+                        * of the recipient.
+                        */
+                       
+                       if (!to) {
+                               smart_str_setl(&tmp2, conn->conn.username, 
+conn->conn.username_len);
+                               to = &tmp2;
+                       }
+                       format_msg(fmt_msg, chan, to, from, &tmp, result, 
+conn->conn.username, conn->conn.username_len, &status);
 
                        if (status == 1)
                                irc_disconnect(&conn->conn, "Connection terminated by 
authenticated CTCP message");
@@ -871,7 +882,7 @@
        smart_str_setl(&s_username, ircc->username, ircc->username_len);
 
        if (msg->c[0] == '\001') {
-               handle_ctcp(conn, chan, from, msg, &m);
+               handle_ctcp(conn, chan, from, chan?chan:NULL, msg, &m);
        } else if (chan) {
                FORMAT_MSG(conn, FMT_MSG_CHAN, chan, &s_username, from, msg, &m, 
conn->conn.username, conn->conn.username_len);
        } else {
@@ -2235,19 +2246,18 @@
                smart_str_setl(&tmp, Z_STRVAL_PP(recipient), Z_STRLEN_PP(recipient));
                smart_str_setl(&tmp2, conn->conn.username, conn->conn.username_len);
 
-
                switch (Z_STRVAL_PP(recipient)[0]) {
                        case '#':
                        case '&':
                                if (l.c[0] == 1) {
-                                       handle_ctcp(conn, &tmp, &tmp2, &l, &m);
+                                       handle_ctcp(conn, &tmp, &tmp2, &tmp, &l, &m);
                                } else {
                                        FORMAT_MSG(conn, FMT_MSG_CHAN, &tmp, NULL, 
&tmp2, &l, &m, conn->conn.username, conn->conn.username_len);
                                }
                                break;
                        default:
                                if (l.c[0] == 1) {
-                                       handle_ctcp(conn, NULL, &tmp2, &l, &m);
+                                       handle_ctcp(conn, NULL, &tmp2, &tmp, &l, &m);
                                } else {
                                        FORMAT_MSG(conn, FMT_MSG_PRIV_FROM_ME, NULL,
                                                        &tmp, &tmp2, &l, &m, 
conn->conn.username, conn->conn.username_len);



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to