From: <svn...@op...> - 2009-09-17 16:37:06
|
Author: dgollub Date: Thu Sep 17 18:36:52 2009 New Revision: 5780 URL: http://www.opensync.org/changeset/5780 Log: Make OSyncMarshal API more future proof and apply a common API pattern: osync_bool osync_masrhal_XXXX(...., OSyncError**) refs #1087, comment:11 Modified: trunk/opensync/client/opensync_client.c trunk/opensync/client/opensync_client_proxy.c trunk/opensync/common/opensync_marshal.c trunk/opensync/common/opensync_marshal.h trunk/opensync/common/opensync_marshal_internals.h trunk/opensync/engine/opensync_engine.c trunk/opensync/engine/opensync_mapping_entry_engine.c trunk/opensync/ipc/opensync_message.c trunk/opensync/ipc/opensync_message_internals.h trunk/opensync/ipc/opensync_queue.c trunk/opensync/ipc/opensync_serializer.c trunk/opensync/ipc/opensync_serializer_internals.h trunk/tests/format-tests/check_objformat.c trunk/tests/ipc-tests/check_ipc.c trunk/tests/mock-plugin/mock_format.c Modified: trunk/opensync/client/opensync_client.c ============================================================================== --- trunk/opensync/client/opensync_client.c Thu Sep 17 16:39:20 2009 (r5779) +++ trunk/opensync/client/opensync_client.c Thu Sep 17 18:36:52 2009 (r5780) @@ -119,7 +119,8 @@ message = baton->message; client = baton->client; osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, data, error); - osync_message_read_string(message, &objtype); + if (!osync_message_read_string(message, &objtype, &error)) + goto error; if (objtype) { // objtype sink (e.g. event, contact, ...) @@ -145,7 +146,8 @@ goto error; //Send connect specific reply data - osync_message_write_int(reply, slowsync); + if (!osync_message_write_int(reply, slowsync, &error)) + goto error_free_message; } else { reply = osync_message_new_errorreply(message, error, &locerror); @@ -269,29 +271,38 @@ version = osync_plugin_info_get_version(client->plugin_info); if (version) { - osync_message_write_int(reply, 1); - osync_message_write_string(reply, osync_version_get_plugin(version)); - osync_message_write_string(reply, osync_version_get_priority(version)); - osync_message_write_string(reply, osync_version_get_vendor(version)); - osync_message_write_string(reply, osync_version_get_modelversion(version)); - osync_message_write_string(reply, osync_version_get_firmwareversion(version)); - osync_message_write_string(reply, osync_version_get_softwareversion(version)); - osync_message_write_string(reply, osync_version_get_hardwareversion(version)); - osync_message_write_string(reply, osync_version_get_identifier(version)); + osync_message_write_int(reply, 1, error); + osync_message_write_string(reply, osync_version_get_plugin(version), error); + osync_message_write_string(reply, osync_version_get_priority(version), error); + osync_message_write_string(reply, osync_version_get_vendor(version), error); + osync_message_write_string(reply, osync_version_get_modelversion(version), error); + osync_message_write_string(reply, osync_version_get_firmwareversion(version), error); + osync_message_write_string(reply, osync_version_get_softwareversion(version), error); + osync_message_write_string(reply, osync_version_get_hardwareversion(version), error); + osync_message_write_string(reply, osync_version_get_identifier(version), error); } else { - osync_message_write_int(reply, 0); + osync_message_write_int(reply, 0, error); } + + if (osync_error_is_set(error)) + goto error; /* Report detected capabilities */ capabilities = osync_plugin_info_get_capabilities(client->plugin_info); if (capabilities) { - osync_message_write_int(reply, 1); + if (!osync_message_write_int(reply, 1, error)) + goto error; + if (!osync_capabilities_assemble(capabilities, &buffer, &size, error)) goto error; - osync_message_write_string(reply, buffer); + + if (!osync_message_write_string(reply, buffer, error)) + goto error; + g_free(buffer); } else { - osync_message_write_int(reply, 0); + if (!osync_message_write_int(reply, 0, error)) + goto error; } return TRUE; @@ -442,7 +453,8 @@ goto error; //Send get_changes specific reply data - osync_message_write_string(reply, osync_change_get_uid(baton->change)); + if (!osync_message_write_string(reply, osync_change_get_uid(baton->change), &locerror)) + goto error; } else { reply = osync_message_new_errorreply(message, error, &locerror); } @@ -493,7 +505,8 @@ goto error; //Send get_changes specific reply data - osync_message_write_string(reply, osync_change_get_uid(baton->change)); + if (!osync_message_write_string(reply, osync_change_get_uid(baton->change), &locerror)) + goto error_free_message; } else { reply = osync_message_new_errorreply(message, error, &locerror); } @@ -635,13 +648,16 @@ osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, client, message, error); - osync_message_read_string(message, &enginepipe); - osync_message_read_string(message, &formatdir); - osync_message_read_string(message, &plugindir); - osync_message_read_string(message, &pluginname); - osync_message_read_string(message, &groupname); - osync_message_read_string(message, &configdir); - osync_message_read_int(message, &haspluginconfig); + osync_message_read_string(message, &enginepipe, error); + osync_message_read_string(message, &formatdir, error); + osync_message_read_string(message, &plugindir, error); + osync_message_read_string(message, &pluginname, error); + osync_message_read_string(message, &groupname, error); + osync_message_read_string(message, &configdir, error); + osync_message_read_int(message, &haspluginconfig, error); + + if (osync_error_is_set(error)) + goto error; if (haspluginconfig && !osync_demarshal_pluginconfig(message, &config, error)) goto error; @@ -705,7 +721,9 @@ #ifdef OPENSYNC_UNITTESTS { long long int memberid; - osync_message_read_long_long_int(message, &memberid); // Introduced (only) for testing/debugging purpose (mock-sync) + if (!osync_message_read_long_long_int(message, &memberid, error)) // Introduced (only) for testing/debugging purpose (mock-sync) + goto error; + client->plugin_info->memberid = memberid; } #endif @@ -896,9 +914,12 @@ goto error; if (osync_plugin_info_get_main_sink(client->plugin_info)) - osync_message_write_int(reply, 1); + osync_message_write_int(reply, 1, error); else - osync_message_write_int(reply, 0); + osync_message_write_int(reply, 0, error); + + if (osync_error_is_set(error)) + goto error_free_message; objtypesinks = osync_plugin_info_get_objtype_sinks(client->plugin_info); list = objtypesinks; @@ -910,7 +931,8 @@ list = list->next; } - osync_message_write_uint(reply, avail); + if (!osync_message_write_uint(reply, avail, error)) + goto error_free_message; list = objtypesinks; while(list) { @@ -930,7 +952,9 @@ res = osync_plugin_config_get_resources(config); num_res = osync_list_length(res); - osync_message_write_uint(reply, num_res); + if (!osync_message_write_uint(reply, num_res, error)) + goto error; + for (; res; res = res->next) { resource = res->data; if (!osync_marshal_pluginresource(reply, resource, error)) @@ -969,9 +993,13 @@ * because the connect functions work asynchronous and the last sink * (usually the main sink) is the current sink. */ - osync_message_read_string(message, &objtype); - osync_message_read_int(message, &slowsync); - osync_message_write_string(message, objtype); + osync_message_read_string(message, &objtype, error); + osync_message_read_int(message, &slowsync, error); + osync_message_write_string(message, objtype, error); + + if (osync_error_is_set(error)) + goto error; + osync_trace(TRACE_INTERNAL, "Searching sink for %s", objtype); if (objtype) { @@ -993,7 +1021,8 @@ goto error; /* SlowSync dummy value for connect reply message handler. */ - osync_message_write_int(reply, FALSE); + if (!osync_message_write_int(reply, FALSE, error)) + goto error_free_reply; if (!osync_queue_send_message(client->outgoing, NULL, reply, error)) goto error_free_reply; @@ -1041,8 +1070,12 @@ osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, client, message, error); - osync_message_read_string(message, &objtype); - osync_message_read_int(message, &slowsync); + osync_message_read_string(message, &objtype, error); + osync_message_read_int(message, &slowsync, error); + + if (osync_error_is_set(error)) + goto error; + osync_trace(TRACE_INTERNAL, "Searching sink for %s (slowsync: %d)", objtype, slowsync); if (objtype) { @@ -1103,7 +1136,9 @@ osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, client, message, error); - osync_message_read_string(message, &objtype); + if (!osync_message_read_string(message, &objtype, error)) + goto error; + osync_trace(TRACE_INTERNAL, "Searching sink for %s", objtype); if (objtype) { @@ -1158,8 +1193,12 @@ osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, client, message, error); - osync_message_read_string(message, &objtype); - osync_message_read_int(message, &slowsync); + osync_message_read_string(message, &objtype, error); + osync_message_read_int(message, &slowsync, error); + + if (osync_error_is_set(error)) + goto error; + osync_trace(TRACE_INTERNAL, "Searching sink for %s (slowsync: %i)", objtype, slowsync); if (objtype) { @@ -1320,7 +1359,9 @@ osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, client, message, error); - osync_message_read_string(message, &objtype); + if (!osync_message_read_string(message, &objtype, error)) + goto error; + osync_trace(TRACE_INTERNAL, "Searching sink for %s", objtype ? objtype : "(MainSink)"); if (objtype) { @@ -1374,7 +1415,9 @@ osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, client, message, error); - osync_message_read_string(message, &objtype); + if (!osync_message_read_string(message, &objtype, error)) + goto error; + osync_trace(TRACE_INTERNAL, "Searching sink for %s", objtype); if (objtype) { Modified: trunk/opensync/client/opensync_client_proxy.c ============================================================================== --- trunk/opensync/client/opensync_client_proxy.c Thu Sep 17 16:39:20 2009 (r5779) +++ trunk/opensync/client/opensync_client_proxy.c Thu Sep 17 18:36:52 2009 (r5780) @@ -260,7 +260,10 @@ if (osync_message_get_cmd(message) == OSYNC_MESSAGE_REPLY) { ctx->init_callback(proxy, ctx->init_callback_data, NULL); } else if (osync_message_get_cmd(message) == OSYNC_MESSAGE_ERRORREPLY) { - osync_demarshal_error(message, &error); + + if (!osync_demarshal_error(message, &error, &locerror)) + goto error; + ctx->init_callback(proxy, ctx->init_callback_data, error); osync_error_unref(&error); } else { @@ -293,7 +296,10 @@ if (osync_message_get_cmd(message) == OSYNC_MESSAGE_REPLY) { ctx->fin_callback(proxy, ctx->fin_callback_data, NULL); } else if (osync_message_get_cmd(message) == OSYNC_MESSAGE_ERRORREPLY) { - osync_demarshal_error(message, &error); + + if (osync_demarshal_error(message, &error, &locerror)) + goto error; + ctx->fin_callback(proxy, ctx->fin_callback_data, error); osync_error_unref(&error); } else { @@ -327,41 +333,50 @@ /* Merger - Set the capabilities */ - osync_message_read_int(message, &sent_version); + if (!osync_message_read_int(message, &sent_version, error)) + goto error; + if (sent_version) { version = osync_version_new(error); if (!version) goto error; - osync_message_read_string(message, &str); + osync_message_read_string(message, &str, error); osync_version_set_plugin(version, str); osync_free(str); - osync_message_read_string(message, &str); + osync_message_read_string(message, &str, error); osync_version_set_priority(version, str); osync_free(str); - osync_message_read_string(message, &str); + osync_message_read_string(message, &str, error); osync_version_set_vendor(version, str); osync_free(str); - osync_message_read_string(message, &str); + osync_message_read_string(message, &str, error); osync_version_set_modelversion(version, str); osync_free(str); - osync_message_read_string(message, &str); + osync_message_read_string(message, &str, error); osync_version_set_firmwareversion(version, str); osync_free(str); - osync_message_read_string(message, &str); + osync_message_read_string(message, &str, error); osync_version_set_softwareversion(version, str); osync_free(str); - osync_message_read_string(message, &str); + osync_message_read_string(message, &str, error); osync_version_set_hardwareversion(version, str); osync_free(str); - osync_message_read_string(message, &str); + osync_message_read_string(message, &str, error); osync_version_set_identifier(version, str); osync_free(str); + + if (osync_error_is_set(error)) + goto error_free_version; } - osync_message_read_int(message, &sent_capabilities); + if (!osync_message_read_int(message, &sent_capabilities, error)) + goto error; + if (sent_capabilities) { - osync_message_read_string(message, &str); + if (!osync_message_read_string(message, &str, error)) + goto error_free_version; + capabilities = osync_capabilities_parse(str, strlen(str), error); osync_free(str); if (!capabilities) @@ -428,9 +443,12 @@ if (osync_message_get_cmd(message) == OSYNC_MESSAGE_REPLY) { - osync_message_read_int(message, &proxy->has_main_sink); + osync_message_read_int(message, &proxy->has_main_sink, &locerror); - osync_message_read_uint(message, &num_sinks); + osync_message_read_uint(message, &num_sinks, &locerror); + + if (osync_error_is_set(&locerror)) + goto error; osync_trace(TRACE_INTERNAL, "main sink?: %i, num objs?: %i", proxy->has_main_sink, num_sinks); @@ -456,7 +474,10 @@ goto error; osync_plugin_config_flush_resources(config); - osync_message_read_uint(message, &num_res); + + if (!osync_message_read_uint(message, &num_res, &locerror)) + goto error; + for (i=0; i < num_res; i++) { if (!osync_demarshal_pluginresource(message, &resource, &locerror)) goto error; @@ -471,7 +492,10 @@ ctx->discover_callback(proxy, ctx->discover_callback_data, NULL); } else if (osync_message_get_cmd(message) == OSYNC_MESSAGE_ERRORREPLY) { - osync_demarshal_error(message, &error); + + if (!osync_demarshal_error(message, &error, &locerror)) + goto error; + ctx->discover_callback(proxy, ctx->discover_callback_data, error); osync_error_unref(&error); } else { @@ -503,10 +527,16 @@ osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, message, user_data); if (osync_message_get_cmd(message) == OSYNC_MESSAGE_REPLY) { - osync_message_read_int(message, &slowsync); + + if (!osync_message_read_int(message, &slowsync, &locerror)) + goto error; + ctx->connect_callback(proxy, ctx->connect_callback_data, slowsync, NULL); } else if (osync_message_get_cmd(message) == OSYNC_MESSAGE_ERRORREPLY) { - osync_demarshal_error(message, &error); + + if (!osync_demarshal_error(message, &error, &locerror)) + goto error; + ctx->connect_callback(proxy, ctx->connect_callback_data, FALSE, error); osync_error_unref(&error); } else { @@ -539,7 +569,10 @@ if (osync_message_get_cmd(message) == OSYNC_MESSAGE_REPLY) { ctx->connect_done_callback(proxy, ctx->connect_done_callback_data, NULL); } else if (osync_message_get_cmd(message) == OSYNC_MESSAGE_ERRORREPLY) { - osync_demarshal_error(message, &error); + + if (!osync_demarshal_error(message, &error, &locerror)) + goto error; + ctx->connect_done_callback(proxy, ctx->connect_done_callback_data, error); osync_error_unref(&error); } else { @@ -572,7 +605,10 @@ if (osync_message_get_cmd(message) == OSYNC_MESSAGE_REPLY) { ctx->disconnect_callback(proxy, ctx->disconnect_callback_data, NULL); } else if (osync_message_get_cmd(message) == OSYNC_MESSAGE_ERRORREPLY) { - osync_demarshal_error(message, &error); + + if (!osync_demarshal_error(message, &error, &locerror)) + goto error; + ctx->disconnect_callback(proxy, ctx->disconnect_callback_data, error); osync_error_unref(&error); } else { @@ -605,7 +641,10 @@ if (osync_message_get_cmd(message) == OSYNC_MESSAGE_REPLY) { ctx->read_callback(proxy, ctx->read_callback_data, NULL); } else if (osync_message_get_cmd(message) == OSYNC_MESSAGE_ERRORREPLY) { - osync_demarshal_error(message, &error); + + if (!osync_demarshal_error(message, &error, &locerror)) + goto error; + ctx->read_callback(proxy, ctx->read_callback_data, error); osync_error_unref(&error); } else { @@ -644,7 +683,10 @@ } } else if (osync_message_get_cmd(message) == OSYNC_MESSAGE_ERRORREPLY) { - osync_demarshal_error(message, &error); + + if (!osync_demarshal_error(message, &error, &locerror)) + goto error; + ctx->get_changes_callback(proxy, ctx->get_changes_callback_data, error); osync_client_proxy_set_error(proxy, error); osync_error_unref(&error); @@ -677,11 +719,17 @@ if (osync_message_get_cmd(message) == OSYNC_MESSAGE_REPLY) { char *uid = NULL; - osync_message_read_string(message, &uid); + + if (!osync_message_read_string(message, &uid, &locerror)) + goto error; + ctx->commit_change_callback(proxy, ctx->commit_change_callback_data, uid, NULL); osync_free(uid); } else if (osync_message_get_cmd(message) == OSYNC_MESSAGE_ERRORREPLY) { - osync_demarshal_error(message, &error); + + if (!osync_demarshal_error(message, &error, &locerror)) + goto error; + ctx->commit_change_callback(proxy, ctx->commit_change_callback_data, NULL, error); osync_error_unref(&error); } else { @@ -714,7 +762,10 @@ if (osync_message_get_cmd(message) == OSYNC_MESSAGE_REPLY) { ctx->committed_all_callback(proxy, ctx->committed_all_callback_data, NULL); } else if (osync_message_get_cmd(message) == OSYNC_MESSAGE_ERRORREPLY) { - osync_demarshal_error(message, &error); + + if (!osync_demarshal_error(message, &error, &locerror)) + goto error; + ctx->committed_all_callback(proxy, ctx->committed_all_callback_data, error); osync_error_unref(&error); } else { @@ -747,7 +798,10 @@ if (osync_message_get_cmd(message) == OSYNC_MESSAGE_REPLY) { ctx->sync_done_callback(proxy, ctx->sync_done_callback_data, NULL); } else if (osync_message_get_cmd(message) == OSYNC_MESSAGE_ERRORREPLY) { - osync_demarshal_error(message, &error); + + if (!osync_demarshal_error(message, &error, &locerror)) + goto error; + ctx->sync_done_callback(proxy, ctx->sync_done_callback_data, error); osync_error_unref(&error); } else { @@ -1187,13 +1241,16 @@ if (!message) goto error; - osync_message_write_string(message, osync_queue_get_path(proxy->incoming)); - osync_message_write_string(message, formatdir); - osync_message_write_string(message, plugindir); - osync_message_write_string(message, plugin); - osync_message_write_string(message, groupname); - osync_message_write_string(message, configdir); - osync_message_write_int(message, haspluginconfig); + osync_message_write_string(message, osync_queue_get_path(proxy->incoming), error); + osync_message_write_string(message, formatdir, error); + osync_message_write_string(message, plugindir, error); + osync_message_write_string(message, plugin, error); + osync_message_write_string(message, groupname, error); + osync_message_write_string(message, configdir, error); + osync_message_write_int(message, haspluginconfig, error); + + if (osync_error_is_set(error)) + goto error; if (haspluginconfig && !osync_marshal_pluginconfig(message, config, error)) goto error; @@ -1228,7 +1285,7 @@ if (proxy->member) memberid = osync_member_get_id(proxy->member); - osync_message_write_long_long_int(message, memberid); + osync_message_write_long_long_int(message, memberid, error); #endif osync_message_set_handler(message, _osync_client_proxy_init_handler, ctx); @@ -1427,8 +1484,11 @@ osync_message_set_handler(message, _osync_client_proxy_connect_handler, ctx); - osync_message_write_string(message, objtype); - osync_message_write_int(message, slowsync); + osync_message_write_string(message, objtype, error); + osync_message_write_int(message, slowsync, error); + + if (osync_error_is_set(error)) + goto error_free_message; if (!osync_queue_send_message_with_timeout(proxy->outgoing, proxy->incoming, message, timeout, error)) goto error_free_message; @@ -1477,8 +1537,11 @@ osync_message_set_handler(message, _osync_client_proxy_connect_done_handler, ctx); - osync_message_write_string(message, objtype); - osync_message_write_int(message, slowsync); + osync_message_write_string(message, objtype, error); + osync_message_write_int(message, slowsync, error); + + if (osync_error_is_set(error)) + goto error_free_message; if (!osync_queue_send_message_with_timeout(proxy->outgoing, proxy->incoming, message, timeout, error)) goto error_free_message; @@ -1526,7 +1589,8 @@ osync_message_set_handler(message, _osync_client_proxy_disconnect_handler, ctx); - osync_message_write_string(message, objtype); + if (!osync_message_write_string(message, objtype, error)) + goto error_free_message; if (!osync_queue_send_message_with_timeout(proxy->outgoing, proxy->incoming, message, timeout, error)) goto error_free_message; @@ -1623,8 +1687,11 @@ osync_message_set_handler(message, _osync_client_proxy_get_changes_handler, ctx); - osync_message_write_string(message, objtype); - osync_message_write_int(message, slowsync); + osync_message_write_string(message, objtype, error); + osync_message_write_int(message, slowsync, error); + + if (osync_error_is_set(error)) + goto error_free_message; if (!osync_queue_send_message_with_timeout(proxy->outgoing, proxy->incoming, message, timeout, error)) goto error_free_message; @@ -1724,7 +1791,10 @@ osync_message_set_handler(message, _osync_client_proxy_committed_all_handler, ctx); - osync_message_write_string(message, objtype); + osync_message_write_string(message, objtype, error); + + if (osync_error_is_set(error)) + goto error; if (!osync_queue_send_message_with_timeout(proxy->outgoing, proxy->incoming, message, timeout, error)) goto error_free_message; @@ -1773,7 +1843,8 @@ osync_message_set_handler(message, _osync_client_proxy_sync_done_handler, ctx); - osync_message_write_string(message, objtype); + if (!osync_message_write_string(message, objtype, error)) + goto error_free_message; if (!osync_queue_send_message_with_timeout(proxy->outgoing, proxy->incoming, message, timeout, error)) goto error_free_message; Modified: trunk/opensync/common/opensync_marshal.c ============================================================================== --- trunk/opensync/common/opensync_marshal.c Thu Sep 17 16:39:20 2009 (r5779) +++ trunk/opensync/common/opensync_marshal.c Thu Sep 17 18:36:52 2009 (r5780) @@ -70,13 +70,15 @@ return marshal->buffer->len; } -void osync_marshal_set_marshal_size(OSyncMarshal *marshal, unsigned int size) +osync_bool osync_marshal_set_marshal_size(OSyncMarshal *marshal, unsigned int size, OSyncError **error) { osync_assert(marshal); marshal->buffer->len = size; + + return TRUE; } -void osync_marshal_get_buffer(OSyncMarshal *marshal, char **data, unsigned int *size) +osync_bool osync_marshal_get_buffer(OSyncMarshal *marshal, char **data, unsigned int *size, OSyncError **error) { osync_assert(marshal); @@ -85,24 +87,32 @@ if (size) *size = marshal->buffer->len; + + return TRUE; } -void osync_marshal_write_int(OSyncMarshal *marshal, int value) +osync_bool osync_marshal_write_int(OSyncMarshal *marshal, int value, OSyncError **error) { g_byte_array_append( marshal->buffer, (unsigned char*)&value, sizeof( int ) ); + + return TRUE; } -void osync_marshal_write_uint(OSyncMarshal *marshal, unsigned int value) +osync_bool osync_marshal_write_uint(OSyncMarshal *marshal, unsigned int value, OSyncError **error) { g_byte_array_append( marshal->buffer, (unsigned char*)&value, sizeof( unsigned int ) ); + + return TRUE; } -void osync_marshal_write_long_long_int(OSyncMarshal *marshal, long long int value) +osync_bool osync_marshal_write_long_long_int(OSyncMarshal *marshal, long long int value, OSyncError **error) { g_byte_array_append( marshal->buffer, (unsigned char*)&value, sizeof( long long int ) ); + + return TRUE; } -void osync_marshal_write_string(OSyncMarshal *marshal, const char *value) +osync_bool osync_marshal_write_string(OSyncMarshal *marshal, const char *value, OSyncError **error) { unsigned int length = 0; @@ -113,106 +123,152 @@ if (value) g_byte_array_append( marshal->buffer, (unsigned char*)value, length ); + + return TRUE; } -void osync_marshal_write_data(OSyncMarshal *marshal, const void *value, unsigned int size) +osync_bool osync_marshal_write_data(OSyncMarshal *marshal, const void *value, unsigned int size, OSyncError **error) { g_byte_array_append( marshal->buffer, value, size ); + + return TRUE; } -void osync_marshal_write_buffer(OSyncMarshal *marshal, const void *value, unsigned int size) +osync_bool osync_marshal_write_buffer(OSyncMarshal *marshal, const void *value, unsigned int size, OSyncError **error) { /* serialize the length of the data to make it possible to determine the end of this data blob in the serialized blob. This makes demarshaling possible! */ - osync_marshal_write_uint(marshal, size); - if (size > 0) - osync_marshal_write_data(marshal, value, size); + if (!osync_marshal_write_uint(marshal, size, error)) + goto error; + + if (size > 0) { + if (!osync_marshal_write_data(marshal, value, size, error)) + goto error; + } + + return TRUE; + +error: + return FALSE; } -void osync_marshal_read_int(OSyncMarshal *marshal, int *value) +osync_bool osync_marshal_read_int(OSyncMarshal *marshal, int *value, OSyncError **error) { osync_assert(marshal->buffer->len >= marshal->buffer_read_pos + sizeof(int)); memcpy(value, &(marshal->buffer->data[ marshal->buffer_read_pos ]), sizeof(int)); marshal->buffer_read_pos += sizeof(int); + + return TRUE; } -void osync_marshal_read_uint(OSyncMarshal *marshal, unsigned int *value) +osync_bool osync_marshal_read_uint(OSyncMarshal *marshal, unsigned int *value, OSyncError **error) { osync_assert(marshal->buffer->len >= marshal->buffer_read_pos + sizeof(unsigned int)); memcpy(value, &(marshal->buffer->data[ marshal->buffer_read_pos ]), sizeof(unsigned int)); marshal->buffer_read_pos += sizeof(unsigned int); + + return TRUE; } -void osync_marshal_read_long_long_int(OSyncMarshal *marshal, long long int *value) +osync_bool osync_marshal_read_long_long_int(OSyncMarshal *marshal, long long int *value, OSyncError **error) { osync_assert(marshal->buffer->len >= marshal->buffer_read_pos + sizeof(long long int)); memcpy(value, &(marshal->buffer->data[ marshal->buffer_read_pos ]), sizeof(long long int)); marshal->buffer_read_pos += sizeof(long long int); + + return TRUE; } -void osync_marshal_read_const_string(OSyncMarshal *marshal, const char **value) +osync_bool osync_marshal_read_const_string(OSyncMarshal *marshal, const char **value, OSyncError **error) { int length = 0; - osync_marshal_read_int(marshal, &length); + + if (!osync_marshal_read_int(marshal, &length, error)) + goto error; if (length == -1) { *value = NULL; - return; + return TRUE; } osync_assert(marshal->buffer->len >= marshal->buffer_read_pos + length); *value = (char *)&(marshal->buffer->data[marshal->buffer_read_pos]); marshal->buffer_read_pos += length; + + return TRUE; +error: + return FALSE; } -void osync_marshal_read_string(OSyncMarshal *marshal, char **value) +osync_bool osync_marshal_read_string(OSyncMarshal *marshal, char **value, OSyncError **error) { unsigned int length = 0; - osync_marshal_read_uint(marshal, &length); + + if (!osync_marshal_read_uint(marshal, &length, error)) + goto error; if (!length) { *value = NULL; - return; + return TRUE; } osync_assert(marshal->buffer->len >= marshal->buffer_read_pos + length); - /* TODO: Error handling? */ - *value = (char*) osync_try_malloc0(length, NULL); + *value = (char*) osync_try_malloc0(length, error); if (!*value) - return; + goto error; memcpy(*value, &(marshal->buffer->data[ marshal->buffer_read_pos ]), length ); marshal->buffer_read_pos += length; + + return TRUE; + +error: + return FALSE; } -void osync_marshal_read_const_data(OSyncMarshal *marshal, void **value, unsigned int size) +osync_bool osync_marshal_read_const_data(OSyncMarshal *marshal, void **value, unsigned int size, OSyncError **error) { osync_assert(marshal->buffer->len >= marshal->buffer_read_pos + size); *value = &(marshal->buffer->data[marshal->buffer_read_pos]); marshal->buffer_read_pos += size; + + return TRUE; } -void osync_marshal_read_data(OSyncMarshal *marshal, void *value, unsigned int size) +osync_bool osync_marshal_read_data(OSyncMarshal *marshal, void *value, unsigned int size, OSyncError **error) { osync_assert(marshal->buffer->len >= marshal->buffer_read_pos + size); memcpy(value, &(marshal->buffer->data[ marshal->buffer_read_pos ]), size ); marshal->buffer_read_pos += size; + + return TRUE; } -void osync_marshal_read_buffer(OSyncMarshal *marshal, void **value, unsigned int *size) +osync_bool osync_marshal_read_buffer(OSyncMarshal *marshal, void **value, unsigned int *size, OSyncError **error) { /* Now, read the data from the marshal */ - osync_marshal_read_uint(marshal, size); + if (!osync_marshal_read_uint(marshal, size, error)) + goto error; if (*size > 0) { - *value = g_malloc0(*size); - osync_marshal_read_data(marshal, *value, *size); + *value = osync_try_malloc0(*size, error); + + if (!*value) + goto error; + + if (!osync_marshal_read_data(marshal, *value, *size, error)) + goto error; } + + return TRUE; + +error: + return FALSE; } Modified: trunk/opensync/common/opensync_marshal.h ============================================================================== --- trunk/opensync/common/opensync_marshal.h Thu Sep 17 16:39:20 2009 (r5779) +++ trunk/opensync/common/opensync_marshal.h Thu Sep 17 18:36:52 2009 (r5780) @@ -77,46 +77,52 @@ * * @param marshal The marshal object * @param size The size of the marshal to set + * @param error Pointer to a error-struct * */ -OSYNC_EXPORT void osync_marshal_set_marshal_size(OSyncMarshal *marshal, unsigned int size); +OSYNC_EXPORT osync_bool osync_marshal_set_marshal_size(OSyncMarshal *marshal, unsigned int size, OSyncError **error); /** @brief Get the buffer/content of the marshal object * * @param marshal The marshal object * @param data Pointer to data * @param size Size of the data + * @param error Pointer to a error-struct * */ -OSYNC_EXPORT void osync_marshal_get_buffer(OSyncMarshal *marshal, char **data, unsigned int *size); +OSYNC_EXPORT osync_bool osync_marshal_get_buffer(OSyncMarshal *marshal, char **data, unsigned int *value, OSyncError **error); /** @brief Appends an integer value to serialized buffer * * @param marshal The marshal object * @param value The integer value to append + * @param error Pointer to a error-struct */ -OSYNC_EXPORT void osync_marshal_write_int(OSyncMarshal *marshal, int value); +OSYNC_EXPORT osync_bool osync_marshal_write_int(OSyncMarshal *marshal, int value, OSyncError **error); /** @brief Appends an unsigned integer value to serialized buffer * * @param marshal The marshal object * @param value The integer value to append + * @param error Pointer to a error-struct */ -OSYNC_EXPORT void osync_marshal_write_uint(OSyncMarshal *marshal, unsigned int value); +OSYNC_EXPORT osync_bool osync_marshal_write_uint(OSyncMarshal *marshal, unsigned int value, OSyncError **error); /** @brief Appends a long long integer value to serialized buffer * * @param marshal The marshal object * @param value The long long integer value to append + * @param error Pointer to a error-struct */ -OSYNC_EXPORT void osync_marshal_write_long_long_int(OSyncMarshal *marshal, long long int value); +OSYNC_EXPORT osync_bool osync_marshal_write_long_long_int(OSyncMarshal *marshal, long long int value, OSyncError **error); /** @brief Appends a string to serialized buffer * * @param marshal The marshal object * @param value The string to append + * @param error Pointer to a error-struct */ -OSYNC_EXPORT void osync_marshal_write_string(OSyncMarshal *marshal, const char *value); +OSYNC_EXPORT osync_bool osync_marshal_write_string(OSyncMarshal *marshal, const char *value, OSyncError **error); /** @brief Appends data with a specific length to the serialized buffer, * plus the length of the data to determine the end. @@ -124,32 +130,36 @@ * @param marshal The marshal object * @param value The data to append * @param size Size of corresponding data parameter + * @param error Pointer to a error-struct */ -OSYNC_EXPORT void osync_marshal_write_buffer(OSyncMarshal *marshal, const void *value, unsigned int size); +OSYNC_EXPORT osync_bool osync_marshal_write_buffer(OSyncMarshal *marshal, const void *value, unsigned int size, OSyncError **error); /** @brief Read serialized integer from marshal buffer. This increments the read * position of the marshal buffer. * * @param marshal The marshal object * @param value Reference to store the integer value + * @param error Pointer to a error-struct */ -OSYNC_EXPORT void osync_marshal_read_int(OSyncMarshal *marshal, int *value); +OSYNC_EXPORT osync_bool osync_marshal_read_int(OSyncMarshal *marshal, int *value, OSyncError **error); /** @brief Read serialized unsigned integer from marshal buffer. This increments the read * position of the marshal buffer. * * @param marshal The marshal object * @param value Reference to store the integer value + * @param error Pointer to a error-struct */ -OSYNC_EXPORT void osync_marshal_read_uint(OSyncMarshal *marshal, unsigned int *value); +OSYNC_EXPORT osync_bool osync_marshal_read_uint(OSyncMarshal *marshal, unsigned int *value, OSyncError **error); /** @brief Read serialized long long integer from marshal buffer. This increments the read * position of the marshal buffer. * * @param marshal The marshal object * @param value Reference to store the long long integer value + * @param error Pointer to a error-struct */ -OSYNC_EXPORT void osync_marshal_read_long_long_int(OSyncMarshal *marshal, long long int *value); +OSYNC_EXPORT osync_bool osync_marshal_read_long_long_int(OSyncMarshal *marshal, long long int *value, OSyncError **error); /** @brief Read serialized string from marshal buffer. This increments the read * position of the marshal buffer. Caller is responsible for freeing the duplicated @@ -157,8 +167,9 @@ * * @param marshal The marshal object * @param value Reference to store the pointer to the newly allocated string + * @param error Pointer to a error-struct */ -OSYNC_EXPORT void osync_marshal_read_string(OSyncMarshal *marshal, char **value); +OSYNC_EXPORT osync_bool osync_marshal_read_string(OSyncMarshal *marshal, char **value, OSyncError **error); /** @brief Read serialized const data from marshal buffer. This increments the read * position of the marshal buffer. @@ -166,16 +177,18 @@ * @param marshal The marshal object * @param value Reference to store the data pointer * @param size The size of data + * @param error Pointer to a error-struct */ -OSYNC_EXPORT void osync_marshal_read_const_data(OSyncMarshal *marshal, void **value, unsigned int size); +OSYNC_EXPORT osync_bool osync_marshal_read_const_data(OSyncMarshal *marshal, void **value, unsigned int size, OSyncError **error); /** @brief Read serialized const string from marshal buffer. This increments the read * position of the marshal buffer. * * @param marshal The marshal object * @param value Reference to store the string pointer + * @param error Pointer to a error-struct */ -OSYNC_EXPORT void osync_marshal_read_const_string(OSyncMarshal *marshal, const char **value); +OSYNC_EXPORT osync_bool osync_marshal_read_const_string(OSyncMarshal *marshal, const char **value, OSyncError **error); /** @brief Read serialized data from marshal buffer. This increments the read * position of the marshal buffer. Caller is responsible for freeing the duplicated @@ -184,8 +197,9 @@ * @param marshal The marshal object * @param value Reference to store the pointer to the newly allocated data * @param size Size of data + * @param error Pointer to a error-struct */ -OSYNC_EXPORT void osync_marshal_read_buffer(OSyncMarshal *marshal, void **value, unsigned int *size); +OSYNC_EXPORT osync_bool osync_marshal_read_buffer(OSyncMarshal *marshal, void **value, unsigned int *size, OSyncError **error); /*@}*/ Modified: trunk/opensync/common/opensync_marshal_internals.h ============================================================================== --- trunk/opensync/common/opensync_marshal_internals.h Thu Sep 17 16:39:20 2009 (r5779) +++ trunk/opensync/common/opensync_marshal_internals.h Thu Sep 17 18:36:52 2009 (r5780) @@ -40,8 +40,9 @@ * @param marshal The marshal object * @param value The data to append * @param size Size of corresponding data parameter + * @param error Pointer to a error-struct */ -OSYNC_TEST_EXPORT void osync_marshal_write_data(OSyncMarshal *marshal, const void *value, unsigned int size); +OSYNC_TEST_EXPORT osync_bool osync_marshal_write_data(OSyncMarshal *marshal, const void *value, unsigned int size, OSyncError **error); /** @brief Read specific size of serialized data from marshal buffer. This increments * the read position of the marshal buffer. Caller is responsible for freeing the @@ -50,8 +51,9 @@ * @param marshal The marshal object * @param value Reference to store the pointer to the newly allocated data * @param size Size of data + * @param error Pointer to a error-struct */ -OSYNC_TEST_EXPORT void osync_marshal_read_data(OSyncMarshal *marshal, void *value, unsigned int size); +OSYNC_TEST_EXPORT osync_bool osync_marshal_read_data(OSyncMarshal *marshal, void *value, unsigned int size, OSyncError **error); /*@}*/ Modified: trunk/opensync/engine/opensync_engine.c ============================================================================== --- trunk/opensync/engine/opensync_engine.c Thu Sep 17 16:39:20 2009 (r5779) +++ trunk/opensync/engine/opensync_engine.c Thu Sep 17 18:36:52 2009 (r5780) @@ -291,7 +291,10 @@ if (!marshal) goto error; - osync_marshal_write_data(marshal, entirebuf, entsize); + if (!osync_marshal_write_data(marshal, entirebuf, entsize, &error)) { + osync_marshal_unref(marshal); + goto error; + } if (!osync_objformat_demarshal(objformat, marshal, &entirebuf, &entsize, &error)) { osync_marshal_unref(marshal); Modified: trunk/opensync/engine/opensync_mapping_entry_engine.c ============================================================================== --- trunk/opensync/engine/opensync_mapping_entry_engine.c Thu Sep 17 16:39:20 2009 (r5779) +++ trunk/opensync/engine/opensync_mapping_entry_engine.c Thu Sep 17 18:36:52 2009 (r5780) @@ -180,7 +180,8 @@ if (!osync_objformat_marshal(objformat, buffer, size, marshal, error)) goto error_free_marshal; - osync_marshal_get_buffer(marshal, &marshalbuf, &marshalsize); + if (!osync_marshal_get_buffer(marshal, &marshalbuf, &marshalsize, error)) + goto error_free_marshal; if (marshalbuf == 0) { marshalbuf = buffer; Modified: trunk/opensync/ipc/opensync_message.c ============================================================================== --- trunk/opensync/ipc/opensync_message.c Thu Sep 17 16:39:20 2009 (r5779) +++ trunk/opensync/ipc/opensync_message.c Thu Sep 17 18:36:52 2009 (r5780) @@ -110,14 +110,14 @@ return osync_marshal_get_marshal_size(message->marshal); } -void osync_message_set_message_size(OSyncMessage *message, unsigned int size) +osync_bool osync_message_set_message_size(OSyncMessage *message, unsigned int size, OSyncError **error) { - osync_marshal_set_marshal_size(message->marshal, size); + return osync_marshal_set_marshal_size(message->marshal, size, error); } -void osync_message_get_buffer(OSyncMessage *message, char **data, unsigned int *size) +osync_bool osync_message_get_buffer(OSyncMessage *message, char **data, unsigned int *size, OSyncError **error) { - osync_marshal_get_buffer(message->marshal, data, size); + return osync_marshal_get_buffer(message->marshal, data, size, error); } void osync_message_set_handler(OSyncMessage *message, OSyncMessageHandler handler, void *user_data) @@ -152,35 +152,47 @@ { OSyncMessage *reply = osync_message_new(OSYNC_MESSAGE_ERRORREPLY, 0, loc_error); if (!reply) - return NULL; + goto error; - osync_marshal_error(reply, error); + if (!osync_marshal_error(reply, error, loc_error)) + goto error; if (message) reply->id = message->id; return reply; + +error: + return NULL; } OSyncMessage *osync_message_new_error(OSyncError *error, OSyncError **loc_error) { OSyncMessage *message = osync_message_new(OSYNC_MESSAGE_ERROR, 0, loc_error); if (!message) - return NULL; + goto error; - osync_marshal_error(message, error); + if (!osync_marshal_error(message, error, loc_error)) + goto error; return message; + +error: + return NULL; } OSyncMessage *osync_message_new_queue_error(OSyncError *error, OSyncError **loc_error) { OSyncMessage *message = osync_message_new(OSYNC_MESSAGE_QUEUE_ERROR, 0, loc_error); if (!message) - return NULL; + goto error; - osync_marshal_error(message, error); + if (!osync_marshal_error(message, error, loc_error)) + goto error; return message; + +error: + return NULL; } osync_bool osync_message_is_error(OSyncMessage *message) @@ -206,75 +218,75 @@ return message->cmd; } -void osync_message_write_int(OSyncMessage *message, int value) +osync_bool osync_message_write_int(OSyncMessage *message, int value, OSyncError **error) { - osync_marshal_write_int(message->marshal, value); + return osync_marshal_write_int(message->marshal, value, error); } -void osync_message_write_uint(OSyncMessage *message, unsigned int value) +osync_bool osync_message_write_uint(OSyncMessage *message, unsigned int value, OSyncError **error) { - osync_marshal_write_uint(message->marshal, value); + return osync_marshal_write_uint(message->marshal, value, error); } -void osync_message_write_long_long_int(OSyncMessage *message, long long int value) +osync_bool osync_message_write_long_long_int(OSyncMessage *message, long long int value, OSyncError **error) { - osync_marshal_write_long_long_int(message->marshal, value); + return osync_marshal_write_long_long_int(message->marshal, value, error); } -void osync_message_write_string(OSyncMessage *message, const char *value) +osync_bool osync_message_write_string(OSyncMessage *message, const char *value, OSyncError **error) { - osync_marshal_write_string(message->marshal, value); + return osync_marshal_write_string(message->marshal, value, error); } -void osync_message_write_data(OSyncMessage *message, const void *value, unsigned int size) +osync_bool osync_message_write_data(OSyncMessage *message, const void *value, unsigned int size, OSyncError **error) { - osync_marshal_write_data(message->marshal, value, size); + return osync_marshal_write_data(message->marshal, value, size, error); } -void osync_message_write_buffer(OSyncMessage *message, const void *value, unsigned int size) +osync_bool osync_message_write_buffer(OSyncMessage *message, const void *value, unsigned int size, OSyncError **error) { - osync_marshal_write_buffer(message->marshal, value, size); + return osync_marshal_write_buffer(message->marshal, value, size, error); } -void osync_message_read_int(OSyncMessage *message, int *value) +osync_bool osync_message_read_int(OSyncMessage *message, int *value, OSyncError **error) { - osync_marshal_read_int(message->marshal, value); + return osync_marshal_read_int(message->marshal, value, error); } -void osync_message_read_uint(OSyncMessage *message, unsigned int *value) +osync_bool osync_message_read_uint(OSyncMessage *message, unsigned int *value, OSyncError **error) { - osync_marshal_read_uint(message->marshal, value); + return osync_marshal_read_uint(message->marshal, value, error); } -void osync_message_read_long_long_int(OSyncMessage *message, long long int *value) +osync_bool osync_message_read_long_long_int(OSyncMessage *message, long long int *value, OSyncError **error) { - osync_marshal_read_long_long_int(message->marshal, value); + return osync_marshal_read_long_long_int(message->marshal, value, error); } /* TODO Change char** to const char ** */ -void osync_message_read_const_string(OSyncMessage *message, const char **value) +osync_bool osync_message_read_const_string(OSyncMessage *message, const char **value, OSyncError **error) { - osync_marshal_read_const_string(message->marshal, value); + return osync_marshal_read_const_string(message->marshal, value, error); } -void osync_message_read_string(OSyncMessage *message, char **value) +osync_bool osync_message_read_string(OSyncMessage *message, char **value, OSyncError **error) { - osync_marshal_read_string(message->marshal, value); + return osync_marshal_read_string(message->marshal, value, error); } -void osync_message_read_const_data(OSyncMessage *message, void **value, unsigned int size) +osync_bool osync_message_read_const_data(OSyncMessage *message, void **value, unsigned int size, OSyncError **error) { - osync_marshal_read_const_data(message->marshal, value, size); + return osync_marshal_read_const_data(message->marshal, value, size, error); } -void osync_message_read_data(OSyncMessage *message, void *value, unsigned int size) +osync_bool osync_message_read_data(OSyncMessage *message, void *value, unsigned int size, OSyncError **error) { - osync_marshal_read_data(message->marshal, value, size); + return osync_marshal_read_data(message->marshal, value, size, error); } -void osync_message_read_buffer(OSyncMessage *message, void **value, unsigned int *size) +osync_bool osync_message_read_buffer(OSyncMessage *message, void **value, unsigned int *size, OSyncError **error) { - osync_marshal_read_buffer(message->marshal, value, size); + return osync_marshal_read_buffer(message->marshal, value, size, error); } char* osync_message_get_commandstr(OSyncMessage *message) Modified: trunk/opensync/ipc/opensync_message_internals.h ============================================================================== --- trunk/opensync/ipc/opensync_message_internals.h Thu Sep 17 16:39:20 2009 (r5779) +++ trunk/opensync/ipc/opensync_message_internals.h Thu Sep 17 18:36:52 2009 (r5780) @@ -180,18 +180,20 @@ * * @param message The message * @param size The size of the message to set + * @param error Pointer to a error-struct * */ -OSYNC_TEST_EXPORT void osync_message_set_message_size(OSyncMessage *message, unsigned int size); +OSYNC_TEST_EXPORT osync_bool osync_message_set_message_size(OSyncMessage *message, unsigned int size, OSyncError **error); /** @brief Get the buffer/content of the message object * * @param message The message * @param data Pointer to data * @param size Size of the data + * @param error Pointer to a error-struct * */ -OSYNC_TEST_EXPORT void osync_message_get_buffer(OSyncMessage *message, char **data, unsigned int *size); +OSYNC_TEST_EXPORT osync_bool osync_message_get_buffer(OSyncMessage *message, char **data, unsigned int *size, OSyncError **error); /** @brief Set timeout (in seconds) for the message object * @@ -277,28 +279,28 @@ * @param message The message * @param value The integer value to append */ -OSYNC_TEST_EXPORT void osync_message_write_int(OSyncMessage *message, int value); +OSYNC_TEST_EXPORT osync_bool osync_message_write_int(OSyncMessage *message, int value, OSyncError **error); /** @brief Appends an unsigned integer value to serialized message buffer * * @param message The message * @param value The integer value to append */ -OSYNC_TEST_EXPORT void osync_message_write_uint(OSyncMessage *message, unsigned int value); +OSYNC_TEST_EXPORT osync_bool osync_message_write_uint(OSyncMessage *message, unsigned int value, OSyncError **error); /** @brief Appends a long long integer value to serialized message buffer * * @param message The message * @param value The long long integer value to append */ -OSYNC_TEST_EXPORT void osync_message_write_long_long_int(OSyncMessage *message, long long int value); +OSYNC_TEST_EXPORT osync_bool osync_message_write_long_long_int(OSyncMessage *message, long long int value, OSyncError **error); /** @brief Appends a string to serialized message buffer * * @param message The message * @param value The string to append */ -OSYNC_TEST_EXPORT void osync_message_write_string(OSyncMessage *message, const char *value); +OSYNC_TEST_EXPORT osync_bool osync_message_write_string(OSyncMessage *message, const char *value, OSyncError **error); /** @brief Appends data with a specific length to the serialized message buffer * @@ -309,7 +311,7 @@ * @param value The data to append * @param size Size of corresponding data parameter */ -OSYNC_TEST_EXPORT void osync_message_write_data(OSyncMessage *message, const void *value, unsigned int size); +OSYNC_TEST_EXPORT osync_bool osync_message_write_data(OSyncMessage *message, const void *value, unsigned int size, OSyncError **error); /** @brief Appends data with a specific length to the serialized message buffer, * plus the length of the data to determine the end. @@ -318,7 +320,7 @@ * @param value The data to append * @param size Size of corresponding data parameter */ -OSYNC_TEST_EXPORT void osync_message_write_buffer(OSyncMessage *message, const void *value, unsigned int size); +OSYNC_TEST_EXPORT osync_bool osync_message_write_buffer(OSyncMessage *message, const void *value, unsigned int size, OSyncError **error); /** @brief Read serialized integer from message buffer. This increments the read * position of the message buffer. @@ -326,7 +328,7 @@ * @param message The message * @param value Reference to store the integer value */ -OSYNC_TEST_EXPORT void osync_message_read_int(OSyncMessage *message, int *value); +OSYNC_TEST_EXPORT osync_bool osync_message_read_int(OSyncMessage *message, int *value, OSyncError **error); /** @brief Read serialized unsigned integer from message buffer. This increments the read * position of the message buffer. @@ -334,7 +336,7 @@ * @param message The message * @param value Reference to store the integer value */ -OSYNC_TEST_EXPORT void osync_message_read_uint(OSyncMessage *message, unsigned int *value); +OSYNC_TEST_EXPORT osync_bool osync_message_read_uint(OSyncMessage *message, unsigned int *value, OSyncError **error); /** @brief Read serialized long long integer from message buffer. This increments the read * position of the message buffer. @@ -342,7 +344,7 @@ * @param message The message * @param value Reference to store the long long integer value */ -OSYNC_TEST_EXPORT void osync_message_read_long_long_int(OSyncMessage *message, long long int *value); +OSYNC_TEST_EXPORT osync_bool osync_message_read_long_long_int(OSyncMessage *message, long long int *value, OSyncError **error); /** @brief Read serialized string from message buffer. This increments the read * position of the message buffer. Caller is responsible for freeing the duplicated @@ -351,7 +353,7 @@ * @param message The message * @param value Reference to store the pointer to the newly allocated string */ -OSYNC_TEST_EXPORT void osync_message_read_string(OSyncMessage *message, char **value); +OSYNC_TEST_EXPORT osync_bool osync_message_read_string(OSyncMessage *message, char **value, OSyncError **error); /** @brief Read specific size of serialized data from message buffer. This increments * the read position of the message buffer. Caller is responsible for freeing the @@ -361,7 +363,7 @@ * @param value Reference to store the pointer to the newly allocated data * @param size Size of data */ -OSYNC_TEST_EXPORT void osync_message_read_data(OSyncMessage *message, void *value, unsigned int size); +OSYNC_TEST_EXPORT osync_bool osync_message_read_data(OSyncMessage *message, void *value, unsigned int size, OSyncError **error); /** @brief Read serialized const data from message buffer. This increments the read * position of the message buffer. @@ -370,7 +372,7 @@ * @param value Reference to store the data pointer * @param size The size of data */ -OSYNC_TEST_EXPORT void osync_message_read_const_data(OSyncMessage *message, void **value, unsigned int size); +OSYNC_TEST_EXPORT osync_bool osync_message_read_const_data(OSyncMessage *message, void **value, unsigned int size, OSyncError **error); /** @brief Read serialized const string from message buffer. This increments the read * position of the message buffer. @@ -378,7 +380,7 @@ * @param message The message * @param value Reference to store the string pointer */ -OSYNC_TEST_EXPORT void osync_message_read_const_string(OSyncMessage *message, const char **value); +OSYNC_TEST_EXPORT osync_bool osync_message_read_const_string(OSyncMessage *message, const char **value, OSyncError **error); /** @brief Read serialized data from message buffer. This increments the read * position of the message buffer. Caller is responsible for freeing the duplicated @@ -388,7 +390,7 @@ * @param value Reference to store the pointer to the newly allocated data * @param size Size of data */ -OSYNC_TEST_EXPORT void osync_message_read_buffer(OSyncMessage *message, void **value, unsigned int *size); +OSYNC_TEST_EXPORT osync_bool osync_message_read_buffer(OSyncMessage *message, void **value, unsigned int *size, OSyncError **error); /*@}*/ Modified: trunk/opensync/ipc/opensync_queue.c ============================================================================== --- trunk/opensync/ipc/opensync_queue.c Thu Sep 17 16:39:20 2009 (r5779) +++ trunk/opensync/ipc/opensync_queue.c Thu Sep 17 18:36:52 2009 (r5780) @@ -521,7 +521,8 @@ if (!_osync_queue_write_int(queue, (int) osync_message_get_timeout(message), &error)) goto error; - osync_message_get_buffer(message, &data, &length); + if (!osync_message_get_buffer(message, &data, &length, &error)) + goto error; if (length) { unsigned int sent = 0; @@ -716,7 +717,9 @@ /* We now get the buffer from the message which will already * have the correct size for the read */ - osync_message_get_buffer(message, &buffer, NULL); + if (!osync_message_get_buffer(message, &buffer, NULL, &error)) + goto error_free_message; + if (size) { int read = 0; do { @@ -733,7 +736,9 @@ read += inc; } while (read < size); } - osync_message_set_message_size(message, size); + + if (!osync_message_set_message_size(message, size, &error)) + goto error_free_message; g_async_queue_push(queue->incoming, message); Modified: trunk/opensync/ipc/opensync_serializer.c ============================================================================== --- trunk/opensync/ipc/opensync_serializer.c Thu Sep 17 16:39:20 2009 (r5779) +++ trunk/opensync/ipc/opensync_serializer.c Thu Sep 17 18:36:52 2009 (r5780) @@ -53,14 +53,18 @@ objformat = osync_data_get_objformat(data); /* Write the format and objtype first */ - osync_message_write_string(message, osync_objformat_get_name(objformat)); - osync_message_write_string(message, osync_data_get_objtype(data)); + osync_message_write_string(message, osync_objformat_get_name(objformat), error); + osync_message_write_string(message, osync_data_get_objtype(data), error); + + if (osync_error_is_set(error)) + goto error; /* Now we get the pointer to the data */ osync_data_get_data(data, &input_data, &input_size); if (input_size > 0) { - osync_message_write_int(message, 1); + if (!osync_message_write_int(message, 1, error)) + goto error; /* If the format must be marshalled, we call the marshal function * and the send the marshalled data. Otherwise we send the unmarshalled data */ @@ -74,10 +78,12 @@ * be removed by the osync_demarshal_data funciton. */ input_size++; - osync_message_write_buffer(message, input_data, input_size); + if (!osync_message_write_buffer(message, input_data, input_size, error)) + goto error; } } else { - osync_message_write_int(message, 0); + if (!osync_message_write_int(message, 0, error)) + goto error; } return TRUE; @@ -106,8 +112,11 @@ * data */ /* Get the objtype and format */ - osync_message_read_string(message, &objformat); - osync_message_read_string(message, &objtype); + osync_message_read_string(message, &objformat, error); + osync_message_read_string(message, &objtype, error); + + if (osync_error_is_set(error)) + goto error; /* Search for the format */ format = osync_format_env_find_objformat(env, objformat); @@ -116,7 +125,8 @@ goto error; } - osync_message_read_int(message, &has_data); + if (!osync_message_read_int(message, &has_data, error)) + goto error; if (has_data) { if (osync_objformat_must_marshal(format) == TRUE) { @@ -124,7 +134,8 @@ if (!osync_objformat_demarshal(format, marshal, &input_data, &input_size, error)) goto error; } else { - osync_message_read_buffer(message, (void *)&input_data, &input_size); + if (!osync_message_read_buffer(message, (void *)&input_data, &input_size, error)) + goto error; /* If the format is a plain, then we have to remove * one from the input_size, since once one was added by @@ -165,9 +176,12 @@ * changetype * data */ - osync_message_write_string(message, osync_change_get_uid(change)); - osync_message_write_string(message, osync_change_get_hash(change)); - osync_message_write_int(message, osync_change_get_changetype(change)); + osync_message_write_string(message, osync_change_get_uid(change), error); + osync_message_write_string(message, osync_change_get_hash(change), error); + osync_message_write_int(message, osync_change_get_changetype(change), error); + + if (osync_error_is_set(error)) + goto error; data = osync_change_get_data(change); if (!osync_marshal_data(message, data, error)) @@ -200,9 +214,12 @@ if (!*change) goto error; - osync_message_read_string(message, &uid); - osync_message_read_string(message, &hash); - osync_message_read_int(message, &change_type); + osync_message_read_string(message, &uid, error); + osync_message_read_string(message, &hash, error); + osync_message_read_int(message, &change_type, error); + + if (osync_error_is_set(error)) + goto error; if (!osync_demarshal_data(message, &data, env, error)) goto error_free_change; @@ -238,10 +255,16 @@ const char *objformat_name = osync_objformat_sink_get_objformat(sink); const char *objformat_sink_config = osync_objformat_sink_get_config(sink); - osync_message_write_string(message, objformat_name); - osync_message_write_string(message, objformat_sink_config); + osync_message_write_string(message, objformat_name, error); + osync_message_write_string(message, objformat_sink_config, error); + + if (osync_error_is_set(error)) + goto error; return TRUE; + +error: + return FALSE; } osync_bool osync_demarshal_objformat_sink(OSyncMessage *message, OSyncObjFormatSink **sink, OSyncError **error) @@ -258,13 +281,16 @@ */ /* Get the objtype and format */ - osync_message_read_string(message, &objformat_name); + if (!osync_message_read_string(message, &objformat_name, error)) + goto error; *sink = osync_objformat_sink_new(objformat_name, error); if (!*sink) goto error; - osync_message_read_string(message, &objformat_sink_config); + if (!osync_message_read_string(message, &objformat_sink_config, error)) + goto error; + osync_objformat_sink_set_config(*sink, objformat_sink_config); osync_free(objformat_sink_config); @@ -303,14 +329,18 @@ */ num = osync_objtype_sink_num_objformat_sinks(sink); - osync_message_write_string(message, osync_objtype_sink_get_name(sink)); + osync_message_write_string(message, osync_objtype_sink_get_name(sink), error); + + osync_message_write_int(message, osync_objtype_sink_get_function_read(sink), error); + osync_message_write_int(message, osync_objtype_sink_get_function_getchanges(sink), error); - osync_message_wr... [truncated message content] |