1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-03 06:53:13 +02:00

Move StripControlCodes() from message.c to misc.c.

Because I need in the core (again) due to early calls / calls during
rehashes / etc...
This commit is contained in:
Bram Matthys
2022-05-23 10:10:47 +02:00
parent 8c1a858d2e
commit 3fbdb7fd4b
5 changed files with 101 additions and 104 deletions
+1 -1
View File
@@ -779,7 +779,6 @@ extern MODVAR int (*match_spamfilter)(Client *client, const char *str_in, int ty
extern MODVAR int (*match_spamfilter_mtags)(Client *client, MessageTag *mtags, const char *cmd);
extern MODVAR int (*join_viruschan)(Client *client, TKL *tk, int type);
extern MODVAR const char *(*StripColors)(const char *text);
extern MODVAR const char *(*StripControlCodes)(const char *text);
extern MODVAR void (*spamfilter_build_user_string)(char *buf, const char *nick, Client *acptr);
extern MODVAR void (*send_protoctl_servers)(Client *client, int response);
extern MODVAR int (*verify_link)(Client *client, ConfigItem_link **link_out);
@@ -1268,3 +1267,4 @@ extern void procio_post_rehash(int failure);
/* end of proc i/o */
extern int minimum_msec_since_last_run(struct timeval *tv_old, long minimum);
extern long get_connected_time(Client *client);
extern const char *StripControlCodes(const char *text);
-1
View File
@@ -2319,7 +2319,6 @@ enum EfunctionType {
EFUNC_FIND_TKLINE_MATCH_ZAP_EX,
EFUNC_SEND_LIST,
EFUNC_STRIPCOLORS,
EFUNC_STRIPCONTROLCODES,
EFUNC_SPAMFILTER_BUILD_USER_STRING,
EFUNC_SEND_PROTOCTL_SERVERS,
EFUNC_VERIFY_LINK,
-2
View File
@@ -74,7 +74,6 @@ int (*match_spamfilter)(Client *client, const char *str_in, int type, const char
int (*match_spamfilter_mtags)(Client *client, MessageTag *mtags, const char *cmd);
int (*join_viruschan)(Client *client, TKL *tk, int type);
const char *(*StripColors)(const char *text);
const char *(*StripControlCodes)(const char *text);
void (*spamfilter_build_user_string)(char *buf, const char *nick, Client *client);
void (*send_protoctl_servers)(Client *client, int response);
int (*verify_link)(Client *client, ConfigItem_link **link_out);
@@ -340,7 +339,6 @@ void efunctions_init(void)
efunc_init_function(EFUNC_MATCH_SPAMFILTER_MTAGS, match_spamfilter_mtags, NULL);
efunc_init_function(EFUNC_JOIN_VIRUSCHAN, join_viruschan, NULL);
efunc_init_function(EFUNC_STRIPCOLORS, StripColors, NULL);
efunc_init_function(EFUNC_STRIPCONTROLCODES, StripControlCodes, NULL);
efunc_init_function(EFUNC_SPAMFILTER_BUILD_USER_STRING, spamfilter_build_user_string, NULL);
efunc_init_function(EFUNC_SEND_PROTOCTL_SERVERS, send_protoctl_servers, NULL);
efunc_init_function(EFUNC_VERIFY_LINK, verify_link, NULL);
+97
View File
@@ -2473,3 +2473,100 @@ int minimum_msec_since_last_run(struct timeval *tv_old, long minimum)
}
return 0;
}
/* strip color, bold, underline, and reverse codes from a string */
const char *StripControlCodes(const char *text)
{
int i = 0, len = strlen(text), save_len=0;
char nc = 0, col = 0, rgb = 0;
const char *save_text=NULL;
static unsigned char new_str[4096];
while (len > 0)
{
if ( col && ((isdigit(*text) && nc < 2) || (*text == ',' && nc < 3)))
{
nc++;
if (*text == ',')
nc = 0;
}
/* Syntax for RGB is ^DHHHHHH where H is a hex digit.
* If < 6 hex digits are specified, the code is displayed
* as text
*/
else if ((rgb && isxdigit(*text) && nc < 6) || (rgb && *text == ',' && nc < 7))
{
nc++;
if (*text == ',')
nc = 0;
}
else
{
if (col)
col = 0;
if (rgb)
{
if (nc != 6)
{
text = save_text+1;
len = save_len-1;
rgb = 0;
continue;
}
rgb = 0;
}
switch (*text)
{
case 3:
/* color */
col = 1;
nc = 0;
break;
case 4:
/* RGB */
save_text = text;
save_len = len;
rgb = 1;
nc = 0;
break;
case 2:
/* bold */
break;
case 31:
/* underline */
break;
case 22:
/* reverse */
break;
case 15:
/* plain */
break;
case 29:
/* italic */
break;
case 30:
/* strikethrough */
break;
case 17:
/* monospace */
break;
case 0xe2:
if (!strncmp(text+1, "\x80\x8b", 2))
{
/* +2 means we skip 3 */
text += 2;
len -= 2;
break;
}
/*fallthrough*/
default:
new_str[i] = *text;
i++;
break;
}
}
text++;
len--;
}
new_str[i] = 0;
return new_str;
}
+3 -100
View File
@@ -22,7 +22,6 @@
/* Forward declarations */
const char *_StripColors(const char *text);
const char *_StripControlCodes(const char *text);
int ban_version(Client *client, const char *text);
CMD_FUNC(cmd_private);
CMD_FUNC(cmd_notice);
@@ -47,7 +46,6 @@ MOD_TEST()
{
MARK_AS_OFFICIAL_MODULE(modinfo);
EfunctionAddConstString(modinfo->handle, EFUNC_STRIPCOLORS, _StripColors);
EfunctionAddConstString(modinfo->handle, EFUNC_STRIPCONTROLCODES, _StripControlCodes);
EfunctionAdd(modinfo->handle, EFUNC_CAN_SEND_TO_CHANNEL, _can_send_to_channel);
return MOD_SUCCESS;
}
@@ -526,8 +524,10 @@ CMD_FUNC(cmd_tagmsg)
/* Taken from xchat by Peter Zelezny
* changed very slightly by codemastr
* RGB color stripping support added -- codemastr
*
* NOTE: if you change/update/enhance StripColors() then consider changing
* the StripControlCodes() function as well (in misc.c) !!
*/
const char *_StripColors(const char *text)
{
int i = 0, len = strlen(text), save_len=0;
@@ -595,103 +595,6 @@ const char *_StripColors(const char *text)
return new_str;
}
/* strip color, bold, underline, and reverse codes from a string */
const char *_StripControlCodes(const char *text)
{
int i = 0, len = strlen(text), save_len=0;
char nc = 0, col = 0, rgb = 0;
const char *save_text=NULL;
static unsigned char new_str[4096];
while (len > 0)
{
if ( col && ((isdigit(*text) && nc < 2) || (*text == ',' && nc < 3)))
{
nc++;
if (*text == ',')
nc = 0;
}
/* Syntax for RGB is ^DHHHHHH where H is a hex digit.
* If < 6 hex digits are specified, the code is displayed
* as text
*/
else if ((rgb && isxdigit(*text) && nc < 6) || (rgb && *text == ',' && nc < 7))
{
nc++;
if (*text == ',')
nc = 0;
}
else
{
if (col)
col = 0;
if (rgb)
{
if (nc != 6)
{
text = save_text+1;
len = save_len-1;
rgb = 0;
continue;
}
rgb = 0;
}
switch (*text)
{
case 3:
/* color */
col = 1;
nc = 0;
break;
case 4:
/* RGB */
save_text = text;
save_len = len;
rgb = 1;
nc = 0;
break;
case 2:
/* bold */
break;
case 31:
/* underline */
break;
case 22:
/* reverse */
break;
case 15:
/* plain */
break;
case 29:
/* italic */
break;
case 30:
/* strikethrough */
break;
case 17:
/* monospace */
break;
case 0xe2:
if (!strncmp(text+1, "\x80\x8b", 2))
{
/* +2 means we skip 3 */
text += 2;
len -= 2;
break;
}
/*fallthrough*/
default:
new_str[i] = *text;
i++;
break;
}
}
text++;
len--;
}
new_str[i] = 0;
return new_str;
}
/** Check ban version { } blocks, returns 1 if banned and 0 if not. */
int ban_version(Client *client, const char *text)
{