/* u3_unix_io_init(): initialize unix sync. */ void u3_unix_io_init(void) { u3_unix* unx_u = &u3_Host.unx_u; unx_u->mon_u = NULL; { u3_usig* sig_u; sig_u = c3_malloc(sizeof(u3_usig)); uv_signal_init(u3L, &sig_u->sil_u); sig_u->num_i = SIGTERM; sig_u->nex_u = unx_u->sig_u; unx_u->sig_u = sig_u; } { u3_usig* sig_u; sig_u = c3_malloc(sizeof(u3_usig)); uv_signal_init(u3L, &sig_u->sil_u); sig_u->num_i = SIGINT; sig_u->nex_u = unx_u->sig_u; unx_u->sig_u = sig_u; } { u3_usig* sig_u; sig_u = c3_malloc(sizeof(u3_usig)); uv_signal_init(u3L, &sig_u->sil_u); sig_u->num_i = SIGWINCH; sig_u->nex_u = unx_u->sig_u; unx_u->sig_u = sig_u; } uv_check_init(u3_Host.lup_u, &u3_Host.unx_u.syn_u); uv_timer_init(u3L, &unx_u->tim_u); unx_u->alm = c3n; unx_u->dyr = c3n; if ( c3n == u3_Host.ops_u.nuu ) { u3v_plan(u3nt(u3_blip, c3__boat, u3_nul), u3nc(c3__boat, u3_nul)); } }
/* _http_conn_new(): create http connection. */ static void _http_conn_new(u2_http *htp_u) { u2_hcon *hon_u = c3_malloc(sizeof(*hon_u)); uv_tcp_init(u2L, &hon_u->wax_u); if ( 0 != uv_accept((uv_stream_t*)&htp_u->wax_u, (uv_stream_t*)&hon_u->wax_u) ) { uL(fprintf(uH, "http: accept: %s\n", uv_strerror(uv_last_error(u2L)))); uv_close((uv_handle_t*)&hon_u->wax_u, 0); free(hon_u); } else { uv_read_start((uv_stream_t*)&hon_u->wax_u, _http_alloc, _http_conn_read_cb); hon_u->coq_l = htp_u->coq_l++; hon_u->seq_l = 1; hon_u->ruc_u = 0; hon_u->req_u = 0; hon_u->qer_u = 0; hon_u->htp_u = htp_u; hon_u->nex_u = htp_u->hon_u; htp_u->hon_u = hon_u; } }
/* _unix_hot_gain(): gain ship. */ static void _unix_hot_gain(u2_noun who, u2_bean mek) { u2_noun hox = u2_dc("scot", 'p', u2k(who)); c3_c* hox_c = u2_cr_string(hox); c3_c* pax_c = _unix_down(u2_Host.cpu_c, hox_c + 1); DIR* rid_u = opendir(pax_c); if ( !rid_u ) { if ( u2_yes == mek ) { _unix_mkdir(pax_c); } else { u2z(who); u2z(hox); return; } } else closedir(rid_u); // uL(fprintf(uH, "GAIN %s\n", pax_c)); free(hox_c); u2z(hox); u2_unix_acquire(pax_c); { u2_uhot* hot_u = c3_malloc(sizeof(u2_uhot)); _unix_dir_watch(&hot_u->dir_u, 0, pax_c); u2_cr_mp(hot_u->who_mp, who); u2z(who); hot_u->nex_u = u2_Host.unx_u.hot_u; u2_Host.unx_u.hot_u = hot_u; } }
/* _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)) || u2_no == u2du(u2t(pax)) ) { c3_assert(0); u2z(pax); u2z(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); }
/* u2_cf_flat_save(): save `som` as `mod` at `pas`. */ u2_bean u2_cf_flat_save(u2_noun mod, u2_noun pas, u2_noun som) { c3_assert(c3__atom == mod); { c3_c* pas_c = u2_cr_string(pas); c3_i fid_i; c3_w fln_w; c3_y* fil_y; fid_i = open(pas_c, O_WRONLY | O_CREAT, 0666); free(pas_c); u2_cz(pas); if ( fid_i < 0 ) { perror(pas_c); u2_cz(som); return u2_no; } fln_w = u2_met(3, som); fil_y = c3_malloc(fln_w); u2_cr_bytes(0, fln_w, fil_y, som); u2_cz(som); if ( fln_w != write(fid_i, fil_y, fln_w) ) { return u2_no; } close(fid_i); return u2_yes; } }
/* u3_walk_load(): load file or bail. */ static u3_noun u3_walk_load(c3_c* pas_c) { struct stat buf_b; c3_i fid_i = open(pas_c, O_RDONLY, 0644); c3_w fln_w, red_w; c3_y* pad_y; if ( (fid_i < 0) || (fstat(fid_i, &buf_b) < 0) ) { fprintf(stderr, "%s: %s\r\n", pas_c, strerror(errno)); return u3_cm_bail(c3__fail); } fln_w = buf_b.st_size; pad_y = c3_malloc(buf_b.st_size); red_w = read(fid_i, pad_y, fln_w); close(fid_i); if ( fln_w != red_w ) { free(pad_y); return u3_cm_bail(c3__fail); } else { u3_noun pad = u3_ci_bytes(fln_w, (c3_y *)pad_y); free(pad_y); return pad; } }
/* _http_list_to_heds(): list to C headers. */ static u3_hhed* _http_list_to_heds(u3_noun lix) { u3_noun yix = lix; u3_hhed* hed_u = 0; while ( 1 ) { if ( u3_nul == lix ) { break; } else { u3_noun i_lix = u3h(lix); u3_noun pi_lix = u3h(i_lix); u3_noun qi_lix = u3t(i_lix); u3_noun t_lix = u3t(lix); u3_hhed* nex_u = c3_malloc(sizeof(u3_hhed)); nex_u->nam_c = u3r_string(pi_lix); nex_u->val_c = u3r_string(qi_lix); nex_u->nex_u = hed_u; hed_u = nex_u; lix = t_lix; } } u3z(yix); return hed_u; }
/* _http_bods_to_octs: translate body into octet-stream noun. */ static u3_noun _http_bods_to_octs(u3_hbod* bod_u) { c3_w len_w; c3_y* buf_y; u3_noun cos; { u3_hbod* bid_u; len_w = 0; for ( bid_u = bod_u; bid_u; bid_u = bid_u->nex_u ) { len_w += bid_u->len_w; } } buf_y = c3_malloc(len_w); { c3_y* ptr_y = buf_y; while ( bod_u ) { memcpy(ptr_y, bod_u->hun_y, bod_u->len_w); ptr_y += bod_u->len_w; bod_u = bod_u->nex_u; } } cos = u3i_bytes(len_w, buf_y); free(buf_y); return u3nc(len_w, cos); }
/* _unix_file_form(): form a filename path downward. */ static c3_c* _unix_file_form(u2_udir* dir_u, u2_noun pre, u2_bean ket, u2_noun ext) { c3_c* pre_c = u2_cr_string(pre); c3_c* ext_c = u2_cr_string(ext); c3_w pax_w = strlen(dir_u->pax_c); c3_w pre_w = strlen(pre_c); c3_w ext_w = strlen(ext_c); c3_w ket_w = (u2_yes == ket) ? 1 : 0; c3_c* pax_c = c3_malloc(pax_w + 1 + pre_w + 1 + ket_w + ext_w + 1); strncpy(pax_c, dir_u->pax_c, pax_w); pax_c[pax_w] = '/'; strncpy(pax_c + pax_w + 1, pre_c, pre_w); pax_c[pax_w + 1 + pre_w] = '.'; if ( u2_yes == ket ) { pax_c[pax_w + 1 + pre_w + 1] = '^'; } strncpy(pax_c + pax_w + 1 + pre_w + 1 + ket_w, ext_c, ext_w); pax_c[pax_w + 1 + pre_w + 1 + ket_w + ext_w] = '\0'; free(pre_c); free(ext_c); u2z(pre); u2z(ext); return pax_c; }
/* _http_conn_new(): create http connection. */ static void _http_conn_new(u3_http *htp_u) { u3_hcon *hon_u = c3_malloc(sizeof(*hon_u)); uv_tcp_init(u3L, &hon_u->wax_u); c3_w ret_w; ret_w = uv_accept((uv_stream_t*)&htp_u->wax_u, (uv_stream_t*)&hon_u->wax_u); if (ret_w == UV_EOF) { uL(fprintf(uH, "http: accept: ERROR\n")); uv_close((uv_handle_t*)&hon_u->wax_u, _http_conn_free_early); } else { uv_read_start((uv_stream_t*)&hon_u->wax_u, _http_alloc, _http_conn_read_cb); hon_u->coq_l = htp_u->coq_l++; hon_u->seq_l = 1; hon_u->ruc_u = 0; hon_u->req_u = 0; hon_u->qer_u = 0; hon_u->htp_u = htp_u; hon_u->nex_u = htp_u->hon_u; htp_u->hon_u = hon_u; } }
/* _http_header_field(): jhttp callback */ static c3_i _http_header_field(http_parser* par_u, const c3_c* buf_c, size_t siz_i) { u3_hreq *req_u = par_u->data; switch ( req_u->rat_e ) { case u3_hreq_non: case u3_hreq_val: { u3_hhed* hed_u = c3_malloc(sizeof(*hed_u)); hed_u->nam_c = _http_more(0, buf_c, siz_i); hed_u->val_c = 0; hed_u->nex_u = req_u->hed_u; req_u->hed_u = hed_u; break; } case u3_hreq_nam: { req_u->hed_u->nam_c = _http_more(req_u->hed_u->nam_c, buf_c, siz_i); break; } } req_u->rat_e = u3_hreq_nam; return 0; }
u2_weak // produce j2_mbc(Pt5, shal)(u2_wire wir_r, u2_atom a, // retain u2_atom b) // retain { c3_assert(u2_fly_is_cat(a)); c3_y* fat_y = c3_malloc(a + 1); u2_bytes(0, a, fat_y, b); { c3_y dig_y[64]; #if defined(U2_OS_osx) CC_SHA512_CTX ctx_h; CC_SHA512_Init(&ctx_h); CC_SHA512_Update(&ctx_h, fat_y, a); CC_SHA512_Final(dig_y, &ctx_h); #else SHA512_CTX ctx_h; SHA512_Init(&ctx_h); SHA512_Update(&ctx_h, fat_y, a); SHA512_Final(dig_y, &ctx_h); #endif free(fat_y); return u2_rl_bytes(wir_r, 64, dig_y); } }
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; }
/* functions */ u2_weak // produce j2_mbc(Pt5, shax)(u2_wire wir_r, u2_atom a) // retain { c3_w met_w = u2_met(3, a); c3_y* fat_y = c3_malloc(met_w + 1); u2_bytes(0, met_w, fat_y, a); { c3_y dig_y[32]; #if defined(U2_OS_osx) CC_SHA256_CTX ctx_h; CC_SHA256_Init(&ctx_h); CC_SHA256_Update(&ctx_h, fat_y, met_w); CC_SHA256_Final(dig_y, &ctx_h); #else SHA256_CTX ctx_h; SHA256_Init(&ctx_h); SHA256_Update(&ctx_h, fat_y, met_w); SHA256_Final(dig_y, &ctx_h); #endif free(fat_y); return u2_rl_bytes(wir_r, 32, dig_y); } }
/* unix_save(): save a file. */ static void _unix_save(c3_c* pax_c, u2_atom oat) { c3_i fid_i = open(pax_c, O_WRONLY | O_CREAT | O_TRUNC, 0666); c3_w fln_w, rit_w; c3_y* oat_y; if ( fid_i < 0 ) { uL(fprintf(uH, "%s: %s\n", pax_c, strerror(errno))); u2_cm_bail(c3__fail); } fln_w = u2_met(3, oat); oat_y = c3_malloc(fln_w); u2_cr_bytes(0, fln_w, oat_y, oat); u2z(oat); rit_w = write(fid_i, oat_y, fln_w); if ( rit_w != fln_w ) { uL(fprintf(uH, "%s: %s\n", pax_c, strerror(errno))); c3_assert(0); } close(fid_i); free(oat_y); }
/* unix_load(): load a file. */ static u2_noun _unix_load(c3_c* pax_c) { struct stat buf_u; c3_i fid_i = open(pax_c, O_RDONLY, 0644); c3_w fln_w, red_w; c3_y* pad_y; if ( (fid_i < 0) || (fstat(fid_i, &buf_u) < 0) ) { // ignore if the file disappeared between getting the sync event and now if ( ENOENT != errno ) { uL(fprintf(uH, "%s: %s\n", pax_c, strerror(errno))); } return 0; } fln_w = buf_u.st_size; pad_y = c3_malloc(buf_u.st_size); red_w = read(fid_i, pad_y, fln_w); close(fid_i); if ( fln_w != red_w ) { free(pad_y); c3_assert(0); return 0; } else { u2_noun pad = u2_ci_bytes(fln_w, (c3_y *)pad_y); free(pad_y); return pad; } }
/* _unix_dir_forge: instantiate directory tracker (and make directory). */ static void _unix_dir_forge(u2_udir* dir_u, u2_udir* par_u, u2_noun tet) { dir_u->yes = u2_yes; dir_u->dry = u2_no; { c3_c* tet_c = u2_cr_string(tet); c3_w pax_w = strlen(par_u->pax_c); c3_w tet_w = strlen(tet_c); c3_c* pax_c = c3_malloc(pax_w + 1 + tet_w + 1); strncpy(pax_c, par_u->pax_c, pax_w + 1); pax_c[pax_w] = '/'; strncpy(pax_c + pax_w + 1, tet_c, tet_w + 1); pax_c[pax_w + tet_w + 1] = '\0'; free(tet_c); u2z(tet); uv_fs_event_init(u2L, &dir_u->was_u, pax_c, _unix_fs_event_cb, 0); _unix_mkdir(pax_c); dir_u->pax_c = pax_c; } dir_u->par_u = par_u; dir_u->dis_u = 0; dir_u->fil_u = 0; dir_u->nex_u = 0; }
/* _unix_write_file_soft(): write to a file, not overwriting if it's changed */ static void _unix_write_file_soft(u3_ufil* fil_u, u3_noun mim) { struct stat buf_u; c3_i fid_i = open(fil_u->pax_c, O_RDONLY, 0644); c3_ws len_ws, red_ws; c3_w old_w; c3_y* old_y; if ( fid_i < 0 || fstat(fid_i, &buf_u) < 0 ) { if ( ENOENT == errno ) { goto _unix_write_file_soft_go; } else { uL(fprintf(uH, "error opening file (soft) %s: %s\r\n", fil_u->pax_c, strerror(errno))); u3z(mim); return; } } len_ws = buf_u.st_size; old_y = c3_malloc(len_ws); red_ws = read(fid_i, old_y, len_ws); if ( close(fid_i) < 0 ) { uL(fprintf(uH, "error closing file (soft) %s: %s\r\n", fil_u->pax_c, strerror(errno))); } if ( len_ws != red_ws ) { if ( red_ws < 0 ) { uL(fprintf(uH, "error reading file (soft) %s: %s\r\n", fil_u->pax_c, strerror(errno))); } else { uL(fprintf(uH, "wrong # of bytes read in file %s: %d %d\r\n", fil_u->pax_c, len_ws, red_ws)); } free(old_y); u3z(mim); return; } old_w = u3r_mug_bytes(old_y, len_ws); if ( old_w != fil_u->gum_w ) { fil_u->gum_w = u3r_mug(u3t(u3t(mim))); // XXX this might fail with free(old_y); // trailing zeros u3z(mim); return; } free(old_y); _unix_write_file_soft_go: fil_u->gum_w = _unix_write_file_hard(fil_u->pax_c, mim); }
/* _unix_sync_change(): sync single change to unix */ static void _unix_sync_change(u3_udir* dir_u, u3_noun pax, u3_noun mim) { c3_assert( c3y == dir_u->dir ); if ( c3n == u3du(pax) ) { if ( u3_nul == pax ) { uL(fprintf(uH,"can't sync out file as top-level, strange\r\n")); } else { uL(fprintf(uH,"sync out: bad path\r\n")); } u3z(pax); u3z(mim); return; } else if ( c3n == u3du(u3t(pax)) ) { uL(fprintf(uH,"can't sync out file as top-level, strangely\r\n")); u3z(pax); u3z(mim); } else { u3_noun i_pax = u3h(pax); u3_noun t_pax = u3t(pax); u3_noun it_pax = u3h(t_pax); u3_noun tt_pax = u3t(t_pax); if ( u3_nul == tt_pax ) { _unix_sync_file(dir_u, u3k(i_pax), u3k(it_pax), mim); } else { c3_c* nam_c = u3r_string(i_pax); c3_w pax_w = strlen(dir_u->pax_c); u3_unod* nod_u; for ( nod_u = dir_u->kid_u; ( nod_u && ( c3n == nod_u->dir || 0 != strcmp(nod_u->pax_c + pax_w + 1, nam_c) ) ); nod_u = nod_u->nex_u ) { } if ( !nod_u ) { nod_u = c3_malloc(sizeof(u3_udir)); _unix_create_dir((u3_udir*) nod_u, dir_u, u3k(i_pax)); } if ( c3n == nod_u->dir ) { uL(fprintf(uH, "weird, we got a file when we weren't expecting to\r\n")); c3_assert(0); } _unix_sync_change((u3_udir*) nod_u, u3k(t_pax), mim); } } u3z(pax); }
static void _term_alloc(uv_handle_t* had_u, size_t len_i, uv_buf_t* buf ) { void* ptr_v = c3_malloc(len_i); *buf = uv_buf_init(ptr_v, len_i); }
/* u2_unix_io_init(): initialize unix sync. */ void u2_unix_io_init(void) { u2_unix* unx_u = &u2_Host.unx_u; uv_timer_init(u2L, &unx_u->tim_u); unx_u->alm = u2_no; { u2_usig* sig_u; sig_u = c3_malloc(sizeof(u2_usig)); uv_signal_init(u2L, &sig_u->sil_u); sig_u->num_i = SIGTERM; sig_u->nex_u = unx_u->sig_u; unx_u->sig_u = sig_u; } { u2_usig* sig_u; sig_u = c3_malloc(sizeof(u2_usig)); uv_signal_init(u2L, &sig_u->sil_u); sig_u->num_i = SIGINT; sig_u->nex_u = unx_u->sig_u; unx_u->sig_u = sig_u; } { u2_usig* sig_u; sig_u = c3_malloc(sizeof(u2_usig)); uv_signal_init(u2L, &sig_u->sil_u); sig_u->num_i = SIGWINCH; sig_u->nex_u = unx_u->sig_u; unx_u->sig_u = sig_u; } #if SYNCLOG unx_u->lot_w = 0; memset(unx_u->sylo, 0, sizeof(unx_u->sylo)); #endif uv_check_init(u2_Host.lup_u, &u2_Host.unx_u.syn_u); }
/* u2_cr_string(): `a` as malloced C string. */ c3_c* u2_cr_string(u2_atom a) { c3_w met_w = u2_cr_met(3, a); c3_c* str_c = c3_malloc(met_w + 1); u2_cr_bytes(0, met_w, (c3_y*)str_c, a); str_c[met_w] = 0; return str_c; }
// initialize loss object // static void _lemp(u3_loss* loc_u, u3_noun hel, u3_noun hev) { loc_u->hel = hel; loc_u->lel_w = u3kb_lent(u3k(hel)); // Read hev into array. { c3_w i_w; loc_u->hev = c3_malloc(u3kb_lent(u3k(hev)) * sizeof(u3_noun)); for ( i_w = 0; u3_nul != hev; i_w++ ) { loc_u->hev[i_w] = u3h(hev); hev = u3t(hev); } loc_u->lev_w = i_w; } loc_u->kct_w = 0; loc_u->kad = c3_malloc( (1 + c3_min(loc_u->lev_w, loc_u->lel_w)) * sizeof(u3_noun)); // Compute equivalence classes. // loc_u->sev = u3_nul; { c3_w i_w; for ( i_w = 0; i_w < loc_u->lev_w; i_w++ ) { u3_noun how = loc_u->hev[i_w]; u3_noun hav; u3_noun teg; hav = u3kdb_get(u3k(loc_u->sev), u3k(how)); teg = u3nc(u3i_words(1, &i_w), (hav == u3_none) ? u3_nul : hav); loc_u->sev = u3kdb_put(loc_u->sev, u3k(how), teg); } } }
/* _term_it_buf(): create a data buffer. */ static u3_ubuf* _term_it_buf(c3_w len_w, const c3_y* hun_y) { u3_ubuf* buf_u = c3_malloc(len_w + sizeof(*buf_u)); buf_u->len_w = len_w; memcpy(buf_u->hun_y, hun_y, len_w); buf_u->nex_u = 0; return buf_u; }
/* _http_bod(): create a data buffer. */ static u3_hbod* _http_bod(c3_w len_w, const c3_y* hun_y) { u3_hbod* bod_u = c3_malloc(len_w + sizeof(*bod_u)); bod_u->len_w = len_w; memcpy(bod_u->hun_y, hun_y, len_w); bod_u->nex_u = 0; return bod_u; }
/* _http_req_new(): new http request. */ static u3_hreq* _http_req_new(u3_hcon* hon_u) { u3_hreq* req_u = c3_malloc(sizeof(*req_u)); req_u->hon_u = hon_u; req_u->seq_l = hon_u->seq_l++; req_u->met_e = (u3_hmet)0; req_u->rat_e = (u3_hrat)0; req_u->par_u = c3_malloc(sizeof(struct http_parser)); http_parser_init(req_u->par_u, HTTP_REQUEST); ((struct http_parser *)(req_u->par_u))->data = req_u; { struct sockaddr_in adr_u; c3_i len_i = sizeof(adr_u); uv_tcp_getpeername(&hon_u->wax_u, (struct sockaddr *)&adr_u, &len_i); if ( adr_u.sin_family != AF_INET ) { req_u->ipf_w = 0; } else req_u->ipf_w = ntohl(adr_u.sin_addr.s_addr); } req_u->liv = c3n; req_u->end = c3n; req_u->url_c = 0; req_u->rub_u = 0; req_u->bur_u = 0; req_u->hed_u = 0; req_u->bod_u = 0; req_u->nex_u = 0; return req_u; }
/* u2_unix_io_init(): initialize unix sync. */ void u2_unix_io_init(void) { u2_unix* unx_u = &u2_Host.unx_u; uv_timer_init(u2L, &unx_u->tim_u); unx_u->alm = u2_no; { u2_usig* sig_u; sig_u = c3_malloc(sizeof(u2_usig)); uv_signal_init(u2L, &sig_u->sil_u); sig_u->num_i = SIGTERM; sig_u->nex_u = unx_u->sig_u; unx_u->sig_u = sig_u; } { u2_usig* sig_u; sig_u = c3_malloc(sizeof(u2_usig)); uv_signal_init(u2L, &sig_u->sil_u); sig_u->num_i = SIGINT; sig_u->nex_u = unx_u->sig_u; unx_u->sig_u = sig_u; } { u2_usig* sig_u; sig_u = c3_malloc(sizeof(u2_usig)); uv_signal_init(u2L, &sig_u->sil_u); sig_u->num_i = SIGWINCH; sig_u->nex_u = unx_u->sig_u; unx_u->sig_u = sig_u; } uv_prepare_init(u2_Host.lup_u, &u2_Host.unx_u.pre_u); }
/* u3_http_io_init(): initialize http I/O. */ void u3_http_io_init() { // Logically secure port. { u3_http *htp_u = c3_malloc(sizeof(*htp_u)); htp_u->sev_l = u3A->sev_l + 1; htp_u->coq_l = 1; htp_u->por_w = 8443; htp_u->sec = c3y; htp_u->hon_u = 0; htp_u->nex_u = 0; htp_u->nex_u = u3_Host.htp_u; u3_Host.htp_u = htp_u; } // Insecure port. // { u3_http *htp_u = c3_malloc(sizeof(*htp_u)); htp_u->sev_l = u3A->sev_l; htp_u->coq_l = 1; htp_u->por_w = 8080; htp_u->sec = c3n; htp_u->hon_u = 0; htp_u->nex_u = 0; htp_u->nex_u = u3_Host.htp_u; u3_Host.htp_u = htp_u; } u3_Host.ctp_u.coc_u = 0; }
/* _unix_down(): descend path. */ static c3_c* _unix_down(c3_c* pax_c, c3_c* sub_c) { c3_w pax_w = strlen(pax_c); c3_w sub_w = strlen(sub_c); c3_c* don_c = c3_malloc(pax_w + sub_w + 2); strncpy(don_c, pax_c, pax_w); don_c[pax_w] = '/'; strncpy(don_c + pax_w + 1, sub_c, sub_w); don_c[pax_w + 1 + sub_w] = '\0'; return don_c; }
/* _unix_initial_update_file(): read file, but don't watch */ static u3_noun _unix_initial_update_file(c3_c* pax_c) { struct stat buf_u; c3_i fid_i = open(pax_c, O_RDONLY, 0644); c3_ws len_ws, red_ws; c3_y* dat_y; if ( fid_i < 0 || fstat(fid_i, &buf_u) < 0 ) { if ( ENOENT == errno ) { return u3_nul; } else { uL(fprintf(uH, "error opening initial file %s: %s\r\n", pax_c, strerror(errno))); return u3_nul; } } len_ws = buf_u.st_size; dat_y = c3_malloc(len_ws); red_ws = read(fid_i, dat_y, len_ws); if ( close(fid_i) < 0 ) { uL(fprintf(uH, "error closing initial file %s: %s\r\n", pax_c, strerror(errno))); } if ( len_ws != red_ws ) { if ( red_ws < 0 ) { uL(fprintf(uH, "error reading initial file %s: %s\r\n", pax_c, strerror(errno))); } else { uL(fprintf(uH, "wrong # of bytes read in initial file %s: %d %d\r\n", pax_c, len_ws, red_ws)); } free(dat_y); return u3_nul; } else { u3_noun pax = _unix_string_to_path_helper(pax_c + strlen(U3_LIB) + 6); /* XX VERY BAD */ u3_noun mim = u3nt(c3__text, u3i_string("plain"), u3_nul); u3_noun dat = u3nt(mim, len_ws, u3i_bytes(len_ws, dat_y)); free(dat_y); return u3nc(u3nt(pax, u3_nul, dat), u3_nul); } }