int main(int ac, char **av) { int flag_exit; struct sockaddr_in sin; t_init data; g_data = &data; signal(SIGPIPE, SIG_IGN); signal(SIGINT, SIG_IGN); srand(time(NULL)); if (get_option_init(ac, av, &data) == -1 || fillstruct(&sin, &data) == -1) return (-1); if ((bind(data.socket, (const struct sockaddr *) &sin, sizeof(sin))) == -1) return (merror("bind")); else printf(STR_LISTENING, data.port); if ((listen(data.socket, 1000)) == -1) return (merror("listen")); aff_options(&data); flag_exit = 0; signal(SIGINT, ctrl_c); while (flag_exit != -1) flag_exit = monitor(&data); close(data.socket); free_all(&data); printf("Job done !\n"); return (EXIT_SUCCESS); }
int main(int ac, char **av, char **environ) { char *term; int a; t_struct vals; t_booly *booh; vals = checkfonc(ac, vals, av); booh = fillin(vals); if ((term = getterm(environ)) == NULL) return (1); a = tgetent(NULL, term); if (dogent(a) == 1) return (1); checkwinsize(&vals); fillstruct(&vals); tputs(vals.tget->hidecurs, 1, my_putchar); tputs(vals.tget->clears, 1, my_putchar); afffile(vals, booh); makeread(vals, booh); return (0); }
struct block postrequest(CURL *curl_handle, const char *url, curl_httppost *data) { char *ct = NULL; char *post = findRchr(url, '?'); struct block b, h; int res; struct HeaderStruct head; struct MemoryStruct chunk; chunk.memory = (char *)malloc(1); /* will be grown as needed by the realloc above */ chunk.size = 0; /* no data at this point */ head.memory = (char *)malloc(1); /* will be grown as needed by the realloc above */ head.size = 0; /* no data at this point */ head.download = 0; /* not yet known at this point */ setmainheaders(curl_handle, url); setrequestheaders(curl_handle, POST); if(curl_handle) { /* we pass our 'chunk' struct to the callback function */ curl_easy_setopt(curl_handle, CURLOPT_HEADERFUNCTION, parseheader); curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk); curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, (void *)&head); if (data == NULL) curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, post+1); else curl_easy_setopt(curl_handle, CURLOPT_HTTPPOST, data); if ((res = curl_easy_perform(curl_handle)) != 0) /*error!*/ { if (data) curl_formfree(data); if (res == CURLE_WRITE_ERROR) { fillstruct(curl_handle, &head, &h); free(head.memory); return h; } Debug(curl_easy_strerror((CURLcode)res)); return emptyblock; } if (data) curl_formfree(data); if(CURLE_OK != curl_easy_getinfo(curl_handle, CURLINFO_CONTENT_TYPE, &ct) || !ct) return emptyblock; } else return emptyblock; b.data = chunk.memory; b.size = chunk.size; free(head.memory); findChr(ct, ';'); strcpy(b.type, ct); return b; }
struct block getrequest(CURL *curl_handle, const char *url, FILE *hfile) { char *ct = NULL; struct block b, h; int res; struct HeaderStruct head; struct MemoryStruct chunk; chunk.memory = (char *)malloc(1); /* will be grown as needed by the realloc above */ chunk.size = 0; /* no data at this point */ head.memory = (char *)malloc(1); /* will be grown as needed by the realloc above */ head.size = 0; /* no data at this point */ head.download = 0; /* not yet known at this point */ setmainheaders(curl_handle, url); setrequestheaders(curl_handle, GET); if(curl_handle) { /* we pass our 'chunk' struct or 'hfile' to the callback function */ if(hfile) { /* send all data to this function */ curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, writedata); curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)hfile); } else { curl_easy_setopt(curl_handle, CURLOPT_HEADERFUNCTION, parseheader); curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk); curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, (void *)&head); } if ((res = curl_easy_perform(curl_handle)) != 0) /*error!*/ { if (res == CURLE_ABORTED_BY_CALLBACK) { h.size = DSTOPPED; return h; } if (res == CURLE_WRITE_ERROR) { fillstruct(curl_handle, &head, &h); free(head.memory); return h; } Debug(curl_easy_strerror((CURLcode)res)); return emptyblock; } if(CURLE_OK != curl_easy_getinfo(curl_handle, CURLINFO_CONTENT_TYPE, &ct) || !ct) return emptyblock; } else return emptyblock; b.data = chunk.memory; b.size = chunk.size; findChr(ct, ';'); strcpy(b.type, ct); free(head.memory); if(hfile) { h.size = DCOMPLETE; fclose(hfile); return h; } return b; }
BOOL quetzal_stack_restore(strid_t stream, glui32 qsize) { glui32 i = 0; int num_frames = 0; kill_stack(); init_stack(1024, 128); while(i < qsize) { unsigned n; unsigned num_locals; zword locals[16]; int num_args; int var; glui32 qframe[5]; i += fillstruct(stream, qstackframe, qframe, NULL); if(qframe[qreturnPC] > total_size) { n_show_error(E_SAVE, "function return PC past end of memory", qframe[qreturnPC]); return FALSE; } if((qframe[qflags] & b11100000) != 0) { n_show_error(E_SAVE, "expected top bits of flag to be zero", qframe[qflags]); return FALSE; } var = qframe[qvar]; if(qframe[qflags] & b00010000) /* from a call_n */ var = -1; num_locals = qframe[qflags] & b00001111; if(num_locals > 15) { n_show_error(E_SAVE, "too many locals", num_locals); return FALSE; } num_args = 0; switch(qframe[qargs]) { default: n_show_error(E_SAVE, "invalid argument count", qframe[qargs]); return FALSE; case b01111111: num_args++; case b00111111: num_args++; case b00011111: num_args++; case b00001111: num_args++; case b00000111: num_args++; case b00000011: num_args++; case b00000001: num_args++; case b00000000: ; } for(n = 0; n < num_locals; n++) { unsigned char v[ZWORD_SIZE]; glk_get_buffer_stream(stream, (char *) v, ZWORD_SIZE); locals[n] = MSBdecodeZ(v); i+=ZWORD_SIZE; } if(zversion != 6 && num_frames == 0) ; /* dummy stack frame; don't really use it */ else add_stack_frame(qframe[qreturnPC], num_locals, locals, num_args, var); for(n = 0; n < qframe[qeval]; n++) { unsigned char v[ZWORD_SIZE]; glk_get_buffer_stream(stream, (char *) v, ZWORD_SIZE); stack_push(MSBdecodeZ(v)); i += ZWORD_SIZE; } num_frames++; } if(!verify_stack()) { n_show_error(E_SAVE, "restored stack fails verification", 0); return FALSE; } return TRUE; }