sas Tue Jul 8 00:59:48 2003 EDT Modified files: /php-src/ext/ircg ircg.c php_ircg.h php_ircg_private.h php_ircg_tokenizer.c php_ircg_tokenizer.h Log: * Added ircg_lusers(int connection) * Added ircg_names(int connection, string channel [, string target]) * Added ircg_oper(int connection, string name, string password) * Added ircg_list(int connection, string channel) * Added support for RPL_LUSER*, RPL_YOUREOPER, various ERR_* * Added HTML-encoding of all data sources (%c etc.) * Added highest used fd/maximum open fds info to phpinfo()
Index: php-src/ext/ircg/ircg.c diff -u php-src/ext/ircg/ircg.c:1.192 php-src/ext/ircg/ircg.c:1.193 --- php-src/ext/ircg/ircg.c:1.192 Mon Jul 7 11:45:43 2003 +++ php-src/ext/ircg/ircg.c Tue Jul 8 00:59:47 2003 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: ircg.c,v 1.192 2003/07/07 15:45:43 sas Exp $ */ +/* $Id: ircg.c,v 1.193 2003/07/08 04:59:47 sas Exp $ */ /* {{{ includes */ @@ -84,6 +84,8 @@ /* initialized in the IRCG control process, so that we can avoid locking */ struct cache_entry *php_ircg_cache_entries; +#define SEEN_FD(fd) do { if ((fd) > php_ircg->highest_fd) php_ircg->highest_fd = (fd); } while (0) + /* }}} */ /* {{{ ircg_functions[] */ @@ -100,25 +102,15 @@ 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) -#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_is_conn_alive, NULL) @@ -126,12 +118,12 @@ 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 -#if IRCG_API_VERSION >= 20021117 + PHP_FE(ircg_names, NULL) PHP_FE(ircg_invite, NULL) -#endif + 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[] */ }; /* }}} */ @@ -183,46 +175,46 @@ /* {{{ Default format messages */ static char *fmt_msgs_default[] = { - "[%c] %f: %m<br />", - "private from %f: %m<br />", - "%f private to %t: %m<br />", - "%f leaves %c<br />", - "%f joins %c<br />", - "%t was kicked by %f from %c (%m)<br />", - "%f changes topic on %c to %m<br />", + "[EMAIL PROTECTED]: %m<br />", + "%f: %m<br />", + "To %t: %m<br />", + "%f leaves %6c<br />", + "%f joins %6c<br />", + "%t was kicked by %f from %6c (%m)<br />", + "%f changes topic on %6c to %m<br />", "Error: %m<br />", "Fatal Error: %m<br />", "", "", "%f changes nick to %t<br />", "%f quits (%m)<br />", - "Users in channel %c:", + "Welcome to channel %6c:", " %f", - " in the channel %c<br />", + " are in the channel %6c<br />", "%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 />", + "%f is on channel %6c<br />", "End of whois for %f<br />", - "%f sets voice flag of %t to %m on %c<br />", - "%f sets channel operator flag of %t to %m on %c<br />", - "banned from %c: %m<br />", - "end of ban list for %c<br />", + "%f sets voice flag of %t to %m on %6c<br />", + "%f sets channel operator flag of %t to %m on %6c<br />", + "banned from %6c: %m<br />", + "end of ban list for %6c<br />", "You have been disconnected<br />", - "Channel %c has %t users and the topic is '%m'<br />", + "Channel %6c has %t users and the topic is '%m'<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 />", + "End of WHO<br />", + "%f has invited %t to %6c<br />", + "[notice %6c] %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 />", + "%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 />", }; ZEND_DECLARE_MODULE_GLOBALS(ircg); @@ -746,6 +738,56 @@ #endif +static void luserclient_handler(irconn_t *c, smart_str *users, smart_str *services, smart_str *servers, void *dummy) +{ + 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, void *dummy) +{ + 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_handler(irconn_t *c, smart_str *str, void *dummy) +{ + 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_handler(irconn_t *c, smart_str *str, void *dummy) +{ + 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_handler(irconn_t *c, smart_str *str, void *dummy) +{ + 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); +} + /* }}} */ static void error_handler(irconn_t *ircc, int id, int fatal, smart_str *msg, void *conn_data) @@ -1081,6 +1123,7 @@ if (conn->fd == -1) { goto out; } + SEEN_FD(conn->fd); if (fcntl(conn->fd, F_SETFD, 1)) { close(conn->fd); @@ -1235,6 +1278,8 @@ if (conn->fd == -1) goto out; + SEEN_FD(conn->fd); + #ifdef USE_FD2IRCONN ircg_hash_index_update(&h_fd2irconn, conn->fd, &Z_LVAL_PP(p1), sizeof(int), NULL); @@ -1346,6 +1391,31 @@ } /* }}} */ +/* {{{ 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)); + put_irconn(conn); + RETVAL_TRUE; +} +/* }}} */ + /* {{{ proto bool ircg_whois( int connection, string nick) Queries user information for nick on server */ #if IRCG_API_VERSION - 0 >= 20010227 @@ -1599,6 +1669,35 @@ #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), ac > 2 ? Z_STRVAL_PP(p3) : NULL); + put_irconn(conn); + RETVAL_TRUE; +} +/* }}} */ + /* {{{ proto bool ircg_kick(int connection, string channel, string nick, string reason) Kicks user from channel */ #if IRCG_API_VERSION - 0 >= 20010226 @@ -1626,6 +1725,28 @@ #endif /* }}} */ +/* {{{ 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); + put_irconn(conn); + RETVAL_TRUE; +} +/* }}} */ + /* {{{ proto bool ircg_part(int connection, string channel) Leaves a channel */ PHP_FUNCTION(ircg_part) @@ -1911,6 +2032,12 @@ #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); irc_set_map_handle(conn, php_ircg_cb_msg_handle); } @@ -1948,8 +2075,8 @@ } /* }}} */ -/* {{{ proto int ircg_pconnect(void) - ??? */ +/* {{{ proto int ircg_pconnect(string username [, string server [, int port [, string format-msg-set-name [, array ctcp-set [, array user-details [, bool bailout-on-trivial]]]]]]) + Create a persistent IRC connection */ PHP_FUNCTION(ircg_pconnect) { int drop_ref = 0; @@ -2066,8 +2193,8 @@ } /* }}} */ -/* {{{ proto bool ircg_disconnect(void) - ??? */ +/* {{{ proto bool ircg_disconnect(int connection, string reason) + Terminate IRC connection */ PHP_FUNCTION(ircg_disconnect) { zval **id, **reason; @@ -2095,8 +2222,8 @@ } /* }}} */ -/* {{{ proto bool ircg_nick(void) - ??? */ +/* {{{ proto bool ircg_nick(int connection, string newnick) + Changes the nickname */ PHP_FUNCTION(ircg_nick) { zval **id, **newnick; @@ -2119,8 +2246,34 @@ } /* }}} */ -/* {{{ proto bool ircg_notice(void) - ??? */ +/* {{{ proto bool ircg_list(int connection, string channel) + List topic/user count of channel(s) */ +PHP_FUNCTION(ircg_list) +{ + zval **id, **p2; + php_irconn_t *conn; + int ac = ZEND_NUM_ARGS(); + + if (ac != 2 || zend_get_parameters_ex(ac, &id, &p2) == FAILURE) + WRONG_PARAM_COUNT; + + convert_to_long_ex(id); + convert_to_string_ex(p2); + + conn = lookup_irconn(Z_LVAL_PP(id)); + + if (!conn) RETURN_FALSE; + + irc_handle_command(&conn->conn, "LIST", 1, Z_STRVAL_PP(p2)); + put_irconn(conn); + + RETURN_TRUE; +} +/* }}} */ + + +/* {{{ proto bool ircg_notice(int connection, string recipient, string message) + Sends a one-way communication NOTICE to a target */ PHP_FUNCTION(ircg_notice) { zval **id, **recipient, **msg; @@ -2143,6 +2296,9 @@ } /* }}} */ +/* {{{ proto array ircg_eval_ecmascript_params(string params) + Decodes a list of JS-encoded parameters into a native array */ + #define ADD_PARA() do { \ if (para.len) smart_str_0(¶); \ add_next_index_stringl(return_value, \ @@ -2152,8 +2308,6 @@ para.c = 0; \ } while (0) -/* {{{ proto array ircg_eval_ecmascript_params(string params) - ??? */ PHP_FUNCTION(ircg_eval_ecmascript_params) { zval **str; @@ -2258,8 +2412,8 @@ } /* }}} */ -/* {{{ proto bool ircg_msg(void) - ??? */ +/* {{{ proto bool ircg_msg(int connection, string recipient, string message [,bool loop-suppress]) + Delivers a message to the IRC network */ PHP_FUNCTION(ircg_msg) { zval **id, **recipient, **msg, **suppress; @@ -2495,7 +2649,10 @@ php_info_print_table_start(); php_info_print_table_header(2, "Property", "Value"); - + php_ircg_print_table_row("Maximum number of open fds (system limit)", + getdtablesize() TSRMLS_CC); + php_ircg_print_table_row("Highest encountered fd", + php_ircg->highest_fd TSRMLS_CC); php_ircg_print_table_row("Maximum concurrent IRC connections", php_ircg->max_concurrency TSRMLS_CC); php_ircg_print_table_row("Scanner result cache hits", Index: php-src/ext/ircg/php_ircg.h diff -u php-src/ext/ircg/php_ircg.h:1.30 php-src/ext/ircg/php_ircg.h:1.31 --- php-src/ext/ircg/php_ircg.h:1.30 Tue Jun 10 16:03:31 2003 +++ php-src/ext/ircg/php_ircg.h Tue Jul 8 00:59:47 2003 @@ -55,8 +55,13 @@ 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); Index: php-src/ext/ircg/php_ircg_private.h diff -u php-src/ext/ircg/php_ircg_private.h:1.8 php-src/ext/ircg/php_ircg_private.h:1.9 --- php-src/ext/ircg/php_ircg_private.h:1.8 Wed Apr 23 00:02:10 2003 +++ php-src/ext/ircg/php_ircg_private.h Tue Jul 8 00:59:47 2003 @@ -47,6 +47,7 @@ unsigned long fmt_sets_exist, fmt_sets_evicted, fmt_sets_updates, fmt_sets_ignored, fmt_sets_created, fmt_sets_destroyed; unsigned long cache_hits, cache_misses; + int highest_fd; time_t next_gc; Index: php-src/ext/ircg/php_ircg_tokenizer.c diff -u php-src/ext/ircg/php_ircg_tokenizer.c:1.4 php-src/ext/ircg/php_ircg_tokenizer.c:1.5 --- php-src/ext/ircg/php_ircg_tokenizer.c:1.4 Fri May 30 07:41:29 2003 +++ php-src/ext/ircg/php_ircg_tokenizer.c Tue Jul 8 00:59:47 2003 @@ -81,6 +81,7 @@ case '3': mode |= P_NOAUTO_LINKS; goto next; case '4': mode |= P_CONV_BR; goto next; case '5': mode |= P_COND_STOP; goto next; + case '6': mode |= P_HTML; goto next; /* associate mode bits with each command where applicable */ case 'c': NEW_TOKEN(C_CHANNEL, v) = mode; break; @@ -88,8 +89,8 @@ case 't': NEW_TOKEN(C_TO, v) = mode; break; case 'f': NEW_TOKEN(C_FROM, v) = mode; break; case 'r': NEW_TOKEN(C_MESSAGE, v) = mode; break; - case 'm': NEW_TOKEN(C_MESSAGE, v) = mode | P_MIRC; break; - case 'j': NEW_TOKEN(C_MESSAGE, v) = mode | P_MIRC | P_JS; break; + case 'm': NEW_TOKEN(C_MESSAGE, v) = mode | P_HTML; break; + case 'j': NEW_TOKEN(C_MESSAGE, v) = mode | P_HTML | P_JS; break; case '%': NEW_TOKEN(C_PERCENT, v) = 0; break; @@ -110,20 +111,17 @@ smart_str *to, smart_str *from, smart_str *msg, smart_str *result, const char *username, int username_len, int *status) { - smart_str encoded_msg = {0}; - int encoded = 0; int i = 0; const token_t *t; int ntoken; - + smart_str tmp = {0}; + if (!fmt_msg) return; ntoken = fmt_msg->ntoken; t = fmt_msg->t; - php_ircg->exec_fmt_msgs++; - -#define IRCG_APPEND(what) \ +#define IRCG_APPEND(what, use_cache) \ if (t[i].para.v & P_COND_STOP) { \ if (username_len != what->len || memcmp(what->c, username, username_len) != 0) \ goto stop; \ @@ -132,13 +130,13 @@ switch (t[i].para.v & 7) { \ case P_JS: \ if (!what) break; \ - php_ircg_js_escape(what, result); \ + php_ircg_js_escape(what, result); \ break; \ case P_NICKNAME_JS: { \ smart_str tmp = {0}; \ if (!what) break; \ php_ircg_nickname_unescape(what, &tmp); \ - php_ircg_js_escape(&tmp, result); \ + php_ircg_js_escape(&tmp, result); \ smart_str_free_ex(&tmp, 1); \ break; \ } \ @@ -150,27 +148,35 @@ if (!what) break; \ smart_str_append_ex(result, what, 1); \ break; \ - case P_MIRC_JS: \ + case P_HTML_JS: \ if (!what) break; \ - if (!encoded) { \ + if (use_cache) { \ ircg_mirc_color_cache(msg, \ - &encoded_msg, channel, \ + &tmp, channel, \ + !(t[i].para.v & P_NOAUTO_LINKS), \ + t[i].para.v & P_CONV_BR); \ + } else { \ + ircg_mirc_color(what->c, &tmp, \ + what->len, \ !(t[i].para.v & P_NOAUTO_LINKS), \ t[i].para.v & P_CONV_BR); \ - encoded = 1; \ } \ - php_ircg_js_escape(&encoded_msg, result); \ + php_ircg_js_escape(&tmp, result); \ + smart_str_free(&tmp); \ break; \ - case P_MIRC: \ + case P_HTML: \ if (!what) break; \ - if (!encoded) { \ - ircg_mirc_color_cache(msg, \ - &encoded_msg, channel, \ + if (use_cache) { \ + ircg_mirc_color_cache(msg, \ + result, channel, \ + !(t[i].para.v & P_NOAUTO_LINKS), \ + t[i].para.v & P_CONV_BR); \ + } else { \ + ircg_mirc_color(what->c, result, \ + what->len, \ !(t[i].para.v & P_NOAUTO_LINKS), \ t[i].para.v & P_CONV_BR); \ - encoded = 1; \ } \ - smart_str_append_ex(result, &encoded_msg, 1); \ break; \ } @@ -179,10 +185,10 @@ case C_STRING_INLINE: smart_str_appendl_ex(result, t[i].para.is.buf, t[i].para.is.buf_len, 1); break; case C_STRING: smart_str_append_ex(result, &t[i].para.s, 1); break; - case C_FROM: IRCG_APPEND(from); break; - case C_TO: IRCG_APPEND(to); break; - case C_CHANNEL: IRCG_APPEND(channel); break; - case C_MESSAGE: IRCG_APPEND(msg); break; + case C_FROM: IRCG_APPEND(from, 0); break; + case C_TO: IRCG_APPEND(to, 0); break; + case C_CHANNEL: IRCG_APPEND(channel, 0); break; + case C_MESSAGE: IRCG_APPEND(msg, 1); break; case C_PERCENT: smart_str_appendc_ex(result, '%', 1); break; case C_TERMINATE_1: /* auth by username */ if (ntoken > 0 && t[i+1].code == C_STRING) { @@ -195,11 +201,10 @@ } stop: - if (encoded) - smart_str_free_ex(&encoded_msg, 1); if (result->c) smart_str_0(result); + php_ircg->exec_fmt_msgs++; } Index: php-src/ext/ircg/php_ircg_tokenizer.h diff -u php-src/ext/ircg/php_ircg_tokenizer.h:1.5 php-src/ext/ircg/php_ircg_tokenizer.h:1.6 --- php-src/ext/ircg/php_ircg_tokenizer.h:1.5 Fri May 30 07:41:29 2003 +++ php-src/ext/ircg/php_ircg_tokenizer.h Tue Jul 8 00:59:47 2003 @@ -41,8 +41,8 @@ P_JS = 1, P_NICKNAME = 2, P_NICKNAME_JS = 3, - P_MIRC = 4, - P_MIRC_JS = 5, + P_HTML = 4, + P_HTML_JS = 5, P_NOAUTO_LINKS = 8, /* Don't automatically convert links */ P_CONV_BR = 16, /* Convert a special character to <br> */ P_COND_STOP = 32, /* If argument != username, stop */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php