Esempio n. 1
0
static xt_status handle_channel(struct xt_node *node, gpointer data)
{
	struct xml_parsedata *xd = data;
	irc_channel_t *ic;
	char *name, *type;

	name = xt_find_attr(node, "name");
	type = xt_find_attr(node, "type");

	if (!name || !type) {
		return XT_ABORT;
	}

	/* The channel may exist already, for example if it's &bitlbee.
	   Also, it's possible that the user just reconnected and the
	   IRC client already rejoined all channels it was in. They
	   should still get the right settings. */
	if ((ic = irc_channel_by_name(xd->irc, name)) ||
	    (ic = irc_channel_new(xd->irc, name))) {
		set_setstr(&ic->set, "type", type);
	}

	handle_settings(node, &ic->set);

	return XT_HANDLED;
}
Esempio n. 2
0
static xt_status handle_account( struct xt_node *node, gpointer data )
{
	struct xml_parsedata *xd = data;
	char *protocol, *handle, *server, *password = NULL, *autoconnect, *tag;
	char *pass_b64 = NULL;
	unsigned char *pass_cr = NULL;
	int pass_len;
	struct prpl *prpl = NULL;
	account_t *acc;
	struct xt_node *c;
	
	handle = xt_find_attr( node, "handle" );
	pass_b64 = xt_find_attr( node, "password" );
	server = xt_find_attr( node, "server" );
	autoconnect = xt_find_attr( node, "autoconnect" );
	tag = xt_find_attr( node, "tag" );
	
	protocol = xt_find_attr( node, "protocol" );
	if( protocol )
		prpl = find_protocol( protocol );
	
	if( !handle || !pass_b64 || !protocol || !prpl )
		return XT_ABORT;
	else if( ( pass_len = base64_decode( pass_b64, (unsigned char**) &pass_cr ) ) &&
	         arc_decode( pass_cr, pass_len, &password, xd->given_pass ) >= 0 )
	{
		acc = account_add( xd->irc->b, prpl, handle, password );
		if( server )
			set_setstr( &acc->set, "server", server );
		if( autoconnect )
			set_setstr( &acc->set, "auto_connect", autoconnect );
		if( tag )
			set_setstr( &acc->set, "tag", tag );
	}
	else
		return XT_ABORT;
	
	g_free( pass_cr );
	g_free( password );
	
	handle_settings( node, &acc->set );
	
	for( c = node->children; ( c = xt_find_node( c, "buddy" ) ); c = c->next )
	{
		char *handle, *nick;
		
		handle = xt_find_attr( c, "handle" );
		nick = xt_find_attr( c, "nick" );
		
		if( handle && nick )
			nick_set_raw( acc, handle, nick );
		else
			return XT_ABORT;
	}	
	return XT_HANDLED;
}
Esempio n. 3
0
	void scheduler::handle_schedule(scheduled_task item) {
		schedule_metadata metadata = get(item.id);
		if (metadata.source == schedule_metadata::MODULE) {
			handle_plugin(metadata);
		} else if (metadata.source == schedule_metadata::SETTINGS) {
			handle_settings();
		} else {
			on_error("Unknown source");
		}
	}
