On Tue, Dec 1, 2009 at 11:15 AM, Iain Hibbert <[email protected]> wrote:
> On Tue, 1 Dec 2009, Matthias Drochner wrote:
>
>>  iconv_open(3), this is more robust than trying to interpret
>>  the locale string
>
> btw nl_langinfo(3) is defined to always return a valid pointer, so the
>
>        if (locale == NULL)
>                return (-1);
>
> is not required..
>
> also, the locale variable can be private to obexapp_util_locale_init() as
> it is not used elsewhere

ok, so, combined patch would look something like the attached.

could you please give it a try and see if it still works?

thanks,
max
Index: Makefile
===================================================================
RCS file: /usr/local/cvs/ports/obexapp/Makefile,v
retrieving revision 1.11
diff -u -r1.11 Makefile
--- Makefile    23 Apr 2007 18:29:18 -0000      1.11
+++ Makefile    1 Dec 2009 20:00:19 -0000
@@ -14,8 +14,7 @@
 DEBUG_FLAGS=   -g
 
 CFLAGS+=       -I/usr/local/include \
-               -I/usr/local/include/openobex \
-               -fno-strict-aliasing
+               -I/usr/local/include/openobex
 
 DPADD=         ${LIBBLUETOOTH} ${LIBSDP} ${LIBBSDXML} ${LIBREADLINE}
 LDADD=         -L/usr/lib -L/usr/local/lib \
Index: client.c
===================================================================
RCS file: /usr/local/cvs/ports/obexapp/client.c,v
retrieving revision 1.18
diff -u -r1.18 client.c
--- client.c    9 Apr 2009 23:16:31 -0000       1.18
+++ client.c    1 Dec 2009 19:40:32 -0000
@@ -1219,9 +1219,8 @@
                int obex_rsp)
 {
        context_p                context = (context_p) OBEX_GetUserData(handle);
-       obex_connect_hdr_t      *hdr = NULL;
        obex_headerdata_t        hv;
-       uint8_t                  hi;
+       uint8_t                  hi, *data = NULL;
        uint32_t                 hlen;
 
        log_debug("%s(): Connect completed, response %#x", __func__, obex_rsp);
@@ -1232,10 +1231,12 @@
        if (obex_rsp != OBEX_RSP_SUCCESS)
                return (obex_rsp);
 
-       if (OBEX_ObjectGetNonHdrData(object, (uint8_t **) &hdr) == sizeof(*hdr))
+       if (OBEX_ObjectGetNonHdrData(object, &data) == 
sizeof(obex_connect_hdr_t))
                log_debug("%s(): OBEX connect header: " \
-                       "version=%#x, flags=%#x, mtu=%d", __func__, 
-                       hdr->version, hdr->flags, ntohs(hdr->mtu));
+                       "version=%#x, flags=%#x, mtu=%d", __func__,
+                       ((obex_connect_hdr_t *) data)->version,
+                       ((obex_connect_hdr_t *) data)->flags,
+                       ntohs(((obex_connect_hdr_t *) data)->mtu));
        else
                log_err("%s(): Invalid OBEX connect header?!", __func__);
 
Index: server.c
===================================================================
RCS file: /usr/local/cvs/ports/obexapp/server.c,v
retrieving revision 1.12
diff -u -r1.12 server.c
--- server.c    20 Aug 2009 21:57:18 -0000      1.12
+++ server.c    1 Dec 2009 20:04:33 -0000
@@ -471,19 +471,20 @@
 obexapp_server_request_connect(obex_t *handle, obex_object_t *object,
                __unused int obex_rsp)
 {
-       obex_connect_hdr_t      *hdr = NULL;
        obex_headerdata_t        hv;
-       uint8_t                  hi;
+       uint8_t                  hi, *data = NULL;
        uint32_t                 hlen;
        uint8_t const           *target = NULL;
        int                      target_len = 0;
 
        log_debug("%s()", __func__);
 
-       if (OBEX_ObjectGetNonHdrData(object, (uint8_t **) &hdr) == sizeof(*hdr))
+       if (OBEX_ObjectGetNonHdrData(object, &data) == 
sizeof(obex_connect_hdr_t))
                log_debug("%s(): OBEX connect header: version=%#x, " \
-                       "flags=%#x, mtu=%d", __func__, hdr->version, hdr->flags,
-                       ntohs(hdr->mtu));
+                       "flags=%#x, mtu=%d", __func__,
+                       ((obex_connect_hdr_t *) data)->version,
+                       ((obex_connect_hdr_t *) data)->flags,
+                       ntohs(((obex_connect_hdr_t *) data)->mtu));
        else
                log_err("%s(): Invalid OBEX connect header?!", __func__);
 
