#include #include #include #include #include #include #include #include #include #include "../const.h" #include "modules.h" int MainModule(struct struct_module *s_module); void Analyse(struct struct_client *s_client, char *buf, int state); char *s_buf_client[MAX_CLIENT]; int MainModule(struct struct_module *s_module) { int i; BindModule(s_module, Analyse, "Content-type", "text/html"); for(i = 0; i < MAX_CLIENT; i++) // initialisation de la structure s_buf_client[i] = NULL; return 0; } void Analyse(struct struct_client *s_client, char *buf, int state) { int begin; int size; TidyBuffer output = {0}; TidyBuffer errbuf = {0}; TidyDoc tdoc; int rc = -1; Bool ok; begin = 0; if(state == RECV) { if(s_buf_client[s_client->numero] == NULL) { begin = 1; size = 0; } else size = strlen(s_buf_client[s_client->numero]); //printf("REALLOC (%d) = %d\n",s_client->numero, (sizeof(char)*(strlen(buf)+size))); s_buf_client[s_client->numero] = realloc(s_buf_client[s_client->numero], (sizeof(char)*(strlen(buf)+size))); if(begin != 1) strcat(s_buf_client[s_client->numero], buf); else strcpy(s_buf_client[s_client->numero], buf); } else if(state == END) { tdoc = tidyCreate(); // Initialize "document" ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes ); // Convert to XHTML if ( ok ) rc = tidySetErrorBuffer( tdoc, &errbuf ); // Capture diagnostics if ( rc >= 0 ) rc = tidyParseString( tdoc, s_buf_client[s_client->numero] ); // Parse the input if ( rc >= 0 ) rc = tidyCleanAndRepair( tdoc ); // Tidy it up! if ( rc >= 0 ) rc = tidyRunDiagnostics( tdoc ); // Kvetch // if ( rc > 1 ) // If error, force output. // rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 ); // if ( rc >= 0 ) rc = tidySaveBuffer( tdoc, &output ); // Pretty Print tidyBufFree( &errbuf ); tidyRelease( tdoc ); printf("SEND TIDY\n"); //printf("%s\n", output.bp); SendClient(s_client, output.bp, output.size); if(s_buf_client[s_client->numero] != NULL) { printf("FREE (%d)\n",s_client->numero); free(s_buf_client[s_client->numero]); s_buf_client[s_client->numero] = NULL; } printf("Tidy End\n"); tidyBufFree( &output ); } else if(state == ERROR) { if(s_buf_client[s_client->numero] != NULL) { printf("FREE (%d)\n",s_client->numero); free(s_buf_client[s_client->numero]); s_buf_client[s_client->numero] = NULL; } } }