enum cmd_retval
cmd_rename_session_exec(struct cmd *self, struct cmd_q *cmdq)
{
	struct args	*args = self->args;
	struct session	*s;
	const char	*newname;

	newname = args->argv[0];
	if (!session_check_name(newname)) {
		cmdq_error(cmdq, "bad session name: %s", newname);
		return (CMD_RETURN_ERROR);
	}
	if (session_find(newname) != NULL) {
		cmdq_error(cmdq, "duplicate session: %s", newname);
		return (CMD_RETURN_ERROR);
	}

	if ((s = cmd_find_session(cmdq, args_get(args, 't'), 0)) == NULL)
		return (CMD_RETURN_ERROR);

	RB_REMOVE(sessions, &sessions, s);
	free(s->name);
	s->name = xstrdup(newname);
	RB_INSERT(sessions, &sessions, s);

	server_status_session(s);
	notify_session_renamed(s);

	return (CMD_RETURN_NORMAL);
}
Пример #2
0
Файл: main.c Проект: hiciu/ekg2
/*
 * logs_session_var_changed()
 *
 * "session-variable-changed" handler
 */
static QUERY(logs_session_var_changed) {
	char *session	= *(va_arg(ap, char**));
	char *var	= *(va_arg(ap, char**));
	int i;

	if (!logs_logs || (0 == logs_logs->len))
		return 0;

	if (!xstrcmp(var, "log_formats")) {
		session_t *s = session_find(session);
		int newformat = logs_log_format(s);

		debug_function("logs_session_var_changed() s=%s, %s=%s\n", session, var, session_get(s, var));

		for (i = logs_logs->len - 1; 0 <= i; i--) {
			logs_log_t *ll = g_ptr_array_index(logs_logs, i);
			if (LOG_FORMAT_RAW == ll->format) continue;
			if (xstrcmp(ll->session, session)) continue;
			if (ll->format != newformat)
				logs_log_reopen(ll);
		}
	}

	return 0;
}
Пример #3
0
struct obc_session *obc_session_create(const char *source,
						const char *destination,
						const char *service,
						uint8_t channel,
						const char *owner,
						session_callback_t function,
						void *user_data)
{
	DBusConnection *conn;
	struct obc_session *session;
	struct obc_transport *transport;
	struct obc_driver *driver;

	if (destination == NULL)
		return NULL;

	session = session_find(source, destination, service, channel, owner);
	if (session != NULL)
		goto proceed;

	/* FIXME: Do proper transport lookup when the API supports it */
	transport = obc_transport_find("Bluetooth");
	if (transport == NULL)
		return NULL;

	driver = obc_driver_find(service);
	if (driver == NULL)
		return NULL;

	conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
	if (conn == NULL)
		return NULL;

	session = g_try_malloc0(sizeof(*session));
	if (session == NULL)
		return NULL;

	session->refcount = 1;
	session->transport = transport;
	session->driver = driver;
	session->conn = conn;
	session->source = g_strdup(source);
	session->destination = g_strdup(destination);
	session->channel = channel;
	session->queue = g_queue_new();

	if (owner)
		obc_session_set_owner(session, owner, owner_disconnected);

proceed:
	if (session_connect(session, function, user_data) < 0) {
		obc_session_unref(session);
		return NULL;
	}

	DBG("session %p transport %s driver %s", session,
			session->transport->name, session->driver->service);

	return session;
}
Пример #4
0
int ekg_session_len(ekg_sessionObj * self)
{
	session_t * s;
	s = session_find(self->name);
	/* XXX, leafnode what about _local_ ones? */
	return s ? s->global_vars_count : 0;
}
Пример #5
0
/*
 * Fetch the specified message part, ie. BODY[<part>], of the
 * messages.
 */
