forked from tjjh89017/eserv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cgi_custom.c
104 lines (85 loc) · 2.12 KB
/
cgi_custom.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "eserv/cgi.h"
#include "eserv/session.h"
int cgi_page_sum(ExHttp *pHttp)
{
const char *lAdd, *rAdd;
int sum;
char buf[32];
printf("\n--add.cgi--\n");
print_param(pHttp);
lAdd = get_param_info(pHttp, "lAdd");
rAdd = get_param_info(pHttp, "rAdd");
sum = atoi(lAdd) + atoi(rAdd);
sprintf(buf, "%d", sum);
ex_send_msg(pHttp, NULL, buf, strlen(buf));
return 0;
}
int cgi_page_txt(ExHttp *pHttp)
{
printf("\n--txt.cgi--\n");
print_param(pHttp);
ex_send_file(pHttp, "hello.txt");
return 0;
}
// session test
int cgi_page_login(ExHttp *pHttp)
{
const char *smsg = "login success";
const char *emsg = "login error";
const char *gss = "get session success";
const char *ss = "send session";
//static const char *user = "eserv";
//static const char *passwd = "passwd";
const char *pRet = emsg;
const char *pUser , *pPasswd, *pSession;
printf("\n--login.cgi--\n");
print_param(pHttp);
pSession = sessionFromHeader(get_head_info(pHttp, "Cookie"));
pUser = get_param_info(pHttp, "user");
pPasswd = get_param_info(pHttp, "passwd");
/*
if (strcmp(user, pUser) == 0 && strcmp(passwd, pPasswd) == 0) {
pRet = smsg;
}
*/
//ex_send_msg(pHttp, NULL, pRet, strlen(pRet));
void *data = sessionCheck(pSession);
if(data != NULL){
ex_send_msg(pHttp, NULL, (char*)data, strlen((char*)data));
}
else{
char *session_id = sessionCreate(pUser, "something");
pRet = ss;
ex_send_msg_session(pHttp, NULL, pRet, strlen(pRet), session_id);
}
return 0;
}
int cgi_page_gallery(ExHttp *pHttp)
{
static int count = 0;
char buf[40];
printf("\n--gallery.cgi--\n");
print_param(pHttp);
count++;
if (count > 3) {
sprintf(buf, "All of pictures are shown. Reset");
count = 0;
} else {
sprintf(buf, "No. %d<br /><img src='%d.jpg' />", count, count);
}
ex_send_msg(pHttp, NULL, buf, strlen(buf));
return 0;
}
/*
* Test ex_hash_next if works
*/
int cgi_hash_test(ExHttp *pHttp){
printf("\n---cgi_hash_test---\n");
ex_hashmap *head_map = &pHttp->headMap;
ex_hashlist *cList = ex_hash_next(head_map);
while(cList != NULL){
printf("%s:%s\n", (char*)cList->key, (char*)cList->value);
cList = cList->next;
}
return 0;
}