--- loncom/debugging_tools/dump_db.c 2006/06/19 21:21:47 1.1 +++ loncom/debugging_tools/dump_db.c 2006/08/24 22:46:30 1.2 @@ -4,6 +4,42 @@ #include #include #include +#include + +static const char c2x_table[] = "0123456789abcdef"; + +void c2x(unsigned what, unsigned char prefix, char *where, + unsigned int offset) +{ + where[offset] = prefix; + where[offset+1] = c2x_table[what >> 4]; + where[offset+2] = c2x_table[what & 0xf]; +} + + +datum* http_escape(datum* data) +{ + datum *escaped_data; + escaped_data = malloc(sizeof(datum)); + escaped_data->dsize = (3 * data->dsize) + 3; + escaped_data->dptr = malloc(escaped_data->dsize); + unsigned int c,i,j; + + j=0; + for (i=0;idsize;i++) { + c = data->dptr[i]; + if (!isalnum(c)) { + c2x(c, '%', escaped_data->dptr, j); + j+=3; + } else { + escaped_data->dptr[j] = c; + j++; + } + } + escaped_data->dsize=j; + return escaped_data; +} + void usage() { @@ -14,22 +50,32 @@ void read_db(char *filename) { GDBM_FILE db; datum key, nextkey, content; + datum *escaped_key, *escaped_content; db = gdbm_open(filename, 0, GDBM_READER, 0, 0); if (db == NULL) { - printf("Unable to open db %s beacsue of %s (%d) -- %s (%d)\n",filename, - gdbm_strerror(gdbm_errno),gdbm_errno,strerror(errno),errno); + printf("ERROR:Unable to open db %s because of %s (%d) -- %s (%d)\n", + filename,gdbm_strerror(gdbm_errno),gdbm_errno,strerror(errno), + errno); return; } key = gdbm_firstkey(db); while ( key.dptr ) { content = gdbm_fetch(db, key); - fwrite(key.dptr, key.dsize, sizeof(char), stdout); + escaped_key = http_escape(&key); + escaped_content = http_escape(&content); + fwrite(escaped_key->dptr, + escaped_key->dsize, sizeof(char), stdout); printf(" -> "); - fwrite(content.dptr, content.dsize, sizeof(char), stdout); + fwrite(escaped_content->dptr, + escaped_content->dsize, sizeof(char), stdout); printf("\n"); free(content.dptr); + free(escaped_content->dptr); + free(escaped_content); + free(escaped_key->dptr); + free(escaped_key); nextkey = gdbm_nextkey(db, key); free(key.dptr); key = nextkey; @@ -61,3 +107,4 @@ int main(int argc, char **argv) return 0; } + 500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.