Пример #1
0
void		session_delete(t_session *session)
{
  t_context	*context;
  t_session	*tmp;
  t_session	*tmp2;

  session_end(session);
  context = get_context_ptr((void *)0);
  VERBOSE(printf("\033[%d;1m<%03d> - session delete\033[m\n",
		 COLOR(session->id), session->id));
  tmp = context->sessions;
  if (tmp == session)
    {
      context->sessions = tmp->next;
      session_free(tmp);
      return ;
    }
  tmp2 = tmp;
  tmp = tmp->next;
  for (tmp2 = tmp, tmp = tmp->next; tmp && tmp != session;
       tmp = tmp->next, tmp2 = tmp2->next)
    ;
  if (tmp == session)
    {
      tmp2->next = tmp->next;
      session_free(tmp);
    }
  return ;
}
Пример #2
0
void
fe_close_window (struct session *sess)
{
    /*
     * There's really no point in doing all of this if the user is
     * quitting the app.  It makes it slow (as they watch individual
     * channels and servers disappear), and the OS is about to free
     * everything much more efficiently than we ever could.
     *
     * If we ever choose to run on Windows ME, this could be a problem :)
     */
    if (gui.quit) {
        session_free (sess);
        return;
    }

    navigation_tree_remove_session (gui.server_tree, sess);
    conversation_panel_remove_session (CONVERSATION_PANEL (gui.conversation_panel), sess);
    topic_label_remove_session (TOPIC_LABEL (gui.topic_label), sess);
    text_entry_remove_session (TEXT_ENTRY (gui.text_entry), sess);
    if (sess->type == SESS_SERVER) {
        status_bar_remove_server (STATUS_BAR (gui.status_bar), sess->server);
    }

    if (sess == gui.current_session) {
        gui.current_session = NULL;
    }

    session_free (sess);
}
Пример #3
0
/*
 * Handle socket events, such as connection failure or success.
 *   - BEV_EVENT_ERROR           - network is unreachable
 *   - BEV_EVENT_ERROR+READING   - connection refused or connection timed out
 *   - BEV_EVENT_TIMEOUT+READING - write timeout, if activated by
 *                                 bufferevent_set_timeouts
 */