int
request_fetchpart(const char *server, const char *port, const char *user,
    const char *mesg, const char *part, char **bodypart, size_t *len)
{
	int t, r, n;
	session *s;
	char *f;

	n = strlen("BODY.PEEK[]") + strlen(part) + 1;
	f = (char *)xmalloc(n * sizeof(char));
	snprintf(f, n, "%s%s%s", "BODY.PEEK[", part, "]");

	if (!(s = session_find(server, port, user)))
		return -1;

	t = imap_fetch(s, mesg, f);
	if ((r = response_fetchbody(s, t, bodypart, len)) == -1)
		goto fail;

	xfree(f);

	return r;
fail:
	close_connection(s);
	session_destroy(s);

	return -1;
}
Пример #6
0
/*
 * Fetch the specified header fields, ie. BODY[HEADER.FIELDS (<fields>)], of
 * the messages.
 */
int
request_fetchfields(const char *server, const char *port, const char *user,
    const char *mesg, const char *headerfields, char **fields, size_t *len)
{
	int t, r, n;
	session *s;
	char *f;

	n = strlen("BODY.PEEK[HEADER.FIELDS ()]") + strlen(headerfields) + 1;
	f = (char *)xmalloc(n * sizeof(char));
	snprintf(f, n, "%s%s%s", "BODY.PEEK[HEADER.FIELDS (", headerfields, ")]");

	if (!(s = session_find(server, port, user)))
		return -1;

	t = imap_fetch(s, mesg, f);
	if ((r = response_fetchbody(s, t, fields, len)) == -1)
		goto fail;

	xfree(f);

	return r;
fail:
	close_connection(s);
	session_destroy(s);

	return -1;
}
Пример #7
0
/*
 * Add, remove or replace the specified flags of the messages.
 */
int
request_store(const char *server, const char *port, const char *user,
    const char *mesg, const char *mode, const char *flags)
{
	int t, r;
	session *s;

	if (!(s = session_find(server, port, user)))
		return -1;

	t = imap_store(s, mesg, mode, flags);
	if ((r = response_generic(s, t)) == -1)
		goto fail;

	if (xstrcasestr(flags, "\\Deleted") && get_option_boolean("expunge"))
		if (response_generic(s, imap_expunge(s)) == -1)
			goto fail;

	return r;
fail:
	close_connection(s);
	session_destroy(s);

	return -1;
}
Пример #8
0
/**
 * Pretty print peer name.
 */
static int
lbox_session_peer(struct lua_State *L)
{
	if (lua_gettop(L) > 1)
		luaL_error(L, "session.peer(sid): bad arguments");

	int fd;
	struct session *session;
	if (lua_gettop(L) == 1)
		session = session_find(luaL_checkint(L, 1));
	else
		session = current_session();
	if (session == NULL)
		luaL_error(L, "session.peer(): session does not exist");
	fd = session->fd;
	if (fd < 0) {
		lua_pushnil(L); /* no associated peer */
		return 1;
	}

	struct sockaddr_storage addr;
	socklen_t addrlen = sizeof(addr);
	if (sio_getpeername(fd, (struct sockaddr *)&addr, &addrlen) < 0)
		luaL_error(L, "session.peer(): getpeername() failed");

	lua_pushstring(L, sio_strfaddr((struct sockaddr *)&addr, addrlen));
	return 1;
}
Пример #9
0
static int session_remove(const char *uid) {
	session_t *s;
	window_t *w;
	char *tmp;

	if (!(s = session_find(uid)))
		return -1;
	if (s == session_current)
		session_current = NULL;

	for (w = windows; w; w = w->next) {
		if (w->session == s) {
			w->session = NULL;
			if (sessions && sessions->next)
				window_session_cycle(w);
		} 
	}
	
	tmp = xstrdup(uid);
	query_emit_id(NULL, SESSION_CHANGED);
	query_emit_id(NULL, SESSION_REMOVED, &tmp);
	xfree(tmp);

	sessions_remove(s);
	return 0;
}
Пример #10
0
static gboolean fx_send_attention(PurpleConnection *gc, const gchar *who, guint UNUSED(type))
{
	PurpleBuddy    *buddy;
	PurplePresence *presence;
	PurpleStatus   *status;
	const gchar    *status_id;
	fetion_account  *sec;
	fetion_account  *ac = purple_connection_get_protocol_data(gc);

	if(!(buddy = purple_find_buddy(ac->account, who))) return 0;
	presence = purple_buddy_get_presence(buddy);
	status   = purple_presence_get_active_status(presence);
	status_id = purple_status_get_id(status);

	/* online,need invite */
	if(strcmp(status_id, "Offline") != 0) {
		if(!(sec = session_find(who)))
			new_chat(ac, who, (gchar*)0);
		else 
			fetion_send_nudge(sec, who);
		return TRUE;
	}

	return FALSE;
}
Пример #11
0
static QUERY(sniff_status_show) {
	char		*uid = *(va_arg(ap, char **));
	session_t	*s = session_find(uid);
	struct pcap_stat stats;

	if (!s)
		return -1;

	if (!s->connected)
		return 0;

	if (!s->priv) {
		debug_error("sniff_status_show() s->priv NULL\n");
		return -1;
	}

/* Device: DEVICE (PROMISC?) */

/* some stats */
	memset(&stats, 0, sizeof(struct pcap_stat));
	if (pcap_stats(GET_DEV(s), &stats) == -1) {
		debug_error("sniff_status_show() pcap_stats() failed\n");
		return -1;
	}

	debug("pcap_stats() recv: %d drop: %d ifdrop: %d\n", stats.ps_recv, stats.ps_drop, stats.ps_ifdrop);
	print("sniff_pkt_rcv",	session_name(s), ekg_itoa(stats.ps_recv));
	print("sniff_pkt_drop",	session_name(s), ekg_itoa(stats.ps_drop));
	print("sniff_conn_db",	session_name(s), ekg_itoa(list_count(tcp_connections)));

	return 0;
}
Пример #12
0
/*
 * Copy the specified messages to another mailbox.
 */
