Exemplo n.º 1
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;
}
static void __display_info(session_t *s, int type, private_data_t *data) {
	int i, uid = private_item_get_int(&data, "uid");
	const char *str;
	char *theme = saprintf("icq_userinfo_%s", icq_lookuptable(meta_name, type));

	for (i=0; userinfo[i].type; i++) {
		if ( (userinfo[i].type != type) || (!userinfo[i].name) )
			continue;
		if (userinfo[i].ltab)
			str = icq_lookuptable(userinfo[i].ltab, private_item_get_int(&data, userinfo[i].name));
		else if (userinfo[i].item == 'L')
			str = private_item_get_int(&data, userinfo[i].name) ? _("Yes") : _("No");
		else
			str = private_item_get(&data, userinfo[i].name);
		if ( str && *str) {
			char *___str = xstrdup(str); /* XXX, guess recode */

			if (!__displayed)
				print("icq_userinfo_start", session_name(s), itoa(uid), theme);
			print(theme, session_name(s), itoa(uid), userinfo[i].display, ___str);
			__displayed = 1;

			xfree(___str);
		}
	}
	xfree(theme);
}
Exemplo n.º 3
0
/* we return 0 even if rmwatch fails, because xmsg_handle_data checks
 * if our session is still connected, so it'll ignore unneeded events */