static void
session_eventcb(struct bufferevent *bev, short what, void *thunk)
{
	struct session *session = thunk;
	switch (what & ~(BEV_EVENT_READING|BEV_EVENT_WRITING)) {
	case BEV_EVENT_CONNECTED:
		session_send(session);
		return;
	case BEV_EVENT_EOF:
		bufferevent_disable(bev, EV_READ|EV_WRITE);
		if (session->completed)
			target_mark(session->t, session->seq, '.');
		else
			target_mark(session->t, session->seq, '%');
		break;
	case BEV_EVENT_ERROR:
		bufferevent_disable(bev, EV_READ|EV_WRITE);
		target_mark(session->t, session->seq, '#');
		break;
	case BEV_EVENT_TIMEOUT:
		target_mark(session->t, session->seq, '?');
		break;
	}
	session_free(session);
}
Пример #4
0
/* Called from main context */
static void sink_input_kill(pa_sink_input* i) {
    struct session *s;
    pa_sink_input_assert_ref(i);
    pa_assert_se(s = i->userdata);

    session_free(s);
}
Пример #5
0
inline NSAPIEnvironment::~NSAPIEnvironment()
{
    // Tidy up the thread-specific "globals" for the next caller
    conf_reset_thread_globals();

    // Discard the request
    if (rq)
        request_free(rq);

    // Discard the session
    if (sn) {
        if (sn->csd && sn->csd_open)
            PR_Close(sn->csd);
        sn->csd_open = 0;
        session_free(sn);
    }

    // Restore the caller's pool.  session_free() set it to NULL
    if (poolCaller)
        systhread_setdata(keyPool, poolCaller);

    // This may have been a request thread.  If it was, we need to restore the
    // HttpRequest* for the thread-specific "globals".
    if (hrq) {
        HttpRequest::SetCurrentRequest(hrq);
        conf_set_thread_globals(hrq);
    }
    else {
        conf_set_thread_globals(threadHrq, threadVS);
    }
}
Пример #6
0
PRIVATE void signal_handler(int sig) {
  switch (sig) {
    case SIGINT:
    case SIGTERM: {
      dbg_printf(P_INFO2, "SIGTERM/SIGINT caught");
      closing = true;
      break;
    }
    case SIGHUP: {
      if(isRunning || !mySession) {
         seenHUP = true;
      } else {
         auto_handle * s = NULL;
         dbg_printf(P_MSG, "Caught SIGHUP. Reloading config file.");
         s = session_init();
         if((parse_config_file(s, AutoConfigFile) != 0) || !setupSession(s)) {
            dbg_printf(P_ERROR, "Error parsing config file. Keeping the old settings.");
            session_free(s);
         }

         seenHUP = false;
      }

      break;
    }
  }
}
Пример #7
0
static void
ssh_relay_event_cb(struct bufferevent *bev, short what, void *ptr)
{
	obfsproxyssh_client_session_t *session = ptr;
	struct evbuffer *buf;

	assert(bev == session->ssh_ev);

	if (what & (BEV_EVENT_EOF | BEV_EVENT_ERROR)) {
		session->ssh_is_valid = 0;
		libssh2_channel_free(session->ssh_channel);
		session->ssh_channel = NULL;
		libssh2_session_free(session->ssh_session);
		session->ssh_session = NULL;
		buf = bufferevent_get_output(session->socks_ev);
		if (0 == session->socks_is_valid || 0 ==
				evbuffer_get_length(buf))
			session_free(session);
		else {
			bufferevent_disable(session->socks_ev, EV_READ);
			bufferevent_setcb(session->socks_ev, NULL,
					socks_relay_teardown_cb,
					socks_event_cb, session);
		}
	}
}
Пример #8
0
static void on_disconnect(netc_t *netc)
{
	struct session *session;
	session = netc->ext_ptr;

	session_free(session);
}
/**
	@brief Free a transport_client, along with all resources it owns.
	@param client Pointer to the transport_client to be freed.
	@return 1 if successful, or 0 if not.  The only error condition is if @a client is NULL.
*/
int client_free( transport_client* client ) {
	if(client == NULL)
		return 0;
	session_free( client->session );
	client->session = NULL;
	return client_discard( client );
}
Пример #10
0
void obc_session_unref(struct obc_session *session)
{
	int refs;

	refs = __sync_sub_and_fetch(&session->refcount, 1);

	DBG("%p: ref=%d", session, refs);

	if (refs > 0)
		return;

	sessions = g_slist_remove(sessions, session);

	if (!session->obex)
		goto disconnect;

	/* Wait OBEX Disconnect to complete if command succeed otherwise
	 * proceed with transport disconnection since there is nothing else to
	 * be done */
	if (g_obex_disconnect(session->obex, disconnect_complete, session,
									NULL))
		return;

disconnect:
	/* Disconnect transport */
	if (session->id > 0 && session->transport != NULL) {
		session->transport->disconnect(session->id);
		session->id = 0;
	}

	session_free(session);
}
Пример #11
0
int session_mem_create(session_opt_t *so, request_t *rq, response_t *rs, 
        session_t **pss)
{
    session_t *ss = NULL;

    dbg_err_if (so == NULL);
    dbg_err_if (rq == NULL);
    dbg_err_if (rs == NULL);
    dbg_err_if (pss == NULL);

    ss = u_zalloc(sizeof(session_t));
    dbg_err_if(ss == NULL);

    ss->load = session_mem_load;
    ss->save = session_mem_save;
    ss->remove = session_mem_remove;
    ss->term = session_mem_term;
    ss->mtime = time(0);
    ss->so = so;

    dbg_err_if(session_prv_init(ss, rq, rs));

    *pss = ss;

    return 0;
err:
    if(ss)
        session_free(ss);
    return ~0;
}
Пример #12
0
static void
ssh_auth_cb(obfsproxyssh_client_session_t *session)
{
	obfsproxyssh_t *state = session->client->state;
	int rval;

	rval = libssh2_userauth_publickey(session->ssh_session,
			bdata(session->user),
			get_rsa_public_key(session->privkey),
			get_rsa_public_key_len(session->privkey),
			sign_with_private_key,
			&session->privkey);
	if (LIBSSH2_ERROR_EAGAIN == rval)
		return;
	else if (0 != rval) {
		log_f(state, "SSH: Error: %s Failed to authenticate - %d",
				bdata(session->ssh_addr), rval);
		libssh2_session_free(session->ssh_session);
		session->ssh_session = NULL;
		session_free(session);
		return;
	}

	session->libssh2_cb = ssh_channel_cb;
	session->libssh2_cb(session);
}
Пример #13
0
static void
socks_relay_teardown_cb(struct bufferevent *bev, void *ptr)
{
	obfsproxyssh_client_session_t *session = ptr;

	session_free(session);
}
Пример #14
0
// This callback is received whenever a session is closed.  The RISP session itself will be destroyed right after this callback exits.
void connclosed_cb(RISPSESSION streamsession, void *dataptr)
{
	assert(streamsession);
	assert(dataptr);
	
	maindata_t *maindata = dataptr;
	assert(maindata);
	assert(maindata->verify == 0xc001b33f);
	
	// we need to go through the list in maindata, to find this particular session.  When we have found it, we remove it.
	assert(maindata->sessions.list);
	assert(maindata->sessions.max > 0);
	
	fprintf(stderr, "Session Closed.  Finding in the list.  Max:%d\n", maindata->sessions.max);
	
	short found = 0; 
	for (int index=0; index < maindata->sessions.max; index++) {
		if (maindata->sessions.list[index]) {
			if (maindata->sessions.list[index]->session_ptr == streamsession) {
				// free the resources used by the session, and the session object itself.
				session_free(maindata->sessions.list[index]);
				
				// clear the entry in the list.
				maindata->sessions.list[index] = NULL;
				
				// we found the one we were looking for, so mark it, and exit the loop.
				found = 1;
				index = maindata->sessions.max;
			}
		} 
	}

	// we should have found one in that list.
	assert(found == 1);
}
Пример #15
0
/**
 * Free the memory associated with the session
 *
 * @param instance	The filter instance
 * @param session	The filter session
 */
