/* Check requested username */ int validUsername (char *username, int client) { if (sanitizeInput(username, 1)) { sendError("Invalid characters in username.", client); return 0; } if (strlen(username) < 3) { sendError("Username is too short.", client); return 0; } if (strlen(username) > USERNAME_LENGTH) { sendError("Username is too long.", client); return 0; } return 1; }
/* Check requested room name */ int validRoomname (char *roomname, int client) { if (sanitizeInput(roomname, 1)) { sendError("Invalid characters in room name.", client); return 0; } if (strlen(roomname) < 3) { sendError("Requested room name is too short.", client); return 0; } if (strlen(roomname) > ROOMNAME_LENGTH) { sendError("Requested room name is too long.", client); return 0; } return 1; }
void editPatient(char* uuid){ //TODO check if uuid is part of DOC's patients PatientT * patient = fetchPatient(uuid); fprintf(stderr, "found patient\n"); int choice=0; char temp[2]; initializeString(temp,2); //display edit menu while(choice!=9){ displayPatient(uuid); printf("\n****Edit Patient\n"); printf("[1] Insurance\n"); printf("[2] Add Immunization\n"); printf("[3] Add Medication\n"); printf("[4] Add Vitals\n"); printf("[5] Add Test Results\n"); printf("[6] Demographics\n"); printf("[9] EXIT\n"); //get input if(fgets(temp,2,stdin)); choice = temp[0]-48; //process choice switch(choice){ case 1: ; while(getchar()!='\n');//clean buffer //edit insurance char name[40]; char policyNumber[30]; initializeString(name,40); initializeString(policyNumber,40); while(getchar()!='\n');//clean buffer printf("INSURANCE NAME: "); if(fgets(name,40,stdin)); while(getchar()!='\n');//clean buffer printf("\nPOLICY NO: "); if(fgets(policyNumber,30,stdin)); printf("\n"); sanitizeInput(name,40); sanitizeInput(policyNumber,30); strncpy(patient->insurance->name,name,40); strncpy(patient->insurance->policyNumber,policyNumber,30); exportUser(patient); printf("\nUPDATED!\n"); break; case 2: break; case 3: break; case 4: break; case 5: break; case 6: ; while(getchar()!='\n');//clean buffer char firstName[30]; initializeString(firstName,30); char lastName[30]; initializeString(lastName,30); bool smokes=3; char race[30]; initializeString(race,30); char gender[30]; initializeString(gender,30); int age=-1; char tempAge[10]; initializeString(tempAge,10); char ssn[10]; initializeString(ssn,10); char dateOfBirth[11]; initializeString(dateOfBirth,11); while(getchar()!='\n');//clean buffer printf("FIRSTNAME: "); if(fgets(firstName,30,stdin)); while(getchar()!='\n');//clean buffer printf("\nLASTNAME: "); if(fgets(lastName,30,stdin)); while(getchar()!='\n');//clean buffer while(smokes!=0&&smokes!=1){ printf("\nSmoker?{1=YES,0=NO}"); if(fgets(temp,2,stdin)); sanitizeInt(temp,2); smokes=temp[0]-48; while(getchar()!='\n');//clean buffer } while(getchar()!='\n');//clean buffer printf("\nGENDER: "); if(fgets(gender,30,stdin)); while(getchar()!='\n');//clean buffer printf("\nRACE: "); if(fgets(race,30,stdin)); while(getchar()!='\n');//clean buffer while(age<=0||age>=999){ printf("\nAGE {000}"); if(fgets(tempAge,3,stdin)); //sanitizeInt(tempAge,4); //age+=((tempAge[0]+48)*1); //age+=((tempAge[1]+48)*10); //age+=((tempAge[2]+48)*100); age= (int) strtol(tempAge,NULL,10); while(getchar()!='\n');//clean buffer } while(getchar()!='\n');//clean buffer printf("\nSSN: "); if(fgets(ssn,10,stdin)); while(getchar()!='\n');//clean buffer printf("\nDOB{MM/DD/YYYY}"); if(fgets(dateOfBirth,11,stdin)); sanitizeInput(firstName,30); sanitizeInput(lastName,30); sanitizeInput(race,30); sanitizeInput(gender,30); sanitizeInput(ssn,10); sanitizeInput(dateOfBirth,11); strncpy(patient->firstName,firstName,30); strncpy(patient->lastName,lastName,30); strncpy(patient->race,race,30); strncpy(patient->gender,gender,30); strncpy(patient->ssn,ssn,10); strncpy(patient->dateOfBirth,dateOfBirth,11); patient->smokes=smokes; patient->age=age; exportUser(patient); printf("\nUPDATED!\n"); break; case 9: break; default: break; } } }
/* *Main thread for each client. Receives all messages *and passes the data off to the correct function. Receives *a pointer to the file descriptor for the socket the thread *should listen on */ void *client_receive(void *ptr) { int client = *(int *) ptr; int received; int logged_in = 0; packet in_pkt, *client_message_ptr = &in_pkt; while (1) { received = recv(client, &in_pkt, sizeof(packet), 0); if (received) { debugPacket(client_message_ptr); // Responses to not logged in clients if (!logged_in) { if(in_pkt.options == REGISTER) { logged_in = register_user(&in_pkt, client); } else if(in_pkt.options == LOGIN) { logged_in = login(&in_pkt, client); } else if(in_pkt.options == EXIT) { close(client); return NULL; } else { sendError("Not logged in.", client); } } // Responses to logged in clients else if (logged_in) { // Handle option messages for logged in client if (in_pkt.options < 1000) { if(in_pkt.options == REGISTER) { sendError("You may not register while logged in.", client); } else if(in_pkt.options == SETPASS) { set_pass(&in_pkt, client); } else if(in_pkt.options == SETNAME) { set_name(&in_pkt, client); } else if(in_pkt.options == LOGIN) { sendError("Already logged in.", client); } else if(in_pkt.options == EXIT) { exit_client(&in_pkt, client); return NULL; } else if(in_pkt.options == INVITE) { invite(&in_pkt, client); } else if(in_pkt.options == JOIN) { join(&in_pkt, client); } else if(in_pkt.options == LEAVE) { leave(&in_pkt, client); } else if(in_pkt.options == GETALLUSERS) { get_active_users(client); } else if(in_pkt.options == GETUSERS) { get_room_users(&in_pkt, client); } else if(in_pkt.options == GETUSER) { user_lookup(&in_pkt, client); } else if(in_pkt.options == GETROOMS) { get_room_list(client); } else if(in_pkt.options == GETMOTD) { sendMOTD(client); } else if(in_pkt.options == 0) { printf("%s --- Error:%s Abrupt disconnect on logged in client.\n", RED, NORMAL); exit_client(&in_pkt, client); return NULL; } else { printf("%s --- Error:%s Unknown message received from client.\n", RED, NORMAL); } } // Handle conversation message for logged in client else { // Will be treated as a message packet, safe to santize entire buffer sanitizeInput((void *)&in_pkt.buf, 0); send_message(&in_pkt, client); } } memset(&in_pkt, 0, sizeof(packet)); } } return NULL; }