Revision 1.1 |
Revision 1.2 |
# include <stdio.h> // debug
# include <ctype.h> // man 3 toupper
|
# include <stdio.h> // debug
# include <ctype.h> // man 3 toupper
|
# include "utl.h" # include "http_message.h"
|
# include "utl.h" # include "http_message.h"
|
void
|
void filetype(msg * req)
|
filetype ( msg* req)
|
|
{
|
{
|
char* pathname = req->p_pathname;
int i = strlen(pathname)-1;
|
char *pathname = req->p_pathname;
int i = strlen(pathname) - 1;
|
|
|
// for now, we simply assume the suffix is correct.
// Also, we handle .html and .txt only
|
// for now, we simply assume the suffix is correct.
// Also, we handle .html and .txt only
|
|
|
if (
('l'==pathname[i] ) &&
('m'==pathname[i-1]) &&
('t'==pathname[i-2]) &&
('h'==pathname[i-3]) &&
('.'==pathname[i-4])
)
{
req->filetype = HTML;
return;
}
if (
('t'==pathname[i] ) &&
('x'==pathname[i-1]) &&
('t'==pathname[i-2]) &&
|
if (('l' == pathname[i]) &&
('m' == pathname[i - 1]) &&
('t' == pathname[i - 2]) &&
('h' == pathname[i - 3]) && ('.' == pathname[i - 4])) {
req->filetype = HTML;
return;
}
if (('t' == pathname[i]) &&
('x' == pathname[i - 1]) &&
('t' == pathname[i - 2]) && ('.' == pathname[i - 3])) {
req->filetype = TXT;
return;
}
req->filetype = DATA;
return;
|
('.'==pathname[i-3])
)
{
req->filetype = TXT;
return;
}
req->filetype = DATA;
return;
|
|
} /* * consume space, tab, cr, lf * return the vlue read. */
|
} /* * consume space, tab, cr, lf * return the vlue read. */
|
int eat_ws ( FILE* fp )
|
int eat_ws(FILE * fp)
|
{
|
{
|
int head;
for(;;)
{
head = getc(fp);
if ('#' == head) { eat_line(fp); head = getc(fp); }
if( (' ' != head) &&
('\t' != head) &&
('\n' != head) &&
('\r' != head)
|
int head;
for (;;) {
head = getc(fp);
if ('#' == head) {
eat_line(fp);
head = getc(fp);
}
if ((' ' != head) && ('\t' != head) && ('\n' != head) && ('\r' != head))
return head;
|
) return head;
|
|
} } /* * consume a line (e.g. for comment lines beginning w/ #) */
|
} } /* * consume a line (e.g. for comment lines beginning w/ #) */
|
void eat_line ( FILE* fp )
|
void eat_line(FILE * fp)
|
{
|
{
|
int head;
for(;;)
{
head = getc(fp);
if(
('\n' == head) ||
|
int head;
for (;;) {
head = getc(fp);
if (('\n' == head) || ('\r' == head) || ('\0' == head))
return;
}
|
('\r' == head) ||
('\0' == head)
) return;
}
|
|
} /*
|
} /*
|
Line 92 |
Line 78 |
char *start = str; while (*str) {
|
char *start = str; while (*str) {
|
if (*str == '-')
*str = '_';
else
*str = toupper(*str);
|
if (*str == '-')
*str = '_';
else
*str = toupper(*str);
|
|
|
str++;
|
str++;
|
} return start; } /* simple int to ascii (from boa) */
|
} return start; } /* simple int to ascii (from boa) */
|
char* simple_itoa(int i)
|
char *simple_itoa(int i)
|
{
|
{
|
static char local[22];
char *p = &local[21];
do {
*p-- = '0' + i%10;
i /= 10;
} while (i>0);
return p+1;
|
static char local[22];
char *p = &local[21];
do {
*p-- = '0' + i % 10;
i /= 10;
}
while (i > 0);
|
|
return p + 1;
|
}
|
}
|