Esempio n. 1
0
static void botnet_event_file(BOT_REC *bot, const char *data, const char *sender, const char *target)
{
	GNode *node;
	char *tempbuf, *str;
	int len;

	if (g_strcasecmp(target, bot->botnet->nick) != 0)
		return;

	node = bot_find_nick(bot->botnet, sender);
	g_return_if_fail(node != NULL);

	bot = node->data;
	if (bot->file_handle <= 0) {
		/* first line - data contains file name */
		str = g_strdup_printf("%s/.irssi/%s", g_get_home_dir(), data);
		bot->file_handle = open(str, O_CREAT|O_TRUNC|O_WRONLY, 0600);
                g_free(str);
	} else if (*data == '\0') {
		/* no data - end of file */
		if (bot->file_handle > 0) {
			close(bot->file_handle);
			bot->file_handle = -1;
		}
	} else {
		/* file data */
		tempbuf = g_malloc(strlen(data)*2+2);
		len = unescape_data(data, tempbuf);
		write(bot->file_handle, tempbuf, len);
		g_free(tempbuf);
	}
}
Esempio n. 2
0
/** Dissects an SIR packet. */
static void
dissect_sir(tvbuff_t *tvb, packet_info *pinfo, proto_tree *root)
{
    gint offset = 0;
    gint bof_offset;
    gint eof_offset;

    while (tvb_length_remaining(tvb, offset) > 0) {
        bof_offset = tvb_find_guint8(tvb, offset, -1, SIR_BOF);
        eof_offset = (bof_offset == -1) ? -1 :
                     tvb_find_guint8(tvb, bof_offset, -1, SIR_EOF);

        if (bof_offset == -1 || eof_offset == -1) {
            if (pinfo->can_desegment) {
                pinfo->desegment_offset = offset;
                pinfo->desegment_len = 1;
            }
            return;
        } else {
            guint preamble_len = bof_offset - offset;
            gint data_offset = bof_offset + 1;
            tvbuff_t* next_tvb = tvb_new_subset(tvb,
                                                data_offset, eof_offset - data_offset, -1);
            next_tvb = unescape_data(next_tvb, pinfo);
            if (root) {
                guint data_len = tvb_length(next_tvb) < 2 ? 0 :
                                 tvb_length(next_tvb) - 2;
                proto_tree* ti = proto_tree_add_protocol_format(root,
                                 proto_sir, tvb, offset, eof_offset - offset + 1,
                                 "Serial Infrared, Len: %d", data_len);
                proto_tree* tree = proto_item_add_subtree(ti, ett_sir);
                if (preamble_len > 0)
                    proto_tree_add_item(tree, hf_sir_preamble, tvb,
                                        offset, preamble_len, ENC_NA);
                proto_tree_add_item(tree, hf_sir_bof, tvb,
                                    bof_offset, 1, ENC_BIG_ENDIAN);
                proto_tree_add_uint(tree, hf_sir_length,
                                    next_tvb, 0, data_len, data_len);
                next_tvb = checksum_data(next_tvb, tree);
                proto_tree_add_item(tree, hf_sir_eof, tvb,
                                    eof_offset, 1, ENC_BIG_ENDIAN);
            } else {
                next_tvb = checksum_data(next_tvb, NULL);
            }
            call_dissector(irda_handle, next_tvb, pinfo, root);
        }
        offset = eof_offset + 1;
    }
}