/* _http_heds_to_list(): C headers to list. */ static u2_noun _http_heds_to_list(u2_hhed* hed_u) { if ( 0 == hed_u ) { return u2_nul; } else { return u2nc(u2nc(u2_ci_string(hed_u->nam_c), hed_u->val_c ? u2_ci_string(hed_u->val_c) : u2_nul), _http_heds_to_list(hed_u->nex_u)); } }
u2_noun u2_cf_path(c3_c* top_c, c3_c* ext_c, u2_noun tah) { c3_w top_w = strlen(top_c); c3_w len_w = _cf_path_1(0, (top_w + 1), tah); c3_w buf_w = len_w + (ext_c ? (1 + strlen(ext_c)) : 0); c3_c* buf_c = c3_malloc(buf_w + 1); c3_w pos_w; u2_noun pas; strncpy(buf_c, top_c, buf_w); buf_c[buf_w] = '\0'; pos_w = top_w; buf_c[pos_w++] = '/'; pos_w = _cf_path_1(buf_c, pos_w, tah); if ( ext_c ) { buf_c[pos_w++] = '.'; strncpy(buf_c + pos_w, ext_c, buf_w - pos_w); } else { buf_c[pos_w] = 0; } pas = u2_ci_string(buf_c); free(buf_c); u2_cz(tah); return pas; }
/* u2_cf_list(): list all the files in directory `pas`. List of cask. */ u2_noun u2_cf_list(u2_noun pas) { c3_c* pas_c = u2_cr_string(pas); u2z(pas); { u2_noun lis = u2_nul; DIR *dir_d = opendir(pas_c); if ( !dir_d ) { free(pas_c); return u2_nul; } else { while ( 1 ) { struct dirent ent_n; struct dirent *out_n; if ( readdir_r(dir_d, &ent_n, &out_n) != 0 ) { perror(pas_c); return u2_cm_bail(c3__fail); } else if ( !out_n ) { break; } else lis = u2nc(u2_ci_string(out_n->d_name), lis); } free(pas_c); return lis; } } }
/* _unix_file_name(): file name/extension. */ static u2_noun _unix_file_name(u2_ufil* fil_u) { c3_w pel_w = strlen(fil_u->par_u->pax_c); c3_c* pax_c = fil_u->pax_c + pel_w + 1; if ( !fil_u->dot_c ) { return u2_ci_string(pax_c); } else { c3_c* ext_c = fil_u->dot_c + 1; return u2nc(u2_ci_bytes((fil_u->dot_c - pax_c), (c3_y*)pax_c), u2_ci_string(ext_c)); } }
static void _test_egz_stress_w() { gettimeofday(&before_tv, NULL); int ii; for (ii = 0; ii < NUM_MESSAGES; ii++){ char payload_str[1024]; sprintf(payload_str, "stress: %i", ii); u2_noun aaa = u2_ci_string(payload_str); c3_d num_d = u2_egz_push_ova(u2A, aaa, LOG_MSG_PRECOMMIT); // uL(fprintf(uH, "ovo w: num_d = %llu\n", (unsigned long long int) num_d)); } ii --; struct timeval after_send_tv; gettimeofday(&after_send_tv, NULL); int delta_ms = (after_send_tv.tv_sec - before_tv.tv_sec ) * 1000 * 1000 + (after_send_tv.tv_usec - before_tv.tv_usec ); delta_ms = delta_ms / 1000; uL(fprintf(uH, "%i writes in %i ms\n", ii + 1, delta_ms)); }
/* u2_cm_foul(): */ u2_noun u2_cm_foul(const c3_c* err_c) { u2_cm_bean(u2_ci_string(err_c)); fprintf(stderr, "foul: %s\n", err_c); return u2_bl_error(u2_Wire, err_c); }
/* _unix_dir_name(): directory name. */ static u2_noun _unix_dir_name(u2_udir* dir_u) { c3_w pel_w = strlen(dir_u->par_u->pax_c); c3_c* pax_c = dir_u->pax_c + pel_w + 1; c3_c* fas_c = strchr(pax_c, '/'); return fas_c ? u2_ci_bytes((fas_c - pax_c), (c3_y*) pax_c) : u2_ci_string(pax_c); }
static void _test_egz_ovo_w() { u2_Host.arv_u->key = 1; u2_egz_write_header(u2_Host.arv_u, 0); char * payload_str = "egz ovo"; printf("input was: %s\n", payload_str); u2_noun aaa = u2_ci_string(payload_str); c3_d num_d = u2_egz_push_ova(u2A, aaa, LOG_MSG_PRECOMMIT); printf("ovo w: num_d = %llu\n", (unsigned long long int) num_d); }
/* _unix_file_tame(): file name/extension for toplevel. */ static u2_noun _unix_file_tame(u2_ufil* fil_u) { c3_c* fas_c = strrchr(fil_u->pax_c, '/'); c3_c* pax_c = fil_u->pax_c + (fas_c-fil_u->pax_c) + 1; if ( !fil_u->dot_c ) { return u2_none; } else { c3_c* ext_c = fil_u->dot_c + 1; c3_w nam_w = fil_u->dot_c - pax_c; return u2nc(u2_ci_bytes(nam_w, (c3_y*)pax_c), u2_ci_string(ext_c)); } }
/* _http_request_to_noun(): translate http request into noun, or u2_none. */ static u2_noun _http_request_to_noun(u2_hreq* req_u) { u2_noun med, url, hed, bod; switch ( req_u->met_e ) { default: fprintf(stderr, "strange request\r\n"); return u2_none; case u2_hmet_put: { med = c3__put; break; } case u2_hmet_get: { med = c3__get; break; } case u2_hmet_post: { med = c3__post; break; } } url = u2_ci_string(req_u->url_c); hed = _http_heds_to_list(req_u->hed_u); bod = req_u->bod_u ? u2nc(u2_nul, _http_bods_to_octs(req_u->bod_u)) : u2_nul; return u2nq(med, url, hed, bod); }
/* _unix_desk_sync_tako(): sync out change. */ static void _unix_desk_sync_tako(u2_udir* dir_u, u2_noun pax, u2_noun mis) { if ( (u2_no == u2du(pax)) ) { c3_assert(!"tack"); } else if ( u2_no == u2du(u2t(pax)) ) { // at toplevel u2_noun i_pax = u2h(pax); u2_noun t_pax = u2t(pax); c3_c* par_u = strrchr(dir_u->pax_c, '/') + 1; u2_noun pem = u2_ci_string(par_u); c3_assert( u2_nul == t_pax ); // XX ugly, wrong _unix_desk_sync_tofu(dir_u->par_u, pem, u2k(i_pax), mis); } else { u2_noun i_pax = u2h(pax); u2_noun t_pax = u2t(pax); u2_noun it_pax = u2h(t_pax); u2_noun tt_pax = u2t(t_pax); if ( u2_nul == tt_pax ) { _unix_desk_sync_tofu(dir_u, u2k(i_pax), u2k(it_pax), mis); } else { u2_udir** dis_u = _unix_pdir(dir_u, u2k(i_pax)); if ( !*dis_u ) { *dis_u = c3_malloc(sizeof(u2_udir)); _unix_dir_forge(*dis_u, dir_u, u2k(i_pax)); } _unix_desk_sync_tako(*dis_u, u2k(t_pax), mis); } } u2z(pax); }
/* _walk_in(): inner loop of _walk(), producing map. */ static u2_noun _walk_in(u2_reck* rec_u, const c3_c* dir_c, c3_w len_w) { DIR* dir_d = opendir(dir_c); u2_noun map = u2_nul; if ( !dir_d ) { return u2_nul; } else while ( 1 ) { struct dirent ent_n; struct dirent* out_n; if ( readdir_r(dir_d, &ent_n, &out_n) != 0 ) { uL(fprintf(uH, "%s: %s\n", dir_c, strerror(errno))); break; } else if ( !out_n ) { break; } else if ( !strcmp(out_n->d_name, ".") || !strcmp(out_n->d_name, "..") || ('~' == out_n->d_name[0]) || ('.' == out_n->d_name[0]) ) // XX restricts some spans { continue; } else { c3_c* fil_c = out_n->d_name; c3_w lef_w = len_w + 1 + strlen(fil_c); c3_c* pat_c = malloc(lef_w + 1); struct stat buf_b; strcpy(pat_c, dir_c); pat_c[len_w] = '/'; strcpy(pat_c + len_w + 1, fil_c); if ( 0 != stat(pat_c, &buf_b) ) { free(pat_c); } else { u2_noun tim = c3_stat_mtime(&buf_b); if ( !S_ISDIR(buf_b.st_mode) ) { c3_c* dot_c = strrchr(fil_c, '.'); c3_c* nam_c = strdup(fil_c); c3_c* ext_c = strdup(dot_c + 1); nam_c[dot_c - fil_c] = 0; { u2_noun nam = u2_ci_string(nam_c); u2_noun ext = u2_ci_string(ext_c); u2_noun get = u2_ckd_by_get(u2k(map), u2k(nam)); u2_noun dat = u2_walk_load(pat_c); u2_noun hax; if ( !strcmp("noun", ext_c) ) { dat = u2_cke_cue(dat); } hax = u2_do("sham", u2k(dat)); if ( u2_none == get ) { get = u2_nul; } get = u2_ckd_by_put(get, ext, u2nt(u2_yes, hax, dat)); map = u2_ckd_by_put(map, nam, u2nc(u2_no, get)); } free(nam_c); free(ext_c); } else { u2_noun dir = _walk_in(rec_u, pat_c, lef_w); if ( u2_nul != dir ) { map = u2_ckd_by_put (map, u2_ci_string(fil_c), u2nc(u2_no, dir)); } else u2z(tim); } free(pat_c); } } } closedir(dir_d); return map; }