diff options
Diffstat (limited to 'server/dbus/tests/test_client.c')
-rw-r--r-- | server/dbus/tests/test_client.c | 96 |
1 files changed, 75 insertions, 21 deletions
diff --git a/server/dbus/tests/test_client.c b/server/dbus/tests/test_client.c index 30401991..daf80db9 100644 --- a/server/dbus/tests/test_client.c +++ b/server/dbus/tests/test_client.c @@ -9,14 +9,32 @@ /* TODO: get this value from LDB */ #define DBUS_ADDRESS "unix:path=/var/lib/sss/pipes/private/dbus" +/* Identity */ +#define TEST_CLIENT_NAME "testclient" +#define TEST_CLIENT_VERSION 1 + /* Monitor Interface */ #define MONITOR_DBUS_INTERFACE "org.freeipa.sssd.monitor" #define MONITOR_DBUS_PATH "/org/freeipa/sssd/monitor" #define MONITOR_METHOD_VERSION "getVersion" +/* Service Interface */ +#define SERVICE_PATH "/org/freeipa/sssd/service" +#define SERVICE_INTERFACE "org.freeipa.sssd.service" +#define SERVICE_METHOD_IDENTITY "getIdentity" + struct test_cli_ctx { - struct sssd_dbus_ctx *sd_ctx; - DBusConnection *conn; + struct sssd_dbus_method_ctx *sd_ctx; + /*DBusConnection *conn;*/ + struct event_context *ev; + struct dbus_connection_toplevel_context *dct_ctx; +}; + +static int provide_identity(DBusMessage *message, void *data, DBusMessage **r); + +struct sssd_dbus_method monitor_service_methods [] = { + {SERVICE_METHOD_IDENTITY, provide_identity}, + {NULL, NULL} }; static void request_version_timed(struct test_cli_ctx *ctx); @@ -55,9 +73,16 @@ static void print_version(DBusPendingCall *pending, void *data) } break; case DBUS_MESSAGE_TYPE_ERROR: + + if (strcmp(DBUS_ERROR_NO_REPLY, dbus_message_get_error_name(reply))==0) { + DEBUG(0, ("Received error. Timeout")); + } + else { + DEBUG(0, ("Received error. Not a timeout: %s", dbus_message_get_error_name(reply))); + } break; default: - DEBUG(0, ("Received unexpected message")); + DEBUG(0, ("Received unexpected message\n")); exit(4); } } @@ -67,7 +92,7 @@ static void test_timed_handler(struct event_context *ev, struct timeval tv, void *data) { struct test_cli_ctx *test_ctx; - struct sssd_dbus_ctx *ctx; + struct sssd_dbus_method_ctx *ctx; DBusPendingCall *pending_reply; DBusMessage *vmsg; DBusError error; @@ -81,10 +106,10 @@ static void test_timed_handler(struct event_context *ev, dbus_error_init(&error); vmsg = dbus_message_new_method_call(NULL, - ctx->path, ctx->name, + ctx->path, ctx->interface, MONITOR_METHOD_VERSION); - dbret = dbus_connection_send_with_reply(test_ctx->conn, vmsg, + dbret = dbus_connection_send_with_reply(sssd_get_dbus_connection(test_ctx->dct_ctx), vmsg, &pending_reply, -1); if (!dbret) { /* Critical failure */ @@ -107,7 +132,7 @@ static void request_version_timed(struct test_cli_ctx *ctx) gettimeofday(&tv, NULL); tv.tv_sec += 5; tv.tv_usec = 0; - te = event_add_timed(ctx->sd_ctx->ev, ctx, tv, test_timed_handler, ctx); + te = event_add_timed(ctx->ev, ctx, tv, test_timed_handler, ctx); if (te == NULL) { DEBUG(0, ("failed to add event!\n")); exit(1); @@ -117,9 +142,9 @@ static void request_version_timed(struct test_cli_ctx *ctx) int main (int argc, const char *argv[]) { struct event_context *event_ctx; - struct sssd_dbus_ctx *ctx; + struct sssd_dbus_method_ctx *ctx; struct test_cli_ctx *test_ctx; - DBusConnection *dbus_conn; + struct sssd_dbus_method_ctx *service_methods; int ret; event_ctx = event_context_init(talloc_autofree_context()); @@ -128,38 +153,46 @@ int main (int argc, const char *argv[]) exit(1); } - ctx = talloc_zero(event_ctx, struct sssd_dbus_ctx); + ctx = talloc_zero(event_ctx, struct sssd_dbus_method_ctx); if (!ctx) { printf("Out of memory!?\n"); exit(1); } - ctx->ev = event_ctx; - ctx->name = talloc_strdup(ctx, MONITOR_DBUS_INTERFACE); + + test_ctx = talloc(event_ctx, struct test_cli_ctx); + if (!test_ctx) { + printf("Out of memory!?\n"); + exit(1); + } + + test_ctx->ev = event_ctx; + ctx->interface = talloc_strdup(ctx, MONITOR_DBUS_INTERFACE); ctx->path = talloc_strdup(ctx, MONITOR_DBUS_PATH); - if (!ctx->name || !ctx->path) { + if (!ctx->interface || !ctx->path) { printf("Out of memory!?\n"); exit(1); } - ret = sssd_new_dbus_connection(ctx, DBUS_ADDRESS, &dbus_conn); + ret = sssd_new_dbus_connection(test_ctx, test_ctx->ev, DBUS_ADDRESS, &(test_ctx->dct_ctx), NULL); if (ret != EOK) { exit(1); } - test_ctx = talloc(ctx, struct test_cli_ctx); - if (!test_ctx) { - printf("Out of memory!?\n"); - exit(1); - } test_ctx->sd_ctx = ctx; - test_ctx->conn = dbus_conn; - dbus_connection_set_exit_on_disconnect(dbus_conn, TRUE); + dbus_connection_set_exit_on_disconnect(sssd_get_dbus_connection(test_ctx->dct_ctx), TRUE); /* Set up a timed event to request the server version every * five seconds and print it to the screen. */ request_version_timed(test_ctx); + + /* Set up handler for service methods */ + service_methods = talloc_zero(test_ctx, struct sssd_dbus_method_ctx); + service_methods->interface = talloc_strdup(service_methods, SERVICE_INTERFACE); + service_methods->path = talloc_strdup(service_methods, SERVICE_PATH); + service_methods->methods = monitor_service_methods; + dbus_connection_add_method_ctx(test_ctx->dct_ctx, service_methods); /* Enter the main loop (and hopefully never return) */ event_loop_wait(event_ctx); @@ -167,3 +200,24 @@ int main (int argc, const char *argv[]) talloc_free(event_ctx); return EXIT_SUCCESS; } + +static int provide_identity(DBusMessage *message, void *data, DBusMessage **r) { + const char *name = TEST_CLIENT_NAME; + dbus_uint16_t version = TEST_CLIENT_VERSION; + + DBusMessage *reply; + dbus_bool_t ret; + + reply = dbus_message_new_method_return(message); + ret = dbus_message_append_args(reply, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_UINT16, &version, + DBUS_TYPE_INVALID); + + if (!ret) { + return EIO; + } + + *r = reply; + return EOK; +} |