diff options
author | Stephen Gallagher <sgallagh@redhat.com> | 2009-02-23 16:54:02 -0500 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2009-02-24 11:23:32 -0500 |
commit | 7a7adf458bd8519e68960748af0222b794e0a02b (patch) | |
tree | 0a7e8587d3339858690c88cdafc567fe9356264f /server/infopipe | |
parent | 13421cbe0af4343f9d110600755ffa756690b282 (diff) | |
download | sssd-7a7adf458bd8519e68960748af0222b794e0a02b.tar.gz sssd-7a7adf458bd8519e68960748af0222b794e0a02b.tar.bz2 sssd-7a7adf458bd8519e68960748af0222b794e0a02b.zip |
Add D-BUS introspection to InfoPipe This function is necessary to play nice with D-BUS clients built in multiple languages. It will read in the XML file on the first request and store the returned XML as a component of the sbus_message_handler_ctx for the connection. All subsequent requests during the process' lifetime will be returned from the stored memory. This is perfectly safe, as the available methods cannot change during the process lifetime.
Diffstat (limited to 'server/infopipe')
-rw-r--r-- | server/infopipe/infopipe.c | 77 | ||||
-rw-r--r-- | server/infopipe/infopipe.h | 2 |
2 files changed, 76 insertions, 3 deletions
diff --git a/server/infopipe/infopipe.c b/server/infopipe/infopipe.c index 1e7a88c8..9c129d26 100644 --- a/server/infopipe/infopipe.c +++ b/server/infopipe/infopipe.c @@ -132,11 +132,82 @@ struct sbus_method infp_methods[] = { { NULL, NULL } }; +#define INTROSPECT_CHUNK_SIZE 128 + int infp_introspect(DBusMessage *message, struct sbus_message_ctx *reply) { - /* TODO: actually return the file */ - reply->reply_message = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); - return EOK; + FILE *xml_stream; + char *introspect_xml; + char *chunk; + TALLOC_CTX *tmp_ctx; + unsigned long xml_size; + size_t chunk_size; + int ret; + dbus_bool_t dbret; + + tmp_ctx = talloc_new(reply); + if(tmp_ctx == NULL) { + return ENOMEM; + } + + if (reply->mh_ctx->introspection_xml == NULL) { + /* Read in the Introspection XML the first time */ + xml_stream = fopen(SSSD_INTROSPECT_PATH"/"INFP_INTROSPECT_XML, "r"); + if(xml_stream == NULL) { + DEBUG(0, ("Could not open the introspection XML for reading: [%d] [%s].\n", errno, SSSD_INTROSPECT_PATH"/"INFP_INTROSPECT_XML)); + return errno; + } + + chunk = talloc_size(tmp_ctx, INTROSPECT_CHUNK_SIZE); + if (chunk == NULL) { + ret = ENOMEM; + goto done; + } + + xml_size = 0; + introspect_xml = NULL; + do { + chunk_size = fread(chunk, 1, INTROSPECT_CHUNK_SIZE, xml_stream); + introspect_xml = talloc_realloc_size(tmp_ctx, introspect_xml, xml_size+chunk_size+1); + if (introspect_xml == NULL) { + ret = ENOMEM; + goto done; + } + memcpy(introspect_xml+xml_size, chunk, chunk_size); + xml_size += chunk_size; + } while(chunk_size == INTROSPECT_CHUNK_SIZE); + introspect_xml[xml_size] = '\0'; + talloc_free(chunk); + + /* Store the instrospection XML for future calls */ + reply->mh_ctx->introspection_xml = introspect_xml; + talloc_steal(reply->mh_ctx, introspect_xml); + } + else { + /* Subsequent calls should just reuse the saved value */ + introspect_xml = reply->mh_ctx->introspection_xml; + } + + /* Return the Introspection XML */ + reply->reply_message = dbus_message_new_method_return(message); + if (reply->reply_message == NULL) { + ret = ENOMEM; + goto done; + } + dbret = dbus_message_append_args(reply->reply_message, + DBUS_TYPE_STRING, &introspect_xml, + DBUS_TYPE_INVALID); + if (!dbret) { + ret = ENOMEM; + goto done; + } + + DEBUG(9, ("%s\n", introspect_xml)); + ret = EOK; + +done: + talloc_free(tmp_ctx); + return ret; } static int infp_process_init(TALLOC_CTX *mem_ctx, diff --git a/server/infopipe/infopipe.h b/server/infopipe/infopipe.h index aabc2bfa..83a3d8d4 100644 --- a/server/infopipe/infopipe.h +++ b/server/infopipe/infopipe.h @@ -25,6 +25,8 @@ #include <dbus/dbus.h> #include "sbus/sssd_dbus.h" +#define INFP_INTROSPECT_XML "infopipe/org.freeipa.sssd.infopipe.Introspect.xml" + #define INFOPIPE_DBUS_NAME "org.freeipa.sssd.infopipe1" #define INFOPIPE_INTERFACE "org.freeipa.sssd.infopipe1" #define INFOPIPE_PATH "/org/freeipa/sssd/infopipe1" |