Fixing str_replace* and other 64 bit stuff

This commit is contained in:
BlackLight 2011-02-10 00:54:06 +01:00
parent 039a82a71f
commit 0636a82ec2
4 changed files with 63 additions and 27 deletions

2
geo.c
View file

@ -94,7 +94,7 @@ AI_geoinfobyaddr ( const char *ip, double **coord )
"Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n" "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n"
"Connection: close\r\n\r\n" "Connection: close\r\n\r\n"
"%s\r\n", "%s\r\n",
strlen ( query ), query (unsigned long int) strlen ( query ), query
); );
do do

72
regex.c
View file

@ -158,37 +158,73 @@ preg_match ( const char* expr, char* str, char*** matches, int *nmatches )
*/ */
char* char*
str_replace ( char *str, char *orig, char *rep ) str_replace ( char *str, const char *pattern, const char *sub )
{ {
char *new_s = NULL; char *new_s = NULL;
unsigned long int new_len = 0; unsigned int pos = 0,
unsigned long int pos = 0; new_len = 0;
if ( !( pos = (unsigned long int) strstr ( str, orig ))) if ( !( pos = (unsigned int) strstr ( str, pattern )))
return str; {
return strdup ( str );
}
new_len = strlen(str) - strlen(orig) + ((rep) ? strlen(rep) : 0) + 1; pos -= (unsigned int) str;
new_len = strlen ( str ) - strlen ( pattern ) + ((sub) ? strlen ( sub ) : 0);
if ( !( new_s = (char*) malloc ( new_len ))) if ( !( new_s = (char*) malloc ( new_len + 1 )))
{
return NULL; return NULL;
}
memset ( new_s, 0, new_len ); memset ( new_s, 0, new_len );
strncpy ( new_s, str, pos - (unsigned long int) str ); strncpy ( new_s, str, pos );
new_s[ pos - (unsigned long int) str] = 0;
if ( rep ) if ( sub )
{ {
if ( strlen ( rep ) != 0 ) if ( strlen ( sub ) > 0 )
sprintf ( new_s + pos - (unsigned long int) str, "%s%s", rep, (char*) pos + strlen ( orig )); {
else strcat ( new_s, sub );
sprintf ( new_s + pos - (unsigned long int) str, "%s", (char*) pos + strlen ( orig )); }
} else {
sprintf ( new_s + pos - (unsigned long int) str, "%s", (char*) pos + strlen ( orig ));
} }
strcat ( new_s, str + pos + strlen ( pattern ) );
return new_s; return new_s;
} /* ----- end of function str_replace ----- */ } /* ----- end of function str_replace ----- */
/* char* */
/* str_replace ( char *str, char *orig, char *rep ) */
/* { */
/* char *new_s = NULL; */
/* unsigned long int new_len = 0; */
/* unsigned long int pos = 0; */
/* */
/* if ( !( pos = (unsigned long int) strstr ( str, orig ))) */
/* return str; */
/* */
/* new_len = strlen(str) - strlen(orig) + ((rep) ? strlen(rep) : 0) + 1; */
/* */
/* if ( !( new_s = (char*) malloc ( new_len ))) */
/* return NULL; */
/* */
/* memset ( new_s, 0, new_len ); */
/* strncpy ( new_s, str, pos - (unsigned long int) str ); */
/* new_s[ pos - (unsigned long int) str] = 0; */
/* */
/* if ( rep ) */
/* { */
/* if ( strlen ( rep ) != 0 ) */
/* sprintf ( new_s + pos - (unsigned long int) str, "%s%s", rep, (char*) pos + strlen ( orig )); */
/* else */
/* sprintf ( new_s + pos - (unsigned long int) str, "%s", (char*) pos + strlen ( orig )); */
/* } else { */
/* sprintf ( new_s + pos - (unsigned long int) str, "%s", (char*) pos + strlen ( orig )); */
/* } */
/* */
/* return new_s; */
/* } */
/** /**
* \brief Replace all of the occurrences of 'orig' in 'str' with 'rep' * \brief Replace all of the occurrences of 'orig' in 'str' with 'rep'
* \param str String to work on * \param str String to work on
@ -198,7 +234,7 @@ str_replace ( char *str, char *orig, char *rep )
*/ */
char* char*
str_replace_all ( char *str, char *orig, char *rep ) str_replace_all ( char *str, const char *orig, const char *rep )
{ {
char *buf = strdup ( str ); char *buf = strdup ( str );
char *tmp = NULL; char *tmp = NULL;

View file

@ -581,8 +581,8 @@ static const char *outdb_config[] __attribute__ (( unused )) = {
/*****************************************************************/ /*****************************************************************/
int preg_match ( const char*, char*, char***, int* ); int preg_match ( const char*, char*, char***, int* );
char* str_replace ( char*, char*, char *); char* str_replace ( char*, const char*, const char* );
char* str_replace_all ( char*, char*, char* ); char* str_replace_all ( char*, const char*, const char* );
void base64_encode ( const char*, size_t, char** ); void base64_encode ( const char*, size_t, char** );
void base64_decode ( const char*, char** ); void base64_decode ( const char*, char** );

View file

@ -42,7 +42,7 @@
#define HTTP_ERR_RESPONSE_FORMAT "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n" \ #define HTTP_ERR_RESPONSE_FORMAT "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n" \
"<html><head>\n" \ "<html><head>\n" \
"<title>%lu %s</title>\n" \ "<title>%d %s</title>\n" \
"</head><body>\n" \ "</head><body>\n" \
"<h1>%s</h1>\n" \ "<h1>%s</h1>\n" \
"<p>%s</p>\n" \ "<p>%s</p>\n" \
@ -304,7 +304,7 @@ __AI_webservlet_thread ( void *arg )
strtime [ strlen(strtime) - 1 ] = 0; strtime [ strlen(strtime) - 1 ] = 0;
snprintf ( http_headers, max_headers_length, HTTP_RESPONSE_HEADERS_FORMAT, snprintf ( http_headers, max_headers_length, HTTP_RESPONSE_HEADERS_FORMAT,
"HTTP/1.1", 400, "Bad Request", strtime, "HTTP/1.1", 400, "Bad Request", strtime,
config->webserv_banner, "text/html", strlen ( http_response )); config->webserv_banner, "text/html", (unsigned long int) strlen ( http_response ));
free ( strtime ); free ( strtime );
free ( line ); free ( line );
line = NULL; line = NULL;
@ -343,7 +343,7 @@ __AI_webservlet_thread ( void *arg )
strtime [ strlen(strtime) - 1 ] = 0; strtime [ strlen(strtime) - 1 ] = 0;
snprintf ( http_headers, max_headers_length, HTTP_RESPONSE_HEADERS_FORMAT, snprintf ( http_headers, max_headers_length, HTTP_RESPONSE_HEADERS_FORMAT,
http_ver, 404, "Not Found", strtime, http_ver, 404, "Not Found", strtime,
config->webserv_banner, "text/html", strlen ( http_response )); config->webserv_banner, "text/html", (unsigned long int) strlen ( http_response ));
free ( strtime ); free ( strtime );
free ( line ); free ( line );
line = NULL; line = NULL;
@ -361,7 +361,7 @@ __AI_webservlet_thread ( void *arg )
strtime [ strlen(strtime) - 1 ] = 0; strtime [ strlen(strtime) - 1 ] = 0;
snprintf ( http_headers, max_headers_length, HTTP_RESPONSE_HEADERS_FORMAT, snprintf ( http_headers, max_headers_length, HTTP_RESPONSE_HEADERS_FORMAT,
http_ver, 403, "Forbidden", strtime, http_ver, 403, "Forbidden", strtime,
config->webserv_banner, "text/html", strlen ( http_response )); config->webserv_banner, "text/html", (unsigned long int) strlen ( http_response ));
free ( strtime ); free ( strtime );
free ( line ); free ( line );
line = NULL; line = NULL;
@ -483,7 +483,7 @@ __AI_webservlet_thread ( void *arg )
http_ver, 200, "Found", strtime, config->webserv_banner, http_ver, 200, "Found", strtime, config->webserv_banner,
content_type, content_type,
/* strlen ( http_response )); */ /* strlen ( http_response )); */
read_bytes ); (unsigned long int) read_bytes );
} }
free ( strtime ); free ( strtime );
@ -503,7 +503,7 @@ __AI_webservlet_thread ( void *arg )
strtime [ strlen(strtime) - 1 ] = 0; strtime [ strlen(strtime) - 1 ] = 0;
snprintf ( http_headers, max_headers_length, HTTP_RESPONSE_HEADERS_FORMAT, snprintf ( http_headers, max_headers_length, HTTP_RESPONSE_HEADERS_FORMAT,
"HTTP/1.1", 405, "Method Not Allowed", strtime, "text/html", "HTTP/1.1", 405, "Method Not Allowed", strtime, "text/html",
config->webserv_banner, strlen ( http_response )); config->webserv_banner, (unsigned long int) strlen ( http_response ));
free ( strtime ); free ( strtime );
free ( line ); free ( line );
line = NULL; line = NULL;