int
request_copy(const char *server, const char *port, const char *user,
    const char *mesg, const char *mbox)
{
	int t, r;
	session *s;
	const char *m;

	if (!(s = session_find(server, port, user)))
		return -1;

	m = apply_namespace(mbox, s->ns.prefix, s->ns.delim);

	do {
		t = imap_copy(s, mesg, m);
		switch (r = response_generic(s, t)) {
		case STATUS_RESPONSE_TRYCREATE:
			if (create_mailbox(s, mbox) == -1)
				goto fail;
			break;
		case -1:
			goto fail;
			break;
		}
	} while (r == STATUS_RESPONSE_TRYCREATE);

	return r;
fail:
	close_connection(s);
	session_destroy(s);

	return -1;
}
Пример #13
0
/*
 * Rename a mailbox.
 */
int
request_rename(const char *server, const char *port, const char *user,
    const char *oldmbox, const char *newmbox)
{
	int r;
	session *s;
	char *o, *n;

	if (!(s = session_find(server, port, user)))
		return -1;

	o = xstrdup(apply_namespace(oldmbox, s->ns.prefix, s->ns.delim));
	n = xstrdup(apply_namespace(newmbox, s->ns.prefix, s->ns.delim));

	r = response_generic(s, imap_rename(s, o, n));

	xfree(o);
	xfree(n);

	if (r == -1)
		goto fail;

	return r;
fail:
	close_connection(s);
	session_destroy(s);

	return -1;
}
Пример #14
0
/*
 * Get mailbox's status.
 */