@@ -1086,9 +1087,8 @@
                __unused int obex_rsp)
 {
        context_p                context = (context_p) OBEX_GetUserData(handle);
-       obex_setpath_hdr_t      *hdr = NULL;
        obex_headerdata_t        hv;
-       uint8_t                  hi;
+       uint8_t                  hi, flags = 0xff, *data = NULL;
        uint32_t                 hlen;
        int                      got_name = 0;
 
@@ -1096,10 +1096,12 @@
 
        context->file[0] = '\0';
 
-       if (OBEX_ObjectGetNonHdrData(object, (uint8_t **) &hdr) == sizeof(*hdr))
-                log_debug("%s(): OBEX setpath header: flags=%#x, constants=%d",
-                       __func__, hdr->flags, hdr->constants);
-       else
+       if (OBEX_ObjectGetNonHdrData(object, &data) == 
sizeof(obex_setpath_hdr_t)) {
+               flags = ((obex_setpath_hdr_t *) data)->flags;
+
+               log_debug("%s(): OBEX setpath header: flags=%#x, constants=%d",
+                       __func__, flags, ((obex_setpath_hdr_t *) 
data)->constants);
+       } else
                log_err("%s(): Invalid OBEX setpath header?!", __func__);
 
        while (OBEX_ObjectGetNextHeader(handle, object, &hi, &hv, &hlen)) {
@@ -1151,9 +1153,9 @@
                 * directory) means "cd ..". Everything else is forbidden.
                 */
        
-               if (hdr->flags != 0x3) {
+               if (flags != 0x3) {
                        log_err("%s(): Invalid flags for 'cd ..', flags=%#x",
-                               __func__, hdr->flags);
+                               __func__, flags);
                                
                        return (OBEXAPP_PACK_RSP_CODES(OBEX_RSP_FORBIDDEN,
                                                        OBEX_RSP_FORBIDDEN));
@@ -1169,9 +1171,9 @@
                 * 'cd /'. Everything else is forbidden
                 */
 
-               if (hdr->flags != 0x2) {
+               if (flags != 0x2) {
                        log_err("%s(): Invalid flags for 'cd /', flags=%#x",
-                               __func__, hdr->flags);
+                               __func__, flags);
                                
                        return (OBEXAPP_PACK_RSP_CODES(OBEX_RSP_FORBIDDEN,
                                                        OBEX_RSP_FORBIDDEN));
@@ -1180,7 +1182,7 @@
                strlcpy(context->file, context->root, PATH_MAX);
        }
 
-       if (hdr->flags == 0) {
+       if (flags == 0) {
                if (mkdir(context->file, 0755) < 0 && errno != EEXIST) {
                        log_err("%s(): mkdir(%s) failed. %s (%d)",
                                __func__, context->file, 
Index: util.c
===================================================================
RCS file: /usr/local/cvs/ports/obexapp/util.c,v
retrieving revision 1.15
diff -u -r1.15 util.c
--- util.c      20 Aug 2009 21:57:18 -0000      1.15
+++ util.c      1 Dec 2009 19:58:53 -0000
@@ -34,6 +34,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <iconv.h>
+#include <langinfo.h>
 #include <libgen.h>
 #include <limits.h>
 #include <locale.h>
@@ -56,7 +57,6 @@
  * Init locale
  */
 
-static char const      *locale = NULL;
 static int32_t          utf16 = 0;
 static iconv_t          utf82locale = (iconv_t) -1;
 static iconv_t          locale2utf8 = (iconv_t) -1;
@@ -66,25 +66,10 @@
 int
 obexapp_util_locale_init(void)
 {
-       int     one = 1;
+       char const      *locale;
 
-       locale = setlocale(LC_CTYPE, "");
-       if (locale == NULL)
-               return (-1);
-
-       if (strcmp(locale, "ASCII") == 0 ||
-           strcmp(locale, "C") == 0 ||
-           strcmp(locale, "POSIX") == 0 ||
-           strcmp(locale, "US-ASCII") == 0)
-               locale = "en_US.US-ASCII";
-
-       locale = strchr(locale, '.');
-       if (locale == NULL)
-               return (-1);
-
-       locale ++;
-       if (locale[0] == '\0')
-               return (-1);
+       setlocale(LC_CTYPE, "");
+       locale = nl_langinfo(CODESET);
 
        utf16 = (strstr(locale, "UTF-16") != NULL)? 1 : 0;
 
@@ -94,7 +79,6 @@
                return (-1);
 
        iconv(utf82locale, NULL, NULL, NULL, NULL);
-       iconvctl(utf82locale, ICONV_SET_DISCARD_ILSEQ, &one);
 
        /* current locale -> UTF-8 */
        locale2utf8 = iconv_open("UTF-8", locale);
@@ -104,7 +88,6 @@
        }
 
        iconv(locale2utf8, NULL, NULL, NULL, NULL);
-       iconvctl(locale2utf8, ICONV_SET_DISCARD_ILSEQ, &one);
 
        /* UTF-16BE -> current locale */
        utf16be2locale = iconv_open(locale, "UTF-16BE");
@@ -114,7 +97,6 @@
        }
 
        iconv(utf16be2locale, NULL, NULL, NULL, NULL);
-       iconvctl(utf16be2locale, ICONV_SET_DISCARD_ILSEQ, &one);
 
        /* current locale -> UTF-16BE */
        locale2utf16be = iconv_open("UTF-16BE", locale);
@@ -124,7 +106,6 @@
        }
 
        iconv(locale2utf16be, NULL, NULL, NULL, NULL);
-       iconvctl(locale2utf16be, ICONV_SET_DISCARD_ILSEQ, &one);
 
        return (0);
 }
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-bluetooth
To unsubscribe, send any mail to "[email protected]"

Reply via email to