Exemple #1
0
gboolean handler_handle_uri(Client *c, const char *uri)
{
    char *handler, *cmd;
    GError *error = NULL;
    gboolean res;

    if (!(handler = handler_lookup(c, uri))) {
        return FALSE;
    }

    cmd = g_strdup_printf(handler, uri);
    if (!g_spawn_command_line_async(cmd, &error)) {
        g_warning("Can't run '%s': %s", cmd, error->message);
        g_clear_error(&error);
        res = FALSE;
    } else {
        res = TRUE;
    }

    g_free(cmd);
    return res;
}
Exemple #2
0
static void
table_msg_dispatch(void)
{
	struct table_open_params op;
	struct dict	 params;
	char		 res[4096];
	int		 type, r;

	memset(res, 0, sizeof res);
	switch (imsg.hdr.type) {
	case PROC_TABLE_OPEN:
		table_msg_get(&op, sizeof op);
		table_msg_end();

		if (op.version != PROC_TABLE_API_VERSION) {
			log_warnx("warn: table-api: bad API version");
			fatalx("table-api: terminating");
		}
		if ((name = strdup(op.name)) == NULL) {
			log_warn("warn: table-api");
			fatalx("table-api: terminating");
		}

		imsg_compose(&ibuf, PROC_TABLE_OK, 0, 0, -1, NULL, 0);
		break;

	case PROC_TABLE_UPDATE:
		table_msg_end();

		if (handler_update)
			r = handler_update();
		else
			r = 1;

		imsg_compose(&ibuf, PROC_TABLE_OK, 0, 0, -1, &r, sizeof(r));
		break;

	case PROC_TABLE_CLOSE:
		quit = 1;
		break;

	case PROC_TABLE_CHECK:
		table_msg_get(&type, sizeof(type));
		table_read_params(&params);
		if (rlen == 0) {
			log_warnx("warn: table-api: no key");
			fatalx("table-api: exiting");
		}
		if (rdata[rlen - 1] != '\0') {
			log_warnx("warn: table-api: key not NUL-terminated");
			fatalx("table-api: exiting");
		}

		if (handler_check)
			r = handler_check(type, &params, rdata);
		else
			r = -1;
		table_clear_params(&params);
		table_msg_get(NULL, rlen);
		table_msg_end();

		table_msg_add(&r, sizeof(r));
		table_msg_close();
		break;

	case PROC_TABLE_LOOKUP:
		table_msg_get(&type, sizeof(type));
		table_read_params(&params);
		if (rlen == 0) {
			log_warnx("warn: table-api: no key");
			fatalx("table-api: exiting");
		}
		if (rdata[rlen - 1] != '\0') {
			log_warnx("warn: table-api: key not NUL-terminated");
			fatalx("table-api: exiting");
		}

		if (handler_lookup)
			r = handler_lookup(type, &params, rdata, res, sizeof(res));
		else
			r = -1;
		table_clear_params(&params);
		table_msg_get(NULL, rlen);
		table_msg_end();

		table_msg_add(&r, sizeof(r));
		if (r == 1)
			table_msg_add(res, strlen(res) + 1);
		table_msg_close();
		break;


	case PROC_TABLE_FETCH:
		table_msg_get(&type, sizeof(type));
		table_read_params(&params);
		if (handler_fetch)
			r = handler_fetch(type, &params, res, sizeof(res));
		else
			r = -1;
		table_clear_params(&params);
		table_msg_end();

		table_msg_add(&r, sizeof(r));
		if (r == 1)
			table_msg_add(res, strlen(res) + 1);
		table_msg_close();
		break;

	default:
		log_warnx("warn: table-api: bad message %d", imsg.hdr.type);
		fatalx("table-api: exiting");
	}
}
Exemple #3
0
static void
table_msg_dispatch(void)
{
	uint32_t	 version;
	char		 res[4096];
	int		 type, r;

	switch (imsg.hdr.type) {
	case PROC_TABLE_OPEN:
		table_msg_get(&version, sizeof(version));
		table_msg_end();

		if (version != PROC_TABLE_API_VERSION) {
			log_warnx("warn: table-api: bad API version");
			fatalx("table-api: terminating");
		}

		imsg_compose(&ibuf, PROC_TABLE_OK, 0, 0, -1, NULL, 0);
		break;

	case PROC_TABLE_UPDATE:
		table_msg_end();

		if (handler_update)
			r = handler_update();
		else
			r = 1;

		imsg_compose(&ibuf, PROC_TABLE_OK, 0, 0, -1, &r, sizeof(r));
		break;

	case PROC_TABLE_CLOSE:
		quit = 1;
		break;

	case PROC_TABLE_CHECK:
		table_msg_get(&type, sizeof(type));
		if (rlen == 0) {
			log_warnx("warn: table-api: no key");
			fatalx("table-api: exiting");
		}
		if (rdata[rlen - 1] != '\0') {
			log_warnx("warn: table-api: key not NUL-terminated");
			fatalx("table-api: exiting");
		}

		if (handler_check)
			r = handler_check(type, rdata);
		else
			r = -1;
		table_msg_get(NULL, rlen);
		table_msg_end();

		table_msg_add(&r, sizeof(r));
		table_msg_close();
		break;

	case PROC_TABLE_LOOKUP:
		table_msg_get(&type, sizeof(type));

		if (rlen == 0) {
			log_warnx("warn: table-api: no key");
			fatalx("table-api: exiting");
		}
		if (rdata[rlen - 1] != '\0') {
			log_warnx("warn: table-api: key not NUL-terminated");
			fatalx("table-api: exiting");
		}

		if (handler_lookup)
			r = handler_lookup(type, rdata, res, sizeof(res));
		else
			r = -1;

		table_msg_get(NULL, rlen);
		table_msg_end();

		table_msg_add(&r, sizeof(r));
		if (r == 1)
			table_msg_add(res, strlen(res) + 1);
		table_msg_close();
		break;


	case PROC_TABLE_FETCH:
		table_msg_get(&type, sizeof(type));
		table_msg_end();

		if (handler_fetch)
			r = handler_fetch(type, res, sizeof(res));
		else
			r = -1;

		table_msg_add(&r, sizeof(r));
		if (r == 1)
			table_msg_add(res, strlen(res) + 1);
		table_msg_close();
		break;

	default:
		log_warnx("warn: table-api: bad message %i", imsg.hdr.type);
		fatalx("table-api: exiting");
	}
}