From: <svn...@op...> - 2010-02-22 13:18:40
|
Author: bellmich Date: Mon Feb 22 14:03:00 2010 New Revision: 1357 URL: http://libsyncml.opensync.org/changeset/1357 Log: - disable features in the help message which are not supported - fixed returns and exit traces of scanArguments - usage exits with 0 if the usage message was explicitly requested - g_key_file_get_keys returns NULL if there is no key. This must be checked because NULL[0] is a segmentation fault. - g_key_file_get_string can only be called on an existing section. The section must be checked previously with g_key_file_has_group. Modified: trunk/tools/syncml-ds-tool.c Modified: trunk/tools/syncml-ds-tool.c ============================================================================== --- trunk/tools/syncml-ds-tool.c Mon Dec 7 15:06:07 2009 (r1356) +++ trunk/tools/syncml-ds-tool.c Mon Feb 22 14:03:00 2010 (r1357) @@ -271,7 +271,7 @@ /* *********** USAGE ****************** */ /* ************************************ */ -static void usage (char *name) +static void usage (char *name, gboolean isError) { fprintf(stderr, "Usage: %s\n\n", name); @@ -304,12 +304,15 @@ fprintf(stderr, "\t--ssl-cert <file>\n\n"); fprintf(stderr, "\t<port>\tmust be a port for the http server.\n\n"); +#ifdef ENABLE_OBEX fprintf(stderr, "\tOBEX client configuration:\n"); fprintf(stderr, "\t==========================\n\n"); fprintf(stderr, "\t-s <device>\tConnect to the serial device.\n"); fprintf(stderr, "\t-u\t\tList all available USB interfaces.\n"); fprintf(stderr, "\t-u <id>\t\tConnect to the given usb interface number.\n"); +#ifdef ENABLE_BLUETOOTH fprintf(stderr, "\t-b <addr> <channel>\tConnect to the given bluetooth device.\n"); +#endif fprintf(stderr, "\t--ip <addr> <port>\tConnect to this TCP/IP address.\n"); fprintf(stderr, "\t--irda\t\tConnect using IrDA.\n"); fprintf(stderr, "\t--irda-service <service>\tUse the given IrDA service (default: OBEX).\n\n"); @@ -317,6 +320,7 @@ fprintf(stderr, "\tOBEX server configuration:\n"); fprintf(stderr, "\t==========================\n\n"); fprintf(stderr, "\t--port <port>\tListen to this TCP/IP port.\n\n"); +#endif fprintf(stderr, "\tGeneral SyncML options:\n"); fprintf(stderr, "\t=======================\n\n"); @@ -351,7 +355,10 @@ fprintf(stderr, "\t--fake-software-version <SwV>\tset the software version of the faked device.\n"); fprintf(stderr, "\n"); - exit (1); + if (isError) + exit (1); + else + exit(0); } /* ************************************ */ @@ -459,7 +466,7 @@ { smlTrace(TRACE_ENTRY, "%s", __func__); if (argc == 1) - usage (argv[0]); + usage (argv[0], TRUE); maxMsgSize = g_strdup("65535"); maxObjSize = g_strdup("3000000"); @@ -493,7 +500,7 @@ i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); sml_data_sync_data_store_set_content_type(datastore->object, argv[i]); if (!strstr(argv[i], "/")) @@ -506,7 +513,7 @@ i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); sml_data_sync_data_store_set_local_uri(datastore->object, argv[i]); @@ -569,10 +576,12 @@ if (!argv[i]) { #ifdef ENABLE_OBEX list_interfaces(); - return 0; + smlTrace(TRACE_EXIT, "%s - OBEX list returned", __func__); + return FALSE; #else printf("OBEX not available in this build\n"); - return 1; + smlTrace(TRACE_EXIT_ERROR, "%s - OBEX list requested but not available", __func__); + return FALSE; #endif } if (!sml_data_sync_set_option( @@ -591,7 +600,7 @@ i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); if (!sml_data_sync_set_option( dsObject, SML_TRANSPORT_CONFIG_BLUETOOTH_ADDRESS, @@ -600,7 +609,7 @@ i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); if (!sml_data_sync_set_option( dsObject, SML_TRANSPORT_CONFIG_BLUETOOTH_CHANNEL, @@ -608,7 +617,8 @@ goto error; #else printf("Bluetooth is not available in this build\n"); - return 1; + smlTrace(TRACE_EXIT, "%s - Bluetooth requested but not available", __func__); + return FALSE; #endif } else if (!strcmp (arg, "--irda")) { if (!sml_data_sync_set_option( @@ -626,7 +636,7 @@ goto error; i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); if (!sml_data_sync_set_option( dsObject, SML_TRANSPORT_CONFIG_IRDA_SERVICE, @@ -642,7 +652,7 @@ i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); if (!sml_data_sync_set_option( dsObject, SML_TRANSPORT_CONFIG_URL, @@ -660,7 +670,7 @@ i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); if (!sml_data_sync_set_option( dsObject, SML_TRANSPORT_CONFIG_BLUETOOTH_CHANNEL, @@ -668,7 +678,8 @@ goto error; #else printf("Bluetooth is not available in this build\n"); - return 1; + smlTrace(TRACE_EXIT, "%s - Bluetooth requested but not available", __func__); + return FALSE; #endif } else if (!strcmp (arg, "--ip")) { if (!sml_data_sync_set_option( @@ -680,7 +691,7 @@ i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); if (!sml_data_sync_set_option( dsObject, SML_TRANSPORT_CONFIG_URL, @@ -689,7 +700,7 @@ i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); if (!sml_data_sync_set_option( dsObject, SML_TRANSPORT_CONFIG_PORT, @@ -705,7 +716,7 @@ i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); if (!sml_data_sync_set_option( dsObject, SML_TRANSPORT_CONFIG_PORT, @@ -714,7 +725,7 @@ } else if (!strcmp (arg, "--identifier")) { i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); if (!sml_data_sync_set_option( dsObject, SML_DATA_SYNC_CONFIG_IDENTIFIER, @@ -724,7 +735,7 @@ } else if (!strcmp (arg, "--target")) { i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); if (!sml_data_sync_set_option( dsObject, SML_DATA_SYNC_CONFIG_TARGET, @@ -734,7 +745,7 @@ } else if (!strcmp (arg, "--username")) { i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); if (!sml_data_sync_set_option( dsObject, SML_DATA_SYNC_CONFIG_AUTH_USERNAME, @@ -743,7 +754,7 @@ } else if (!strcmp (arg, "--password")) { i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); if (!sml_data_sync_set_option( dsObject, SML_DATA_SYNC_CONFIG_AUTH_PASSWORD, @@ -752,7 +763,7 @@ } else if (!strcmp (arg, "--maxMsgSize")) { i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); maxMsgSize = argv[i]; if (!sml_data_sync_set_option( dsObject, @@ -762,7 +773,7 @@ } else if (!strcmp (arg, "--maxObjSize")) { i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); maxObjSize = argv[i]; if (!sml_data_sync_set_option( dsObject, @@ -797,7 +808,8 @@ i++; if (!argv[i]) { fprintf(stdout, "Version: %s ($Revision$)\n", VERSION); - return 0; + smlTrace(TRACE_EXIT, "%s - Only the version was requested.", __func__); + return FALSE; } if (!sml_data_sync_set_option( @@ -807,7 +819,7 @@ goto error; syncmlVersion = g_strdup(argv[i]); } else if (!strcmp (arg, "--help")) { - usage (argv[0]); + usage (argv[0], FALSE); } else if (!strcmp (arg, "--wbxml")) { if (!sml_data_sync_set_option( dsObject, @@ -821,13 +833,13 @@ } else if (!strcmp (arg, "--remoteWinsConflicts")) { localWinsConflicts = FALSE; if (sessionType == SML_SESSION_TYPE_CLIENT) - usage(argv[0]); + usage(argv[0], TRUE); } else if (!strcmp(arg, "--read-only")) { readOnly = TRUE; } else if (!strcmp (arg, "--http-client")) { i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); if (!sml_data_sync_set_option( dsObject, SML_TRANSPORT_CONFIG_URL, @@ -836,7 +848,7 @@ } else if (!strcmp (arg, "--ssl-ca-certs")) { i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); if (!sml_data_sync_set_option( dsObject, SML_TRANSPORT_CONFIG_SSL_CA_FILE, @@ -845,7 +857,7 @@ } else if (!strcmp (arg, "--http-server")) { i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); if (!sml_data_sync_set_option( dsObject, SML_TRANSPORT_CONFIG_PORT, @@ -854,7 +866,7 @@ } else if (!strcmp (arg, "--ssl-key")) { i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); if (!sml_data_sync_set_option( dsObject, SML_TRANSPORT_CONFIG_SSL_KEY, @@ -863,7 +875,7 @@ } else if (!strcmp (arg, "--ssl-cert")) { i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); if (!sml_data_sync_set_option( dsObject, SML_TRANSPORT_CONFIG_SSL_SERVER_CERT, @@ -872,7 +884,7 @@ } else if (!strcmp (arg, "--fake-manufacturer")) { i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); if (!sml_data_sync_set_option( dsObject, SML_DATA_SYNC_CONFIG_FAKE_DEVICE, @@ -886,7 +898,7 @@ } else if (!strcmp (arg, "--fake-model")) { i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); if (!sml_data_sync_set_option( dsObject, SML_DATA_SYNC_CONFIG_FAKE_DEVICE, @@ -900,7 +912,7 @@ } else if (!strcmp (arg, "--fake-software-version")) { i++; if (!argv[i]) - usage (argv[0]); + usage (argv[0], TRUE); if (!sml_data_sync_set_option( dsObject, SML_DATA_SYNC_CONFIG_FAKE_DEVICE, @@ -915,7 +927,7 @@ break; } else { g_warning("Unknown parameter: %s", arg); - usage (argv[0]); + usage (argv[0], TRUE); } } @@ -933,7 +945,7 @@ error: smlTrace(TRACE_EXIT_ERROR, - "Failed to start the client: %s\n", + "%s - Failed to start the client: %s\n", (*error)->message); return FALSE; } @@ -944,6 +956,7 @@ static void writeSyncStatus(gboolean success) { + smlTrace(TRACE_ENTRY, "%s (%s)", __func__, success ? "TRUE" : "FALSE"); GError *error = NULL; SmlDsToolLocationType *datastore = NULL; GList *o = datastores; @@ -958,7 +971,7 @@ /* migrate all entries from committed_index to last_index */ char **keys = g_key_file_get_keys(datastore->index, "committed_index", NULL, NULL); int pos = 0; - while (keys[pos] != NULL) + while (keys != NULL && keys[pos] != NULL) { char *digest = g_key_file_get_string(datastore->index, "committed_index", keys[pos], &error); if (!digest && error) @@ -988,8 +1001,10 @@ smlSafeCFree(&absolute); } } + smlTrace(TRACE_EXIT, "%s"); return; error: + smlTrace(TRACE_EXIT_ERROR, "%s - %s", error->message); g_error("%s", error->message); } @@ -1049,7 +1064,9 @@ if (!digest) goto error; #endif - char *original = g_key_file_get_string(datastore->index, "last_index", filename, NULL); + char *original = NULL; + if (g_key_file_has_group(datastore->index, "last_index")) + original = g_key_file_get_string(datastore->index, "last_index", filename, NULL); /* fix indexes */ SmlChangeType changeType = SML_CHANGE_UNKNOWN; @@ -1125,9 +1142,12 @@ */ gsize count = 0; - char **keys = g_key_file_get_keys(datastore->index, "last_index", &count, error); - if (*error) - goto error; + char **keys = NULL; + if (g_key_file_has_group(datastore->index, "last_index")) { + keys = g_key_file_get_keys(datastore->index, "last_index", &count, error); + if (*error) + goto error; + } gsize i = 0; for (; !datastore->slow && i < count; i++) { @@ -1183,6 +1203,7 @@ g_message("ERROR: %s\n", error->message); writeSyncStatus(FALSE); // g_error_free(error); + smlTrace(TRACE_EXIT_ERROR, "%s - failed."); exit(2); break; case SML_DATA_SYNC_SESSION_EVENT_CONNECT: @@ -1312,7 +1333,8 @@ char *index_digest = NULL; char *item_digest = NULL; char *file_digest = NULL; - index_digest = g_key_file_get_string(datastore->index, "last_index", safeUID, NULL); + if (g_key_file_has_group(datastore->index, "last_index")) + index_digest = g_key_file_get_string(datastore->index, "last_index", safeUID, NULL); const char *data = sml_data_sync_change_item_get_data(item); if (data) { @@ -1884,6 +1906,7 @@ } /* close the object */ g_object_unref(dsObject); + g_message("syncml-ds-tool succeeded."); return 0; error: @@ -1891,5 +1914,6 @@ fprintf(stderr, "ERROR: %s\n", error->message); g_error_free(error); } + g_message("syncml-ds-tool failed."); return 1; } |