sas             Sat Nov 16 08:51:37 2002 EDT

  Modified files:              
    /php4/ext/ircg      ircg.c php_ircg.h 
  Log:
  Add ircg_who(), and
  Change function table so that it leaves unsupported functions undefined.
  
  
Index: php4/ext/ircg/ircg.c
diff -u php4/ext/ircg/ircg.c:1.141 php4/ext/ircg/ircg.c:1.142
--- php4/ext/ircg/ircg.c:1.141  Thu Nov 14 20:55:27 2002
+++ php4/ext/ircg/ircg.c        Sat Nov 16 08:51:37 2002
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: ircg.c,v 1.141 2002/11/15 01:55:27 sas Exp $ */
+/* $Id: ircg.c,v 1.142 2002/11/16 13:51:37 sas Exp $ */
 
 /* {{{ includes */
 
@@ -54,6 +54,8 @@
 #include <arpa/inet.h>
 #endif
 
+#include "if_irc.h"
+#include "irc_write_buffer.h"
 
 /* }}} */
 
@@ -101,13 +103,18 @@
        FMT_MSG_DISCONNECTED,
        FMT_MSG_LIST,
        FMT_MSG_LISTEND,
+       FMT_MSG_WHOREPLY1,
+       FMT_MSG_WHOREPLY2,
+       FMT_MSG_ENDOFWHO,
        NO_FMTS
 };
 /* }}} */
 
 /* {{{ ircg_functions[] */
 function_entry ircg_functions[] = {
+#ifdef IRCG_PENDING_URL
        PHP_FE(ircg_set_on_die, NULL)
+#endif
        PHP_FE(ircg_pconnect, NULL)
        PHP_FE(ircg_set_current, NULL)
        PHP_FE(ircg_set_file, NULL)
@@ -116,31 +123,41 @@
        PHP_FE(ircg_msg, NULL)
        PHP_FE(ircg_notice, NULL)
        PHP_FE(ircg_nick, NULL)
+#if IRCG_API_VERSION - 0 >= 20010226
        PHP_FE(ircg_topic, NULL)
-       PHP_FE(ircg_channel_mode, NULL) 
+#endif
+#if IRCG_API_VERSION - 0 >= 20010227
+       PHP_FE(ircg_channel_mode, NULL)
+#endif 
        PHP_FE(ircg_html_encode, NULL)
+#if IRCG_API_VERSION - 0 >= 20010227
        PHP_FE(ircg_whois, NULL)
+#endif
+#if IRCG_API_VERSION - 0 >= 20010226
        PHP_FE(ircg_kick, NULL)
+#endif
        PHP_FE(ircg_nickname_escape, NULL)
        PHP_FE(ircg_nickname_unescape, NULL)
+#if IRCG_API_VERSION - 0 >= 20010402
        PHP_FE(ircg_ignore_add, NULL)
+       PHP_FE(ircg_ignore_del, NULL)
+#endif
        PHP_FE(ircg_disconnect, NULL)
        PHP_FE(ircg_fetch_error_msg, NULL)
-       PHP_FE(ircg_ignore_del, NULL)
        PHP_FE(ircg_is_conn_alive, NULL)
        PHP_FE(ircg_lookup_format_messages, NULL)
        PHP_FE(ircg_register_format_messages, NULL)
        PHP_FE(ircg_get_username, NULL)
        PHP_FE(ircg_eval_ecmascript_params, NULL)
+#if IRCG_API_VERSION >= 20021115
+       PHP_FE(ircg_who, NULL)
+#endif
        {NULL, NULL, NULL}      /* Must be the last line in ircg_functions[] */
 };
 /* }}} */
 
 /* {{{ Structures, enumerations, definitions */
 
-#include "if_irc.h"
-#include "irc_write_buffer.h"
-
 #if IRCG_API_VERSION - 0 < 20010303
 # error "Please upgrade to at least IRCG 2.0b1"
 #endif
@@ -256,7 +273,10 @@
        "end of ban list for %c<br />",
        "You have been disconnected<br />",
        "Channel %c has %t users and the topic is '%m'<br />",
-       "End of LIST<br />"
+       "End of LIST<br />",
+       "Nickname %t has ident %f, realname '%m', hostname %c, ",
+       "is on server %t, has flag %f, hopcount %m, and channel %c.<br />",
+       "end of who<br />",
 };
 
 /* }}} */
@@ -984,6 +1004,37 @@
        msg_send(conn, &m);
 }
 
