sas Mon Jul 7 10:39:03 2003 EDT Modified files: (Branch: PHP_4_3) /php-src/ext/ircg ircg.c php_ircg.h Log: Add support for who/invite/notice/lusers Add ircg_names/ircg_invite/ircg_lusers/ircg_oper/ircg_who/ircg_list # feature patch applied to PHP_4_3 due to "won't be released status" # of PHP_4 and HEAD being IRCG 3 incompatible.
Index: php-src/ext/ircg/ircg.c diff -u php-src/ext/ircg/ircg.c:1.137.2.11 php-src/ext/ircg/ircg.c:1.137.2.12 --- php-src/ext/ircg/ircg.c:1.137.2.11 Thu Jul 3 02:59:43 2003 +++ php-src/ext/ircg/ircg.c Mon Jul 7 10:39:03 2003 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: ircg.c,v 1.137.2.11 2003/07/03 06:59:43 sas Exp $ */ +/* $Id: ircg.c,v 1.137.2.12 2003/07/07 14:39:03 sas Exp $ */ /* {{{ includes */ @@ -105,6 +105,18 @@ FMT_MSG_DISCONNECTED, FMT_MSG_LIST, FMT_MSG_LISTEND, + FMT_MSG_WHOREPLY1, + FMT_MSG_WHOREPLY2, + FMT_MSG_ENDOFWHO, + FMT_MSG_INVITE, + FMT_MSG_NOTICE_CHAN, + FMT_MSG_NOTICE_TO_ME, + FMT_MSG_NOTICE_FROM_ME, + FMT_MSG_LUSERCLIENT, + FMT_MSG_LUSEROP, + FMT_MSG_LUSERUNKNOWN, + FMT_MSG_LUSERCHANNELS, + FMT_MSG_LUSERME, NO_FMTS }; /* }}} */ @@ -136,6 +148,12 @@ PHP_FE(ircg_register_format_messages, NULL) PHP_FE(ircg_get_username, NULL) PHP_FE(ircg_eval_ecmascript_params, NULL) + PHP_FE(ircg_names, NULL) + PHP_FE(ircg_invite, NULL) + PHP_FE(ircg_lusers, NULL) + PHP_FE(ircg_oper, NULL) + PHP_FE(ircg_who, NULL) + PHP_FE(ircg_list, NULL) {NULL, NULL, NULL} /* Must be the last line in ircg_functions[] */ }; /* }}} */ @@ -260,7 +278,19 @@ "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 />", + "%f is inviting %t to %c<br />", + "[notice %c] %f: %m<br />", + "notice from %f: %m<br />", + "notice to %t: %m<br />", + "%t users, %f services, %r servers<br />", + "%r operators<br />", + "%r unknown connections<br />", + "%r formed channels<br />", + "I have %t clients and %r servers<br />", }; /* }}} */ @@ -885,6 +915,27 @@ msg_send(conn, &m); } +static void notice_handler(irconn_t *ircc, smart_str *chan, smart_str *from, + smart_str *msg, void *conn_data, void *chan_data) +{ + php_irconn_t *conn = conn_data; + smart_str m = {0}; + smart_str s_username; + + smart_str_setl(&s_username, ircc->username, ircc->username_len); + + if (msg->c[0] == '\001') { + handle_ctcp(conn, chan, from, chan?chan:&s_username, msg, &m); + } else if (chan) { + FORMAT_MSG(conn, FMT_MSG_NOTICE_CHAN, chan, &s_username, from, msg, &m, conn->conn.username, conn->conn.username_len); + } else { + FORMAT_MSG(conn, FMT_MSG_NOTICE_TO_ME, NULL, &s_username, from, + msg, &m, conn->conn.username, conn->conn.username_len); + } + + msg_send(conn, &m); +} + static void nick_handler(irconn_t *c, smart_str *oldnick, smart_str *newnick, void *dummy) { @@ -976,6 +1027,104 @@ msg_send(conn, &m); } +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); +} + +static void invite_handler(irconn_t *c, smart_str *nick, smart_str *chan, int mode, void *dummy) +{ + php_irconn_t *conn = dummy; + smart_str m = {0}; + smart_str *from, *to, tmp = {0}; + + smart_str_setl(&tmp, conn->conn.username, conn->conn.username_len); + if (mode == 1) { + from = &tmp; + to = nick; + } else { + from = nick; + to = &tmp; + } + + FORMAT_MSG(conn, FMT_MSG_INVITE, chan, to, from, NULL, &m, + conn->conn.username, conn->conn.username_len); + msg_send(conn, &m); +} + + +static void luserclient_handler(irconn_t *c, smart_str *users, smart_str *services, smart_str *servers) +{ + php_irconn_t *conn = dummy; + smart_str m = {0}; + + FORMAT_MSG(conn, FMT_MSG_LUSERCLIENT, NULL, users, services, servers, &m, + conn->conn.username, conn->conn.username_len); + msg_send(conn, &m); +} + +static void luserme_handler(irconn_t *c, smart_str *users, smart_str *servers) +{ + php_irconn_t *conn = dummy; + smart_str m = {0}; + + FORMAT_MSG(conn, FMT_MSG_LUSERME, NULL, users, NULL, servers, &m, + conn->conn.username, conn->conn.username_len); + msg_send(conn, &m); +} + +static void luserop_t(irconn_t *dummy, smart_str *str) +{ + php_irconn_t *conn = dummy; + smart_str m = {0}; + + FORMAT_MSG(conn, FMT_MSG_LUSEROP, NULL, NULL, NULL, str, &m, + conn->conn.username, conn->conn.username_len); + msg_send(conn, &m); +} + +static void luserunknown_t(irconn_t *dummy, smart_str *str) +{ + php_irconn_t *conn = dummy; + smart_str m = {0}; + + FORMAT_MSG(conn, FMT_MSG_LUSERUNKNOWN, NULL, NULL, NULL, str, &m, + conn->conn.username, conn->conn.username_len); + msg_send(conn, &m); +} + +static void luserchannels_t(irconn_t *dummy, smart_str *str) +{ + php_irconn_t *conn = dummy; + smart_str m = {0}; + + FORMAT_MSG(conn, FMT_MSG_LUSERCHANNELS, NULL, NULL, NULL, str, &m, + conn->conn.username, conn->conn.username_len); + msg_send(conn, &m); +} + /* }}} */ /* {{{ Post-connection error-storage */ @@ -1514,7 +1663,32 @@ } /* }}} */ -/* {{{ proto bool ircg_whois( int connection, string nick) +/* {{{ proto bool ircg_oper(int connection, string name, string password) + Elevates privileges to IRC OPER */ +PHP_FUNCTION(ircg_oper) +{ + zval **p1, **p2, **p3; + php_irconn_t *conn; + + if (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); + convert_to_string_ex(p3); + + conn = lookup_irconn(Z_LVAL_PP(p1)); + + if (!conn) RETURN_FALSE; + + irc_handle_command(&conn->conn, "OPER", 2, Z_STRVAL_PP(p2), Z_STRVAL_PP(p3)); + + RETVAL_TRUE; +} +/* }}} */ + +/* {{{ proto bool ircg_whois(int connection, string nick) Queries user information for nick on server */ PHP_FUNCTION(ircg_whois) { @@ -1538,7 +1712,99 @@ } /* }}} */ -/* {{{ proto bool ircg_ignore_add(resource connection, string nick) +/* {{{ 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"); + + put_irconn(conn); + + RETVAL_TRUE; +} +#endif +/* }}} */ + +/* {{{ proto bool ircg_invite(int connection, string channel, string nickname) + INVITEs nickname to channel */ +#if IRCG_API_VERSION >= 20021117 +PHP_FUNCTION(ircg_invite) +{ + zval **p1, **p2, **p3; + php_irconn_t *conn; + + if (ZEND_NUM_ARGS() != 3 + || zend_get_parameters_ex(3, &p1, &p2, &p3) == FAILURE) + WRONG_PARAM_COUNT; + + convert_to_long_ex(p1); + convert_to_string_ex(p2); + convert_to_string_ex(p3); + + conn = lookup_irconn(Z_LVAL_PP(p1)); + + if (!conn) RETURN_FALSE; + + irc_handle_command(&conn->conn, "INVITE", 2, Z_STRVAL_PP(p3), + Z_STRVAL_PP(p2)); + put_irconn(conn); + + RETVAL_TRUE; +} +#endif +/* }}} */ + + +/* {{{ proto bool ircg_names( int connection, string channel [, string target]) + Queries visible usernames */ +PHP_FUNCTION(ircg_names) +{ + zval **p1, **p2, **p3; + php_irconn_t *conn; + int ac = ZEND_NUM_ARGS(); + + if (ac < 2 || ac > 3 || zend_get_parameters_ex(ac, &p1, &p2, &p3) == FAILURE) + + WRONG_PARAM_COUNT; + + convert_to_long_ex(p1); + convert_to_string_ex(p2); + + if (ac > 2) { + convert_to_string_ex(p3); + } + + conn = lookup_irconn(Z_LVAL_PP(p1)); + + if (!conn) RETURN_FALSE; + + irc_handle_command(&conn->conn, "NAMES", ac > 2 ? 2 : 1, Z_STRVAL_PP(p2), Z_STRVAL_PP(p3)); + RETVAL_TRUE; +} +/* }}} */ + +/* {{{ proto bool ircg_ignore_add(int connection, string nick) Adds a user to your ignore list on a server */ PHP_FUNCTION(ircg_ignore_add) { @@ -1721,6 +1987,28 @@ } /* }}} */ +/* {{{ proto bool ircg_lusers(int connection) + IRC network statistics */ +PHP_FUNCTION(ircg_lusers) +{ + zval **p1; + php_irconn_t *conn; + + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &p1) == FAILURE) + WRONG_PARAM_COUNT; + + convert_to_long_ex(p1); + + conn = lookup_irconn(Z_LVAL_PP(p1)); + + if (!conn) RETURN_FALSE; + + irc_handle_command(&conn->conn, "LUSERS", 0); + RETVAL_TRUE; +} +/* }}} */ + + /* {{{ proto bool ircg_part(int connection, string channel) Leaves a channel */ PHP_FUNCTION(ircg_part) @@ -1890,7 +2178,26 @@ #else IFMSG(FMT_MSG_MASS_JOIN_ELEMENT, IRCG_USER_ADD, user_add); #endif - + +#if IRCG_API_VERSION >= 20021115 + if (MSG_NOT_EMPTY(FMT_MSG_WHOREPLY1) + || MSG_NOT_EMPTY(FMT_MSG_WHOREPLY2)) { + irc_register_hook(conn, IRCG_WHOREPLY, whoreply_handler); + } + IFMSG(FMT_MSG_ENDOFWHO, IRCG_ENDOFWHO, endofwho_handler); +#endif + +#if IRCG_API_VERSION >= 20021117 + IFMSG(FMT_MSG_INVITE, IRCG_INVITE, invite_handler); +#endif + + irc_register_hook(conn, IRCG_NOTICE, notice_handler); + + IFMSG(FMT_MSG_LUSERCLIENT, IRCG_LUSERCLIENT, luserclient_handler); + IFMSG(FMT_MSG_LUSERME, IRCG_LUSERME, luserme_handler); + IFMSG(FMT_MSG_LUSEROP, IRCG_LUSEROP, luserop_handler); + IFMSG(FMT_MSG_LUSERUNKNOWN, IRCG_LUSERUNKNOWN, luserunknown_handler); + IFMSG(FMT_MSG_LUSERCHANNELS, IRCG_LUSERCHANNELS, luserchannels_handler); } /* }}} */ Index: php-src/ext/ircg/php_ircg.h diff -u php-src/ext/ircg/php_ircg.h:1.20.2.1 php-src/ext/ircg/php_ircg.h:1.20.2.2 --- php-src/ext/ircg/php_ircg.h:1.20.2.1 Tue Dec 31 11:34:48 2002 +++ php-src/ext/ircg/php_ircg.h Mon Jul 7 10:39:03 2003 @@ -54,6 +54,12 @@ PHP_FUNCTION(ircg_nickname_unescape); PHP_FUNCTION(ircg_get_username); PHP_FUNCTION(ircg_eval_ecmascript_params); +PHP_FUNCTION(ircg_list); +PHP_FUNCTION(ircg_who); +PHP_FUNCTION(ircg_invite); +PHP_FUNCTION(ircg_names); +PHP_FUNCTION(ircg_lusers); +PHP_FUNCTION(ircg_oper); 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