/** * the socket in index idx got closed */ int ev_closed(int idx, void *u_ptr) { dbuf_t *d; #ifdef WITH_SSL if(cdata[idx].is_ssl) { SSL_shutdown(cdata[idx].ssl); SSL_free(cdata[idx].ssl); cdata[idx].ssl = NULL; } #endif while((d = rpop(&cdata[idx].xmit_list))) { dunlock(d); } if(cdata[idx].handlers.ev_closed) { cdata[idx].handlers.ev_closed(idx, u_ptr); } dunlock(cdata[idx].appdata); if(cdata[idx].inbound) { nclients--; /* if(nclients == 0) { debug(DBG_GLOBAL, 1, "Last client went away, close the outbound connection"); close(ufds[delayed_idx].fd); ufds[delayed_idx].fd = -1; } */ } return 1; }
/** * * _pwd(debug); * * Print current working directory. * **/ PUBLIC void _pwd(DEBUG *debug) { DISPLAY *display = debug->display; dlock(display); #ifdef OLDCODE dprintf(display, "Current Directory is %s", debug->env.Objv[0]->Name); #endif /* -- crf : 12/08/91 - clean up use of Environment Objv */ dprintf(display, "Current Directory is %s", debug->env.Objv[OV_Cdir]->Name); dunlock(display); }
void check_timeouts(reasm_pile_struct_t *rp, time_t now) { reasm_chunk_t *chk; reasm_chunk_t *chk_next; debug(DBG_REASM, 50, "LRU Traversing start, now: %ld", now); for (chk = rp->lru.tqh_first; chk != NULL; chk = chk_next) { chk_next = chk->entries.tqe_next; debug(DBG_REASM, 50, "LRU chunk xid: %lu, deadline: %ld", chk->xid, chk->deadline); if (chk->deadline < now) { debug(DBG_REASM, 50, "chunk xid %lu deadline (%ld) < now (%ld), deleting", chk->xid, chk->deadline, now); dunlock(chk->d); dispose_chk(rp, chk); } } debug(DBG_REASM, 50, "LRU Traversing end"); }
static int lua_fn_dsend(lua_State *L) { int n = lua_gettop(L); int idx = lua_tonumber(L, 1); size_t len; int nwrote; char *data = (void *)lua_tolstring(L, 2, &len); dbuf_t *d = dalloc(len); memcpy(d->buf, data, len); d->dsize = len; sock_write_data(idx, d, &nwrote); dunlock(d); lua_pushnumber(L, nwrote); return 1; }
/** * deactivate the timer (it should have been already dequeued!) * @param idx index of the timer */ void timer_deactivate_internal(uint32_t idx) { timerwheel_entry_t *timers = (timerwheel_entry_t *) timers_list->buf; assert(!lbelongs(&timerwheel[timers[idx].wheel_idx], timers[idx].wheel_li)); check_timer_index(idx); if(timers[idx].user.param_dbuf != NULL) { dunlock(timers[idx].user.param_dbuf); } timers[idx].user.param_dbuf = NULL; timers[idx].user.param_int = 0; memset(&timers[idx].user.param_uuid, 0, sizeof(timers[idx].user.param_uuid)); timers[idx].state = TIMER_INACTIVE; assert(timers[timer_last_inactive].state == TIMER_INACTIVE); timers[timer_last_inactive].next_inactive_index = idx; timer_last_inactive = idx; timers[idx].next_inactive_index = 0; }
int tun_read_ev(int idx, dbuf_t *d, void *p) { lua_State *L; http_parser_t *parser = &http_parser; http_parser_init(parser); L = lua_open(); lua_init_state(L); if(http_parser_data(parser, d->buf, d->dsize)) { char *reply = "File not found!\n"; char *content_type = "text/plain"; char headers[512]; char trailer[1024]; char *xfile; size_t xfile_sz; debug(DBG_GLOBAL, 1, "Parser done. Method: '%s', URI: '%s'", parser->req_method, parser->req_uri); if(strstr(parser->req_uri, ".css")) { content_type = "text/css"; } else if(strstr(parser->req_uri, ".html")) { content_type = "text/html"; } else if(strstr(parser->req_uri, ".js")) { content_type = "application/javascript"; } else if(strstr(parser->req_uri, ".png")) { content_type = "image/png"; } memcpy(trailer, parser->end, parser->content_length); trailer[parser->content_length] = 0; debug(DBG_GLOBAL, 0, "Parser trailer: '%s'", trailer); xfile = mz_zip_extract_archive_file_to_heap("data.zip", parser->req_uri+1, &xfile_sz, 0); if(xfile) { debug(0, 0, "File '%s' => size is %d", parser->req_uri+1, xfile_sz); xfile[xfile_sz] = 0; if(strstr(parser->req_uri, ".lua")) { if(luaL_loadstring(L, xfile)) { debug(0, 0, "Lua file load error: %s", lua_tostring(L,-1)); } else { lua_pcall(L, 0, LUA_MULTRET, 0); lua_getglobal(L, "request"); lua_pushinteger(L, idx); int err = lua_pcall(L, 1, 0, 0); if (err != 0) { debug(0,0,"%d: LUA error %s\n",getpid(), lua_tostring(L,-1)); } } } else { snprintf(headers, sizeof(headers)-1, "HTTP/1.0 200 OK\r\nConnection: keep-alive\r\nContent-length: %d\r\nContent-type: %s\r\n\r\n", (int)xfile_sz, content_type); dunlock(sock_write_data(idx, dstrcpy(headers), NULL)); dunlock(sock_write_data(idx, dalloc_ptr(xfile, xfile_sz), NULL)); xfile = NULL; } } else { snprintf(headers, sizeof(headers)-1, "HTTP/1.0 404 Not Found\r\nConnection: keep-alive\r\nContent-length: %d\r\nContent-type: %s\r\n\r\n", (int)strlen(reply), content_type); dunlock(sock_send_data(idx, dstrcpy(headers), NULL)); dunlock(sock_send_data(idx, dstrcpy(reply), NULL)); } if(xfile) { free(xfile); } lua_close(L); } else { lua_close(L); return 0; } // printf("Got packet, sending back!\n"); return -1; }
static int lua_fn_packet_unlock(lua_State *L) { dbuf_t *d = luaL_checkuserdata(L, 1); dunlock(d); return 0; }