+#if IRCG_API_VERSION >= 20021115
+
+static void whoreply_handler(irconn_t *c, smart_str *chan, smart_str *user,
+        smart_str *host, smart_str *server, smart_str *nick, smart_str *flag,
+        smart_str *hopcount, smart_str *realname, void *dummy,
+        void *chan_data)
+{
+       php_irconn_t *conn = dummy;
+       smart_str m = {0};
+
+       FORMAT_MSG(conn, FMT_MSG_WHOREPLY1, host, nick, user, realname, &m,
+                       conn->conn.username, conn->conn.username_len);
+
+       FORMAT_MSG(conn, FMT_MSG_WHOREPLY2, chan, server, flag, hopcount, &m,
+                       conn->conn.username, conn->conn.username_len);
+       msg_send(conn, &m);
+}
+
+static void endofwho_handler(irconn_t *c, void *dummy)
+{
+       php_irconn_t *conn = dummy;
+       smart_str m = {0};
+
+       FORMAT_MSG(conn, FMT_MSG_ENDOFWHO, NULL, NULL, NULL, NULL, &m,
+                       conn->conn.username, conn->conn.username_len);
+
+       msg_send(conn, &m);
+}
+
+#endif
+
 /* }}} */
 
 /* {{{ Post-connection error-storage */
@@ -1290,9 +1341,9 @@
 
 /* {{{ proto bool ircg_set_on_die(int connection, string host, int port, string data) 
    Sets hostaction to be executed when connection dies */
+#ifdef IRCG_PENDING_URL
 PHP_FUNCTION(ircg_set_on_die)
 {
-#ifdef IRCG_PENDING_URL
        zval **p1, **p2, **p3, **p4;
        php_irconn_t *conn;
        
@@ -1318,8 +1369,8 @@
        conn->od_len = Z_STRLEN_PP(p4);
 
        RETURN_TRUE;
-#endif
 }
+#endif
 /* }}} */
 
 /* {{{ proto string ircg_get_username(int connection)
@@ -1519,9 +1570,9 @@
 
 /* {{{ proto bool ircg_whois( int connection, string nick)
    Queries user information for nick on server */
+#if IRCG_API_VERSION - 0 >= 20010227
 PHP_FUNCTION(ircg_whois)
 {
-#if IRCG_API_VERSION - 0 >= 20010227
        zval **p1, **p2;
        php_irconn_t *conn;
 
@@ -1537,15 +1588,15 @@
        
        irc_handle_command(&conn->conn, "WHOIS", 1, Z_STRVAL_PP(p2));
        RETVAL_TRUE;
-#endif
 }
+#endif
 /* }}} */
 
 /* {{{ proto bool ircg_ignore_add(resource connection, string nick)
    Adds a user to your ignore list on a server */
+#if IRCG_API_VERSION - 0 >= 20010402
 PHP_FUNCTION(ircg_ignore_add)
 {
-#if IRCG_API_VERSION - 0 >= 20010402
        zval **args[2];
        php_irconn_t *conn;
        smart_str s;
@@ -1562,8 +1613,8 @@
        smart_str_setl(&s, Z_STRVAL_PP(args[1]), Z_STRLEN_PP(args[1]));
        if (irc_ignore_check(&conn->conn, &s) == 0)
                irc_ignore_add(&conn->conn, &s, 1);
-#endif
 }
+#endif
 /* }}} */
 
 /* {{{ proto array ircg_fetch_error_msg(int connection)
@@ -1591,9 +1642,9 @@
 
 /* {{{ proto bool ircg_ignore_del(int connection, string nick)
    Removes a user from your ignore list */
+#if IRCG_API_VERSION - 0 >= 20010402
 PHP_FUNCTION(ircg_ignore_del)
 {
-#if IRCG_API_VERSION - 0 >= 20010402
        zval **args[2];
        php_irconn_t *conn;
        smart_str s;
@@ -1611,15 +1662,15 @@
        if (irc_ignore_del(&conn->conn, &s))
                RETURN_FALSE;
        RETURN_TRUE;
-#endif
 }
+#endif
 /* }}} */
 
 /* {{{ proto bool ircg_channel_mode(int connection, string channel, string mode_spec, 
string nick)
    Sets channel mode flags for user */
+#if IRCG_API_VERSION - 0 >= 20010227
 PHP_FUNCTION(ircg_channel_mode)
 {
-#if IRCG_API_VERSION - 0 >= 20010227
        zval **args[4];
        php_irconn_t *conn;
 
@@ -1637,15 +1688,15 @@
        irc_handle_command(&conn->conn, "MODE", 3, Z_STRVAL_PP(args[1]),
                        Z_STRVAL_PP(args[2]), Z_STRVAL_PP(args[3]));
        RETVAL_TRUE;
-#endif
 }
