decode_query_string.c

Go to the documentation of this file.
00001 
00024 #include <stdlib.h>
00025 #include <stdio.h>
00026 #include <string.h>
00027 
00028 char* decode_query_string(char *query_str) { 
00029   int i;
00030   int j = 0;
00031   char *decoded_query_str = NULL;
00032   int len = strlen(query_str);
00033   char temp[3];
00034   int value;
00035 
00036   if(!(decoded_query_str = (char*)calloc((unsigned int)(len + 1), sizeof(char)))) {
00037     printf("Could not alloc memory for decoded query string buffer!\n");
00038     return NULL;
00039   }
00040 
00041   for(i = 0; i < len; i++) {
00042     
00043     if(query_str[i] == '\%') {
00044       memset(temp, 3, 0);
00045       memcpy(temp, query_str+i+1, 2);
00046       value = 0;
00047       sscanf(temp, "%02X", &value);
00048       decoded_query_str[j++] = value;
00049       i += 2;
00050     }
00051     else {
00052       decoded_query_str[j++] = query_str[i];
00053     }
00054   }
00055 
00056   return decoded_query_str;
00057 }

Generated on Fri Mar 9 19:59:52 2007 for MAD-FCL by  doxygen 1.5.0