diff options
author | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-04-05 18:49:57 +0000 |
---|---|---|
committer | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-04-05 18:49:57 +0000 |
commit | 88a5d0cdda513357496b9d53878618e1620f47e8 (patch) | |
tree | 4f3c2bedbac4b715ff783de5e1c8d1aefe4395af /src/common/strlib.c | |
parent | a7fd6bfe9bcce1862b554f5841d9ff1aedf473e3 (diff) | |
download | hercules-88a5d0cdda513357496b9d53878618e1620f47e8.tar.gz hercules-88a5d0cdda513357496b9d53878618e1620f47e8.tar.bz2 hercules-88a5d0cdda513357496b9d53878618e1620f47e8.tar.xz hercules-88a5d0cdda513357496b9d53878618e1620f47e8.zip |
* Made a crazy attempt to at least partially synchronize login&char code
* Major edit to the way the servers handle ip addresses, making them obey the "host byte order inside, network byte order outside" rule
- hopefully covered all entry- and exit-points for IP address data
- discovered several places where Gravity's client breaks the convention, will need to come up with a suitable countermeasure for that
- other than that, the code should be portable, except for printing and ipban mask testing (those still assume a specific byte order)
- tested both txt and sql in all usual situations; tested single- and multi-server setups, all seems to work (but watch out for hidden bugs!)
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@10162 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common/strlib.c')
-rw-r--r-- | src/common/strlib.c | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/src/common/strlib.c b/src/common/strlib.c index 9d79e2745..327b2daf1 100644 --- a/src/common/strlib.c +++ b/src/common/strlib.c @@ -11,12 +11,15 @@ #include "../common/utils.h" #include "../common/malloc.h" -//----------------------------------------------- -// string lib. -char* jstrescape (char* pt) { + +#define J_MAX_MALLOC_SIZE 65535 + +// escapes a string in-place (' -> \' , \ -> \\ , % -> _) +char* jstrescape (char* pt) +{ //copy from here char *ptr; - int i =0, j=0; + int i = 0, j = 0; //copy string to temporary CREATE(ptr, char, J_MAX_MALLOC_SIZE); @@ -41,10 +44,12 @@ char* jstrescape (char* pt) { } pt[j++] = '\0'; aFree(ptr); - return &pt[0]; + return pt; } -char* jstrescapecpy (char* pt, const char* spt) { +// escapes a string into a provided buffer +char* jstrescapecpy (char* pt, const char* spt) +{ //copy from here //WARNING: Target string pt should be able to hold strlen(spt)*2, as each time //a escape character is found, the target's final length increases! [Skotlex] @@ -75,7 +80,10 @@ char* jstrescapecpy (char* pt, const char* spt) { pt[j++] = '\0'; return &pt[0]; } -int jmemescapecpy (char* pt,char* spt, int size) { + +// escapes exactly 'size' bytes of a string into a provided buffer +int jmemescapecpy (char* pt, const char* spt, int size) +{ //copy from here int i =0, j=0; @@ -100,11 +108,9 @@ int jmemescapecpy (char* pt,char* spt, int size) { return j; } -//----------------------------------------------------- // Function to suppress control characters in a string. -//----------------------------------------------------- -//int remove_control_chars(char *str) { -int remove_control_chars(unsigned char *str) { +int remove_control_chars(char* str) +{ int i; int change = 0; @@ -119,11 +125,11 @@ int remove_control_chars(unsigned char *str) { } //Trims a string, also removes illegal characters such as \t and reduces continous spaces to a single one. by [Foruken] -char *trim(char *str, const char *delim) +char* trim(char* str, const char* delim) { - char *strp = strtok(str,delim); + char* strp = strtok(str,delim); char buf[1024]; - char *bufp = buf; + char* bufp = buf; memset(buf,0,sizeof buf); while(strp) { @@ -143,7 +149,7 @@ char *trim(char *str, const char *delim) //stristr: Case insensitive version of strstr, code taken from //http://www.daniweb.com/code/snippet313.html, Dave Sinkula // -const char *stristr(const char *haystack, const char *needle) +const char* stristr(const char* haystack, const char* needle) { if ( !*needle ) { @@ -153,9 +159,7 @@ const char *stristr(const char *haystack, const char *needle) { if ( TOUPPER(*haystack) == TOUPPER(*needle) ) { - /* - * Matched starting char -- loop through remaining chars. - */ + // matched starting char -- loop through remaining chars const char *h, *n; for ( h = haystack, n = needle; *h && *n; ++h, ++n ) { @@ -164,9 +168,9 @@ const char *stristr(const char *haystack, const char *needle) break; } } - if ( !*n ) /* matched all of 'needle' to null termination */ + if ( !*n ) // matched all of 'needle' to null termination { - return haystack; /* return the start of the match */ + return haystack; // return the start of the match } } } @@ -174,7 +178,7 @@ const char *stristr(const char *haystack, const char *needle) } #ifdef __WIN32 -char *_strtok_r(char *s1, const char *s2, char **lasts) +char* _strtok_r(char *s1, const char *s2, char **lasts) { char *ret; |