From ce67cf04564fa94bb5d6e8bc0dd3ee3b97e95e92 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 1 Nov 2008 01:29:12 +0100 Subject: Install additional libutil headers. --- lib/util/config.mk | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/util') diff --git a/lib/util/config.mk b/lib/util/config.mk index 61e193b0c4..22f22b5771 100644 --- a/lib/util/config.mk +++ b/lib/util/config.mk @@ -34,10 +34,12 @@ PUBLIC_HEADERS += $(addprefix $(libutilsrcdir)/, util.h \ byteorder.h \ data_blob.h \ debug.h \ + memory.h \ mutex.h \ safe_string.h \ time.h \ util_ldb.h \ + talloc_stack.h \ xfile.h) [SUBSYSTEM::ASN1_UTIL] -- cgit From 9de80e7abceb3c64c658f2aeeb5ca68e980e89c8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 1 Nov 2008 03:14:43 +0100 Subject: Samba3: Include util.h header file rather than having custom prototypes. --- lib/util/util.h | 30 +++++++++++++++++++++++------- lib/util/util_ldb.h | 2 ++ 2 files changed, 25 insertions(+), 7 deletions(-) (limited to 'lib/util') diff --git a/lib/util/util.h b/lib/util/util.h index 6a341b218d..bfd09ba20b 100644 --- a/lib/util/util.h +++ b/lib/util/util.h @@ -49,13 +49,22 @@ extern const char *panic_action; /** * assert macros */ +#ifdef DEVELOPER #define SMB_ASSERT(b) do { if (!(b)) { \ - DEBUG(0,("PANIC: assert failed at %s(%d)\n", __FILE__, __LINE__)); \ - smb_panic("assert failed"); }} while (0) + DEBUG(0,("PANIC: assert failed at %s(%d): %s\n", \ + __FILE__, __LINE__, #b)), smb_panic("assert failed: " #b); }} while(0) +#else +/* redefine the assert macro for non-developer builds */ +#define SMB_ASSERT(b) do { if (!(b)) { \ + DEBUG(0,("PANIC: assert failed at %s(%d): %s\n", \ + __FILE__, __LINE__, #b)); }} while (0) +#endif +#if _SAMBA_BUILD_ == 4 #if defined(VALGRIND) #define strlen(x) valgrind_strlen(x) #endif +#endif #include "../lib/util/memory.h" @@ -69,10 +78,12 @@ _PUBLIC_ void call_backtrace(void); **/ _PUBLIC_ _NORETURN_ void smb_panic(const char *why); +#if _SAMBA_BUILD_ == 4 /** setup our fault handlers **/ _PUBLIC_ void fault_setup(const char *pname); +#endif /** register a fault handler. @@ -168,12 +179,14 @@ _PUBLIC_ char *generate_random_str_list(TALLOC_CTX *mem_ctx, size_t len, const c _PUBLIC_ char *generate_random_str(TALLOC_CTX *mem_ctx, size_t len); /* The following definitions come from lib/util/dprintf.c */ +#if _SAMBA_BUILD_ == 4 _PUBLIC_ void d_set_iconv(smb_iconv_t); _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0); _PUBLIC_ int d_fprintf(FILE *f, const char *format, ...) PRINTF_ATTRIBUTE(2,3); _PUBLIC_ int d_printf(const char *format, ...) PRINTF_ATTRIBUTE(1,2); _PUBLIC_ void display_set_stderr(void); +#endif /* The following definitions come from lib/util/util_str.c */ @@ -285,11 +298,6 @@ limited by 'n' bytes **/ _PUBLIC_ size_t ascii_len_n(const char *src, size_t n); -/** - Return a string representing a CIFS attribute for a file. -**/ -_PUBLIC_ char *attrib_string(TALLOC_CTX *mem_ctx, uint32_t attrib); - /** Set a boolean variable from the text value stored in the passed string. Returns true in success, false if the passed string does not correctly @@ -306,10 +314,12 @@ _PUBLIC_ bool set_boolean(const char *boolean_string, bool *boolean); */ _PUBLIC_ bool conv_str_bool(const char * str, bool * val); +#if _SAMBA_BUILD_ == 4 /** * Convert a size specification like 16K into an integral number of bytes. **/ _PUBLIC_ bool conv_str_size(const char * str, uint64_t * val); +#endif /** * Parse a uint64_t value from a string @@ -354,7 +364,9 @@ _PUBLIC_ bool strequal(const char *s1, const char *s2); /* The following definitions come from lib/util/util_strlist.c */ /* separators for lists */ +#ifndef LIST_SEP #define LIST_SEP " \t,\n\r" +#endif /** build a null terminated list of strings from a input string and a @@ -642,6 +654,7 @@ _PUBLIC_ int sys_fsusage(const char *path, uint64_t *dfree, uint64_t *dsize); * @brief MS-style Filename matching */ +#if _SAMBA_BUILD_ == 4 /* protocol types. It assumes that higher protocols include lower protocols as subsets. FIXME: Move to one of the smb-specific headers */ enum protocol_types { @@ -658,6 +671,7 @@ int ms_fnmatch(const char *pattern, const char *string, enum protocol_types prot /** a generic fnmatch function - uses for non-CIFS pattern matching */ int gen_fnmatch(const char *pattern, const char *string); +#endif /* The following definitions come from lib/util/mutex.c */ @@ -707,10 +721,12 @@ _PUBLIC_ int idr_remove(struct idr_context *idp, int id); /* The following definitions come from lib/util/become_daemon.c */ +#if _SAMBA_BUILD_ == 4 /** Become a daemon, discarding the controlling terminal. **/ _PUBLIC_ void become_daemon(bool fork); +#endif /** * Load a ini-style file. diff --git a/lib/util/util_ldb.h b/lib/util/util_ldb.h index 43f98ae1a9..f9eb028916 100644 --- a/lib/util/util_ldb.h +++ b/lib/util/util_ldb.h @@ -1,6 +1,8 @@ #ifndef __LIB_UTIL_UTIL_LDB_H__ #define __LIB_UTIL_UTIL_LDB_H__ +struct ldb_dn; + /* The following definitions come from lib/util/util_ldb.c */ int gendb_search_v(struct ldb_context *ldb, -- cgit From dfc78b1dc2738264791e631c599d75e832aebde2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 1 Nov 2008 03:27:41 +0100 Subject: Only provide valgrind_strlen prototype when it's being compiled in. --- lib/util/util.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/util') diff --git a/lib/util/util.h b/lib/util/util.h index bfd09ba20b..66861fba8b 100644 --- a/lib/util/util.h +++ b/lib/util/util.h @@ -61,8 +61,9 @@ extern const char *panic_action; #endif #if _SAMBA_BUILD_ == 4 -#if defined(VALGRIND) +#ifdef VALGRIND #define strlen(x) valgrind_strlen(x) +size_t valgrind_strlen(const char *s); #endif #endif @@ -269,7 +270,6 @@ _PUBLIC_ void all_string_sub(char *s,const char *pattern,const char *insert, siz Unescape a URL encoded string, in place. **/ _PUBLIC_ void rfc1738_unescape(char *buf); -size_t valgrind_strlen(const char *s); /** format a string into length-prefixed dotted domain format, as used in NBT -- cgit From d880faae92eb8b90b3c52b00bb0c163bc84511df Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 1 Nov 2008 15:13:00 +0100 Subject: Fix includes in installed version of talloc_stack.h. --- lib/util/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/util') diff --git a/lib/util/util.h b/lib/util/util.h index 66861fba8b..0f09747a3a 100644 --- a/lib/util/util.h +++ b/lib/util/util.h @@ -52,7 +52,7 @@ extern const char *panic_action; #ifdef DEVELOPER #define SMB_ASSERT(b) do { if (!(b)) { \ DEBUG(0,("PANIC: assert failed at %s(%d): %s\n", \ - __FILE__, __LINE__, #b)), smb_panic("assert failed: " #b); }} while(0) + __FILE__, __LINE__, #b)); smb_panic("assert failed: " #b); }} while(0) #else /* redefine the assert macro for non-developer builds */ #define SMB_ASSERT(b) do { if (!(b)) { \ -- cgit From 1b05be10399a8fab80072e7aaccd55a3f6e8f651 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 1 Nov 2008 15:21:31 +0100 Subject: ALlow util/debug.h to be included more than once. --- lib/util/debug.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/util') diff --git a/lib/util/debug.h b/lib/util/debug.h index 8c634f910a..632c24fadb 100644 --- a/lib/util/debug.h +++ b/lib/util/debug.h @@ -17,6 +17,9 @@ along with this program. If not, see . */ +#ifndef _SAMBA_DEBUG_H_ +#define _SAMBA_DEBUG_H_ + /** * @file * @brief Debugging macros @@ -131,3 +134,5 @@ _PUBLIC_ void register_debug_handlers(const char *name, struct debug_ops *ops); _PUBLIC_ void dbgtext(const char *format, ...) PRINTF_ATTRIBUTE(1,2); extern XFILE *dbf; + +#endif -- cgit From e5081d6dad3924ac0a816878a6af5266f87bbfb7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 1 Nov 2008 20:44:12 +0100 Subject: Move ABS() to libutil. --- lib/util/util.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/util') diff --git a/lib/util/util.h b/lib/util/util.h index 0f09747a3a..ec1cfef110 100644 --- a/lib/util/util.h +++ b/lib/util/util.h @@ -67,6 +67,10 @@ size_t valgrind_strlen(const char *s); #endif #endif +#ifndef ABS +#define ABS(a) ((a)>0?(a):(-(a))) +#endif + #include "../lib/util/memory.h" /** -- cgit From fa7bb8ac533e69c3f66541dedbb3e9708e15fa3e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 1 Nov 2008 20:56:27 +0100 Subject: Remove convert_string_talloc_descriptor, add iconv_talloc(). --- lib/util/charset/charcnv.c | 130 +++++++++++++++++++++++++-------------------- lib/util/charset/charset.h | 6 ++- 2 files changed, 77 insertions(+), 59 deletions(-) (limited to 'lib/util') diff --git a/lib/util/charset/charcnv.c b/lib/util/charset/charcnv.c index 9dd68f05ea..1f3b1ac846 100644 --- a/lib/util/charset/charcnv.c +++ b/lib/util/charset/charcnv.c @@ -155,71 +155,21 @@ static smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic, return ic->conv_handles[from][to]; } - /** * Convert string from one encoding to another, making error checking etc * + * @param mem_ctx Memory context + * @param cd Iconv handle * @param src pointer to source string (multibyte or singlebyte) * @param srclen length of the source string in bytes * @param dest pointer to destination string (multibyte or singlebyte) * @param destlen maximal length allowed for string * @returns the number of bytes occupied in the destination **/ -_PUBLIC_ ssize_t convert_string_convenience(struct smb_iconv_convenience *ic, - charset_t from, charset_t to, - void const *src, size_t srclen, - void *dest, size_t destlen) -{ - size_t i_len, o_len; - size_t retval; - const char* inbuf = (const char*)src; - char* outbuf = (char*)dest; - smb_iconv_t descriptor; - - if (srclen == (size_t)-1) - srclen = strlen(inbuf)+1; - - descriptor = get_conv_handle(ic, from, to); - - if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { - /* conversion not supported, use as is */ - size_t len = MIN(srclen,destlen); - memcpy(dest,src,len); - return len; - } - - i_len=srclen; - o_len=destlen; - retval = smb_iconv(descriptor, &inbuf, &i_len, &outbuf, &o_len); - if(retval==(size_t)-1) { - const char *reason; - switch(errno) { - case EINVAL: - reason="Incomplete multibyte sequence"; - return -1; - case E2BIG: - reason="No more room"; - if (from == CH_UNIX) { - DEBUG(0,("E2BIG: convert_string(%s,%s): srclen=%d destlen=%d - '%s'\n", - charset_name(ic, from), charset_name(ic, to), - (int)srclen, (int)destlen, - (const char *)src)); - } else { - DEBUG(0,("E2BIG: convert_string(%s,%s): srclen=%d destlen=%d\n", - charset_name(ic, from), charset_name(ic, to), - (int)srclen, (int)destlen)); - } - return -1; - case EILSEQ: - reason="Illegal multibyte sequence"; - return -1; - } - /* smb_panic(reason); */ - } - return destlen-o_len; -} - -_PUBLIC_ ssize_t convert_string_talloc_descriptor(TALLOC_CTX *ctx, smb_iconv_t descriptor, void const *src, size_t srclen, void **dest) +_PUBLIC_ ssize_t iconv_talloc(TALLOC_CTX *ctx, + smb_iconv_t cd, + void const *src, size_t srclen, + void **dest) { size_t i_len, o_len, destlen; size_t retval; @@ -247,7 +197,7 @@ convert: end */ i_len = srclen; o_len = destlen-2; - retval = smb_iconv(descriptor, + retval = smb_iconv(cd, &inbuf, &i_len, &outbuf, &o_len); if(retval == (size_t)-1) { @@ -275,8 +225,72 @@ convert: *dest = ob; return destlen; + } +/** + * Convert string from one encoding to another, making error checking etc + * + * @param src pointer to source string (multibyte or singlebyte) + * @param srclen length of the source string in bytes + * @param dest pointer to destination string (multibyte or singlebyte) + * @param destlen maximal length allowed for string + * @returns the number of bytes occupied in the destination + **/ +_PUBLIC_ ssize_t convert_string_convenience(struct smb_iconv_convenience *ic, + charset_t from, charset_t to, + void const *src, size_t srclen, + void *dest, size_t destlen) +{ + size_t i_len, o_len; + size_t retval; + const char* inbuf = (const char*)src; + char* outbuf = (char*)dest; + smb_iconv_t descriptor; + + if (srclen == (size_t)-1) + srclen = strlen(inbuf)+1; + + descriptor = get_conv_handle(ic, from, to); + + if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { + /* conversion not supported, use as is */ + size_t len = MIN(srclen,destlen); + memcpy(dest,src,len); + return len; + } + + i_len=srclen; + o_len=destlen; + retval = smb_iconv(descriptor, &inbuf, &i_len, &outbuf, &o_len); + if(retval==(size_t)-1) { + const char *reason; + switch(errno) { + case EINVAL: + reason="Incomplete multibyte sequence"; + return -1; + case E2BIG: + reason="No more room"; + if (from == CH_UNIX) { + DEBUG(0,("E2BIG: convert_string(%s,%s): srclen=%d destlen=%d - '%s'\n", + charset_name(ic, from), charset_name(ic, to), + (int)srclen, (int)destlen, + (const char *)src)); + } else { + DEBUG(0,("E2BIG: convert_string(%s,%s): srclen=%d destlen=%d\n", + charset_name(ic, from), charset_name(ic, to), + (int)srclen, (int)destlen)); + } + return -1; + case EILSEQ: + reason="Illegal multibyte sequence"; + return -1; + } + /* smb_panic(reason); */ + } + return destlen-o_len; +} + /** * Convert between character sets, allocating a new buffer using talloc for the result. * @@ -310,7 +324,7 @@ _PUBLIC_ ssize_t convert_string_talloc_convenience(TALLOC_CTX *ctx, return -1; } - return convert_string_talloc_descriptor(ctx, descriptor, src, srclen, dest); + return iconv_talloc(ctx, descriptor, src, srclen, dest); } /* diff --git a/lib/util/charset/charset.h b/lib/util/charset/charset.h index cace79f949..b69bef2d61 100644 --- a/lib/util/charset/charset.h +++ b/lib/util/charset/charset.h @@ -122,6 +122,11 @@ ssize_t convert_string(charset_t from, charset_t to, void const *src, size_t srclen, void *dest, size_t destlen); +ssize_t iconv_talloc(TALLOC_CTX *mem_ctx, + smb_iconv_t cd, + void const *src, size_t srclen, + void **dest); + extern struct smb_iconv_convenience *global_iconv_convenience; codepoint_t next_codepoint(const char *str, size_t *size); @@ -145,7 +150,6 @@ ssize_t convert_string_convenience(struct smb_iconv_convenience *ic, charset_t from, charset_t to, void const *src, size_t srclen, void *dest, size_t destlen); -ssize_t convert_string_talloc_descriptor(TALLOC_CTX *ctx, smb_iconv_t descriptor, void const *src, size_t srclen, void **dest); ssize_t convert_string_talloc_convenience(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, charset_t from, charset_t to, -- cgit From 57a60f0920e77e26a3ce7f5d43540904ee4cbd8e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 1 Nov 2008 22:13:47 +0100 Subject: Move lp_*() calls a bit higher up the calls tack. --- lib/util/dprintf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/util') diff --git a/lib/util/dprintf.c b/lib/util/dprintf.c index e4f02758eb..3e6d0e8bca 100644 --- a/lib/util/dprintf.c +++ b/lib/util/dprintf.c @@ -60,7 +60,7 @@ _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) if (ret <= 0) return ret; - clen = convert_string_talloc_descriptor(NULL, display_cd, p, ret, (void **)&p2); + clen = iconv_talloc(NULL, display_cd, p, ret, (void **)&p2); if (clen == -1) { /* the string can't be converted - do the best we can, filling in non-printing chars with '?' */ -- cgit From 29177203e5da4cb42e0c5bc2f2981d6cffbe042c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 2 Nov 2008 04:50:32 +0100 Subject: Rename class to "cls" since the first is a keyword name in C++. Thanks, Brad. --- lib/util/debug.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/util') diff --git a/lib/util/debug.h b/lib/util/debug.h index 632c24fadb..a5962b04bb 100644 --- a/lib/util/debug.h +++ b/lib/util/debug.h @@ -83,7 +83,7 @@ enum debug_logtype {DEBUG_STDOUT = 0, DEBUG_FILE = 1, DEBUG_STDERR = 2}; */ _PUBLIC_ void dbghdr(int level, const char *location, const char *func); -_PUBLIC_ void dbghdrclass(int level, int class, const char *location, const char *func); +_PUBLIC_ void dbghdrclass(int level, int cls, const char *location, const char *func); /** reopen the log file (usually called because the log file name might have changed) -- cgit