int
request_status(const char *server, const char *port, const char *user,
    const char *mbox, unsigned int *exists, unsigned int *recent,
    unsigned int *unseen, unsigned int *uidnext)
{
	int t, r;
	session *s;
	const char *m;

	if (!(s = session_find(server, port, user)))
		return -1;

	m = apply_namespace(mbox, s->ns.prefix, s->ns.delim);

	if (s->protocol == PROTOCOL_IMAP4REV1) {
		t = imap_status(s, m, "MESSAGES RECENT UNSEEN UIDNEXT");
		if ((r = response_status(s, t, exists, recent, unseen, uidnext)) == -1)
			goto fail;
	} else {
		t = imap_examine(s, m);
		if ((r = response_examine(s, t, exists, recent)) == -1)
			goto fail;
	}

	return r;
fail:
	close_connection(s);
	session_destroy(s);

	return -1;
}
Пример #15
0
int
cmd_rename_session_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct args	*args = self->args;
	struct session	*s;
	const char	*newname;

	newname = args->argv[0];
	if (!session_check_name(newname)) {
		ctx->error(ctx, "bad session name: %s", newname);
		return (-1);
	}
	if (session_find(newname) != NULL) {
		ctx->error(ctx, "duplicate session: %s", newname);
		return (-1);
	}

	if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
		return (-1);

	RB_REMOVE(sessions, &sessions, s);
	xfree(s->name);
	s->name = xstrdup(newname);
	RB_INSERT(sessions, &sessions, s);

	server_status_session(s);
	control_notify_session_renamed(s);

	return (0);
}
Пример #16
0
static int fx_im_send(PurpleConnection *gc, const gchar *who, const gchar *what, PurpleMessageFlags UNUSED(flags))
{
	PurpleBuddy    *buddy;
	PurplePresence *presence;
	PurpleStatus   *status;
	const gchar    *status_id;
	fetion_account  *sec;
	PurpleConversation *conv;
	fetion_account  *ac = purple_connection_get_protocol_data(gc);

	Contact        *cnt;
	gint            shutdown = 0;

	if(!(buddy = purple_find_buddy(ac->account, who))) return 0;
	presence = purple_buddy_get_presence(buddy);
	status   = purple_presence_get_active_status(presence);
	status_id = purple_status_get_id(status);

	cnt = fetion_contact_list_find_by_userid(ac->user->contactList, who);
	if(cnt->relationStatus == RELATION_STATUS_UNAUTHENTICATED) {
		if(!(conv = purple_find_conversation_with_account(
						PURPLE_CONV_TYPE_ANY, who, ac->account))) return -1;
			purple_conversation_write(conv, NULL,
					  _("Failed to send message: Unverified Buddy!"),
					  PURPLE_MESSAGE_ERROR, time(NULL));
			return -1;
	}
	
	if(cnt->serviceStatus == BASIC_SERVICE_ABNORMAL){
		if(cnt->carrierStatus == CARRIER_STATUS_CLOSED){
			shutdown = 1;
		}else{
			if((cnt->carrier[0] != '\0' && cnt->mobileno[0] == '\0') || cnt->carrier[0] == '\0')
				shutdown = 1;
		}
	}else if(cnt->carrierStatus == CARRIER_STATUS_DOWN)
		if(cnt->carrier[0] != '\0') shutdown = 1;

	if(shutdown) {
		if(!(conv = purple_find_conversation_with_account(
						PURPLE_CONV_TYPE_ANY, who, ac->account))) return -1;
			purple_conversation_write(conv, NULL,
					  _("Fail to send message: Buddy has cancled Fetion service!"),
					  PURPLE_MESSAGE_ERROR, time(NULL));
			return -1;
	}

	/* online,need invite */
	if(strcmp(status_id, "Offline") != 0) {
		if(!(sec = session_find(who))) new_chat(ac, who, what);
		else  fetion_send_sms(sec, who, what);
		return 1;
	}

	fetion_send_sms(ac, who, what);
	return 1;
}
Пример #17
0
/**
 * Check whether or not a session exists.
 */
static int
lbox_session_exists(struct lua_State *L)
{
	if (lua_gettop(L) != 1)
		luaL_error(L, "session.exists(sid): bad arguments");

	uint32_t sid = luaL_checkint(L, -1);
	lua_pushboolean(L, session_find(sid) != NULL);
	return 1;
}
Пример #18
0
PyObject *ekg_session_connected(ekg_sessionObj * self)
{
	session_t * s;
	s = session_find(self->name);
	debug("[python] Checking if session %s is connected\n", self->name);
	if (session_connected_get(s)) {
		Py_RETURN_TRUE;
	} else {
		Py_RETURN_FALSE;
	}
}
Пример #19
0
static QUERY(sniff_session_deinit) {
	char *session = *(va_arg(ap, char**));
	session_t *s = session_find(session);

	if (!s || !s->priv || s->plugin != &sniff_plugin)
		return 1;

	debug("sniff closing pcap dev: 0x%x\n", s->priv);
	pcap_close(GET_DEV(s));	

	s->priv = NULL;
	return 0;
}
Пример #20
0
/**
 * Check whether or not a session exists.
 */
