/* CGI utility function definitions - C version */ static char hex2char(char *x) /****************************************************************/ /* converts the two digit hex number pointed to by x to the */ /* corresponding ASCII character. */ /****************************************************************/ { char c; /* note : (x & 0xdf) makes x upper case */ c = (x[0] >= 'A' ? ((x[0] & 0xdf) - 'A') + 10: (x[0] - '0')); c *=16; c +=(x[1] >= 'A' ? ((x[1] & 0xdf) - 'A') + 10: (x[1] - '0')); return c; } void splitword(char *output, char *input, char separator) /*************************************************************************/ /* extracts first word terminated by the separator character from input, */ /* places it in output and left shifts rest of input */ /*************************************************************************/ { int i,j; for (i=0; input[i] && (input[i] != separator); i++) output[i] = input[i]; output[i] = '\0'; if (input[i]) i++; else { input[0] = '\0'; return; } /* left shift the rest */ for (j=0; input[i]; ) input[j++] = input[i++]; input[j] = '\0'; } void unescape_url(char *url) /****************************************************************/ /* decodes the CGI encoded string from the web browser */ /****************************************************************/ { int i, j; for (i=0, j=0; url[j]; ++i,++j) { /* replace all hex values with corresponding characters */ if ((url[i] = url[j]) == '%') { url[i] = hex2char(&url[j+1]); j += 2; } else if (url[i] == '+') url[i] = ' '; } url[i] = '\0'; /* terminate url after the processing */ }