sas             Mon Feb 26 15:11:06 2001 EDT

  Modified files:              
    /php4/ext/ircg      ircg.c php_ircg.h 
  Log:
  Support for the new whois functionality in ircg
  
  
Index: php4/ext/ircg/ircg.c
diff -u php4/ext/ircg/ircg.c:1.39 php4/ext/ircg/ircg.c:1.40
--- php4/ext/ircg/ircg.c:1.39   Sun Feb 25 22:07:00 2001
+++ php4/ext/ircg/ircg.c        Mon Feb 26 15:11:06 2001
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: ircg.c,v 1.39 2001/02/26 06:07:00 andi Exp $ */
+/* $Id: ircg.c,v 1.40 2001/02/26 23:11:06 sas Exp $ */
 
 #include "php.h"
 #include "php_ini.h"
@@ -55,6 +55,11 @@
        FMT_MSG_MASS_JOIN_BEGIN,
        FMT_MSG_MASS_JOIN_ELEMENT,
        FMT_MSG_MASS_JOIN_END,
+       FMT_MSG_WHOIS_USER,
+       FMT_MSG_WHOIS_SERVER,
+       FMT_MSG_WHOIS_IDLE,
+       FMT_MSG_WHOIS_CHANNEL,
+       FMT_MSG_WHOIS_END,
        NO_FMTS
 };
 
@@ -68,6 +73,7 @@
        PHP_FE(ircg_msg, NULL)
        PHP_FE(ircg_nick, NULL)
        PHP_FE(ircg_topic, NULL)
+       PHP_FE(ircg_whois, NULL)
        PHP_FE(ircg_kick, NULL)
        PHP_FE(ircg_disconnect, NULL)
        PHP_FE(ircg_is_conn_alive, NULL)
@@ -112,7 +118,12 @@
        "%f quits (%m)<br />",
        "Welcome",
        " %f",
-       " in this very fine channel"
+       " in this very fine channel",
+       "%f: user(%t) host(%c) real name(%m)<br />",
+       "%f: server(%c) server info(%m)<br />",
+       "%f has been idle for %m seconds<br />",
+       "%f is on channel %c<br />",
+       "End of whois for %f<br />"
 };
 
 #define MSG(conn, type) \
@@ -353,6 +364,72 @@
        msg_send(conn, &m);
 }
 
+static void whois_user_handler(irconn_t *c, smart_str *nick, smart_str *user,
+               smart_str *host, smart_str *real_name, void *dummy)
+{
+       php_irconn_t *conn = dummy;
+       static smart_str m;
+
+       m.len = 0;
+       format_msg(MSG(conn, FMT_MSG_WHOIS_USER), host->c, user->c, nick->c,
+                       real_name->c, &m);
+       msg_send(conn, &m);
+}
+
+
+static void whois_server_handler(irconn_t *c, smart_str *nick, 
+               smart_str *server, smart_str *server_info, void *dummy)
+{
+       php_irconn_t *conn = dummy;
+       static smart_str m;
+
+       m.len = 0;
+       format_msg(MSG(conn, FMT_MSG_WHOIS_SERVER), server->c, NULL, nick->c,
+                       server_info->c, &m);
+       msg_send(conn, &m);
+}
+
+
+static void whois_idle_handler(irconn_t *c, smart_str *nick, 
+               smart_str *idletime, void *dummy)
+{
+       php_irconn_t *conn = dummy;
+       static smart_str m;
+
+       m.len = 0;
+       format_msg(MSG(conn, FMT_MSG_WHOIS_IDLE), NULL, NULL, nick->c,
+                       idletime->c, &m);
+       msg_send(conn, &m);
+}
+
+static void end_of_whois_handler(irconn_t *c, smart_str *nick, void *dummy)
+{
+       php_irconn_t *conn = dummy;
+       static smart_str m;
+
+       m.len = 0;
+       format_msg(MSG(conn, FMT_MSG_WHOIS_END), NULL, NULL, nick->c, NULL, &m);
+       msg_send(conn, &m);
+}
+
+
+static void whois_channels_handler(irconn_t *c, smart_str *nick, 
+               smart_str *channels, int nr, void *dummy)
+{
+       php_irconn_t *conn = dummy;
+       static smart_str m;
+       int i;
+       
+       m.len = 0;
+
+       for (i = 0; i < nr; i++) {
+               format_msg(MSG(conn, FMT_MSG_WHOIS_CHANNEL), channels[i].c, NULL, 
+                               nick->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;
@@ -515,6 +592,27 @@
        RETVAL_TRUE;
 }
 
+PHP_FUNCTION(ircg_whois)
+{
+#if defined(IRCG_API_VERSION) && IRCG_API_VERSION >= 20010227
+       zval **p1, **p2;
+       php_irconn_t *conn;
+
+       if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &p1, &p2) == FAILURE)
+               WRONG_PARAM_COUNT;
+
+       convert_to_long_ex(p1);
+       convert_to_string_ex(p2);
+
+       conn = lookup_irconn(Z_LVAL_PP(p1));
+
+       if (!conn) RETURN_FALSE;
+       
+       irc_handle_command(&conn->conn, "WHOIS", 1, Z_STRVAL_PP(p2));
+       RETVAL_TRUE;
+#endif
+}
+
 PHP_FUNCTION(ircg_topic)
 {
 #if defined(IRCG_API_VERSION) && IRCG_API_VERSION >= 20010226
@@ -680,6 +778,14 @@
        irc_register_hook(conn, IRCG_USER_KICK, user_kick);
        irc_register_hook(conn, IRCG_USER_QUIT, user_quit);
        irc_register_hook(conn, IRCG_TOPIC, new_topic);
+
+#if defined(IRCG_API_VERSION) && IRCG_API_VERSION >= 20010227
+       irc_register_hook(conn, IRCG_WHOISUSER, whois_user_handler);
+       irc_register_hook(conn, IRCG_WHOISSERVER, whois_server_handler);
+       irc_register_hook(conn, IRCG_WHOISIDLE, whois_idle_handler);
+       irc_register_hook(conn, IRCG_WHOISCHANNELS, whois_channels_handler);
+       irc_register_hook(conn, IRCG_ENDOFWHOIS, end_of_whois_handler);
+#endif
 }
 
 static int ircg_copy_ctcp_msgs(zval **array, php_irconn_t *conn)
Index: php4/ext/ircg/php_ircg.h
diff -u php4/ext/ircg/php_ircg.h:1.6 php4/ext/ircg/php_ircg.h:1.7
--- php4/ext/ircg/php_ircg.h:1.6        Sun Feb 25 22:07:00 2001
+++ php4/ext/ircg/php_ircg.h    Mon Feb 26 15:11:06 2001
@@ -34,6 +34,7 @@
 PHP_FUNCTION(ircg_set_current);
 PHP_FUNCTION(ircg_part);
 PHP_FUNCTION(ircg_register_current_conn);
+PHP_FUNCTION(ircg_whois);
 PHP_FUNCTION(ircg_msg);
 PHP_FUNCTION(ircg_nick);
 PHP_FUNCTION(ircg_kick);



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