Author: derrell Date: 2005-12-29 16:24:25 +0000 (Thu, 29 Dec 2005) New Revision: 12575
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=12575 Log: [EMAIL PROTECTED]: derrell | 2005-12-29 11:16:29 -0500 bug (enhancement) #2651: add option to log debug messages to stderr instead of stdout Modified: trunk/ trunk/examples/libsmbclient/testbrowse.c trunk/source/include/libsmb_internal.h trunk/source/libsmb/libsmbclient.c Changeset: Property changes on: trunk ___________________________________________________________________ Name: svk:merge - 3a72dc49-98ff-0310-ab52-9b7ed7945d91:/local/samba-trunk:12087 + 3a72dc49-98ff-0310-ab52-9b7ed7945d91:/local/samba-trunk:12116 Modified: trunk/examples/libsmbclient/testbrowse.c =================================================================== --- trunk/examples/libsmbclient/testbrowse.c 2005-12-29 16:04:34 UTC (rev 12574) +++ trunk/examples/libsmbclient/testbrowse.c 2005-12-29 16:24:25 UTC (rev 12575) @@ -29,6 +29,7 @@ main(int argc, char * argv[]) { int debug = 0; + int debug_stderr = 0; int scan = 0; int iterations = -1; int again; @@ -37,6 +38,7 @@ char * q; char buf[1024]; poptContext pc; + SMBCCTX * context; struct poptOption long_options[] = { POPT_AUTOHELP @@ -45,6 +47,10 @@ 0, "Set debug level", "integer" }, { + "stderr", 'e', POPT_ARG_NONE, &debug_stderr, + 0, "Debug log to stderr instead of stdout", "integer" + }, + { "scan", 's', POPT_ARG_NONE, &scan, 0, "Scan for servers and shares", "integer" }, @@ -69,14 +75,36 @@ } } + /* Allocate a new context */ + context = smbc_new_context(); + if (!context) { + printf("Could not allocate new smbc context\n"); + return 1; + } + + /* Set mandatory options (is that a contradiction in terms?) */ + context->debug = debug; + context->callbacks.auth_fn = (scan ? no_auth_data_fn : get_auth_data_fn); + + /* If we've been asked to log to stderr instead of stdout... */ + if (debug_stderr) { + /* ... then set the option to do so */ + smbc_option_set(context, "debug_stderr", NULL); + } + + /* Initialize the context using the previously specified options */ + if (!smbc_init_context(context)) { + smbc_free_context(context, 0); + printf("Could not initialize smbc context\n"); + return 1; + } + + /* Tell the compatibility layer to use this context */ + smbc_set_context(context); + + if (scan) { - if (smbc_init(no_auth_data_fn, debug) != 0) - { - printf("Could not initialize smbc_ library\n"); - return 1; - } - for (; iterations == -1 || iterations > 0; iterations = (iterations == -1 ? iterations : --iterations)) @@ -87,12 +115,6 @@ } else { - if (smbc_init(get_auth_data_fn, debug) != 0) - { - printf("Could not initialize smbc_ library\n"); - return 1; - } - for (; iterations == -1 || iterations > 0; iterations = (iterations == -1 ? iterations : --iterations)) Modified: trunk/source/include/libsmb_internal.h =================================================================== --- trunk/source/include/libsmb_internal.h 2005-12-29 16:04:34 UTC (rev 12574) +++ trunk/source/include/libsmb_internal.h 2005-12-29 16:24:25 UTC (rev 12575) @@ -47,11 +47,12 @@ struct smbc_internal_data { - /** INTERNAL: is this handle initialized ? + /* + * Is this handle initialized ? */ - int _initialized; + BOOL _initialized; - /** INTERNAL: dirent pointer location + /* dirent pointer location * * Leave room for any urlencoded filename and the comment field. * @@ -64,13 +65,20 @@ */ char _dirent[1024]; - /** INTERNAL: server connection list + /* + * server connection list */ SMBCSRV * _servers; - /** INTERNAL: open file/dir list + /* + * open file/dir list */ SMBCFILE * _files; + + /* + * Log to standard error instead of the more typical standard output + */ + BOOL _debug_stderr; }; Modified: trunk/source/libsmb/libsmbclient.c =================================================================== --- trunk/source/libsmb/libsmbclient.c 2005-12-29 16:04:34 UTC (rev 12574) +++ trunk/source/libsmb/libsmbclient.c 2005-12-29 16:24:25 UTC (rev 12575) @@ -5938,6 +5938,27 @@ /* + * Each time the context structure is changed, we have binary backward + * compatibility issues. Instead of modifying the public portions of the + * context structure to add new options, instead, we put them in the internal + * portion of the context structure and provide a set function for these new + * options. + */ +void +smbc_option_set(SMBCCTX *context, + char *option_name, + void *option_value) +{ + if (strcmp(option_name, "debug_stderr") == 0) { + /* + * Log to standard error instead of standard output. + */ + context->internal->_debug_stderr = True; + } +} + + +/* * Initialise the library etc * * We accept a struct containing handle information. @@ -5984,6 +6005,12 @@ load_case_tables(); setup_logging( "libsmbclient", True); + setup_logging("libsmbclient", True); + if (context->internal->_debug_stderr) { + dbf = x_stderr; + x_setbuf(x_stderr, NULL); + } + /* Here we would open the smb.conf file if needed ... */ in_client = True; /* FIXME, make a param */ @@ -6099,7 +6126,7 @@ * FIXME: Should we check the function pointers here? */ - context->internal->_initialized = 1; + context->internal->_initialized = True; return context; }