static int
lbox_session_fd(struct lua_State *L)
{
	if (lua_gettop(L) != 1)
		luaL_error(L, "session.fd(sid): bad arguments");

	uint32_t sid = luaL_checkint(L, -1);
	struct session *session = session_find(sid);
	if (session == NULL)
		luaL_error(L, "session.fd(): session does not exist");
	lua_pushinteger(L, session->fd);
	return 1;
}
Пример #21
0
Файл: main.c Проект: hiciu/ekg2
static logs_log_t *logs_log_new(const char *session, const char *target, gboolean raw) {
	logs_log_t *ll;
	log_format_t format;
	char *uid, *tmp;

	if (LOG_FORMAT_NONE == (format = raw ? LOG_FORMAT_RAW : logs_log_format(session_find(session))))
		return NULL;

	if (!(uid = g_strdup(get_uid_any(session_find(session), target))))
		uid = g_strdup(target);
	if ((tmp = xstrchr(uid, '/')))
		*tmp = '\0';		// strip resource

	ll = logs_log_find(session, uid, raw);

	if (ll) {
		g_free(uid);
		return ll;
	}

	// Create new
	ll = xmalloc(sizeof(logs_log_t));
	ll->session = g_strdup(session);
	ll->uid = uid;
	ll->format = format;
	ll->fname = logs_prepare_fname(ll);

	g_ptr_array_add(logs_logs, ll);

	if (ll->format == LOG_FORMAT_IRSSI && xstrlen(IRSSI_LOG_EKG2_OPENED)) {
		logs_open_file(ll);
		logs_irssi_sysmsg(ll, prepare_timestamp_format(IRSSI_LOG_EKG2_OPENED, time(NULL)));
	}

	debug("[logs] log_new s=%s uid=%s ff=%d logs_log_t %x\n", __(session), __(uid), ll->format, ll);

	return ll;
}
Пример #22
0
/**
 * paxos_sync - GEvent-friendly wrapper around proposer_sync.
 */
int paxos_sync(void *data)
{
  pax_uuid_t *uuid;

  // Set the session.  We parametrize paxos_sync with a pointer to a session
  // ID when we add it to the main event loop.
  uuid = (pax_uuid_t *)data;
  pax = session_find(&state.sessions, uuid);

  if (is_proposer()) {
    proposer_sync();
  }

  return TRUE;
}
Пример #23
0
/*
 * Logout from the IMAP server and disconnect from the server.
 */
int
request_logout(const char *server, const char *port, const char *user)
{
	int r;
	session *s;

	if (!(s = session_find(server, port, user)))
		return -1;

	r = response_generic(s, imap_logout(s));

	close_connection(s);
	session_destroy(s);

	return r;
}
Пример #24
0
PyObject *ekg_session_status_set(ekg_sessionObj * self, PyObject * pyargs)
{
	char *status = NULL;
	char *descr = NULL;
	const char *command;

	if (!PyArg_ParseTuple(pyargs, "s|s", &status, &descr))
		return NULL;

	command = ekg_status_string(ekg_status_int(status), 1);
	if (descr == NULL)
		descr = xstrdup("-");

	command_exec_format(NULL, session_find(self->name), 0, "/%s %s", command, descr);
	xfree(descr); xfree(status); /* ? */
	Py_RETURN_TRUE;
}
Пример #25
0
PyObject *ekg_session_get(ekg_sessionObj * self, PyObject * key)
{
	const char * name = PyString_AsString(key);
	const char * out;
	char buf[100];
	session_t * s;
	s = session_find(self->name);
	debug("[python] Getting '%s' value for '%s' session\n", name, self->name);
	out = session_get(s, name);
	if (out) {
		return Py_BuildValue("s", out);
	} else {
		snprintf(buf, 99, "Can't find variable '%s'", name);
		PyErr_SetString(PyExc_KeyError, buf);
		Py_INCREF(Py_None);
		return Py_None;
	}
}
Пример #26
0
PyObject *ekg_session_users(ekg_sessionObj * self)
{
	session_t * s = session_find(self->name);
	PyObject *list;
	userlist_t *ul;
	int len = LIST_COUNT2(s->userlist);

	list = PyList_New(len);
	len = 0;

	for (ul = s->userlist; ul; ul = ul->next) {
		userlist_t * u = ul;
		PyList_SetItem(list, len, python_build_user(self->name, u->uid));
		len++;
	}
	Py_INCREF(list);
	return list;
}
Пример #27
0
/*
 * Append supplied message to the specified mailbox.
 */
