component new_component(block_t heap, int lineno, enum component_class vclass, ...) { va_list args; component newp = allocate(heap, sizeof *newp); newp->vclass = vclass; newp->lineno = lineno; va_start(args, vclass); switch (vclass) { case c_assign: newp->u.assign.symbol = va_arg(args, const char *); newp->u.assign.value = va_arg(args, component); break; case c_vref: case c_recall: newp->u.recall = va_arg(args, const char *); break; case c_constant: { constant cst = va_arg(args, constant); if (cst->vclass == cst_expression) newp = cst->u.expression; else newp->u.cst = cst; break; } case c_closure: newp->u.closure = va_arg(args, function); break; case c_block: newp->u.blk = va_arg(args, block); break; case c_execute: newp->u.execute = va_arg(args, clist); break; case c_builtin: newp->u.builtin.fn = va_arg(args, enum builtin_op); int nargs = va_arg(args, int); newp->u.builtin.args = make_clist(heap, nargs, args); break; case c_labeled: case c_exit: newp->u.labeled.name = va_arg(args, const char *); newp->u.labeled.expression = va_arg(args, component); break; default: abort(); } va_end(args); return newp; }
Resampler::Resampler(int src_x, int src_y, int dst_x, int dst_y, Boundary_Op boundary_op, Resample_Real sample_low, Resample_Real sample_high, const char* Pfilter_name, Contrib_List* Pclist_x, Contrib_List* Pclist_y, Resample_Real filter_x_scale, Resample_Real filter_y_scale, Resample_Real src_x_ofs, Resample_Real src_y_ofs) { int i, j; Resample_Real support, (*func)(Resample_Real); resampler_assert(src_x > 0); resampler_assert(src_y > 0); resampler_assert(dst_x > 0); resampler_assert(dst_y > 0); #if RESAMPLER_DEBUG_OPS total_ops = 0; #endif m_lo = sample_low; m_hi = sample_high; m_delay_x_resample = false; m_intermediate_x = 0; m_Pdst_buf = NULL; m_Ptmp_buf = NULL; m_clist_x_forced = false; m_Pclist_x = NULL; m_clist_y_forced = false; m_Pclist_y = NULL; m_Psrc_y_count = NULL; m_Psrc_y_flag = NULL; m_Pscan_buf = NULL; m_status = STATUS_OKAY; m_resample_src_x = src_x; m_resample_src_y = src_y; m_resample_dst_x = dst_x; m_resample_dst_y = dst_y; m_boundary_op = boundary_op; if ((m_Pdst_buf = (Sample*)malloc(m_resample_dst_x * sizeof(Sample))) == NULL) { m_status = STATUS_OUT_OF_MEMORY; return; } // Find the specified filter. if (Pfilter_name == NULL) Pfilter_name = RESAMPLER_DEFAULT_FILTER; for (i = 0; i < NUM_FILTERS; i++) if (strcmp(Pfilter_name, g_filters[i].name) == 0) break; if (i == NUM_FILTERS) { m_status = STATUS_BAD_FILTER_NAME; return; } func = g_filters[i].func; support = g_filters[i].support; /* Create contributor lists, unless the user supplied custom lists. */ if (!Pclist_x) { m_Pclist_x = make_clist(m_resample_src_x, m_resample_dst_x, m_boundary_op, func, support, filter_x_scale, src_x_ofs); if (!m_Pclist_x) { m_status = STATUS_OUT_OF_MEMORY; return; } } else { m_Pclist_x = Pclist_x; m_clist_x_forced = true; } if (!Pclist_y) { m_Pclist_y = make_clist(m_resample_src_y, m_resample_dst_y, m_boundary_op, func, support, filter_y_scale, src_y_ofs); if (!m_Pclist_y) { m_status = STATUS_OUT_OF_MEMORY; return; } } else { m_Pclist_y = Pclist_y; m_clist_y_forced = true; } if ((m_Psrc_y_count = (int*)calloc(m_resample_src_y, sizeof(int))) == NULL) { m_status = STATUS_OUT_OF_MEMORY; return; } if ((m_Psrc_y_flag = (unsigned char*)calloc(m_resample_src_y, sizeof(unsigned char))) == NULL) { m_status = STATUS_OUT_OF_MEMORY; return; } /* Count how many times each source line * contributes to a destination line. */ for (i = 0; i < m_resample_dst_y; i++) for (j = 0; j < m_Pclist_y[i].n; j++) m_Psrc_y_count[resampler_range_check(m_Pclist_y[i].p[j].pixel, m_resample_src_y)]++; if ((m_Pscan_buf = (Scan_Buf*)malloc(sizeof(Scan_Buf))) == NULL) { m_status = STATUS_OUT_OF_MEMORY; return; } for (i = 0; i < MAX_SCAN_BUF_SIZE; i++) { m_Pscan_buf->scan_buf_y[i] = -1; m_Pscan_buf->scan_buf_l[i] = NULL; } m_cur_src_y = m_cur_dst_y = 0; { // Determine which axis to resample first by comparing the number of multiplies required // for each possibility. int x_ops = count_ops(m_Pclist_x, m_resample_dst_x); int y_ops = count_ops(m_Pclist_y, m_resample_dst_y); // Hack 10/2000: Weight Y axis ops a little more than X axis ops. // (Y axis ops use more cache resources.) int xy_ops = x_ops * m_resample_src_y + (4 * y_ops * m_resample_dst_x)/3; int yx_ops = (4 * y_ops * m_resample_src_x)/3 + x_ops * m_resample_dst_y; #if RESAMPLER_DEBUG_OPS printf("src: %i %i\n", m_resample_src_x, m_resample_src_y); printf("dst: %i %i\n", m_resample_dst_x, m_resample_dst_y); printf("x_ops: %i\n", x_ops); printf("y_ops: %i\n", y_ops); printf("xy_ops: %i\n", xy_ops); printf("yx_ops: %i\n", yx_ops); #endif // Now check which resample order is better. In case of a tie, choose the order // which buffers the least amount of data. if ((xy_ops > yx_ops) || ((xy_ops == yx_ops) && (m_resample_src_x < m_resample_dst_x)) ) { m_delay_x_resample = true; m_intermediate_x = m_resample_src_x; } else { m_delay_x_resample = false; m_intermediate_x = m_resample_dst_x; } #if RESAMPLER_DEBUG_OPS printf("delaying: %i\n", m_delay_x_resample); #endif } if (m_delay_x_resample) { if ((m_Ptmp_buf = (Sample*)malloc(m_intermediate_x * sizeof(Sample))) == NULL) { m_status = STATUS_OUT_OF_MEMORY; return; } } }
/* Interaction of the child process with the client */ void Talk_to_client ( int cfd ) { char id[10], pw[10]; int nbytes, status; int src_addr, dest_addr; int abc, xyz=0, maskedpw; int i = 0, flag, j; Msg send_msg; Msg recv_msg; FILE *fp; long int q, alpha, secret_key, public_key, private_key; long int X_B, Y_A, Y_B; dest_addr = inet_addr("DEFAULT_SERVER"); src_addr = inet_addr("192.168.1.245"); /* Wait for responses from the clent (Alice, User A) */ while ( 1 ) { /* receive messages from server */ nbytes = recv(cfd, &recv_msg, sizeof(Msg), 0); if (nbytes == -1) { fprintf(stderr, "*** Client error: unable to receive\n"); } switch ( recv_msg.hdr.opcode ) { case REGISTER : /* Registration from Client */ printf("\n\nMessage:: REGISTER received from source (%d)\n", recv_msg.hdr.src_addr); strcpy(id, recv_msg.m.auth.id); strcpy(pw, recv_msg.m.auth.pw); printf("Received ID:\t%s\nPW:\t%s\n", id, pw); make_clist(id, pw); fp = fopen("ClientList.txt", "a"); // append mode if( fp == NULL ) { perror("Error while opening the file.\n"); exit(EXIT_FAILURE); } fwrite(&clist, sizeof(clist), 1, fp); fclose(fp); printf("Written to file.\n"); printf("\nUpdated Client List is:"); display_clist(); break; case LOGINREQ : /* Login Request from Client */ printf("\n\nMessage:: LOGINREQ received from source (%d)\n", recv_msg.hdr.src_addr); strcpy(id, recv_msg.m.auth.id); strcpy(pw, recv_msg.m.auth.pw); printf("Received ID:\t%s\nPW:\t%s\n", id, pw); send_msg.hdr.opcode = LOGINREP; send_msg.hdr.src_addr = src_addr; send_msg.hdr.dest_addr = dest_addr; flag = 0; fp = fopen("ClientList.txt", "r"); // read mode if( fp == NULL ) { printf("Clientlist does not exist!"); send_msg.hdr.opcode = REQCOM; send_msg.hdr.src_addr = src_addr; send_msg.hdr.dest_addr = dest_addr; strcpy(send_msg.m.buf, "No user registered!"); status = send(cfd, &send_msg, sizeof(Msg), 0); if (status == -1) { fprintf(stderr, "*** Client error: unable to send\n"); return; } } else { while(fread(&clist, sizeof(clist), 1, fp) != 0) { if( strcmp(id, clist.id) == 0 ) { xyz = 0; for(i = 0; pw[i] != '\0'; i++) { abc = (int) pw[i]; xyz = xyz ^ abc; } maskedpw = clist.salt ^ xyz; if(maskedpw == clist.maskedpw) { flag = 1; break; } } } fclose(fp); if(flag == 0) { printf("Wrong ID/Password!\n"); strcpy(send_msg.m.buf, "Wrong ID/Password!"); } else { printf("Authenticated!\n"); strcpy(send_msg.m.buf, "Authenticated!"); } status = send(cfd, &send_msg, sizeof(Msg), 0); if (status == -1) { fprintf(stderr, "*** Client error: unable to send\n"); return; } } break; case PUBKEY : /* Public key */ printf("\n\nMessage:: PUBKEY received from source (%d)\n", recv_msg.hdr.src_addr); /* Compute the secret shared key based on public key received from Bob (User B) */ q = recv_msg.m.dhpubkey.q; alpha = recv_msg.m.dhpubkey.g; Y_A = recv_msg.m.dhpubkey.Y; printf("Received public values from Alice are q = %ld, alpha = %ld, Y_A = %ld\n\r", q, alpha, Y_A); /* Select a private key X_B < q */ private_key = rand() % q; X_B = private_key; printf("Private key for Bob (User B) is %ld\n\r", X_B); /* Compute the public key Y_B */ public_key = ModPower(alpha, X_B, q); Y_B = public_key; printf("Public key for Bob (User B) is %ld\n\r", Y_B); /* Send the public key to Alice */ printf("Sending the public key to Alice (User A)\n"); send_msg.hdr.opcode = PUBKEY; send_msg.hdr.src_addr = src_addr; send_msg.hdr.dest_addr = dest_addr; /* send the public key to Alice */ send_msg.m.dhpubkey.q = q; /* q */ send_msg.m.dhpubkey.g = alpha; /* alpha */ send_msg.m.dhpubkey.Y = Y_B; /* value of public key */ /* Now compute the secret key shared between Alice and Bob */ secret_key = ModPower(Y_A, X_B, q); printf("Computed secret key between Alice and Bob (by User B, Bob ) is %ld\n\r", secret_key); /* Send an acknowledgement to Alice that the secret key is computed */ status = send(cfd, &send_msg, sizeof(Msg), 0); if (status == -1) { fprintf(stderr, "*** Client error: unable to send\n"); return; } break; case REQSERV : /* Request from Client for Encrypted data */ printf("\n\nMessage:: REQSERV received from source (%d)\n", recv_msg.hdr.src_addr); printf("%s\n", recv_msg.m.buf); int count; fp = fopen(recv_msg.m.buf, "r"); // read mode if( fp == NULL ) { send_msg.hdr.opcode = REQCOM; send_msg.hdr.src_addr = src_addr; send_msg.hdr.dest_addr = dest_addr; strcpy(send_msg.m.buf, "File does not exist!"); status = send(cfd, &send_msg, sizeof(Msg), 0); if (status == -1) { fprintf(stderr, "*** Client error: unable to send\n"); return; } } else { printf("The contents of %s file are :- \n", recv_msg.m.buf); while( (count = fread(buffer, 1, MAX_LEN - 1, fp) ) != 0) { buffer[count] = '\0'; printf("\nPlain Text is:\n\n%s\n", buffer); EncryptionAlgorithm(buffer, secret_key); printf("\nEncrypted Text is:\n\n%s\n", buffer); send_msg.hdr.opcode = ENCMSG; send_msg.hdr.src_addr = src_addr; send_msg.hdr.dest_addr = dest_addr; strcpy(send_msg.m.buf, buffer); status = send(cfd, &send_msg, sizeof(Msg), 0); if (status == -1) { fprintf(stderr, "*** Client error: unable to send\n"); return; } } fclose(fp); send_msg.hdr.opcode = REQCOM; send_msg.hdr.src_addr = src_addr; send_msg.hdr.dest_addr = dest_addr; strcpy(send_msg.m.buf, "Request Complete!"); status = send(cfd, &send_msg, sizeof(Msg), 0); if (status == -1) { fprintf(stderr, "*** Client error: unable to send\n"); return; } } break; case DISCONNECT :/* Disconnect */ printf("\n\nMessage:: DISCONNECT received from source (%d)\n", recv_msg.hdr.src_addr); printf("%s\n", recv_msg.m.buf); send_msg.hdr.opcode = DISCONNECT; send_msg.hdr.src_addr = src_addr; send_msg.hdr.dest_addr = dest_addr; strcpy(send_msg.m.buf, "Disconnect..."); status = send(cfd, &send_msg, sizeof(Msg), 0); if (status == -1) { fprintf(stderr, "*** Client error: unable to send\n"); return; } exit(0); break; } } }
/************************************************************** * function: main() * args: none * returns: none * side effects: coalesces all existing checkpoint files into a * single map and a single data file. * called from: ckpt_recover(), take_ckpt() *************************************************************/ void main(int argc, char ** argv) { int i=0, j, no_files; long no_chunks, total_chunks; int map_fd, data_fd; char mapfile[256], datafile[256], maptemp[256], datatemp[256]; char * addr; caddr_t stopaddr, topstack; long size, pn; off_t seekptr; CLIST list; int page1; char buf[BUFSIZE]; if(argc != 5){ fprintf(stderr, "Error: Coalesce called with wrong number of args\n"); exit(1); } FILEAREA = (caddr_t)(uintptr_t)atoi(argv[1]); filename = strdup(argv[2]); verbose = (BOOL)atoi(argv[3]); DEBUG = atoi(argv[4]); /*-- checking for the number of checkpoint files --*/ while(1){ sprintf(datafile, "%s.%s.%d", filename, "data", i); data_fd = OPEN(datafile, O_RDONLY, 0644); sprintf(mapfile, "%s.%s.%d", filename, "map", i); map_fd = OPEN(mapfile, O_RDONLY, 0644); if(data_fd == -1 || map_fd == -1){ CLOSE(data_fd); CLOSE(map_fd); break; } CLOSE(data_fd); CLOSE(map_fd); i++; } no_files = i; if(no_files == 0){ fprintf(stderr, "Error: Recovery specified, but no checkpoint files found\n"); exit(-1); } else if(no_files == 1){ return; } /*-- reset buffer counts --*/ datanochars=0; mapnochars=0; if(verbose) fprintf(stderr, "CKPT: coalescing %d sets of checkpoint files\n", no_files); sprintf(datatemp, "%s.%s.temp", filename, "data"); remove(datatemp); datatemp_fd = OPEN(datatemp, O_WRONLY | O_CREAT, 0644); sprintf(maptemp, "%s.%s.temp", filename, "map"); remove(maptemp); maptemp_fd = OPEN(maptemp, O_WRONLY | O_CREAT, 0644); /*-- transfer data to the relevant temp file (most recent to least recent) --*/ for(i=no_files-1; i>=0; i--){ sprintf(mapfile, "%s.%s.%d", filename, "map", i); map_fd = OPEN(mapfile, O_RDONLY, 0644); if(i==no_files-1){ /*-- read this info from last file only --*/ read(map_fd, (char *)&topstack, POINTERSIZE); read(map_fd, (char *)&DATASTART, POINTERSIZE); read(map_fd, (char *)&stopaddr, POINTERSIZE); read(map_fd, (char *)&no_chunks, LONGSIZE); write(maptemp_fd, (char *)&topstack, POINTERSIZE); write(maptemp_fd, (char *)&DATASTART, POINTERSIZE); write(maptemp_fd, (char *)&stopaddr, POINTERSIZE); write(maptemp_fd, (char *)&no_chunks, POINTERSIZE); list = make_clist(stopaddr); } else{ lseek(map_fd, POINTERSIZE*3, SEEK_SET); read(map_fd, (char *)&no_chunks, LONGSIZE); } no_chunks--; /*-- exclude the stack's chunk --*/ /*-- exclude filearea, if present --*/ if(FILEAREA != 0){ no_chunks--; } for(j=0; j<no_chunks; j++){ read(map_fd, (char *)&addr, POINTERSIZE); read(map_fd, (char *)&size, LONGSIZE); read(map_fd, (char *)&seekptr, LONGSIZE); clist_insertchunk(list, addr, size, i, seekptr); } CLOSE(map_fd); } total_chunks = coa_transfer_chunks(list); destroy_clist(list); sprintf(datafile, "%s.%s.%d", filename, "data", no_files-1); data_fd = OPEN(datafile, O_RDONLY, 0644); sprintf(mapfile, "%s.%s.%d", filename, "map", no_files-1); map_fd = OPEN(mapfile, O_RDONLY, 0644); /*-- We must advance the seekptr in the map file appropriately --*/ lseek(map_fd, POINTERSIZE*3, SEEK_SET); read(map_fd, (char *)&no_chunks, LONGSIZE); no_chunks--; /*-- exclude the stack's chunk --*/ if(FILEAREA != 0){ /*-- exclude filearea, if present --*/ no_chunks--; } lseek(map_fd, no_chunks*MAPCHUNKSIZE, SEEK_CUR); if(FILEAREA != 0){ read(map_fd, (char *)&addr, POINTERSIZE); read(map_fd, (char *)&size, POINTERSIZE); read(map_fd, (char *)&seekptr, POINTERSIZE); coa_write_chunk(addr, size, data_fd, seekptr); debug(stderr, "DEBUG: writing 0x%x - Ox%x from ckptfile %d\n", addr, addr+size, no_files-1); total_chunks++; } read(map_fd, (char *)&addr, POINTERSIZE); read(map_fd, (char *)&size, POINTERSIZE); read(map_fd, (char *)&seekptr, POINTERSIZE); coa_write_chunk(addr, size, data_fd, seekptr); debug(stderr, "DEBUG: writing 0x%x - Ox%x from ckptfile %d\n", addr, addr+size, no_files-1); total_chunks++; CLOSE(map_fd); CLOSE(data_fd); flush_buffers(); lseek(maptemp_fd, POINTERSIZE*3, SEEK_SET); write(maptemp_fd, (char *)&total_chunks, LONGSIZE); CLOSE(maptemp_fd); CLOSE(datatemp_fd); sprintf(datafile, "%s.%s.0", filename, "data"); sprintf(mapfile, "%s.%s.0", filename, "map"); rename(datatemp, datafile); rename(maptemp, mapfile); for(i=no_files-1; i>0; i--){ sprintf(datafile, "%s.%s.%d", filename, "data", i); sprintf(mapfile, "%s.%s.%d", filename, "map", i); remove(datafile); remove(mapfile); } if(verbose) fprintf(stderr, "CKPT: coalescing complete\n"); }