#include #include #include #ifdef WIN32 #include "ds.h" #else #include #endif #include "chtbl.h" #include "hashpjw.h" #include "cgi_theme_gest.h" #define FALSE 0 #define TRUE 1 //#define DEBUG extern char cgi_BaseName[256]; int cgi_started = FALSE; int cgi_paramparsed = FALSE; typedef struct cgiparam_ { char nom[25]; char value[100]; } cgiparam; CHTbl Parametres; void GererParam(char *param); int TestEgalite(const void *val1, const void *val2) { cgiparam *val_1 = (cgiparam *)val1 , *val_2 = (cgiparam *)val2; int a = strcmp(val_1->nom,val_2->nom); if ( a == 0) a = 1; else a = 0; return a; } int hashage(const void *cle) { return hashpjw((void*) ( ((cgiparam*) cle)->nom)); } void cgi_start() { if ( cgi_started == FALSE ) printf("Content-type: text/html\nCache-Control: no-cache\nPragma: no-cache\n\n"); cgi_started = TRUE; } int cgi_printfile(char *filename) { FILE *fp; char strline[255]; if( (fp = fopen(filename,"rt") ) == NULL ) return -1; do { fgets(strline,255,fp); printf("%s",strline); } while(!feof(fp)); fclose(fp); return 0; } int cgi_parseparam() { #ifdef DEBUG char params[1001]; #else char *params; #endif char temp[126]; int OuQu_onest; int LenParams,index,LenParam,index2,index3; cgiparam *Param; if ( cgi_paramparsed == TRUE ) return 1; chtbl_init(&Parametres,1000,hashage,TestEgalite,free); #ifndef DEBUG params = getenv("QUERY_STRING"); #else strcpy(params,"erreur=consulter"); #endif if (params == NULL) return -1; LenParams = strlen(params); memset(temp,0,126); LenParam=0; for(index=0;index<(LenParams+1);index++) { if ( (params[index] == '&') || (params[index] == 0) ) { if ( (Param = (cgiparam*) malloc(sizeof(cgiparam))) == NULL) return -1; memset(Param,0,sizeof(cgiparam)); OuQu_onest = 0; index3=0; for(index2=0;index2 le parametre est "THEME" ) */ void GererParam(char *param) { ds_t ds_desc; char temp[512]; if (strcmp(param,"THEME")==0) { /* On envois le theme courant*/ printf("%s",get_act_theme()); } else if(strcmp(param,"GET_THEME")==0) { /* On envois la liste de theme */ cgi_parsefile("./theme/listtheme.file"); } else if(strcmp(param,"CGI_BASENAME")==0) { /* On envois le nom de base du cgi */ printf("%s",cgi_BaseName); } else { /* Sinon on va chercher la valeur de la variable "qnx" grace a ds */ ds_desc=ds_register(); memset(temp,0,512); if ( ds_get(ds_desc,param,temp,511) > 0) { printf("%s",temp); } ds_deregister(ds_desc); } }