#include "main.h"
char** allocRegex(const char* str_req,const char* str_regex, int nbExp)
{
int err;
regex_t preg;
err = regcomp (&preg, str_regex, REG_EXTENDED);
if (err == 0)
{
int match;
size_t nmatch = 0;
regmatch_t *pmatch = NULL;
nmatch = preg.re_nsub;
pmatch = malloc (sizeof (*pmatch) * nmatch);
if (pmatch)
{
match = regexec (&preg, str_req, nmatch, pmatch, 0);
regfree (&preg);
if (match == 0)
{
char** arg = malloc( nbExp * sizeof *arg);
int i;
for(i = 0; i < nbExp ; ++i)
{
int start = pmatch[i].rm_so;
int end = pmatch[i].rm_eo;
size_t size = end - start;
arg[i] = malloc (sizeof *arg[i] * (size + 1));
if (arg[i])
{
strncpy (arg[i], &str_req[start], size);
arg[i][size] = '\0';
}
}
return arg;
}
else
goto regexErr;
}
else
goto regexErr2;
}
regexErr:
fprintf(stderr, "L'analyse de %s a provoquer une erreur\n", str_req);
exit (EXIT_FAILURE);
regexErr2:
fprintf (stderr, "L'analyse de %s a provoquer 2 erreurs\n", str_req);
exit (EXIT_FAILURE);
}
#define puts(b) FCGX_FPrintF(req->out,"%s\n", b)
#define printf(...) FCGX_FPrintF(req->out, __VA_ARGS__)
void start(char* titre, char* description, FCGX_Request *req) {
puts("Content-Type: text/html;\r\n\r");
printf("\n"
" "
"
"
"%s"
""
"" //"
""
""
""
""
""
"\n"
, titre, description);
}
void end(FCGX_Request *req)
{
puts(" ");
puts(""
"");
}
void sideBar(FCGX_Request *req) {
puts("");
}
void erreur(const char* motif, FCGX_Request *req)
{
start("Erreur", "Page d'erreur", req);
puts("Error
");
puts(motif);
end(req);
exit(0);
}
void afficherSVG(char* chemin, FCGX_Request* req) {
char* c = 0;
char ligne[201] = {0};
FILE* fichier = fopen(chemin, "r");
if(fichier)
{
while( c = fgets (ligne, 200, fichier) ) {
if( strstr(ligne, "