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
|
#include <fcgiapp.h>
#include <stdlib.h>
#include "main.h"
#define printf(...) FCGX_FPrintF(req->out, __VA_ARGS__)
#define putsF(b) FCGX_FPrintF(req.out,"%s\n", b)
#define get_param(KEY) FCGX_GetParam(KEY, req->envp)
void handle_req(FCGX_Request *req) {
char *value;
printf("Content-Type: text/html\r\n\r\n");
/*
if ((value = get_param("req_METHOD")) != NULL) {
printf("%s ", value);
}
if ((value = get_param("req_URI")) != NULL) {
printf("%s", value);
}
if ((value = get_param("QUERY_STRING")) != NULL) {
printf("?%s", value);
}
if ((value = get_param("SERVER_PROTOCOL")) != NULL) {
printf(" %s", value);
}*/
printf("\n");
}
int main(void) {
int count = 0;
char article[50] = "...", *env;
char* tmp_h = NULL;
int num = 0, i;
int sock;
FCGX_Request req;
FCGX_Init();
sock = FCGX_OpenSocket(":1337", 5);
FCGX_InitRequest(&req, sock, 0);
while(FCGX_Accept_r(&req) >= 0 ) {
handle_req(&req);
env = FCGX_GetParam("QUERY_STRING",req.envp);
if(!env || sscanf(env, "article=%d", &num) != 1)
num = 0;
if( num >= 0)
{
int nb_CR = 0, c;
FILE* fichier = fopen("article/_liste", "r");
if(!fichier)
erreur("Impossible de charger la page. Veuillez reessayer ultérieurement.", &req);
for(nb_CR=-1;nb_CR < num && fgets(article, 50, fichier);++nb_CR);
if(nb_CR != num)
erreur("Article introuvable", &req);
for(tmp_h=article;*tmp_h;tmp_h++)
if( isspace(*tmp_h) )
*tmp_h = '\0';
char date[20], titre[50] = "Vive la lettre H !", ident[50];
int type = getinfo(article, titre, date, ident);
if( titre )
start(titre, "Site d'ache : Articles et présentation de mes projets", &req);
else
start("Ache", "Site d'ache : Articles et présentation de mes projets", &req);
}
++count;
puts("Try");
fflush(NULL);
sideBar(&req);
//sommaire();
slideContenu(article, num,&req);
voirAussi(&req);
end(&req);
FCGX_Finish_r(&req);
}
return 0;
}
|