Esempio n. 4
0
static storage_status_t xml_load_real( irc_t *irc, const char *my_nick, const char *password, xml_pass_st action )
{
	struct xml_parsedata xd[1];
	char *fn, buf[2048];
	int fd, st;
	struct xt_parser *xp = NULL;
	struct xt_node *node;
	storage_status_t ret = STORAGE_OTHER_ERROR;
	
	xd->irc = irc;
	strncpy( xd->given_nick, my_nick, MAX_NICK_LENGTH );
	xd->given_nick[MAX_NICK_LENGTH] = '\0';
	nick_lc( NULL, xd->given_nick );
	xd->given_pass = (char*) password;
	
	fn = g_strconcat( global.conf->configdir, xd->given_nick, ".xml", NULL );
	if( ( fd = open( fn, O_RDONLY ) ) < 0 )
	{
		ret = STORAGE_NO_SUCH_USER;
		goto error;
	}
	
	xp = xt_new( handlers, xd );
	while( ( st = read( fd, buf, sizeof( buf ) ) ) > 0 )
	{
		st = xt_feed( xp, buf, st );
		if( st != 1 )
			break;
	}
	close( fd );
	if( st != 0 )
		goto error;
	
	node = xp->root;
	if( node == NULL || node->next != NULL || strcmp( node->name, "user" ) != 0 )
		goto error;
	
	{
		char *nick = xt_find_attr( node, "nick" );
		char *pass = xt_find_attr( node, "password" );
		
		if( !nick || !pass )
		{
			goto error;
		}
		else if( ( st = md5_verify_password( xd->given_pass, pass ) ) != 0 )
		{
			ret = STORAGE_INVALID_PASSWORD;
			goto error;
		}
	}
	
	if( action == XML_PASS_CHECK_ONLY )
	{
		ret = STORAGE_OK;
		goto error;
	}
	
	/* DO NOT call xt_handle() before verifying the password! */
	if( xt_handle( xp, NULL, 1 ) == XT_HANDLED )
		ret = STORAGE_OK;
	
	handle_settings( node, &xd->irc->b->set );
	
error:
	xt_free( xp );
	g_free( fn );
	return ret;
}
Esempio n. 5
0
static xt_status handle_account(struct xt_node *node, gpointer data)
{
	struct xml_parsedata *xd = data;
	char *protocol, *handle, *server, *password = NULL, *autoconnect, *tag, *locked;
	char *pass_b64 = NULL;
	unsigned char *pass_cr = NULL;
	int pass_len, local = 0;
	struct prpl *prpl = NULL;
	account_t *acc;
	struct xt_node *c;

	handle = xt_find_attr(node, "handle");
	pass_b64 = xt_find_attr(node, "password");
	server = xt_find_attr(node, "server");
	autoconnect = xt_find_attr(node, "autoconnect");
	tag = xt_find_attr(node, "tag");
	locked = xt_find_attr(node, "locked");

	protocol = xt_find_attr(node, "protocol");
	if (protocol) {
		prpl = find_protocol(protocol);
		if (!prpl) {
			irc_rootmsg(xd->irc, "Error loading user config: Protocol not found: `%s'", protocol);
			return XT_ABORT;
		}
		local = protocol_account_islocal(protocol);
	}

	if (!handle || !pass_b64 || !protocol || !prpl) {
		return XT_ABORT;
	}

	pass_len = base64_decode(pass_b64, (unsigned char **) &pass_cr);
	if (xd->irc->auth_backend) {
		password = g_strdup((char *)pass_cr);
	} else {
		pass_len = arc_decode(pass_cr, pass_len, &password, xd->given_pass);
		if (pass_len < 0) {
			g_free(pass_cr);
			g_free(password);
			return XT_ABORT;
		}
	}

	acc = account_add(xd->irc->b, prpl, handle, password);
	if (server) {
		set_setstr(&acc->set, "server", server);
	}
	if (autoconnect) {
		set_setstr(&acc->set, "auto_connect", autoconnect);
	}
	if (tag) {
		set_setstr(&acc->set, "tag", tag);
	}
	if (local) {
		acc->flags |= ACC_FLAG_LOCAL;
	}
	if (locked && !g_strcasecmp(locked, "true")) {
		acc->flags |= ACC_FLAG_LOCKED;
	}

	g_free(pass_cr);
	g_free(password);

	handle_settings(node, &acc->set);

	for (c = node->children; (c = xt_find_node(c, "buddy")); c = c->next) {
		char *handle, *nick;

		handle = xt_find_attr(c, "handle");
		nick = xt_find_attr(c, "nick");

		if (handle && nick) {
			nick_set_raw(acc, handle, nick);
		} else {
			return XT_ABORT;
		}
	}
	return XT_HANDLED;
}
Esempio n. 6
0
static storage_status_t xml_load_real(irc_t *irc, const char *my_nick, const char *password, xml_action action)
{
	struct xml_parsedata xd[1];
	char *fn, buf[2048];
	int fd, st;
	struct xt_parser *xp = NULL;
	struct xt_node *node;
	storage_status_t ret = STORAGE_OTHER_ERROR;

	xd->irc = irc;
	strncpy(xd->given_nick, my_nick, MAX_NICK_LENGTH);
	xd->given_nick[MAX_NICK_LENGTH] = '\0';
	nick_lc(NULL, xd->given_nick);
	xd->given_pass = (char *) password;

	fn = g_strconcat(global.conf->configdir, xd->given_nick, ".xml", NULL);
	if ((fd = open(fn, O_RDONLY)) < 0) {
		if (errno == ENOENT) {
			ret = STORAGE_NO_SUCH_USER;
		} else {
			irc_rootmsg(irc, "Error loading user config: %s", g_strerror(errno));
		}
		goto error;
	}

	xp = xt_new(handlers, xd);
	while ((st = read(fd, buf, sizeof(buf))) > 0) {
		st = xt_feed(xp, buf, st);
		if (st != 1) {
			break;
		}
	}
	close(fd);
	if (st != 0) {
		goto error;
	}

	node = xp->root;
	if (node == NULL || node->next != NULL || strcmp(node->name, "user") != 0) {
		goto error;
	}

	if (action == XML_PASS_CHECK) {
		char *nick = xt_find_attr(node, "nick");
		char *pass = xt_find_attr(node, "password");
		char *backend = xt_find_attr(node, "auth_backend");

		if (!nick || !(pass || backend)) {
			goto error;
		}

		if (backend) {
			g_free(xd->irc->auth_backend);
			xd->irc->auth_backend = g_strdup(backend);
			ret = STORAGE_CHECK_BACKEND;
		} else if ((st = md5_verify_password(xd->given_pass, pass)) != 0) {
			ret = STORAGE_INVALID_PASSWORD;
		} else {
			ret = STORAGE_OK;
		}
		goto error;
	}

	if (xt_handle(xp, NULL, 1) == XT_HANDLED) {
		ret = STORAGE_OK;
	}

	handle_settings(node, &xd->irc->b->set);

error:
	xt_free(xp);
	g_free(fn);
	return ret;
}
Esempio n. 7
0
/*
 * This function handles RIL_UNSOL_DATA_CALL_LIST_CHANGED messages,
 * as well as RIL_REQUEST_DATA_CALL_LIST/SETUP_DATA_CALL replies, as
 * all have the same payload.
 */
