diff options
Diffstat (limited to 'main.c')
-rwxr-xr-x | main.c | 453 |
1 files changed, 0 insertions, 453 deletions
@@ -1,453 +0,0 @@ -#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("<!DOCTYPE html>\n" - "<html> " - "<head> " - "<meta charset=\"utf-8\" /><title>%s</title>" - "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />" - "<link rel=\"canonical\" href=\"http://ache.one/\"/>" //<link rel=\"next\" href=\"http://ache.one/index.cgi?page=2\"/>" - "<link rel=\"shortcut icon\" type=\"image/svg\" href=\"/res/ache.ico\" />" - "<link rel=\"stylesheet\" type=\"text/css\" title=\"Design\" href=\"design/design.css\" />" - "<style>" - "@import url(\"design/design.css\");" - "</style>" - "<meta name= \"description\" content=\"%s\" />" - "</head>" - "<body>\n" - , titre, description); -} -void end(FCGX_Request *req) -{ - puts(" <div id=\"foot\"></div>"); - puts("</body>" - "</html>"); -} -void sideBar(FCGX_Request *req) { - puts("<aside id=\"side-bar\">"); - afficherSVG("./res/ache.svg", req); - puts("<h2> Ache </h2>\n" - "<div id=\"desc\">" - " Étudiant en Math-Info <br />" - " <span id=\"about\">GNU\\Linux, C, C++, Python, Math, ... <br /> </span>" - "</div>" - "<nav>" - " <ul>" - " <li class=\"about_bar\">"); - afficherSVG("./res/tw.svg", req); - puts("</li>" - "<li class=\"about_bar\">"); - afficherSVG("./res/gith.svg", req); - puts("</li>" - "<li class=\"about_bar\">"); - afficherSVG("./res/rss.svg", req); - puts("</li>" - "</ul>" - " </nav>" - "<nav><ul>" - "<li class=\"sommaire_blien\"><a href=\"http://ache.one\">Accueil</a></li>" - "<li class=\"sommaire_blien\"><a href=\"http://projet.ache.one/\"><s>Projets</s></a></li>" - "<li class=\"sommaire_blien\"><a href=\"http://ache.one/contact/\">Contact</a></li>" - "</ul></nav>" -"</aside>"); -} -void erreur(const char* motif, FCGX_Request *req) -{ - start("Erreur", "Page d'erreur", req); - puts("<big><big>Error</big></big><br /><br />"); - 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, "<svg ") || strstr(ligne, "< svg")) - break; - } - if( c ) { - do - printf("%s", ligne); - while( fgets(ligne, 200, fichier) ); - } - } -} -void voirAussi(FCGX_Request *req) -{ - fprintf(stdout, "Hello\n"); - int nbArt = 0, i = 0; - FILE* fichier = fopen("article/_liste", "r"); - - if( !fichier ) { - perror(""); - return; - } - char t[50] = {0}; - char* tmp_h = NULL; - - printf("%s", "<div id=\"autres_articles\"><h4>Voir aussi :</h4>"); - while(fgets(t, 50, fichier))++nbArt; - rewind(fichier); - - if( nbArt<5 ) - { - while( fgets(t, 100, fichier)) - { - char date[20] = {0}, titre[50] = {0}, ident[50] = {0}; - for(tmp_h=t;*tmp_h;tmp_h++) - if( isspace(*tmp_h) ) - *tmp_h = '\0'; - - getinfo(t, titre, date, ident); - printf("<div><a href=\"index.cgi?article=%d\">%s</a></div>", i++, titre); - } - fclose(fichier); - } - else - { - char tab[4] = {-1, -1, -1, -1}; - while(i<4) - { - char date[20] = {0}, titre[50] = {0}, ident[50] = {0}; - int has, z; - rewind(fichier); - do - has = rand() % nbArt; - while( memchr(tab, has, 4) ); - z = has; - while( fgets(t, 100, fichier) && has-- ); - for(tmp_h=t;*tmp_h;tmp_h++) - if( isspace(*tmp_h) ) - *tmp_h = '\0'; - getinfo(t, titre, date, ident); - printf("<div><a href=\"index.cgi?article=%d\">%s</a></div>", z, titre); - tab[i++] = z; - } - fclose(fichier); - } - printf("</div>"); -} -void slideContenu(char* article, int num, FCGX_Request* req) -{ - char d[20], t[50] = "Vive la lettre H !", i[50]; - int type = getinfo(article, t, d, i); - (void)num; - int year, month, day; - sscanf(d, "%d/%d/%d", &day, &month, &year); - printf( "<article id=\"contenu\" role=\"article\" class=\"post hentry clearfix\">"); - switch(type) - { - case 0: - { - char tab[50] = {0}; - strncpy(tab, i, strrchr(i, '.')-i); - strcat(tab, ".png"); - printf("<object type=\"image/svg+xml\" data=\"%s\" style=\"float:left;width:100px;height:100px;\">" - "<img src=\"%s\" alt=\"Logo Article\"/>" - "<p>%s</p>" - "</object>",i,tab,i); - } - break; - case 1: - printf("<img id=\"fr\" src=\"%s\" alt=\"%s\" />", i, i); - break; - case 2: - printf("<iframe src=\"%s\" frameborder=\"0\" style=\"border:0;overflow:hidden;width:100px;height:100px;float:left;\"></iframe>", i); - } - printf( - "<header>" - "<h1 id=\"contenu_top2\">%s</h1>" - "<p>Posté le <time datetime=\"%d-%.2d-%d\">%s</time></p>" - "</header>" - , t, year, month, day, d); - - puts("<section class=\"entry-content clearfix\">"); - lireIntro(article, req); - puts("</section>"); - puts("</article>"); -} -void contenu(char* article, int num, FCGX_Request* req) -{ - char d[20], t[50] = "Vive la lettre H !", i[50]; - int type = getinfo(article, t, d, i); - (void)num; - int year, month, day; - sscanf(d, "%d/%d/%d", &day, &month, &year); - printf( - "<article id=\"contenu\" role=\"article\" class=\"post hentry clearfix\">" - "<header>" - "<h1 id=\"contenu_top2\">%s</h1>" - "<p>Posté le <time datetime=\"%d-%.2d-%d\">%s</time></p>" - "</header>" - , t, year, month, day, d); - switch(type) - { - case 0: - { - char tab[50] = {0}; - strncpy(tab, i, strrchr(i, '.')-i); - strcat(tab, ".png"); - printf("<object type=\"image/svg+xml\" data=\"%s\" style=\"float:right;width:200px;height:200px;\">" - "<img src=\"%s\" alt=\"Logo Article\"/>" - "<p>%s</p>" - "</object>",i,tab,i); - } - break; - case 1: - printf("<img id=\"fr\" src=\"%s\" alt=\"%s\" />", i, i); - break; - case 2: - printf("<iframe src=\"%s\" frameborder=\"0\" style=\"border:0;overflow:hidden;width:250px;height:250px;float:right;\"></iframe>", i); - } - puts("<section class=\"entry-content clearfix\">"); - lireArticle(article, req); - puts("</section>"); - puts("</article>"); -} -#define putchar(a) FCGX_PutChar( a, req->out) -void lireArticle(char* chemin, FCGX_Request* req) -{ - int c = 0; - FILE* fichier = fopen(chemin, "r"); - if(fichier) - { - while((c = fgetc (fichier)) != '\n'); - while((c = fgetc (fichier)) != EOF) - { - if(c != 195) - if(c != '\n') - putchar(c); - else - printf("%s", "<br />"); - else - { - c = fgetc (fichier); - switch(c) - { - CaSe(160, "à");// a - CaSe(162, "à"); - CaSe(164, "â"); - CaSe(128, "À"); - CaSe(130, "Â"); - CaSe(132, "Ä"); - CaSe(169, "é");//e - CaSe(168, "è"); - CaSe(170, "è"); - CaSe(171, "ë"); - CaSe(137, "É"); - CaSe(136, "È"); - CaSe(138, "Ê"); - CaSe(139, "Ë");// o - CaSe(180, "õ"); - CaSe(182, "ö"); - CaSe(148, "Ô"); - CaSe(150, "Ö");// u - CaSe(185, "ù"); - CaSe(187, "û"); - CaSe(188, "ü"); - CaSe(153, "Ù"); - CaSe(155, "Û"); - CaSe(156, "Ü"); - CaSe(174, "î");// i - CaSe(175, "ï"); - CaSe(142, "Î"); - CaSe(143, "Ï"); - CaSe(167, "ç");// c - CaSe(135, "Ç"); - default: - printf("%d", c); - } - } - } - fclose(fichier); - } -} -void lireIntro(char* chemin, FCGX_Request* req) -{ - int c = 0; - FILE* fichier = fopen(chemin, "r"); - if(fichier) - { - while((c = fgetc (fichier)) != '\n'); - while((c = fgetc (fichier)) != EOF && c != '\n') { - if(c != 195) - if(c != '\n') - putchar(c); - else - printf("%s", "<br />"); - else - { - c = fgetc (fichier); - switch(c) - { - CaSe(160, "à");// a - CaSe(162, "à"); - CaSe(164, "â"); - CaSe(128, "À"); - CaSe(130, "Â"); - CaSe(132, "Ä"); - CaSe(169, "é");//e - CaSe(168, "è"); - CaSe(170, "è"); - CaSe(171, "ë"); - CaSe(137, "É"); - CaSe(136, "È"); - CaSe(138, "Ê"); - CaSe(139, "Ë");// o - CaSe(180, "õ"); - CaSe(182, "ö"); - CaSe(148, "Ô"); - CaSe(150, "Ö");// u - CaSe(185, "ù"); - CaSe(187, "û"); - CaSe(188, "ü"); - CaSe(153, "Ù"); - CaSe(155, "Û"); - CaSe(156, "Ü"); - CaSe(174, "î");// i - CaSe(175, "ï"); - CaSe(142, "Î"); - CaSe(143, "Ï"); - CaSe(167, "ç");// c - CaSe(135, "Ç"); - default: - printf("%d", c); - } - } - } - fclose(fichier); - } -} -#undef putchar - - -#undef puts -#undef printf -/* -void confirmation(void) -{ - puts("<div id=\"menu\">" - "<div id=\"boutons\">" - "<div id=\"bouton\">" - "<div id=\"close\"><div></div><div></div></div>" - "</div>" - "</div>" - "<div id=\"boutons\">" - "<div id=\"bouton\">" - "<div id=\"reduire\"><div></div></div>" - "</div>" - "</div>" - "<div id=\"menu_mes\"><br/>" - "Voulez confirmez l'envoye de ce ??? ? " - "</div>" - "</div>"); -}*/ -int getinfo(char* chemin, char* titre, char* date, char* image) -{ - char line[300] = "", type[5] = ""; - char** infos; - - FILE* fichier = fopen(chemin, "r"); - if(fichier) - { -///* - fgets(line, 300, fichier); - line[strlen(line)-1] = 0; - infos = allocRegex(line, "([[:print:]]+)\\|([[:print:]]+)\\|([[:print:]]+)\\|([[:print:]]+)()", 5); - fclose(fichier); - - strcpy(titre, infos[1]) ; - strcpy(date , infos[2]) ; - strcpy(type , infos[3]) ; - strcpy(image, infos[4]) ; - - free(infos[0]), free(infos[1]), free(infos[2]), free(infos[3]), free(infos[4]), free(infos); -/* - fscanf(fichier, "%[^|\n]s", titre); - fscanf(fichier, "|%[^\n|]s", date); - fscanf(fichier, "|%[^\n|]s", type); - fscanf(fichier, "|%[^\n|]s", image); - fclose(fichier); - */ - return ((!strcmp(type, "svg")) ? 0 : (!strcmp(type, "png")) ? 1 : (!strcmp(type, "js")) ? 2 : -1); - } - return -2; -} -void imput_(char* str) -{ - char* str2 = str; - do - { - if(*str == '+') - *str2++ = ' '; - else if(*str == '%') - { - int u = 0; - char t[3] = ""; - sscanf(++str, "%2c", t); - sscanf(t, "%x", &u); - *str2++ = u; - ++str; - } - else - *str2++ = *str; - }while(*str++); -} |