summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ws2a/bugcomment.c8
-rw-r--r--ws2a/testhtmlreplace.c37
2 files changed, 35 insertions, 10 deletions
diff --git a/ws2a/bugcomment.c b/ws2a/bugcomment.c
index eeba8fe..6464314 100644
--- a/ws2a/bugcomment.c
+++ b/ws2a/bugcomment.c
@@ -24,6 +24,14 @@ char* replaceHTML(char* str){
int hex;
sscanf(str+strp,"%%%x",&hex);
//printf("Was:%c\n",(char)hex);
+ if(hex == 0x0D) continue;
+ if(hex == 0x0A){
+ nstr[nstrp] = '\\';
+ nstr[nstrp+1] = 'n';
+ nstrp+=2;
+ strp++;
+ continue;
+ }
nstr[nstrp] = (char)hex;
nstrp++;
strp+=3;
diff --git a/ws2a/testhtmlreplace.c b/ws2a/testhtmlreplace.c
index 56bd5cd..6ac6f90 100644
--- a/ws2a/testhtmlreplace.c
+++ b/ws2a/testhtmlreplace.c
@@ -3,29 +3,43 @@
#include <stdlib.h>
#include <stdint.h>
-void replaceHTML(char* str){
- printf("Replaceing:%s\n",str);
+char* replaceHTML(char* str){
+ //printf("Replaceing:%s\n",str);
char* nstr = malloc((sizeof(char)*strlen(str)) + 1);
if(nstr == NULL){
+ printf("%s%c%c\n","Content-Type:text/html;charset=iso-8859-1",13,10);
printf("Failed to allocate memory!\n");
}
int strp = 0;
int nstrp = 0;
while(str[strp] != '\0'){
- printf("Strp=%d nstrp=%d\n",strp,nstrp);
+ //printf("Strp=%d nstrp=%d\n",strp,nstrp);
if(str[strp] == '+'){
nstr[nstrp] = ' ';
strp++;
nstrp++;
}else if(str[strp] == '%'){
- printf("Hit encodeing!\n");
+ //printf("Hit encodeing!\n");
int hex;
sscanf(str+strp,"%%%x",&hex);
- printf("Was:%c\n",(char)hex);
+ //printf("Was:%c\n",(char)hex);
+ if(hex == 0x0D) continue;
+ if(hex == 0x0A){
+ nstr[nstrp] = '\\';
+ nstr[nstrp+1] = 'n';
+ nstrp+=2;
+ strp++;
+ continue;
+ }
nstr[nstrp] = (char)hex;
nstrp++;
strp+=3;
+ }else if(str[strp] == '\n'){
+ nstr[nstrp] = '\\';
+ nstr[nstrp+1] = 'n';
+ nstrp+=2;
+ strp++;
}else{
nstr[nstrp] = str[strp];
nstrp++;
@@ -33,7 +47,8 @@ void replaceHTML(char* str){
}
}
nstr[nstrp] = '\0';
- printf("Done, str is now:%s\n",nstr);
+ //printf("Done, str is now:%s\n",nstr);
+ return nstr;
}
char* useridhash(char* str){
@@ -67,9 +82,11 @@ char* useridhash(char* str){
}
int main(){
- char teststring[] = "This+is+a+test";
- useridhash(teststring);
- char teststring2[] = "This+is+a+tost";
- useridhash(teststring2);
+ char teststring[] = "This+is+a+test\nWith\nSome\nNewlines";
+ char* parsed = replaceHTML(teststring);
+ printf("%s\n",parsed);
+ char teststring2[] = "This+is+another+test";
+ char* parsed2 = replaceHTML(teststring2);
+ printf("%s\n",parsed2);
return 0;
}