struct ril_data_call_list *g_ril_unsol_parse_data_call_list(GRil *gril,
						const struct ril_msg *message)
{
	struct ril_data_call *call;
	struct parcel rilp;
	struct ril_data_call_list *reply = NULL;
	unsigned int active, cid, i, num_calls, retry, status;
	char *type = NULL, *ifname = NULL, *raw_addrs = NULL;
	char *raw_dns = NULL, *raw_gws = NULL;

	DBG("");

	/* Can happen for RIL_REQUEST_DATA_CALL_LIST replies */
	if (message->buf_len < MIN_DATA_CALL_LIST_SIZE) {
		if (message->req == RIL_REQUEST_SETUP_DATA_CALL) {
			ofono_error("%s: message too small: %d",
					__func__,
					(int) message->buf_len);
			goto error;
		} else {
			g_ril_append_print_buf(gril, "{");
			goto done;
		}
	}

	reply = g_try_new0(struct ril_data_call_list, 1);
	if (reply == NULL) {
		ofono_error("%s: out of memory", __func__);
		goto error;
	}

	g_ril_init_parcel(message, &rilp);

	/*
	 * ril.h documents the reply to a RIL_REQUEST_DATA_CALL_LIST
	 * as being an array of  RIL_Data_Call_Response_v6 structs,
	 * however in reality, the response also includes a version
	 * to start.
	 */
	reply->version = parcel_r_int32(&rilp);
	num_calls = parcel_r_int32(&rilp);

	g_ril_append_print_buf(gril,
				"{version=%d,num=%d",
				reply->version,
				num_calls);

	for (i = 0; i < num_calls; i++) {
		status = parcel_r_int32(&rilp);
		retry = parcel_r_int32(&rilp);          /* ignore */
		cid = parcel_r_int32(&rilp);
		active = parcel_r_int32(&rilp);
		type = parcel_r_string(&rilp);
		ifname = parcel_r_string(&rilp);
		raw_addrs = parcel_r_string(&rilp);
		raw_dns = parcel_r_string(&rilp);
		raw_gws = parcel_r_string(&rilp);

		/* malformed check */
		if (rilp.malformed) {
			ofono_error("%s: malformed parcel received", __func__);
			goto error;
		}

		g_ril_append_print_buf(gril,
					"%s [status=%d,retry=%d,cid=%d,"
					"active=%d,type=%s,ifname=%s,"
					"address=%s,dns=%s,gateways=%s]",
					print_buf,
					status,
					retry,
					cid,
					active,
					type,
					ifname,
					raw_addrs,
					raw_dns,
					raw_gws);

		call = g_try_new0(struct ril_data_call, 1);
		if (call == NULL) {
			ofono_error("%s: out of memory", __func__);
			goto error;
		}

		call->status = status;
		call->cid = cid;
		call->active = active;

		if (message->req == RIL_REQUEST_SETUP_DATA_CALL &&
			status == PDP_FAIL_NONE &&
			handle_settings(call, type, ifname, raw_addrs,
					raw_dns, raw_gws) == FALSE)
			goto error;

		g_free(type);
		g_free(ifname);
		g_free(raw_addrs);
		g_free(raw_dns);
		g_free(raw_gws);

		reply->calls =
			g_slist_insert_sorted(reply->calls, call,
						data_call_compare);
	}

done:
	g_ril_append_print_buf(gril, "%s}", print_buf);

	if (message->unsolicited)
		g_ril_print_unsol(gril, message);
	else
		g_ril_print_response(gril, message);

	return reply;

error:
	g_free(type);
	g_free(ifname);
	g_free(raw_addrs);
	g_free(raw_dns);
	g_free(raw_gws);
	g_ril_unsol_free_data_call_list(reply);

	return NULL;
}
Esempio n. 8
0
void process_messages()
{
#ifdef UART0_DISCONNECT_ON_DTR
	if ((PORT_UART0_DTR & (1 << PIN_UART0_DTR)))
	{
		if (state == StateConnected)
		{
			send_error(ErrorDisconnect, 0);
		}
		uart0_flush();
		return;
	}
#endif
	MessageParseResult res;
	while ((res = message_parse()) == ParseOk)
	{
		switch (message.identifier)
		{
			case IdAckMessage:
				handle_ack();
				break;
			case IdInitMessage:
				handle_init();
				break;
			case IdFootSwitchMessage:
				handle_footswitch();
				break;
			case IdInterlockResetMessage:
				handle_int_reset();
				break;
			case IdServoCtrlMessage:
				handle_servo_ctrl();
				break;
			case IdDockingLimitMessage:
				handle_docking_limit();
				break;
			case IdErrorMessage:
				handle_error();
				break;
			case IdDockingTareMessage:
				handle_docking_tare();
				break;
			case IdSettingsMessage:
				handle_settings();
				break;
			default:
				send_error(ErrorUnhandled, message.sequence);
				return;
		}
	}

	switch (res)
	{
		case ParseNotEnoughData: // buffer empty, done
			break;
//		case ParseInvalidIdentifier: // fall
//		case ParseInvalidSizeError: // fall
//		case ParseChecksumError: // fall
		default:
			send_error(ErrorParser, 0);
			break;
	}
}