static void
freeSession(FILTER *instance, void *session)
{
TEE_SESSION	*my_session = (TEE_SESSION *)session;
SESSION*	ses = my_session->branch_session;
session_state_t state;
#ifdef SS_DEBUG
skygw_log_write(LOGFILE_TRACE,"Tee free: %d", atomic_add(&debug_seq,1));
#endif
	if (ses != NULL)
	{
            state = ses->state;
            
		if (state == SESSION_STATE_ROUTER_READY)
		{
			session_free(ses);
		}
                else if (state == SESSION_STATE_TO_BE_FREED)
		{
			/** Free branch router session */
			ses->service->router->freeSession(
				ses->service->router_instance,
				ses->router_session);
			/** Free memory of branch client session */
			ses->state = SESSION_STATE_FREE;
			free(ses);
			/** This indicates that branch session is not available anymore */
			my_session->branch_session = NULL;
		}
                else if(state == SESSION_STATE_STOPPING)
                {
                    orphan_session_t* orphan;
                    if((orphan = malloc(sizeof(orphan_session_t))) == NULL)
                    {
                        skygw_log_write(LOGFILE_ERROR,"Error : Failed to "
                                "allocate memory for orphan session struct, "
                                "child session might leak memory.");
                    }else{
                        orphan->session = ses;
                        spinlock_acquire(&orphanLock);
                        orphan->next = allOrphans;
                        allOrphans = orphan;
                        spinlock_release(&orphanLock);
                    }
                }
	}
	if (my_session->dummy_filterdef)
	{
		filter_free(my_session->dummy_filterdef);
	}
        if(my_session->tee_replybuf)
            gwbuf_free(my_session->tee_replybuf);
	free(session);
        
	orphan_free(NULL);

        return;
}
Пример #16
0
PRIVATE void shutdown_daemon(auto_handle *as) {
  dbg_printft(P_MSG, "Shutting down daemon");
  if (as && as->bucket_changed) {
    save_state(as->statefile, as->downloads);
  }

  session_free(as);
  SessionID_free();
  log_close();
  exit(EXIT_SUCCESS);
}
Пример #17
0
static void setup_destroy(void *user_data)
{
	struct network_adapter *na = user_data;
	struct network_session *setup = na->setup;

	if (!setup)
		return;

	na->setup = NULL;

	session_free(setup);
}
static int manager_sysview_session_remove(Manager *m, sysview_event *event) {
        sysview_session *session = event->session_remove.session;
        Session *s;

        s = sysview_session_get_userdata(session);
        if (!s)
                return 0;

        session_free(s);

        return 0;
}
Пример #19
0
static void audio_client_free(struct audio_client *ac)
{
    session_free(ac->session, ac);

    if (ac->buf[0].data)
        dma_free_coherent(NULL, ac->buf[0].size,
                          ac->buf[0].data, ac->buf[0].phys);
    if (ac->buf[1].data)
        dma_free_coherent(NULL, ac->buf[1].size,
                          ac->buf[1].data, ac->buf[1].phys);
    kfree(ac);
}
Пример #20
0
NBBOOL session_delete(sessions_t *sessions, char *name)
{
	session_t *session = sessions->first_session;
	session_t *next_session;

	/* Check if we have any sessions. */
	if(!session)
	{
		fprintf(stderr, "There are no sessions to delete\n");
		return FALSE;
	}

	/* Check if the first session is the one we're deleting. */
	if(!strcasecmp(sessions->first_session->name, name))
	{
		fprintf(stderr, "Found session to delete: %s\n", name);
		session = (session_t*)sessions->first_session->next_session;
		session_free(sessions, sessions->first_session);
		sessions->first_session = session;

		return TRUE;
	}

	/* Check if any of the other sessions match. */
	while((next_session = (session_t *)session->next_session) != NULL)
	{
		if(!strcasecmp(next_session->name, name))
		{
			fprintf(stderr, "Found session to delete: %s\n", name);
			session->next_session = next_session->next_session;
			session_free(sessions, next_session);

			return TRUE;
		}

		session = next_session;
	}

	return FALSE;
}
Пример #21
0
static void on_disconnect(netc_t *netc)
{
	jlog(L_DEBUG, "disconnect");

	struct session *session = NULL;
	struct mac_list *mac_itr = NULL;

	session = netc->ext_ptr;

	if (session == NULL) {
		return;
	}

	if (session->state == SESSION_STATE_NOT_AUTHED) {
		session_free(session);
		return;
	}

	/* If the context is still valid, update the node in it. */
	if (session->context != NULL) {

		linkst_disjoin(session->context->linkst, session->id);

		while (session->mac_list != NULL) {
			mac_itr = session->mac_list;
			session->mac_list = mac_itr->next;
			ftable_erase(session->context->ftable, mac_itr->mac_addr);
			free(mac_itr);
		}

		ctable_erase(session->context->ctable, session->node_info->uuid);
		context_del_session(session->context, session);
	}

	transmit_node_connectinfo(ConnectState_disconnected,
				session->ip, session->cert_name);
	session_free(session);

	return;
}
Пример #22
0
int cmd_rm(int argc, char **argv)
{
	unsigned char key[KDF_HASH_LEN];
	struct session *session = NULL;
	struct blob *blob = NULL;
	static struct option long_options[] = {
		{"sync", required_argument, NULL, 'S'},
		{"color", required_argument, NULL, 'C'},
		{0, 0, 0, 0}
	};
	int option;
	int option_index;
	char *name;
	enum blobsync sync = BLOB_SYNC_AUTO;
	struct account *found;

	while ((option = getopt_long(argc, argv, "", long_options, &option_index)) != -1) {
		switch (option) {
			case 'S':
				sync = parse_sync_string(optarg);
				break;
			case 'C':
				terminal_set_color_mode(
					parse_color_mode_string(optarg));
				break;
			case '?':
			default:
				die_usage(cmd_rm_usage);
		}
	}

	if (argc - optind != 1)
		die_usage(cmd_rm_usage);
	name = argv[optind];

	init_all(sync, key, &session, &blob);
	found = find_unique_account(blob, name);
	if (!found)
		die("Could not find specified account '%s'.", name);
	if (found->share && found->share->readonly)
		die("%s is a readonly shared entry from %s. It cannot be deleted.", found->fullname, found->share->name);

	list_del(&found->list);

	lastpass_remove_account(sync, key, session, found, blob);
	blob_save(blob, key);
	account_free(found);

	session_free(session);
	blob_free(blob);
	return 0;
}
Пример #23
0
static void session_release(struct worker_ctx *worker, struct session *s)
{
	if (!s) {
		return;
	}
	if (worker->pool_sessions.len < MP_FREELIST_SIZE) {
		session_clear(s);
		array_push(worker->pool_sessions, s);
		kr_asan_poison(s, sizeof(*s));
	} else {
		session_free(s);
	}
}
Пример #24
0
void obc_session_unref(struct obc_session *session)
{
	gboolean ret;

	ret = g_atomic_int_dec_and_test(&session->refcount);

	DBG("%p: ref=%d", session, session->refcount);

	if (ret == FALSE)
		return;

	session_free(session);
}
Пример #25
0
static void session_inactivity_timer_handler(EV_P_ ev_timer *w, int revents) {
  session_context *sc = (session_context *)w->data;
  ev_tstamp now = ev_now(EV_A);

  (void)revents;
  log_debug("session_inactivity_timer_handler - sc=%x timeout: "
            "now=%.3f - last_activity=%.3f (duration=%.3f) > timeout=%d",
            sc, now, sc->last_activity, now - sc->last_activity,
            sc->options->session_timeout);
  log_info("(%s:%d) Session timeout", sc->client_ip_str, sc->client_port);
  session_free(EV_A_ sc);
  active_session_context = NULL;
}
Пример #26
0
void context_free(context_t *context)
{
	if (context) {
		pki_passport_destroy(context->passport);
		linkst_free(context->linkst);
		ftable_delete(context->ftable);
		ctable_delete(context->ctable);
		ctable_delete(context->atable);
		bitpool_free(context->bitpool);
		session_free(context->access_session);
		free(context);
	}
}
Пример #27
0
/*
 * Read response status. Attempt to read the status line, but if CRLF
 * can not be found in the first 2048 bytes, consider it an error and
 * disconnect. Once status line is read switch to draining the rest of
 * the data. The server should close the connection due to
 * "Connection: close" header otherwise it will be caught by timeout.
 *
 * Even though status line says 200, the actual success is registered
 * on socket close.
 */
