sas             Sat Feb 17 00:30:11 2001 EDT

  Modified files:              
    /php4/ext/ircg      ircg.c php_ircg.h 
  Log:
  Convert to the new hooks-based callback system.
  
  Also add a facility to change our own nick as well as tracking other
  nick changes.
  
  
Index: php4/ext/ircg/ircg.c
diff -u php4/ext/ircg/ircg.c:1.24 php4/ext/ircg/ircg.c:1.25
--- php4/ext/ircg/ircg.c:1.24   Fri Feb 16 14:53:18 2001
+++ php4/ext/ircg/ircg.c        Sat Feb 17 00:30:10 2001
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: ircg.c,v 1.24 2001/02/16 22:53:18 sas Exp $ */
+/* $Id: ircg.c,v 1.25 2001/02/17 08:30:10 sas Exp $ */
 
 #include "php.h"
 #include "php_ini.h"
@@ -50,6 +50,7 @@
        FMT_MSG_FATAL_ERROR,
        FMT_MSG_JOIN_LIST_END,
        FMT_MSG_SELF_PART,
+       FMT_MSG_NICK,
        NO_FMTS
 };
 
@@ -61,6 +62,7 @@
        PHP_FE(ircg_join, NULL)
        PHP_FE(ircg_part, NULL)
        PHP_FE(ircg_msg, NULL)
+       PHP_FE(ircg_nick, NULL)
        PHP_FE(ircg_disconnect, NULL)
        PHP_FE(ircg_is_conn_alive, NULL)
        PHP_FE(ircg_lookup_format_messages, NULL)
@@ -95,7 +97,8 @@
        "Error: %m<br />",
        "Fatal Error: %m<br />",
        "",
-       ""
+       "",
+       "%f changes nick to %t<br />"
 };
 
 #define MSG(conn, type) \
@@ -286,6 +289,18 @@
        msg_send(conn, &m);
 }
 
+static void nick_handler(irconn_t *c, smart_str *oldnick, smart_str *newnick,
+               void *dummy)
+{
+       php_irconn_t *conn = dummy;
+       static smart_str m;
+
+       m.len = 0;
+       format_msg(MSG(conn, FMT_MSG_NICK), NULL, newnick->c, oldnick->c, NULL,
+                       &m);
+       msg_send(conn, &m);
+}
+
 static void error_handler(irconn_t *ircc, int id, int fatal, smart_str *msg, void 
*conn_data)
 {
        php_irconn_t *conn = conn_data;
@@ -424,7 +439,7 @@
 
        if (!conn) RETURN_FALSE;
        
-       irc_join(&conn->conn, Z_STRVAL_PP(p2), NULL, part_handler, user_add, 
user_leave, user_kick, new_topic, conn);
+       irc_join(&conn->conn, Z_STRVAL_PP(p2), NULL,  conn);
        RETVAL_TRUE;
 }
 
@@ -511,6 +526,20 @@
        RETVAL_TRUE;    
 }
 
+static void register_hooks(irconn_t *conn, void *dummy)
+{
+       irc_register_hook(conn, IRCG_MSG, msg_handler);
+       irc_register_hook(conn, IRCG_QUIT, quit_handler);
+       irc_register_hook(conn, IRCG_ERROR, error_handler);
+       irc_register_hook(conn, IRCG_NICK, nick_handler);
+
+       irc_register_hook(conn, IRCG_PART, part_handler);
+       irc_register_hook(conn, IRCG_USER_ADD, user_add);
+       irc_register_hook(conn, IRCG_USER_LEAVE, user_leave);
+       irc_register_hook(conn, IRCG_USER_KICK, user_kick);
+       irc_register_hook(conn, IRCG_TOPIC, new_topic);
+}
+
 PHP_FUNCTION(ircg_pconnect)
 {
        zval **p1, **p2, **p3, **p4 = NULL;
@@ -546,7 +575,7 @@
        conn = malloc(sizeof(*conn));
        conn->fd = -1;
 
-       if (irc_connect(username, NULL, msg_handler, quit_handler, error_handler,
+       if (irc_connect(username, register_hooks, 
                        conn, server, port, &conn->conn)) {
                free(conn);
                RETURN_FALSE;
@@ -573,6 +602,27 @@
 
        zend_hash_index_del(&h_irconn, Z_LVAL_PP(id));
 
+       RETURN_TRUE;
+}
+
+
+PHP_FUNCTION(ircg_nick)
+{
+       zval **id, **newnick;
+       php_irconn_t *conn;
+       
+       if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &id, &newnick) == 
+FAILURE)
+               WRONG_PARAM_COUNT;
+
+       convert_to_long_ex(id);
+       convert_to_string_ex(newnick);
+
+       conn = lookup_irconn(Z_LVAL_PP(id));
+
+       if (!conn) RETURN_FALSE;
+       
+       irc_nick(&conn->conn, Z_STRVAL_PP(newnick));
+       
        RETURN_TRUE;
 }
 
Index: php4/ext/ircg/php_ircg.h
diff -u php4/ext/ircg/php_ircg.h:1.3 php4/ext/ircg/php_ircg.h:1.4
--- php4/ext/ircg/php_ircg.h:1.3        Fri Jan 12 06:27:27 2001
+++ php4/ext/ircg/php_ircg.h    Sat Feb 17 00:30:10 2001
@@ -35,6 +35,7 @@
 PHP_FUNCTION(ircg_part);
 PHP_FUNCTION(ircg_register_current_conn);
 PHP_FUNCTION(ircg_msg);
+PHP_FUNCTION(ircg_nick);
 PHP_FUNCTION(ircg_disconnect);
 PHP_FUNCTION(ircg_is_conn_alive);
 PHP_FUNCTION(ircg_lookup_format_messages);



-- 
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