sas Mon Jul 7 21:16:59 2003 EDT
Modified files: (Branch: PHP_4_3)
/php-src/ext/ircg ircg.c
Log:
Enable HTML-encoding for all IRC data
Encode all channel names in the default format messages
Index: php-src/ext/ircg/ircg.c
diff -u php-src/ext/ircg/ircg.c:1.137.2.13 php-src/ext/ircg/ircg.c:1.137.2.14
--- php-src/ext/ircg/ircg.c:1.137.2.13 Mon Jul 7 11:33:08 2003
+++ php-src/ext/ircg/ircg.c Mon Jul 7 21:16:59 2003
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: ircg.c,v 1.137.2.13 2003/07/07 15:33:08 sas Exp $ */
+/* $Id: ircg.c,v 1.137.2.14 2003/07/08 01:16:59 sas Exp $ */
/* {{{ includes */
@@ -229,8 +229,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 */
@@ -251,39 +251,39 @@
/* {{{ Default format messages */
static char *fmt_msgs_default[] = {
- "[EMAIL PROTECTED]: %m<br />",
+ "[EMAIL PROTECTED]: %m<br />",
"%f: %m<br />",
"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 />",
+ "%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 />",
- "Welcome to channel %c:",
+ "Welcome to channel %6c:",
" %f",
- " are 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 />",
@@ -620,6 +620,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;
@@ -627,8 +628,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;
@@ -650,15 +651,14 @@
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 = fmt_msg->t;
int ntoken = fmt_msg->ntoken;
+ smart_str tmp = {0};
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;
\
@@ -685,37 +685,45 @@
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;
\
}
\
- ircg_js_escape(&encoded_msg, result); \
+ ircg_js_escape(&tmp, result); \
+ smart_str_free(&tmp); \
break;
\
- case P_MIRC:
\
+ case P_HTML:
\
if (!what) break;
\
- if (!encoded) {
\
+ if (use_cache) {
\
ircg_mirc_color_cache(msg, \
- &encoded_msg, channel, \
+ 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;
\
}
for (; ntoken-- > 0; i++) {
switch (t[i].code) {
case C_STRING: smart_str_append_ex(result, t[i].para.ptr, 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) {
@@ -728,8 +736,6 @@
}
stop:
- if (encoded)
- smart_str_free_ex(&encoded_msg, 1);
if (result->c)
smart_str_0(result);
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php