static void
session_readcb_status(struct bufferevent *bev, void *thunk)
{
	struct session *session = thunk;
	struct evbuffer *evbuf = bufferevent_get_input(bev);
	size_t len;
	char *line;
	char *protocol;
	char *number;

	line = evbuffer_readln(evbuf, &len, EVBUFFER_EOL_CRLF);
	if (line == NULL) {
		if (evbuffer_get_length(evbuf) > 2048) {
			session_free(session);
			return;
		} else
			return; /* wait for more data */
	}
	/* Parse response line */
	protocol = strsep(&line, " ");
	if (line == NULL)
		return session_free(session);
	number = strsep(&line, " ");
	if (line == NULL)
		return session_free(session);
	(void)protocol;
	(void)number;
	switch (atoi(number)) {
	case 200:
		session->completed = 1;
		break;
	default:
		target_mark(session->t, session->seq, '%');
		break;
	}
	/* Drain the response on future callbacks */
	bufferevent_setcb(session->bev, session_readcb_drain, NULL,
	    session_eventcb, session);
}
Пример #28
0
void io_deinit(uv_handle_t *handle)
{
	if (!handle) {
		return;
	}
	uv_loop_t *loop = handle->loop;
	if (loop && loop->data) {
		struct worker_ctx *worker = loop->data;
		session_release(worker, handle->data);
	} else {
		session_free(handle->data);
	}
	handle->data = NULL;
}
Пример #29
0
/**
 * Free the memory associated with the session
 *
 * @param instance	The filter instance
 * @param session	The filter session
 */