int
request_append(const char *server, const char *port, const char *user,
    const char *mbox, const char *mesg, size_t mesglen, const char *flags,
    const char *date)
{
	int t, r;
	session *s;
	const char *m;

	if (!(s = session_find(server, port, user)))
		return -1;

	m = apply_namespace(mbox, s->ns.prefix, s->ns.delim);

	do {
		if ((t = imap_append(s, m, flags, date, mesglen)) == -1)
			goto fail;
		if ((r = response_continuation(s)) == -1)
			goto fail;

		switch (r) {
		case STATUS_RESPONSE_CONTINUE:
			if (imap_continuation(s, mesg, mesglen) == -1)
				goto fail;
			if ((r = response_generic(s, t)) == -1)
				goto fail;
			break;
		case STATUS_RESPONSE_TRYCREATE:
			if (create_mailbox(s, mbox) == -1)
				goto fail;
			break;
		case -1:
			goto fail;
			break;
		}
	} while (r == STATUS_RESPONSE_TRYCREATE);

	return r;
fail:
	close_connection(s);
	session_destroy(s);

	return -1;
}
Пример #28
0
/*
 * msg_queue_flush()
 *
 * wysy³a wiadomo¶ci z kolejki.
 *
 * 0 je¶li wys³ano, -1 je¶li nast±pi³ b³±d przy wysy³aniu, -2 je¶li
 * kolejka pusta.
 */
int msg_queue_flush(const char *session)
{
	msg_queue_t *m;
	int ret = -1;

	if (!msgs_queue)
		return -2;

	for (m = msgs_queue; m; m = m->next)
		m->mark = 1;

	for (m = msgs_queue; m; m = m->next) {
		session_t *s;
		char *cmd = "/msg \"%s\" %s";

		/* czy wiadomo¶æ dodano w trakcie opró¿niania kolejki? */
		if (!m->mark)
			continue;

		if (session && xstrcmp(m->session, session)) 
			continue;
				/* wiadomo¶æ wysy³ana z nieistniej±cej ju¿ sesji? usuwamy. */
		else if (!(s = session_find(m->session))) {
			m = msgs_queue_removei(m);
			continue;
		}

		switch (m->mclass) {
			case EKG_MSGCLASS_SENT_CHAT:
				cmd = "/chat \"%s\" %s";
				break;
			case EKG_MSGCLASS_SENT:
				break;
			default:
				debug_error("msg_queue_flush(), unsupported message mclass in query: %d\n", m->mclass);
		}
		command_exec_format(NULL, s, 1, cmd, m->rcpts, m->message);

		m = msgs_queue_removei(m);
		ret = 0;
	}

	return ret;
}
Пример #29
0
/*
 * Remove all messages marked for deletion from selected mailbox.
 */
int
request_expunge(const char *server, const char *port, const char *user)
{
	int r;
	session *s;

	if (!(s = session_find(server, port, user)))
		return -1;

	if ((r = response_generic(s, imap_expunge(s))) == -1)
		goto fail;

	return r;
fail:
	close_connection(s);
	session_destroy(s);

	return -1;
}
Пример #30
0
/*
 * Fetch the text, ie. BODY[TEXT], of the messages.
 */
int
request_fetchtext(const char *server, const char *port, const char *user,
    const char *mesg, char **text, size_t *len)
{
	int t, r;
	session *s;

	if (!(s = session_find(server, port, user)))
		return -1;

	t = imap_fetch(s, mesg, "BODY.PEEK[TEXT]");
	if ((r = response_fetchbody(s, t, text, len)) == -1)
		goto fail;

	return r;
fail:
	close_connection(s);
	session_destroy(s);

	return -1;
}