void* remoteResponse(){ char bankPath[32] = {0}; sprintf(bankPath,"resources/bank%.4s",bankId); char fifoPath[64] = {0}; sprintf(fifoPath,"%s/response.fifo",bankPath); mkfifo(fifoPath,DEFAULT); int remoteResponseFD = open(fifoPath,O_RDONLY); int end = 0; while(!end){ char cardNumber[16+1]; char messageType[8+1]; char value[13+1]; // only 13 digit needed for the richest man of the world char* string = litLigne(remoteResponseFD); if(string == NULL || decoupe(string,cardNumber,messageType,value) == 0){ perror("(acquisition(remote response))message in wrong format"); fprintf(stderr,"%s:%d: message: %s\n",__FILE__,__LINE__, string); end = 1; continue; } sprintf(fifoPath,"%s/%s.fifo",bankPath,cardNumber); mkfifo(fifoPath,DEFAULT); int term = open(fifoPath,O_WRONLY); if(term == -1){ perror("miaou"); fprintf(stderr,"%s:%d: pipe (%s)\n",__FILE__,__LINE__,string); } ecritLigne(term,string); close(term); } return NULL; }
void affiche_directory(char* last_dir, char* cwd){ char *liste_dir[MAX_ARG]; strcpy(last_dir,""); /* on remet a zero l'affichage */ int nbdir = decoupe(liste_dir,cwd,"/"); /* on apelle la fonction qui decoupe avec les /*/ int i; int nb_dir_affiche = 3; if (nbdir < nb_dir_affiche) /* si on a moins de dossier que le nombre que l'ont veut afficher on met le nombre d'affichage au max*/ nb_dir_affiche = nbdir; for (i = nbdir-nb_dir_affiche; i < nbdir ;i++) /* on copie les derniers dossiers dans la chaine que l'ont voudra afficher*/ { strcat(last_dir,liste_dir[i]); strcat(last_dir,"/"); } }
void* connection(int *associatedBank_) { int associatedBank[] = {associatedBank_[0], associatedBank_[1]}; char cardNumber[16+1]; char messageType[7+1]; char value[13+1]; // only 13 digit needed for the richest man of the world int end = 0; while(!end) { errno = 0; char* string = litLigne(associatedBank[READ]); if(string == NULL || decoupe(string,cardNumber,messageType,value) == 0) { perror("(interbancaire(connection)) message is wrong format"); end = 1; break; } ConnectionPipe *remotePipe = malloc(sizeof (ConnectionPipe)); remotePipe->bankResponse = dup(associatedBank[WRITE]); char bankId[5]; sprintf(bankId,"%.4s",cardNumber); remotePipe->bankId = atoi(bankId); char bankPath[20] = {0}; sprintf(bankPath,"resources/bank%.4s",bankId); mkdir(bankPath,0755); char fifoPath[64] = {0}; sprintf(fifoPath,"%s/remoteInput.fifo",bankPath); mkfifo(fifoPath,DEFAULT); remotePipe->interDemand = open(fifoPath,O_WRONLY); sprintf(fifoPath,"%s/interRéponse.fifo",bankPath); mkfifo(fifoPath,DEFAULT); remotePipe->interResponse = open(fifoPath,O_RDONLY); RemoteAuthData *data = malloc(sizeof (RemoteAuthData)); data->pipe = remotePipe; data->string = string; write(threadPoolPipe[WRITE], &data, sizeof (void*)); } return (void*)1; }
int main(void) { char *file; char **line; int num; system("./script.sh 2> /dev/null"); file = ft_get_file(".result"); if (file && ft_strlen(file) > 100) { num = -1; line = ft_strsplit(file, '\n'); while (line[++num]) if ((line[num])[0] != '#' && (line[num])[0] != ' ') if ((line[num])[0] != '\t' && ft_strlen(line[num]) > 10) decoupe(line[num]); ft_tabstrdel(&line); } ft_strdel(&file); return (0); }
void* routeRemoteRequest(char* bankPath){ char remoteFifo[64]; RemotePipe remote; sprintf(remoteFifo,"%s/remoteAuthDemande.fifo",bankPath); mkfifo(remoteFifo,DEFAULT); remote.authDemand = open(remoteFifo,O_WRONLY); sprintf(remoteFifo,"%s/remoteInput.fifo",bankPath); mkfifo(remoteFifo,DEFAULT); remote.input = open(remoteFifo,O_RDONLY); sprintf(remoteFifo,"%s/interRéponse.fifo",bankPath); mkfifo(remoteFifo,DEFAULT); remote.interResponse = open(remoteFifo,O_WRONLY); char cardNumber[16+1]; char messageType[7+1]; char value[13+1]; // only 13 digit needed for the richest man of the world char* string; int end = 0; while(!end){ string = litLigne(remote.input); if(string == NULL || decoupe(string,cardNumber,messageType,value) == 0){ perror("(remote acquisition) message in wrong format"); end = 1; continue; } if(strcmp(messageType,"Demande") == 0){ ecritLigne(remote.authDemand,string); }else{ ecritLigne(remote.interResponse,string); } free(string); } return NULL; }
// decoupe avec "je-suis-ton-pere" en " je suis ton pere" inline std::vector<std::string> decoupe (const std::string& chaine, const char* separateur) { return decoupe(chaine,std::string(separateur)); }
int main(int argc, char* argv[]){ if(argc == 3){ opterr = 0; int indexptr; int opt; while((opt = getopt_long(argc, argv, "b:",longopts, &indexptr)) != -1){ switch(opt){ case 'b': bankId = optarg; break; default: printHelp(argv[0]); break; } } char cardNumber[16+1]; char messageType[7+1]; char value[13+1]; // only 13 digit needed for the richest man of the world char* string; int end = 0; char bankPath[20] = {0}; char fifoPath[64] = {0}; sprintf(bankPath,"resources/bank%.4s",bankId); mkdir(bankPath,0755); sprintf(fifoPath,"%s/localAuth.fifo",bankPath); mkfifo(fifoPath,DEFAULT); int localAuth = open(fifoPath,O_WRONLY); sprintf(fifoPath,"%s/input.fifo",bankPath); mkfifo(fifoPath,DEFAULT); int bank = open(fifoPath,O_RDONLY); sprintf(fifoPath,"%s/interRemoteDemande.fifo",bankPath); mkfifo(fifoPath,DEFAULT); int localInter = open(fifoPath,O_WRONLY); pthread_t remoteThread; pthread_create(&remoteThread,NULL,remoteResponse,NULL); pthread_create(&remoteThread, NULL, (void* (*) (void*))routeRemoteRequest, (void*)&bankPath); while(!end){ string = litLigne(bank); errno = 0; if(string == NULL || decoupe(string,cardNumber,messageType,value) == 0){ perror("(acquisition)message in wrong format"); fprintf(stderr,"%s:%d: [bank %s] %s",__FILE__,__LINE__,bankId,string); end = 1; continue; } if(strncmp(cardNumber,bankId,4) == 0){ ecritLigne(localAuth,string); }else{ // to interbancaire ecritLigne(localInter,string); } free(string); } if(pthread_join(remoteThread,NULL)){ perror("local auth"); } }else{ printHelp(argv[0]); } return 0; }