static void
freeSession(FILTER *instance, void *session)
{
    TEE_SESSION *my_session = (TEE_SESSION *) session;
    SESSION* ses = my_session->branch_session;
    session_state_t state;
#ifdef SS_DEBUG
    MXS_INFO("Tee free: %d", atomic_add(&debug_seq, 1));
#endif
    if (ses != NULL)
    {
        state = ses->state;

        if (state == SESSION_STATE_ROUTER_READY)
        {
            session_free(ses);
        }
        else if (state == SESSION_STATE_TO_BE_FREED)
        {
            /** Free branch router session */
            ses->service->router->freeSession(
                                              ses->service->router_instance,
                                              ses->router_session);
            /** Free memory of branch client session */
            ses->state = SESSION_STATE_FREE;
            free(ses);
            /** This indicates that branch session is not available anymore */
            my_session->branch_session = NULL;
        }
        else if (state == SESSION_STATE_STOPPING)
        {
            create_orphan(ses);
        }
    }
    if (my_session->dummy_filterdef)
    {
        filter_free(my_session->dummy_filterdef);
    }
    if (my_session->tee_replybuf)
    {
        gwbuf_free(my_session->tee_replybuf);
    }
    free(session);

    orphan_free(NULL);

    return;
}
Пример #30
0
/* This function kills an existing embryonic session. It stops the connection's
 * transport layer, releases assigned resources, resumes the listener if it was
 * disabled and finally kills the file descriptor. This function requires that
 * sess->origin points to the incoming connection.
 */