+#endif
 /* }}} */
 
 /* {{{ proto bool ircg_topic(int connection, string channel, string topic)
    Sets topic for channel */
+#if IRCG_API_VERSION - 0 >= 20010226
 PHP_FUNCTION(ircg_topic)
 {
-#if IRCG_API_VERSION - 0 >= 20010226
        zval **p1, **p2, **p3;
        php_irconn_t *conn;
 
@@ -1662,8 +1713,8 @@
        
        irc_handle_command(&conn->conn, "TOPIC", 2, Z_STRVAL_PP(p2), Z_STRVAL_PP(p3));
        RETVAL_TRUE;
-#endif
 }
+#endif
 /* }}} */
 
 /* {{{ proto string ircg_html_encode(string html_text)
@@ -1698,11 +1749,43 @@
 }
 /* }}} */
 
+/* {{{ proto bool ircg_who(int connection, string mask [, bool ops_only])
+   Queries server for WHO information */
+#if IRCG_API_VERSION >= 20021115
+PHP_FUNCTION(ircg_who)
+{
+       int ops = 0;
+       zval **p1, **p2, **p3;
+       php_irconn_t *conn;
+       
+       if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 3
+                       || zend_get_parameters_ex(ZEND_NUM_ARGS(), &p1, &p2, &p3) == 
+FAILURE)
+               WRONG_PARAM_COUNT;
+
+       convert_to_long_ex(p1);
+       convert_to_string_ex(p2);
+
+       if (ZEND_NUM_ARGS() > 2) {
+               convert_to_boolean_ex(p3);
+               ops = Z_BVAL_PP(p3);
+       }
+       
+       conn = lookup_irconn(Z_LVAL_PP(p1));
+
+       if (!conn) RETURN_FALSE;
+
+       irc_handle_command(&conn->conn, "WHO", ops ? 2 : 1, Z_STRVAL_PP(p2), "o");
+       
+       RETVAL_TRUE;
+}
+#endif
+/* }}} */
+
 /* {{{ proto bool ircg_kick(int connection, string channel, string nick, string 
reason)
    Kicks user from channel */
+#if IRCG_API_VERSION - 0 >= 20010226
 PHP_FUNCTION(ircg_kick)
 {
-#if IRCG_API_VERSION - 0 >= 20010226
        zval **p1, **p2, **p3, **p4;
        php_irconn_t *conn;
 
@@ -1720,8 +1803,8 @@
        
        irc_handle_command(&conn->conn, "KICK", 3, Z_STRVAL_PP(p2), Z_STRVAL_PP(p3), 
Z_STRVAL_PP(p4));
        RETVAL_TRUE;
-#endif
 }
+#endif
 /* }}} */
 
 /* {{{ proto bool ircg_part(int connection, string channel)
@@ -1893,7 +1976,14 @@
 #else  
        IFMSG(FMT_MSG_MASS_JOIN_ELEMENT, IRCG_USER_ADD, user_add);
 #endif
-       
+
+#if IRCG_API_VERSION >= 20021115
+       if (MSG(irconn, FMT_MSG_WHOREPLY1)->ntoken
+                       || MSG(irconn, FMT_MSG_WHOREPLY2)->ntoken) {
+               irc_register_hook(conn, IRCG_WHOREPLY, whoreply_handler);
+       }
+       IFMSG(FMT_MSG_ENDOFWHO, IRCG_ENDOFWHO, endofwho_handler);
+#endif
 }
 /* }}} */
 
Index: php4/ext/ircg/php_ircg.h
diff -u php4/ext/ircg/php_ircg.h:1.20 php4/ext/ircg/php_ircg.h:1.21
--- php4/ext/ircg/php_ircg.h:1.20       Sat Sep 21 16:14:18 2002
+++ php4/ext/ircg/php_ircg.h    Sat Nov 16 08:51:37 2002
@@ -54,6 +54,7 @@
 PHP_FUNCTION(ircg_nickname_unescape);
 PHP_FUNCTION(ircg_get_username);
 PHP_FUNCTION(ircg_eval_ecmascript_params);
+PHP_FUNCTION(ircg_who);
 
 PHP_MINIT_FUNCTION(ircg);
 PHP_MSHUTDOWN_FUNCTION(ircg);

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

Reply via email to