static COMMAND(xmsg_disconnect)
{
	if (!session_connected_get(session)) {
		printq("not_connected", session_name(session));
		return -1;
	}
	
	xmsg_timer_change(session, NULL);
	if (!timer_remove_session(session, "o"))
		xdebug("old oneshot resume timer removed");
	session_status_set(session, EKG_STATUS_NA);

	if (quiet == -1)
		protocol_disconnected_emit(session, format_find("xmsg_umount"), EKG_DISCONNECT_NETWORK);
	else
		protocol_disconnected_emit(session, NULL, EKG_DISCONNECT_USER);

#ifdef HAVE_INOTIFY
	if (session->priv && inotify_rm_watch(in_fd, (long int) session->priv))
		xdebug2(DEBUG_ERROR, "rmwatch failed");
	else
		xdebug("inotify watch removed: %d", (long int) session->priv);
#endif /*HAVE_INOTIFY*/

	return 0;
}
Exemplo n.º 4
0
static COMMAND(xmsg_connect)
{
	if (session_connected_get(session)) {
		printq("already_connected", session_name(session));
		return -1;
	}
	if (command_exec(NULL, session, "/session --lock", 0) == -1)
		return -1;

	if (xmsg_add_watch(session, session_uid_get(session)+XMSG_UID_DIROFFSET)) {
		print("conn_failed", format_find("xmsg_addwatch_failed"), session_name(session));
		return -1;
	}
	
	session_status_set(session, EKG_STATUS_AVAIL);
	protocol_connected_emit(session);

	xmsg_iterate_dir(0, (void*) session);
	xmsg_timer_change(session, "rescan_timer");

	return 0;
}
Exemplo n.º 5
0
static COMMAND(sniff_command_disconnect) {
	if (!session_connected_get(session)) {
		printq("not_connected", session_name(session));
		return -1;
	}

	protocol_disconnected_emit(session, NULL, EKG_DISCONNECT_USER);

	if (!GET_DEV(session)) {
		debug_error("sniff_command_disconnect() not dev?!\n");
		return -1;
	}

	pcap_close(GET_DEV(session));
	session->priv = NULL;

	return 0;
}
Exemplo n.º 6
0
void muroa::CCmdStreamTests::serializeRequestJoin() {

	boost::asio::ip::address server_addr = address::from_string("192.168.1.77");
	uint32_t cmdID = 2;
	string session_name("default session");

	evRequestJoin rjoin;
	rjoin.m_cmd_id = cmdID;
	rjoin.m_session_name = session_name;
	rjoin.m_mcast_addr = server_addr;
	m_rpc_s->sendEvent(&rjoin);

	const CmdStreamBase* cmdBase = m_rpc_r->getLastEv();
	CPPUNIT_ASSERT( cmdBase != 0 );

	const evRequestJoin* r_jreq = dynamic_cast<const evRequestJoin*>(cmdBase);
	CPPUNIT_ASSERT( rjoin == *r_jreq );

}
void display_whoami(session_t *s) {
	icq_private_t *j = s->priv;
	int uid = private_item_get_int(&j->whoami, "uid");
	int end = 0;
	__displayed = 0;
	__display_info(s, META_BASIC_USERINFO,		j->whoami);
	end |= __displayed; __displayed = 0;
	__display_info(s, META_MORE_USERINFO,		j->whoami);
	end |= __displayed; __displayed = 0;
	__display_info(s, META_EMAIL_USERINFO,		j->whoami);
	end |= __displayed; __displayed = 0;
	__display_info(s, META_NOTES_USERINFO,		j->whoami);
	end |= __displayed; __displayed = 0;
	__display_info(s, META_HPAGECAT_USERINFO,	j->whoami);
	end |= __displayed; __displayed = 0;
	__display_info(s, META_WORK_USERINFO,		j->whoami);
	end |= __displayed; __displayed = 0;
	__display_info(s, META_INTERESTS_USERINFO,	j->whoami);
	end |= __displayed; __displayed = 0;
	__display_info(s, META_AFFILATIONS_USERINFO,	j->whoami);
	if (end)
		print("icq_userinfo_end", session_name(s), itoa(uid));
}
static int icq_meta_info_reply(session_t *s, unsigned char *buf, int len, private_data_t **info, int show) {
	/* SNAC(15,03)/07DA SRV_META_INFO_REPLY	Meta information response
	 *
	 * This is the server response to client meta info request SNAC(15,02)/07D0.
	 */
	struct {
		uint16_t subtype;
		uint8_t result;
		unsigned char *data;
	} pkt;
	int userinfo = 0;

	metasnac_subhandler_t handler;

	if (!ICQ_UNPACK(&pkt.data, "wc", &pkt.subtype, &pkt.result)) {
		debug_error("icq_meta_info_reply() broken\n");
		return -1;
	}

	debug_white("icq_meta_info_reply() subtype=%.4x result=%.2x (len=%d)\n", pkt.subtype, pkt.result, len);

	if ( (handler = get_userinfo_extension_handler(pkt.subtype)) ) {
		userinfo = 1;
	} else {
		switch (pkt.subtype) {
			/* search */
			case SRV_LAST_USER_FOUND:	handler = icq_snac_extension_userfound_last; break;
			case SRV_USER_FOUND:		handler = icq_snac_extension_userfound; break;
		
			case META_SET_FULLINFO_ACK:	handler = icq_snac_extension_fullinfo_ack; break;

			case SRV_RANDOM_FOUND:		handler = NULL; break;	/* XXX, SRV_RANDOM_FOUND */
			default:			handler = NULL;
		}
	}

	__displayed = 0;
	if (!handler) {
		debug_error("icq_meta_info_reply() ignored: %.4x\n", pkt.subtype);
		icq_hexdump(DEBUG_ERROR, pkt.data, len);
		return 0;
	} else {
		int uid = info ? private_item_get_int(info, "uid") : -1;
		debug_function("icq_snac_extensions_%s()", icq_lookuptable(meta_name, pkt.subtype));
		if (userinfo)
			debug_function(" uid: %u", uid);
		debug_function("\n");

		if (pkt.result == 0x0A) {
			handler(s, pkt.data, len, info);
		} else if (!userinfo){
			/* Failed search */
			debug_error("icq_snac_extension_userfound() search error: %u\n", pkt.result);
		}

		if (show) {
			__display_info(s, pkt.subtype, *info);
			if (__displayed)
				print("icq_userinfo_end", session_name(s), itoa(uid));
		}
	}

	return 0;
}
//virtual
BOOL LLIMFloater::postBuild()
{
	const LLUUID& other_party_id = LLIMModel::getInstance()->getOtherParticipantID(mSessionID);
	if (other_party_id.notNull())
	{
		mOtherParticipantUUID = other_party_id;
	}

	mControlPanel->setSessionId(mSessionID);
	mControlPanel->getParent()->setVisible(gSavedSettings.getBOOL("IMShowControlPanel"));

	LLButton* slide_left = getChild<LLButton>("slide_left_btn");
	slide_left->setVisible(mControlPanel->getParent()->getVisible());
	slide_left->setClickedCallback(boost::bind(&LLIMFloater::onSlide, this));

	LLButton* slide_right = getChild<LLButton>("slide_right_btn");
	slide_right->setVisible(!mControlPanel->getParent()->getVisible());
	slide_right->setClickedCallback(boost::bind(&LLIMFloater::onSlide, this));

	mInputEditor = getChild<LLLineEditor>("chat_editor");
	mInputEditor->setMaxTextLength(1023);
	// enable line history support for instant message bar
	mInputEditor->setEnableLineHistory(TRUE);
	// *TODO Establish LineEditor with autoreplace callback
	mInputEditor->setAutoreplaceCallback(boost::bind(&LLAutoReplace::autoreplaceCallback, LLAutoReplace::getInstance(), _1, _2));

	LLFontGL* font = LLViewerChat::getChatFont();
	mInputEditor->setFont(font);	
	
	mInputEditor->setFocusReceivedCallback( boost::bind(onInputEditorFocusReceived, _1, this) );
	mInputEditor->setFocusLostCallback( boost::bind(onInputEditorFocusLost, _1, this) );
	mInputEditor->setKeystrokeCallback( onInputEditorKeystroke, this );
	mInputEditor->setCommitOnFocusLost( FALSE );
	mInputEditor->setRevertOnEsc( FALSE );
	mInputEditor->setReplaceNewlinesWithSpaces( FALSE );
	mInputEditor->setPassDelete( TRUE );

	childSetCommitCallback("chat_editor", onSendMsg, this);
	
	mChatHistory = getChild<LLChatHistory>("chat_history");

	setDocked(true);

	mTypingStart = LLTrans::getString("IM_typing_start_string");

	// Disable input editor if session cannot accept text
	LLIMModel::LLIMSession* im_session =
		LLIMModel::instance().findIMSession(mSessionID);
	if( im_session && !im_session->mTextIMPossible )
	{
		mInputEditor->setEnabled(FALSE);
		mInputEditor->setLabel(LLTrans::getString("IM_unavailable_text_label"));
	}

	if ( im_session && im_session->isP2PSessionType())
	{
		// look up display name for window title
		LLAvatarNameCache::get(im_session->mOtherParticipantID,
							   boost::bind(&LLIMFloater::onAvatarNameCache,
										   this, _1, _2));
	}
	else
	{
		std::string session_name(LLIMModel::instance().getName(mSessionID));
		updateSessionName(session_name, session_name);
	}
	
	//*TODO if session is not initialized yet, add some sort of a warning message like "starting session...blablabla"
	//see LLFloaterIMPanel for how it is done (IB)

	if(isChatMultiTab())
	{
		return LLFloater::postBuild();
	}
	else
	{
		return LLDockableFloater::postBuild();
	}
}
Exemplo n.º 10
0
static COMMAND(xmsg_msg)
{
	char fn[sizeof(XMSG_TMPFILE_PATH)];
	int fd;
	char *msg = (char*) params[1];
	const char *uid;
	int fs;
	int n;
	const char *msgcmd = session_get(session, "send_cmd");
	char *msgx = NULL, *mymsg;
	
	if (!(uid = get_uid(session, target))) {
		printq("invalid_session");
		return -1;
	}

	if (!msgcmd || *msgcmd == '\0') {
		printq("xmsg_nosendcmd", session_name(session));
		return -1;
	}
	
	xstrcpy(fn, XMSG_TMPFILE_PATH);
	
	fd = mkstemp(fn);
	if (fd == -1)
		xerrn("Unable to create temp file");
	{
		const char *charset = session_get(session, "charset");

		if (charset)
			msgx = ekg_convert_string(msg, NULL, charset);
		mymsg = (msgx ? msgx : msg);
	}
	fs = xstrlen(mymsg);

	while (fs > 0) {
		if ((n = write(fd, mymsg, fs)) == -1) {
			unlink(fn);
			close(fd);
			xfree(msgx);
			xerrn("Unable to write message into temp file");
		}
		fs -= n;
		mymsg += n;
	}

	xfree(msgx);	
	close(fd);
	if ((command_exec_format(NULL, session, 1, "!^%s \"%s\" \"%s\"", msgcmd, target+XMSG_UID_DIROFFSET, fn)))
		xerr("msgcmd exec failed");
	
	{
		char **rcpts	= xcalloc(2, sizeof(char *));
		int class	= (xstrcmp(name, "chat") ? EKG_MSGCLASS_SENT : EKG_MSGCLASS_SENT_CHAT);

		rcpts[0]	= xstrdup(uid);
		rcpts[1]	= NULL;

		protocol_message_emit(session, session->uid, rcpts, params[1], NULL, time(NULL), class, NULL, EKG_NO_BEEP, 0);

		array_free(rcpts);
	}
			
	return 0;
}
Exemplo n.º 11
0
static int xmsg_handle_file(session_t *s, const char *fn)
{
	const int nounlink = !session_int_get(s, "unlink_sent");
	const int utb = session_int_get(s, "unlink_toobig");
	const int maxfs = session_int_get(s, "max_filesize");
	const char *dfsuffix = session_get(s, "dotfile_suffix");
	char *namesep = (char*) session_get(s, "name_separator");
	char *dir;
	int dirlen;

	char *msg = NULL;
	int err, fs;
	time_t ft = 0;
	
	if (*fn == '.') /* we're skipping ALL dotfiles */
		return -1;
	dir = (char*) xmsg_dirfix(session_uid_get(s)+XMSG_UID_DIROFFSET);
	dirlen = xstrlen(dir);
		/* first check if buffer is long enough to fit the whole path for dotfile */
	if (strlcpy(dir+dirlen+1, fn, PATH_MAX-dirlen-2-xstrlen(dfsuffix)) >= PATH_MAX-dirlen-2-xstrlen(dfsuffix))
		xerr("Buffer too small for: fn = %s, len(fn) = %d, dirlen = %d, dfsuffixlen = %d", fn, xstrlen(fn), dirlen, xstrlen(dfsuffix));

		/* then fill in middle part of path */
	dir[dirlen] = '/';
		/* and take a much closer look the file */	
	xdebug("s = %s, d = %s, fn = %s", session_uid_get(s), dir, fn);
	if ((err = xmsg_checkoutfile(dir, &msg, &fs, &ft, maxfs))) {
		if (err == EFBIG) {
			print((utb ? "xmsg_toobigrm" : "xmsg_toobig"), fn, session_name(s));
			if (utb) {
				unlink(dir);
				return -1;
			} /* else we need to create the dotfile first */
		} else if (err != ENOENT && err != EINVAL)
			return -1;
	} else if (!nounlink && (utb == (err == EFBIG)))
		unlink(dir);

		/* here: dir = dotf */
	memmove(dir+dirlen+2, dir+dirlen+1, xstrlen(dir) - dirlen);
	dir[dirlen+1] = '.';
	xstrcpy(dir+xstrlen(dir), dfsuffix); /* we've already checked whether it fits */
	
	{
		struct stat st;
		int r;
		
		if (nounlink || !utb) {
			r = !(stat(dir, &st) || S_ISDIR(st.st_mode));
		} else
			r = 0;
		
		if (err == ENOENT) {
			if (r) /* clean up stale dotfile */
				unlink(dir);
			xfree(msg);
			return -1;
		} else if (r) {
			xfree(msg); /* XXX: I think that we rather shouldn't first read, then check if it is needed,
					at least for nounlink mode */
			return -1;
		} else if ((nounlink && !(utb && err == EFBIG)) || (!utb && err == EFBIG))
			close(open(dir, O_WRONLY|O_CREAT|O_TRUNC|O_NOFOLLOW, 0600));
	}
	
	if (err == EFBIG)
		return -1;
	else if (err == EINVAL)
		xdebug("empty file, not submitting");
	else {
		char *uid	= xmalloc(strlen(fn) + 6);
		char *msgx	= NULL;

		{
			const char *charset = session_get(s, "charset");

			if (charset && (msgx = ekg_convert_string(msg, charset, NULL)))
				xfree(msg);
			else
				msgx = msg;
		}

		xstrcpy(uid, "xmsg:");
		xstrcat(uid, fn);
		if (namesep) {
			char *p, *q = NULL;

			for (p = namesep; *p; p++) {
				char *r = xstrrchr(uid+XMSG_UID_DIROFFSET, *p);
				if (r > q)
					q = r;
			}
			if (q)
				*q = '\0';
		}

		protocol_message_emit(s, uid, NULL, msgx, NULL, ft, EKG_MSGCLASS_CHAT, NULL, EKG_TRY_BEEP, 0);

		xfree(msgx);
		xfree(uid);
	}
	
	return 0;
}
Exemplo n.º 12
0
static COMMAND(sniff_command_connect) {
	struct bpf_program fp;
	char errbuf[PCAP_ERRBUF_SIZE] = { 0 };
	pcap_t *dev;
	const char *filter;
	char *device;
	char *tmp;

	filter = session_get(session, "filter");

	if (session_connected_get(session)) {
		printq("already_connected", session_name(session));
		return -1;
	}

	if (session->uid[6] != '/') {
		if ((tmp = xstrchr(session->uid+6, ':')))
			device = xstrndup(session->uid+6, tmp-(session->uid+6));
		else	device = xstrdup(session->uid+6);

		dev = pcap_open_live(device, SNAPLEN, PROMISC, 1000, errbuf);
	} else {
		device = xstrdup(session->uid+6);
		dev = pcap_open_offline(device, errbuf);
	}

	if (!dev) {
		debug_error("Couldn't open dev: %s (%s)\n", device, errbuf);
		printq("conn_failed", errbuf, session_name(session));
		xfree(device);
		return -1;
	}

	if (pcap_setnonblock(dev, 1, errbuf) == -1) {
		debug_error("Could not set device \"%s\" to non-blocking: %s\n", device, errbuf);
		pcap_close(dev);
		xfree(device);
		return -1;
	}

	xfree(device);
	if (filter && *filter) {
		if (pcap_compile(dev, &fp, (char *) filter, 0, 0 /*net*/) == -1) {
			debug_error("Couldn't parse filter %s: %s\n", filter, pcap_geterr(dev));
			pcap_close(dev);
			return -1;
		}

		if (pcap_setfilter(dev, &fp) == -1) {
			debug_error("Couldn't install filter %s: %s\n", filter, pcap_geterr(dev));
			pcap_close(dev);
			return -1;
		}
		/* pcap_freecode(&fp); */
	}

	session->priv = dev;
	
	switch (pcap_datalink(dev)) {
		case DLT_LINUX_SLL:
			watch_add_session(session, pcap_fileno(dev), WATCH_READ, sniff_pcap_read_SLL);
			break;

		case DLT_EN10MB:
			watch_add_session(session, pcap_fileno(dev), WATCH_READ, sniff_pcap_read_EN10MB);
			break;

		default:
			debug_error("_connect() unk: %s\n", pcap_datalink_val_to_name(pcap_datalink(dev)));
			watch_add_session(session, pcap_fileno(dev), WATCH_READ, sniff_pcap_read);
	}
	

	session->status = EKG_STATUS_AVAIL;
	protocol_connected_emit(session);
	return 0;
}