static void session_kill_embryonic(struct session *sess)
{
	int level = LOG_INFO;
	struct connection *conn = __objt_conn(sess->origin);
	struct task *task = sess->task;
	unsigned int log = sess->fe->to_log;
	const char *err_msg;

	if (sess->fe->options2 & PR_O2_LOGERRORS)
		level = LOG_ERR;

	if (log && (sess->fe->options & PR_O_NULLNOLOG)) {
		/* with "option dontlognull", we don't log connections with no transfer */
		if (!conn->err_code ||
		    conn->err_code == CO_ER_PRX_EMPTY || conn->err_code == CO_ER_PRX_ABORT ||
		    conn->err_code == CO_ER_CIP_EMPTY || conn->err_code == CO_ER_CIP_ABORT ||
		    conn->err_code == CO_ER_SSL_EMPTY || conn->err_code == CO_ER_SSL_ABORT)
			log = 0;
	}

	if (log) {
		if (!conn->err_code && (task->state & TASK_WOKEN_TIMER)) {
			if (conn->flags & CO_FL_ACCEPT_PROXY)
				conn->err_code = CO_ER_PRX_TIMEOUT;
			else if (conn->flags & CO_FL_ACCEPT_CIP)
				conn->err_code = CO_ER_CIP_TIMEOUT;
			else if (conn->flags & CO_FL_SSL_WAIT_HS)
				conn->err_code = CO_ER_SSL_TIMEOUT;
		}

		session_prepare_log_prefix(sess);
		err_msg = conn_err_code_str(conn);
		if (err_msg)
			send_log(sess->fe, level, "%s: %s\n", trash.str, err_msg);
		else
			send_log(sess->fe, level, "%s: unknown connection error (code=%d flags=%08x)\n",
				 trash.str, conn->err_code, conn->flags);
	}

	/* kill the connection now */
	conn_stop_tracking(conn);
	conn_full_close(conn);
	conn_free(conn);

	task_delete(task);
	task_free(task);
	session_free(sess);
}