[srvx-commits] CVS: services/src common.h,1.73,1.74 compat.c,1.9,1.10 compat.h,1.6,1.7 proto-bahamut
Brought to you by:
entrope
|
From: Entrope <en...@us...> - 2002-07-08 15:19:33
|
Update of /cvsroot/srvx/services/src
In directory usw-pr-cvs1:/tmp/cvs-serv17948/src
Modified Files:
common.h compat.c compat.h proto-bahamut.c proto-p10.c tools.c
Log Message:
remove checks and compatibility code for strcasecmp, strncasecmp,
stricmp, strcasestr and strstr functions
add declarations for irccasecmp, ircncasecmp, irccasestr functions
correct use of strstr() in parse_foreach() to be strchr() instead
Index: common.h
===================================================================
RCS file: /cvsroot/srvx/services/src/common.h,v
retrieving revision 1.73
retrieving revision 1.74
diff -C2 -r1.73 -r1.74
*** common.h 7 Jul 2002 03:23:37 -0000 1.73
--- common.h 8 Jul 2002 15:19:30 -0000 1.74
***************
*** 198,202 ****
--- 198,208 ----
const char *preposition(const char *word);
int set_policer_param(const char *param, void *data, void *extra);
+
+ void tools_init(void);
void tools_cleanup(void);
+
+ int irccasecmp(const unsigned char *stra, const unsigned char *strb);
+ int ircncasecmp(const unsigned char *stra, const unsigned char *strb, unsigned int len);
+ const unsigned char *irccasestr(const unsigned char *haystack, const unsigned char *needle);
DECLARE_LIST(string_buffer, char);
Index: compat.c
===================================================================
RCS file: /cvsroot/srvx/services/src/compat.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** compat.c 6 May 2002 23:33:12 -0000 1.9
--- compat.c 8 Jul 2002 15:19:30 -0000 1.10
***************
*** 113,149 ****
#endif
- #if !defined(HAVE_STRCASECMP) && !defined(HAVE_STRICMP)
- extern int strcasecmp(char const * str1, char const * str2)
- {
- unsigned int i;
- int a;
- int b;
-
- if (!str1 || !str2)
- return -1;
-
- /* some versions of tolower() break when given already lowercase characters */
- for (i=0; str1[i]!='\0' && str2[i]!='\0'; i++)
- {
- if (isupper((int)str1[i]))
- a = (int)tolower((int)str1[i]);
- else
- a = (int)str1[i];
-
- if (isupper((int)str2[i]))
- b = (int)tolower((int)str2[i]);
- else
- b = (int)str2[i];
-
- if (a<b)
- return -1;
- if (a>b)
- return +1;
- }
-
- return 0;
- }
- #endif
-
#ifndef HAVE_STRDUP
extern char * strdup(char const * str)
--- 113,116 ----
***************
*** 422,491 ****
#endif
return "Unknown error";
- }
- #endif
-
- #ifndef HAVE_STRNCASECMP
- extern int strncasecmp(char const * str1, char const * str2, unsigned int cnt)
- {
- unsigned int i;
- int a;
- int b;
-
- if (!str1 || !str2)
- return -1;
-
- /* some versions of tolower() break when given already lowercase characters */
- for (i=0; i<cnt && str1[i]!='\0' && str2[i]!='\0'; i++)
- {
- if (isupper((int)str1[i]))
- a = (int)tolower((int)str1[i]);
- else
- a = (int)str1[i];
-
- if (isupper((int)str2[i]))
- b = (int)tolower((int)str2[i]);
- else
- b = (int)str2[i];
-
- if (a<b)
- return -1;
- if (a>b)
- return +1;
- }
-
- return 0;
- }
- #endif
-
- #ifndef HAVE_STRSTR
- char *
- strstr(const char *string, const char *pattern)
- {
- char *cp;
- int len;
-
- len = strlen (pattern);
-
- for (cp = string;cp = strchr (cp, *pattern);) {
- if (strncmp (cp, pattern, len) == 0)
- return cp;
-
- cp++;
- }
- return 0;
- }
- #endif
-
- #ifndef HAVE_STRCASESTR
- const unsigned char *
- strcasestr(const unsigned char *haystack, const unsigned char *needle)
- {
- unsigned int hay_len = strlen(haystack), needle_len = strlen(needle), pos;
- if (hay_len < needle_len) return NULL;
- for (pos=0; pos<(hay_len+1-needle_len); pos++) {
- if (tolower(haystack[pos]) != tolower(*needle)) continue;
- if (!strncasecmp(haystack+pos, needle, needle_len)) return haystack+pos;
- }
- return NULL;
}
#endif
--- 389,392 ----
Index: compat.h
===================================================================
RCS file: /cvsroot/srvx/services/src/compat.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** compat.h 6 May 2002 23:33:12 -0000 1.6
--- compat.h 8 Jul 2002 15:19:30 -0000 1.7
***************
*** 29,41 ****
#endif
- #ifndef HAVE_STRCASECMP
- # ifdef HAVE_STRICMP
- # define strcasecmp(s1, s2) stricmp(s1, s2)
- # else
- extern int strcasecmp(char const * str1, char const * str2);
- # define stricmp(s1, s2) strcasecmp(s1, s2)
- # endif
- #endif
-
#ifndef HAVE_STRDUP
extern char * strdup(char const * str);
--- 29,32 ----
***************
*** 44,59 ****
#ifndef HAVE_STRERROR
extern char const * strerror(int errornum);
- #endif
-
- #ifndef HAVE_STRNCASECMP
- extern int strncasecmp(char const * str1, char const * str2, unsigned int cnt);
- #endif
-
- #ifndef HAVE_STRSTR
- extern char *strstr(const char *string, const char *pattern);
- #endif
-
- #ifndef HAVE_STRCASESTR
- extern const unsigned char *strcasestr(const unsigned char *haystack, const unsigned char *needle);
#endif
--- 35,38 ----
Index: proto-bahamut.c
===================================================================
RCS file: /cvsroot/srvx/services/src/proto-bahamut.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** proto-bahamut.c 8 Jul 2002 14:43:59 -0000 1.5
--- proto-bahamut.c 8 Jul 2002 15:19:30 -0000 1.6
***************
*** 483,487 ****
if (*target_list == '@') {
user = NULL;
! } else if (strstr(target_list, "@")) {
struct server *server;
--- 483,487 ----
if (*target_list == '@') {
user = NULL;
! } else if (strchr(target_list, '@')) {
struct server *server;
Index: proto-p10.c
===================================================================
RCS file: /cvsroot/srvx/services/src/proto-p10.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** proto-p10.c 8 Jul 2002 14:43:59 -0000 1.5
--- proto-p10.c 8 Jul 2002 15:19:30 -0000 1.6
***************
*** 1312,1316 ****
if (*target_list == '@') {
user = NULL;
! } else if (strstr(target_list, "@")) {
struct server *server;
--- 1312,1316 ----
if (*target_list == '@') {
user = NULL;
! } else if (strchr(target_list, '@')) {
struct server *server;
Index: tools.c
===================================================================
RCS file: /cvsroot/srvx/services/src/tools.c,v
retrieving revision 1.106
retrieving revision 1.107
diff -C2 -r1.106 -r1.107
*** tools.c 26 Jun 2002 11:45:28 -0000 1.106
--- tools.c 8 Jul 2002 15:19:30 -0000 1.107
***************
*** 41,45 ****
#endif
-
#include "common.h"
#include "hash.h"
--- 41,44 ----
***************
*** 81,86 ****
};
- extern struct policer_params *oper_policer_params, *luser_policer_params;
-
unsigned long int
base64toint(const unsigned char* s, int count)
--- 80,83 ----
***************
*** 104,107 ****
--- 101,129 ----
}
+ static unsigned char irc_tolower[256];
+
+ int
+ irccasecmp(const unsigned char *stra, const unsigned char *strb) {
+ while (*stra && (irc_tolower[*stra] == irc_tolower[*strb])) stra++, strb++;
+ return irc_tolower[*stra] - irc_tolower[*strb];
+ }
+
+ int
+ ircncasecmp(const unsigned char *stra, const unsigned char *strb, unsigned int len) {
+ while (*stra && (irc_tolower[*stra] == irc_tolower[*strb]) && len) stra++, strb++, len--;
+ return irc_tolower[*stra] - irc_tolower[*strb];
+ }
+
+ const unsigned char *
+ irccasestr(const unsigned char *haystack, const unsigned char *needle) {
+ unsigned int hay_len = strlen(haystack), needle_len = strlen(needle), pos;
+ if (hay_len < needle_len) return NULL;
+ for (pos=0; pos<hay_len+1-needle_len; ++pos) {
+ if ((irc_tolower[haystack[pos]] == irc_tolower[*needle])
+ && !ircncasecmp(haystack+pos, needle, needle_len)) return haystack+pos;
+ }
+ return NULL;
+ }
+
static oper_func_t *of_list;
static unsigned int of_size = 0, of_used = 0;
***************
*** 134,138 ****
--- 156,162 ----
void mod_usermode(struct userNode *user, const char *mode_change) {
+ extern struct policer_params *oper_policer_params, *luser_policer_params;
int add = 1;
+
if (!user || !mode_change || !*mode_change) return;
while (1) {
***************
*** 991,994 ****
--- 1015,1031 ----
memmove(buf->list+from+repl_len, buf->list+from+len, strlen(buf->list+from+len));
strcpy(buf->list+from, repl);
+ }
+
+ void
+ tools_init(void)
+ {
+ unsigned int upr, lwr;
+ for (lwr=0; lwr<256; ++lwr) irc_tolower[lwr] = lwr;
+ for (upr='A', lwr='a'; lwr <= 'z'; ++upr, ++lwr) irc_tolower[upr] = lwr;
+ #ifdef WITH_PROTOCOL_P10
+ for (upr='[', lwr='{'; lwr <= '~'; ++upr, ++lwr) irc_tolower[upr] = lwr;
+ for (upr=0xc0, lwr=0xe0; lwr <= 0xf6; ++upr, ++lwr) irc_tolower[upr] = lwr;
+ for (upr=0xd8, lwr=0xf8; lwr <= 0xfe; ++upr, ++lwr) irc_tolower[upr] = lwr;
+ #endif
}
|