struct lua_http_cbdata {
struct rspamd_http_connection *conn;
struct rspamd_async_session *session;
- struct rspamd_async_watcher *w;
+ struct rspamd_symcache_item *item;
struct rspamd_http_message *msg;
struct event_base *ev_base;
struct rspamd_config *cfg;
+ struct rspamd_task *task;
struct timeval tv;
struct rspamd_cryptobox_keypair *local_kp;
struct rspamd_cryptobox_pubkey *peer_pk;
lua_http_maybe_free (struct lua_http_cbdata *cbd)
{
if (cbd->session) {
- if (cbd->w) {
- /* We still need to clear watcher */
- rspamd_session_watcher_pop (cbd->session, cbd->w);
- }
if (cbd->flags & RSPAMD_LUA_HTTP_FLAG_RESOLVED) {
/* Event is added merely for resolved events */
rspamd_session_remove_event (cbd->session, lua_http_fin, cbd);
}
+
+ if (cbd->item) {
+ rspamd_symcache_item_async_dec_check (cbd->task, cbd->item);
+ }
}
else {
lua_http_fin (cbd);
{
struct lua_http_cbdata *cbd = (struct lua_http_cbdata *)conn->ud;
struct rspamd_http_header *h, *htmp;
- struct rspamd_async_watcher *existing_watcher = NULL;
const gchar *body;
gsize body_len;
lua_settable (L, -3);
}
- if (cbd->w) {
+ if (cbd->item) {
/* Replace watcher to deal with nested calls */
- existing_watcher = rspamd_session_replace_watcher (cbd->session, cbd->w);
+ rspamd_symbols_cache_set_cur_item (cbd->task, cbd->item);
}
if (lua_pcall (L, 4, 0, 0) != 0) {
lua_pop (L, 1);
}
- if (cbd->w) {
- /* Restore existing watcher */
- rspamd_session_replace_watcher (cbd->session, existing_watcher);
- }
-
lua_http_maybe_free (cbd);
lua_thread_pool_restore_callback (&lcbd);
const gchar *body;
gsize body_len;
struct rspamd_http_header *h, *htmp;
- struct rspamd_async_watcher *existing_watcher = NULL;
if (err) {
lua_pushstring (L, err);
lua_settable (L, -3);
}
- if (cbd->w) {
+ if (cbd->item) {
/* Replace watcher to deal with nested calls */
- existing_watcher = rspamd_session_replace_watcher (cbd->session, cbd->w);
+ rspamd_symbols_cache_set_cur_item (cbd->task, cbd->item);
}
lua_thread_resume (cbd->thread, 2);
-
- if (cbd->w) {
- /* Restore existing watcher */
- rspamd_session_replace_watcher (cbd->session, existing_watcher);
- }
}
static gboolean
cbd->msg = NULL;
if (cbd->session) {
- rspamd_session_add_event (cbd->session, cbd->w,
+ rspamd_session_add_event (cbd->session,
(event_finalizer_t) lua_http_fin, cbd,
g_quark_from_static_string ("lua http"));
cbd->flags |= RSPAMD_LUA_HTTP_FLAG_RESOLVED;
}
+ if (cbd->item) {
+ rspamd_symcache_item_async_inc (cbd->task, cbd->item);
+ }
+
return TRUE;
}
if (!lua_http_make_connection (cbd)) {
lua_http_push_error (cbd, "unable to make connection to the host");
lua_http_maybe_free (cbd);
+
+ return;
}
}
+
+ if (cbd->item) {
+ rspamd_symcache_item_async_dec_check (cbd->task, cbd->item);
+ }
}
static void
return 1;
}
if (task == NULL && cfg == NULL) {
- return luaL_error (L, "Bad params to rspamd_http:request(): either task or config should be set");
+ return luaL_error (L,
+ "Bad params to rspamd_http:request(): either task or config should be set");
}
+
if (ev_base == NULL) {
- return luaL_error (L, "Bad params to rspamd_http:request(): ev_base isn't passed");
+ return luaL_error (L,
+ "Bad params to rspamd_http:request(): ev_base isn't passed");
}
cbd = g_malloc0 (sizeof (*cbd));
cbd->max_size = max_size;
cbd->url = url;
cbd->auth = auth;
+ cbd->task = task;
+
+ if (task) {
+ cbd->item = rspamd_symbols_cache_get_cur_item (task);
+ }
if (msg->host) {
cbd->host = rspamd_fstring_cstr (msg->host);
if (session) {
cbd->session = session;
-
- cbd->w = rspamd_session_get_watcher (cbd->session);
- rspamd_session_watcher_push_specific (cbd->session, cbd->w);
}
if (rspamd_parse_inet_address (&cbd->addr, msg->host->str, msg->host->len)) {
lua_http_maybe_free (cbd);
lua_pushboolean (L, FALSE);
- if (cbd->w) {
- rspamd_session_watcher_pop (cbd->session, cbd->w);
- }
-
return 1;
}
}
lua_pushboolean (L, FALSE);
g_free (to_resolve);
- if (cbd->w) {
- rspamd_session_watcher_pop (cbd->session, cbd->w);
- }
-
return 1;
}
lua_http_maybe_free (cbd);
lua_pushboolean (L, FALSE);
- if (cbd->w) {
- rspamd_session_watcher_pop (cbd->session, cbd->w);
- }
-
return 1;
}
+ else {
+ rspamd_symcache_item_async_inc (cbd->task, cbd->item);
+ }
}
}