thcErrorType thcRenewCookie (char* cookieName, thcLanguageType* language) { thcErrorType errorCode; char content[THC_COOKIE_CONTENT_LENGHT + 1]; char readedContent [THC_COOKIE_CONTENT_LENGHT + 1]; char IP [THC_COOKIE_MAXIMUM_IP_LENGHT + 1]; time_t expiration, localTime; /*Get Local Time*/ localTime = time(NULL); /*Get cookie from user*/ errorCode = mlCgiGetSpecificCookie(cookieName, THC_COOKIE_NAME_LENGHT, content, THC_COOKIE_CONTENT_LENGHT); if (errorCode != ML_CGI_OK) return THC_ERROR_TRYING_TO_GET_COOKIE; errorCode = thcReadCookie(cookieName ,&expiration,readedContent, IP); if (errorCode != THC_OK) return errorCode; /*Check for cookie expiration*/ if (expiration < localTime) return THC_ERROR_EXPIRATED_SESSION; /*Check for cookie content*/ if (strcmp(content, readedContent) != 0) return THC_PERMISSION_DENIED; /*Sends the new cookie*/ expiration = time (NULL) + THC_COOKIE_EXPIRATION; mlCgiSetCookie(cookieName, content, THC_COOKIE_EXPIRATION, NULL, NULL, NULL); /*Saves cookie on file*/ errorCode = thcGenerateCookie(cookieName, &expiration, content, IP); if (errorCode != THC_OK) return errorCode; if (content[0] == 'e') *language = english; if (content[0] == 'b') *language = portuguese; return THC_OK; }
int main (int argc, char **argv) { environmentType enviro; thcUserDataType data; char cookieName [THC_COOKIE_NAME_LENGHT + 1]; char username [THC_NICKNAME_MAXIMUM_LENGHT + 1]; char password [THC_PASSWORD_MAXIMUM_LENGHT + 1]; thcErrorType errorCode; char cookieContent [THC_COOKIE_CONTENT_LENGHT+1]; time_t expiration; char languageString[THC_LANGUAGE_MAXIMUM_LENGHT+1]; thcLanguageType language = THC_DEFAULT_LANGUAGE; /*Initiate and check environment*/ if (mlCgiInitialize (&enviro)) exit (THC_OK); if (enviro == commandLine) { thcGetTextErrorMessage(language, THC_ERROR_INVALID_INTERFACE); exit (THC_OK); } /*Web interface*/ mlCgiBeginHttpHeader ("text/html"); errorCode = mlCgiGetFormStringNoNewLines ("thcLanguage",languageString,THC_LANGUAGE_MAXIMUM_LENGHT); if (errorCode == ML_CGI_OK) { if (strcmp(languageString,"br") == 0) language = portuguese; if (strcmp(languageString,"en") == 0) language = english; } errorCode = mlCgiGetFormStringNoNewLines ("thcUsername", username, THC_NICKNAME_MAXIMUM_LENGHT); if (errorCode != ML_CGI_OK) { thcGetHtmlErrorMessage(language, THC_ERROR_ON_WEB_FORM); exit(THC_OK); } errorCode = mlCgiGetFormStringNoNewLines ("thcPassword", password, THC_PASSWORD_MAXIMUM_LENGHT); if (errorCode != ML_CGI_OK) { thcGetHtmlErrorMessage(language, THC_ERROR_ON_WEB_FORM); exit(THC_OK); } errorCode = thcUserLogin(username,password,&data); if (errorCode != THC_OK) { mlCgiEndHttpHeader (); thcGetHtmlErrorMessage(language,errorCode); exit(THC_OK); } /*Login correct*/ /*Generate the cookie content*/ errorCode = thcGenerateCookieContent(cookieContent); if (errorCode != THC_OK) { mlCgiEndHttpHeader (); thcGetHtmlErrorMessage(language,errorCode); exit(THC_OK); } /*send language information to cookie*/ if (language == english) cookieContent[0] = 'e'; if (language == portuguese) cookieContent[0] = 'b'; /*Generate cookie name using the user ID*/ if (sprintf(cookieName,THC_COOKIE_NAME_PRINTF_FORMAT,data.UID) != THC_COOKIE_NAME_LENGHT) { mlCgiEndHttpHeader (); thcGetHtmlErrorMessage(language,THC_ERROR_GENERATING_COOKIE_NAME); exit(THC_OK); } /*send cookie*/ expiration = time(NULL) + THC_COOKIE_EXPIRATION; errorCode = thcGenerateCookie(cookieName, &expiration, cookieContent, THC_DEFAULT_COOKIE_IP); if (errorCode != THC_OK) { mlCgiEndHttpHeader (); thcGetHtmlErrorMessage(language,errorCode); exit(THC_OK); } /*Sends the cookie to user*/ mlCgiSetCookie(cookieName, cookieContent, THC_COOKIE_EXPIRATION, NULL, NULL, NULL); mlCgiEndHttpHeader (); if (data.flag == abeyance) { thcWebShowHeader(); printf("<body> \n"); printf(" <div class=\"content\"> \n"); printf(" <h1>%s</h1> \n",menssage[1][language]); printf(" <a href='thcCgiShowChangePasswordForm.cgi?thcNickname=%s'>%s</a> \n",data.nickname,menssage[0][language]); printf(" </div> \n"); printf("</body> \n"); exit(THC_OK); } if (data.flag == passwordReset) { thcWebShowHeader(); printf("<body> \n"); printf(" <div class=\"content\"> \n"); printf(" <h1>%s</h1> \n",menssage[1][language]); printf(" <a href='thcCgiShowChangePasswordForm.cgi?thcNickname=%s'>%s</a> \n",data.nickname,menssage[2][language]); printf(" </div> \n"); printf("</body> \n"); exit(THC_OK); } /*Prints header*/ thcWebShowHeader(); printf(" <body> \n"); printf(" <div class=\"content\"> \n"); printf(" <h1>%s</h1> \n",menssage[1][language]); printf(" </div> \n"); printf(" \n"); /*Prints menu*/ thcWebShowMenu(language,data); /*Prints footer*/ thcWebShowFooter(); mlCgiFreeResources (); return THC_OK; }
int main (int argc, char **argv) { unsigned errorCode; char cookieName[COOKIE_NAME_LENGTH +1]; char cookieValue[COOKIE_VALUE_LENGTH +1]; char cookieFileName[MAX_LENGTH_LONG_FILENAME +1]; char temp[20 +1]; userIdType callerOfProgramId, givenId, givenId2, givenId3, givenId4; if ((errorCode = mlCgiInitialize ()) != ML_CGI_OK) { if (errorCode == ML_CGI_FATAL_ERROR) showHtmlErrorPage (FATAL_ERROR); if (errorCode == ML_CGI_MEMORY_ALLOCATION_ERROR) showHtmlErrorPage (MEMORY_ALLOCATION_ERROR); if (errorCode == ML_CGI_INVALID_CONTENT_LENGTH) showHtmlErrorPage (INVALID_CONTENT_LENGTH); if (errorCode == ML_CGI_IO_ERROR) showHtmlErrorPage (CGI_IO_ERROR); if (errorCode == ML_CGI_INVALID_CONTENT_TYPE) showHtmlErrorPage (INVALID_CONTENT_TYPE); if (errorCode == ML_CGI_INVALID_REQUEST_METHOD) showHtmlErrorPage (INVALID_REQUEST_METHOD); exit (ML_CGI_OK); } if (!isCgi) { printf ("%s\n", showTextErrorMessage (IS_NOT_CGI)); exit (ML_CGI_OK); } mlCgiBeginHttpHeader ("text/html"); if ((errorCode = mlCgiGetFormStringNoNewLines ("cookieName", cookieName, COOKIE_NAME_LENGTH)) != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) showHtmlErrorPage (FORM_FIELD_NOT_FOUND); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_FIELD_LENGTH); exit (ML_CGI_OK); } if ((errorCode = mlCgiGetSpecificCookie (cookieName, COOKIE_NAME_LENGTH, cookieValue, COOKIE_VALUE_LENGTH)) != ML_CGI_OK) { mlCgiEndHttpHeader(); mlCgiFreeResources (); if (errorCode == ML_CGI_INVALID_COOKIE_NAME) showHtmlErrorPage (INVALID_COOKIE_NAME); if (errorCode == ML_CGI_INVALID_COOKIE_VALUE) showHtmlErrorPage (INVALID_COOKIE_VALUE); if (errorCode == ML_CGI_COOKIE_NOT_FOUND) showHtmlErrorPage (COOKIE_NOT_FOUND); exit (ML_CGI_OK); } if ((errorCode = validateCookie (cookieName, cookieValue, mlCgiEnvironmentVariablesValues[ML_CGI_REMOTE_ADDRESS])) != OK) { if (errorCode != VALIDATE_COOKIE__COOKIE_FILE_DOES_NOT_EXIST) { if ((errorCode = getCookieValue (cookieName, cookieValue)) != OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); showHtmlErrorPage (errorCode); exit (ML_CGI_OK); } if ((errorCode = mlCgiSetCookie (cookieName, cookieValue, 0, NULL, NULL, NULL)) != ML_CGI_OK) { mlCgiEndHttpHeader(); mlCgiFreeResources (); if (errorCode == ML_CGI_INVALID_COOKIE_NAME) showHtmlErrorPage (INVALID_COOKIE_NAME); if (errorCode == ML_CGI_INVALID_COOKIE_VALUE) showHtmlErrorPage (INVALID_COOKIE_VALUE); if (errorCode == ML_CGI_INVALID_COOKIE_EXPIRATION) showHtmlErrorPage (INVALID_COOKIE_EXPIRATION); exit (ML_CGI_OK); } if ((errorCode = getLongFilename (COOKIES_DIR, cookieName, cookieFileName)) != OK) { mlCgiEndHttpHeader(); mlCgiFreeResources (); showHtmlErrorPage (errorCode); exit (ML_CGI_OK); } remove (cookieFileName); } mlCgiEndHttpHeader(); mlCgiFreeResources (); showHtmlErrorPage (errorCode); exit (ML_CGI_OK); } if ((errorCode = mlCgiGetFormStringNoNewLines ("userId", temp, 20)) != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) showHtmlErrorPage (FORM_USER_ID_NOT_FOUND); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_USER_ID_LENGTH); exit (ML_CGI_OK); } givenId = strtoul (temp, NULL, 10); callerOfProgramId = strtoul (cookieName, NULL, 10); if ((errorCode = mlCgiGetFormStringNoNewLines ("userId2", temp, 20)) != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) showHtmlErrorPage (FORM_USER_ID_NOT_FOUND); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_USER_ID_LENGTH); exit (ML_CGI_OK); } givenId2 = strtoul (temp, NULL, 10); if ((errorCode = mlCgiGetFormStringNoNewLines ("userId3", temp, 20)) != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) showHtmlErrorPage (FORM_USER_ID_NOT_FOUND); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_USER_ID_LENGTH); exit (ML_CGI_OK); } givenId3 = strtoul (temp, NULL, 10); if ((errorCode = mlCgiGetFormStringNoNewLines ("userId4", temp, 20)) != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) showHtmlErrorPage (FORM_USER_ID_NOT_FOUND); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_USER_ID_LENGTH); exit (ML_CGI_OK); } givenId2 = strtoul (temp, NULL, 10); if ((callerOfProgramId != 0) && (givenId != callerOfProgramId) && (givenId2 != callerOfProgramId) && (givenId3 != callerOfProgramId) && (givenId4 != callerOfProgramId)) { mlCgiEndHttpHeader (); mlCgiFreeResources (); showHtmlErrorPage (YOU_CAN_ONLY_EDIT_YOUR_PARENT_RELATIONSHIP); exit (ML_CGI_OK); } mlCgiEndHttpHeader(); mlCgiFreeResources (); if ((errorCode = editParentRelationship (givenId, givenId2, givenId3, givenId4)) != OK) showHtmlErrorPage (errorCode); else showHtmlOKPage (); exit (ML_CGI_OK); }
int main (int argc, char **argv) { unsigned ret; char cookieName[COOKIE_NAME_LENGTH +1]; char cookieValue[COOKIE_VALUE_LENGTH +1]; char *cookieFileName; if ((ret = mlCgiInitialize ()) != ML_CGI_OK) { showHtmlErrorPage (E_SHOW_WELCOME_PAGE); exit (ML_CGI_OK); } if (!isCgi) { log_msg (error_messages[E_IS_NOT_CGI]); exit (ML_CGI_OK); } mlCgiBeginHttpHeader ("text/html"); if ((ret = mlCgiGetFormStringNoNewLines ("cookieName", cookieName, COOKIE_NAME_LENGTH)) != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); showHtmlErrorPage (E_SHOW_WELCOME_PAGE); exit (ML_CGI_OK); } if ((ret = mlCgiGetSpecificCookie (cookieName, COOKIE_NAME_LENGTH, cookieValue, COOKIE_VALUE_LENGTH)) != ML_CGI_OK) { mlCgiEndHttpHeader(); mlCgiFreeResources (); showHtmlErrorPage (E_SHOW_WELCOME_PAGE); exit (ML_CGI_OK); } if ((ret = validateCookie (cookieName, cookieValue, mlCgiEnvironmentVariablesValues[ML_CGI_REMOTE_ADDRESS])) != OK) { if (ret != E_COOKIE_FILE_DOES_NOT_EXIST) { if ((ret = getCookieValue (cookieName, cookieValue)) != OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); showHtmlErrorPage (ret); exit (ML_CGI_OK); } if ((ret = mlCgiSetCookie (cookieName, cookieValue, 0, NULL, NULL, NULL)) != ML_CGI_OK) { mlCgiEndHttpHeader(); mlCgiFreeResources (); showHtmlErrorPage (E_SET_COOKIE); exit (ML_CGI_OK); } if ((cookieFileName = getLongFilename (COOKIES_DIR, cookieName)) == NULL) { mlCgiEndHttpHeader(); mlCgiFreeResources (); showHtmlErrorPage (E_SHOW_WELCOME_PAGE); exit (ML_CGI_OK); } remove (cookieFileName); } mlCgiEndHttpHeader(); mlCgiFreeResources (); showHtmlErrorPage (ret); exit (ML_CGI_OK); } mlCgiEndHttpHeader(); mlCgiFreeResources (); showHtmlWelcomePage (cookieName); exit (ML_CGI_OK); }
int main (int argc, char **argv) { unsigned errorCode; char cookieName[COOKIE_NAME_LENGTH +1]; char cookieValue[COOKIE_VALUE_LENGTH +1]; char cookieFileName[MAX_LENGTH_LONG_FILENAME +1]; char temp[10 +1]; char givenId[20 +1]; userDataType userData; userIdType callerOfProgramId; if ((errorCode = mlCgiInitialize ()) != ML_CGI_OK) { if (errorCode == ML_CGI_FATAL_ERROR) showHtmlErrorPage (FATAL_ERROR); if (errorCode == ML_CGI_MEMORY_ALLOCATION_ERROR) showHtmlErrorPage (MEMORY_ALLOCATION_ERROR); if (errorCode == ML_CGI_INVALID_CONTENT_LENGTH) showHtmlErrorPage (INVALID_CONTENT_LENGTH); if (errorCode == ML_CGI_IO_ERROR) showHtmlErrorPage (CGI_IO_ERROR); if (errorCode == ML_CGI_INVALID_CONTENT_TYPE) showHtmlErrorPage (INVALID_CONTENT_TYPE); if (errorCode == ML_CGI_INVALID_REQUEST_METHOD) showHtmlErrorPage (INVALID_REQUEST_METHOD); exit (ML_CGI_OK); } if (!isCgi) { printf ("%s\n", showTextErrorMessage (IS_NOT_CGI)); exit (ML_CGI_OK); } mlCgiBeginHttpHeader ("text/html"); if ((errorCode = mlCgiGetFormStringNoNewLines ("cookieName", cookieName, COOKIE_NAME_LENGTH)) != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) showHtmlErrorPage (FORM_FIELD_NOT_FOUND); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_FIELD_LENGTH); exit (ML_CGI_OK); } if ((errorCode = mlCgiGetSpecificCookie (cookieName, COOKIE_NAME_LENGTH, cookieValue, COOKIE_VALUE_LENGTH)) != ML_CGI_OK) { mlCgiEndHttpHeader(); mlCgiFreeResources (); if (errorCode == ML_CGI_INVALID_COOKIE_NAME) showHtmlErrorPage (INVALID_COOKIE_NAME); if (errorCode == ML_CGI_INVALID_COOKIE_VALUE) showHtmlErrorPage (INVALID_COOKIE_VALUE); if (errorCode == ML_CGI_COOKIE_NOT_FOUND) showHtmlErrorPage (COOKIE_NOT_FOUND); exit (ML_CGI_OK); } if ((errorCode = validateCookie (cookieName, cookieValue, mlCgiEnvironmentVariablesValues[ML_CGI_REMOTE_ADDRESS])) != OK) { if (errorCode != VALIDATE_COOKIE__COOKIE_FILE_DOES_NOT_EXIST) { if ((errorCode = getCookieValue (cookieName, cookieValue)) != OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); showHtmlErrorPage (errorCode); exit (ML_CGI_OK); } if ((errorCode = mlCgiSetCookie (cookieName, cookieValue, 0, NULL, NULL, NULL)) != ML_CGI_OK) { mlCgiEndHttpHeader(); mlCgiFreeResources (); if (errorCode == ML_CGI_INVALID_COOKIE_NAME) showHtmlErrorPage (INVALID_COOKIE_NAME); if (errorCode == ML_CGI_INVALID_COOKIE_VALUE) showHtmlErrorPage (INVALID_COOKIE_VALUE); if (errorCode == ML_CGI_INVALID_COOKIE_EXPIRATION) showHtmlErrorPage (INVALID_COOKIE_EXPIRATION); exit (ML_CGI_OK); } if ((errorCode = getLongFilename (COOKIES_DIR, cookieName, cookieFileName)) != OK) { mlCgiEndHttpHeader(); mlCgiFreeResources (); showHtmlErrorPage (errorCode); exit (ML_CGI_OK); } remove (cookieFileName); } mlCgiEndHttpHeader(); mlCgiFreeResources (); showHtmlErrorPage (errorCode); exit (ML_CGI_OK); } if ((errorCode = mlCgiGetFormStringNoNewLines ("userId", givenId, 20)) != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) showHtmlErrorPage (FORM_USER_ID_NOT_FOUND); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_USER_ID_LENGTH); exit (ML_CGI_OK); } userData.userId = strtoul (givenId , NULL, 10); callerOfProgramId = strtoul (cookieName, NULL, 10); if ((callerOfProgramId != 0) && (userData.userId != callerOfProgramId)) { mlCgiEndHttpHeader (); mlCgiFreeResources (); showHtmlErrorPage (ONLY_THE_ADMINISTRATOR_CAN_EDIT_DATA_OF_OTHERS_USERS); exit (ML_CGI_OK); } if ((errorCode = getDataFromId (userData.userId, &userData)) != OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); showHtmlErrorPage (errorCode); exit (ML_CGI_OK); } if ((errorCode = mlCgiGetFormStringNoNewLines ("name", userData.name, MAX_LENGTH_NAME)) != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) showHtmlErrorPage (FORM_NAME_NOT_FOUND); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_NAME_LENGTH); exit (ML_CGI_OK); } if (userData.category == webUser) { if ((errorCode = mlCgiGetFormStringNoNewLines ("email", userData.email, MAX_LENGTH_EMAIL)) != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) showHtmlErrorPage (FORM_EMAIL_NOT_FOUND); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_EMAIL_LENGTH); exit (ML_CGI_OK); } } else { errorCode = mlCgiGetFormStringNoNewLines ("email", userData.email, MAX_LENGTH_EMAIL); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) userData.email[0] = EOS; if (errorCode != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_EMAIL_LENGTH); exit (ML_CGI_OK); } } errorCode = mlCgiGetFormStringNoNewLines ("homepage", userData.homepage, MAX_LENGTH_HOMEPAGE); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) userData.homepage[0] = EOS; if (errorCode != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_HOMEPAGE_LENGTH); exit (ML_CGI_OK); } errorCode = mlCgiGetFormStringNoNewLines ("street", userData.address.street, MAX_LENGTH_STREET); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) userData.address.street[0] = EOS; if (errorCode != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_STREET_LENGTH); exit (ML_CGI_OK); } errorCode = mlCgiGetFormStringNoNewLines ("homeNumber", userData.address.homeNumber, MAX_LENGTH_HOME_NUMBER); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) userData.address.homeNumber[0] = EOS; if (errorCode != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_HOME_NUMBER_LENGTH); exit (ML_CGI_OK); } errorCode = mlCgiGetFormStringNoNewLines ("complement", userData.address.complement, MAX_LENGTH_COMPLEMENT); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) userData.address.complement[0] = EOS; if (errorCode != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_COMPLEMENT_LENGTH); exit (ML_CGI_OK); } errorCode = mlCgiGetFormStringNoNewLines ("district", userData.address.district, MAX_LENGTH_DISTRICT); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) userData.address.district[0] = EOS; if (errorCode != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_DISTRICT_LENGTH); exit (ML_CGI_OK); } errorCode = mlCgiGetFormStringNoNewLines ("city", userData.address.city, MAX_LENGTH_CITY); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) userData.address.city[0] = EOS; if (errorCode != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_CITY_LENGTH); exit (ML_CGI_OK); } errorCode = mlCgiGetFormStringNoNewLines ("state", userData.address.state, MAX_LENGTH_STATE); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) userData.address.homeNumber[0] = EOS; if (errorCode != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_STATE_LENGTH); exit (ML_CGI_OK); } errorCode = mlCgiGetFormStringNoNewLines ("country", userData.address.country, MAX_LENGTH_COUNTRY); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) userData.address.country[0] = EOS; if (errorCode != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_COUNTRY_LENGTH); exit (ML_CGI_OK); } errorCode = mlCgiGetFormStringNoNewLines ("zipCode", userData.address.zipCode, MAX_LENGTH_ZIP_CODE); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) userData.address.zipCode[0] = EOS; if (errorCode != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_ZIP_CODE_LENGTH); exit (ML_CGI_OK); } errorCode = mlCgiGetFormStringNoNewLines ("telNumber", userData.telNumber, MAX_LENGTH_TEL_NUMBER); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) userData.telNumber[0] = EOS; if (errorCode != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_TEL_NUMBER_LENGTH); exit (ML_CGI_OK); } errorCode = mlCgiGetFormStringNoNewLines ("cellNumber", userData.cellNumber, MAX_LENGTH_CELL_NUMBER); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) userData.cellNumber[0] = EOS; if (errorCode != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_CELL_NUMBER_LENGTH); exit (ML_CGI_OK); } errorCode = mlCgiGetFormStringNoNewLines ("gender", temp, 10); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) userData.gender = notAnswered; if (errorCode != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_GENDER_LENGTH); exit (ML_CGI_OK); } if (!strcmp (temp, "male")) userData.gender = male; else if (!strcmp (temp, "female")) userData.gender = female; else userData.gender = notAnswered; errorCode = mlCgiGetFormStringNoNewLines ("relationshipStatus", temp, 10); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) userData.relationshipStatus = notGiven; if (errorCode != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_RELATIONSHIP_STATUS_LENGTH); exit (ML_CGI_OK); } if (!strcmp (temp, "single")) userData.relationshipStatus = single; else if (!strcmp (temp, "married")) userData.relationshipStatus = married; else if (!strcmp (temp, "widowed")) userData.relationshipStatus = widowed; else userData.relationshipStatus = notGiven; if ((errorCode = mlCgiGetFormStringNoNewLines ("birthday", userData.birthday, MAX_LENGTH_BIRTHDAY)) != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) showHtmlErrorPage (FORM_BIRTHDAY_NOT_FOUND); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_BIRTHDAY_LENGTH); exit (ML_CGI_OK); } errorCode = mlCgiGetFormStringNoNewLines ("description", userData.description, MAX_LENGTH_DESCRIPTION); if (errorCode == ML_CGI_FORM_FIELD_NOT_FOUND) userData.description[0] = EOS; if (errorCode != ML_CGI_OK) { mlCgiEndHttpHeader (); mlCgiFreeResources (); if (errorCode == ML_CGI_INVALID_FORM_LENGTH) showHtmlErrorPage (INVALID_FORM_DESCRIPTION_LENGTH); exit (ML_CGI_OK); } mlCgiEndHttpHeader(); mlCgiFreeResources (); if (userData.category == relative) { userData.userName[0] = EOS; userData.plainPass[0] = EOS; userData.encryptedPass[0] = EOS; } else { strcpy (userData.plainPass, "noPass"); if ((errorCode = encodePassword (userData.plainPass, userData.encryptedPass)) != OK) { showHtmlErrorPage (errorCode); exit (ML_CGI_OK); } } if ((errorCode = editUserData (&userData)) != OK) showHtmlErrorPage (errorCode); else showHtmlOKPage (); exit (ML_CGI_OK); }
int main (int argc, char **argv) { thcUserDataType data; environmentType enviro; thcErrorType errorCode; thcLanguageType language = THC_DEFAULT_LANGUAGE; time_t localTime; char nickname[THC_NICKNAME_MAXIMUM_LENGHT+1]; char cookieName [THC_COOKIE_NAME_LENGHT + 1]; char cookieContent [THC_COOKIE_CONTENT_LENGHT + 1]; if (mlCgiInitialize (&enviro)) exit (THC_OK); if (enviro == commandLine) { thcGetTextErrorMessage(language,THC_ERROR_INVALID_INTERFACE); mlCgiFreeResources(); exit (THC_OK); } /*Start header*/ mlCgiBeginHttpHeader("text/html"); /*Get nickname*/ errorCode = mlCgiGetFormStringNoNewLines ("thcNickname",nickname,THC_NICKNAME_MAXIMUM_LENGHT); if (errorCode != ML_CGI_OK) { mlCgiEndHttpHeader(); thcGetHtmlErrorMessage(language, THC_ERROR_ON_WEB_FORM); mlCgiFreeResources(); exit(THC_OK); } /*Get the cookie name*/ errorCode = thcSearchUser(nickname,&data); if (errorCode != THC_OK) { mlCgiEndHttpHeader (); thcGetHtmlErrorMessage(language, errorCode); mlCgiFreeResources(); exit(THC_OK); } if (sprintf(cookieName,THC_COOKIE_NAME_PRINTF_FORMAT,data.UID) != THC_COOKIE_NAME_LENGHT) { mlCgiEndHttpHeader (); thcGetHtmlErrorMessage(language,THC_ERROR_GENERATING_COOKIE_NAME); exit(THC_OK); } /*Send cookie with expiration time 0*/ mlCgiGetSpecificCookie (cookieName,THC_NICKNAME_MAXIMUM_LENGHT,cookieContent,THC_COOKIE_CONTENT_LENGHT); mlCgiSetCookie(cookieName,cookieContent,0,NULL,NULL,NULL); mlCgiEndHttpHeader(); localTime = time(NULL); thcGenerateCookie(cookieName, &localTime, cookieContent, THC_DEFAULT_COOKIE_IP); printf("<head> \n"); if (cookieContent[0] == 'e') printf("<meta HTTP-EQUIV='REFRESH' content='0; url=%s'> ",THC_WEB_SERVER_URL); if (cookieContent[0] == 'b') printf("<meta HTTP-EQUIV='REFRESH' content='0; url=%s'> ",THC_WEB_SERVER_URL_BR); printf("</head> \n"); mlCgiFreeResources(); return THC_OK; }