http_utils.c

Go to the documentation of this file.
00001 #include <config.h>
00002 
00003 #ifdef HAVE_STRING_H
00004 #include <string.h>
00005 #endif
00006 
00007 #include "http_utils.h"
00008 
00009 
00022 /* ------------------------------------------------------------------ Public */
00023   
00024 
00025 /* Pices from the ancient NCSA HTTPd by Rob McCool */
00026 
00027 char x2c(char *what) {
00028   
00029   register char digit;
00030   
00031   digit = ((what[0] >= 'A') ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0'));
00032   digit *= 16;
00033   digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0'));
00034   
00035   return(digit);
00036   
00037 }
00038 
00039 
00040 void unescape_url(char *url) {
00041   
00042   register int x,y;
00043   
00044   for(x=0,y=0;url[y];++x,++y) {
00045     if((url[x] = url[y]) == '%') {
00046       url[x] = x2c(&url[y+1]);
00047       y+=2;
00048     }
00049   }
00050   url[x] = '\0';
00051   
00052 }
00053 
00054 
00055 char *makeword(char *line, char stop) {
00056 
00057   int x= 0, y;
00058   char *word= xmalloc(sizeof(char) * (strlen(line) + 1));
00059   
00060   for(x=0;((line[x]) && (line[x] != stop));x++)
00061       word[x] = line[x];
00062   
00063   word[x] = '\0';
00064   if(line[x]) ++x;
00065   y=0;
00066   while((line[y++] = line[x++]));
00067   
00068   return word;
00069   
00070 }
00071 
00072 
00073 void plustospace(char *str) {
00074 
00075   register int x;
00076   
00077   for(x=0;str[x];x++) if(str[x] == '+') str[x] = ' ';
00078   
00079 }