/** * Closes the browse host context and releases its memory. * * @return An initialized browse host context. */ static void browse_host_close(struct special_upload *ctx, bool fully_served) { struct browse_host_upload *bh = cast_to_browse_host_upload(ctx); GSList *sl; g_assert(bh); for (sl = bh->hits; sl; sl = g_slist_next(sl)) { pmsg_t *mb = sl->data; pmsg_free(mb); } gm_slist_free_null(&bh->hits); if (bh->w_buf) { wfree(bh->w_buf, bh->w_buf_size); bh->w_buf = NULL; } tx_free(bh->tx); /* * Update statistics if fully served. */ if (fully_served) { if (bh->flags & BH_F_HTML) { gnet_prop_incr_guint32(PROP_HTML_BROWSE_SERVED); } else if (bh->flags & BH_F_QHITS) { gnet_prop_incr_guint32(PROP_QHITS_BROWSE_SERVED); } } wfree(bh, sizeof *bh); }
int main() { int tx_port = 0; char *source = "test/test_defs.b"; sys_init(0); tx_server(source, "bin/state", &tx_port); vol_init(0, "bin/volume"); char *code = sys_load(source); env = env_new(source, code); mem_free(code); int len = 0; char **files = sys_list("test/data", &len); vars = vars_new(len); rvars = vars_new(len); for (int i = 0; i < len; ++i) { vars_add(rvars, files[i], 0, NULL); vars_add(vars, files[i], 0, NULL); } vars_add(vars, "___param", 0, NULL); test_vars(); test_load(); test_param(); test_clone(); test_eq(); test_store(); test_select(); test_rename(); test_extend(); test_join(); test_project(); test_semidiff(); test_summary(); test_union(); test_compound(); test_call(); tx_free(); env_free(env); mem_free(files); vars_free(vars); vars_free(rvars); return 0; }
/** * Closes the THEX upload context and releases its memory. * * @return An initialized THEX upload context. */ static void thex_upload_close(struct special_upload *special_upload, bool fully_served) { struct thex_upload *ctx = cast_to_thex_upload(special_upload); g_assert(ctx); /* * Update statistics if fully served. */ if (fully_served) { gnet_prop_incr_guint32(PROP_THEX_FILES_SERVED); } tx_free(ctx->tx); thex_upload_free_data(ctx); atom_tth_free_null(&ctx->tth); WFREE(ctx); }
/** * Creates a new browse host context. The context must be freed with * browse_host_close(). * * @param owner the owner of the TX stack (the upload) * @param host the host to which we're talking to * @param writable no document * @param deflate_cb callbacks for the deflate layer * @param link_cb callbacks for the link layer * @param wio no document * @param flags opening flags * * @return An initialized browse host context. */ struct special_upload * browse_host_open( void *owner, struct gnutella_host *host, special_upload_writable_t writable, const struct tx_deflate_cb *deflate_cb, const struct tx_link_cb *link_cb, struct wrap_io *wio, int flags) { struct browse_host_upload *bh; /* BH_HTML xor BH_QHITS set */ g_assert(flags & (BH_F_HTML|BH_F_QHITS)); g_assert((flags & (BH_F_HTML|BH_F_QHITS)) != (BH_F_HTML|BH_F_QHITS)); WALLOC(bh); bh->special.read = (flags & BH_F_HTML) ? browse_host_read_html : browse_host_read_qhits; bh->special.write = browse_host_write; bh->special.flush = browse_host_flush; bh->special.close = browse_host_close; browse_host_next_state(bh, BH_STATE_HEADER); bh->hits = NULL; bh->file_index = 0; bh->flags = flags; /* * Instantiate the TX stack. */ { struct tx_link_args args; args.cb = link_cb; args.wio = wio; args.bws = bsched_out_select_by_addr(gnet_host_get_addr(host)); bh->tx = tx_make(owner, host, tx_link_get_ops(), &args); } if (flags & BH_F_CHUNKED) { bh->tx = tx_make_above(bh->tx, tx_chunk_get_ops(), 0); } if (flags & (BH_F_DEFLATE | BH_F_GZIP)) { struct tx_deflate_args args; txdrv_t *tx; args.cq = cq_main(); args.cb = deflate_cb; args.nagle = FALSE; args.reduced = FALSE; args.gzip = 0 != (flags & BH_F_GZIP); args.buffer_flush = INT_MAX; /* Flush only at the end */ args.buffer_size = BH_BUFSIZ; tx = tx_make_above(bh->tx, tx_deflate_get_ops(), &args); if (tx == NULL) { tx_free(bh->tx); link_cb->eof_remove(owner, "Cannot setup compressing TX stack"); WFREE(bh); return NULL; } bh->tx = tx; } /* * Put stack in "eager" mode: we want to be notified whenever * we can write something. */ tx_srv_register(bh->tx, writable, owner); tx_eager_mode(bh->tx, TRUE); /* * Update statistics. */ if (flags & BH_F_HTML) { gnet_prop_incr_guint32(PROP_HTML_BROWSE_COUNT); } else if (flags & BH_F_QHITS) { gnet_prop_incr_guint32(PROP_QHITS_BROWSE_COUNT); } return &bh->special; }
int main(int argc, char *argv[]) { int port = 0; char *data = NULL; char *state = NULL; char *source = NULL; char *tx_addr = NULL; sys_init(1); if (argc < 2) usage(argv[0]); for (int i = 2; (i + 1) < argc; i += 2) if (str_cmp(argv[i], "-d") == 0) data = argv[i + 1]; else if (str_cmp(argv[i], "-c") == 0) source = argv[i + 1]; else if (str_cmp(argv[i], "-s") == 0) state = argv[i + 1]; else if (str_cmp(argv[i], "-p") == 0) port = parse_port(argv[i + 1]); else if (str_cmp(argv[i], "-t") == 0) { tx_addr = argv[i + 1]; if (str_len(tx_addr) >= MAX_ADDR) sys_die("tx address exceeds the maximum length\n"); } else usage(argv[0]); if (str_cmp(argv[1], "start") == 0 && source != NULL && data != NULL && state != NULL && port != 0 && tx_addr == NULL) { int tx_port = 0; tx_server(source, state, &tx_port); vol_init(0, data); char addr[MAX_ADDR]; str_print(addr, "127.0.0.1:%d", tx_port); multiplex(argv[0], addr, port); tx_free(); } else if (str_cmp(argv[1], "processor") == 0 && source == NULL && data == NULL && state == NULL && port != 0 && tx_addr != NULL) { processor(tx_addr, port); } else if (str_cmp(argv[1], "tx") == 0 && source != NULL && data == NULL && state != NULL && port != 0 && tx_addr == NULL) { tx_server(source, state, &port); } else if (str_cmp(argv[1], "vol") == 0 && source == NULL && data != NULL && state == NULL && port != 0 && tx_addr != NULL) { tx_attach(tx_addr); vol_init(port, data); } else if (str_cmp(argv[1], "exec") == 0 && source == NULL && data == NULL && state == NULL && port != 0 && tx_addr != NULL) { tx_attach(tx_addr); multiplex(argv[0], tx_addr, port); } else if (str_cmp(argv[1], "convert") == 0 && source == NULL && data == NULL && state == NULL && port == 0 && tx_addr == NULL) { conv_parse(); } else usage(argv[0]); return 0; }