[9078] | 1 | --- libbtctl-0.11.1/src/Makefile.am.unicode 2014-11-11 18:43:29.000000000 -0800 |
---|
| 2 | +++ libbtctl-0.11.1/src/Makefile.am 2014-11-11 19:00:55.000000000 -0800 |
---|
| 3 | @@ -70,7 +70,7 @@ |
---|
| 4 | obex-server-source.c obex-server-source.h \ |
---|
| 5 | obex-server-source-private.h \ |
---|
| 6 | btobex.c btobex.h obexsdp.h obexsdp.c \ |
---|
| 7 | - obex-client-source.c obex-client-source.h \ |
---|
| 8 | + obex-client-source.c obex-client-source.h unicode.c unicode.h common.h \ |
---|
| 9 | btobex-client.c btobex-client.h \ |
---|
| 10 | btctl-types.h btctl-types.c |
---|
| 11 | |
---|
| 12 | --- libbtctl-0.11.1/src/btobex.c.unicode 2007-07-24 07:53:51.000000000 -0700 |
---|
| 13 | +++ libbtctl-0.11.1/src/btobex.c 2014-11-11 18:56:25.000000000 -0800 |
---|
| 14 | @@ -29,6 +29,7 @@ |
---|
| 15 | #include "btctl-types.h" |
---|
| 16 | #include "btctl-marshal.h" |
---|
| 17 | #include "obexsdp.h" |
---|
| 18 | +#include "unicode.h" |
---|
| 19 | |
---|
| 20 | static gpointer parent_class = NULL; |
---|
| 21 | |
---|
| 22 | @@ -310,7 +311,7 @@ |
---|
| 23 | if ((namebuf = g_new0 (gchar, hlen/2))) { |
---|
| 24 | /* FIXME: figure out which encoding of unicode is |
---|
| 25 | * being used and handle it properly */ |
---|
| 26 | - OBEX_UnicodeToChar (namebuf, hv.bs, hlen); |
---|
| 27 | + UnicodeToChar (namebuf, hv.bs, hlen); |
---|
| 28 | name = namebuf; |
---|
| 29 | } |
---|
| 30 | break; |
---|
| 31 | --- libbtctl-0.11.1/src/obex-client-source.c.unicode 2007-03-05 15:07:19.000000000 -0800 |
---|
| 32 | +++ libbtctl-0.11.1/src/obex-client-source.c 2014-11-11 18:57:30.000000000 -0800 |
---|
| 33 | @@ -34,6 +34,7 @@ |
---|
| 34 | |
---|
| 35 | #include "obex-client-source.h" |
---|
| 36 | #include "obex-server-source-private.h" |
---|
| 37 | +#include "unicode.h" |
---|
| 38 | |
---|
| 39 | #define OBEX_STREAM_CHUNK 4096 |
---|
| 40 | |
---|
| 41 | @@ -327,7 +328,7 @@ |
---|
| 42 | bfname = g_path_get_basename (fname); |
---|
| 43 | uname_size = (strlen (bfname)+1)*2; |
---|
| 44 | uname = g_malloc (uname_size); |
---|
| 45 | - OBEX_CharToUnicode (uname, bfname, uname_size); |
---|
| 46 | + CharToUnicode (uname, bfname, uname_size); |
---|
| 47 | |
---|
| 48 | hd.bs = uname; |
---|
| 49 | OBEX_ObjectAddHeader (bc->handle, object, |
---|
| 50 | --- /dev/null 2014-11-11 18:16:49.229711166 -0800 |
---|
| 51 | +++ libbtctl-0.11.1/src/unicode.h 2013-03-05 12:43:50.000000000 -0800 |
---|
| 52 | @@ -0,0 +1,39 @@ |
---|
| 53 | +/** |
---|
| 54 | + \file obexftp/unicode.h |
---|
| 55 | + Unicode charset and encoding conversions. |
---|
| 56 | + ObexFTP library - language bindings for OBEX file transfer. |
---|
| 57 | + |
---|
| 58 | + Copyright (c) 2007 Christian W. Zuckschwerdt <zany@triq.net> |
---|
| 59 | + |
---|
| 60 | + ObexFTP is free software; you can redistribute it and/or modify |
---|
| 61 | + it under the terms of the GNU Lesser General Public License as |
---|
| 62 | + published by the Free Software Foundation; either version 2 of |
---|
| 63 | + the License, or (at your option) any later version. |
---|
| 64 | + |
---|
| 65 | + This program is distributed in the hope that it will be useful, |
---|
| 66 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 67 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 68 | + GNU Lesser General Public License for more details. |
---|
| 69 | + |
---|
| 70 | + You should have received a copy of the GNU Lesser General Public |
---|
| 71 | + License along with ObexFTP. If not, see <http://www.gnu.org/>. |
---|
| 72 | + */ |
---|
| 73 | + |
---|
| 74 | +#ifndef OBEXFTP_UNICODE_H |
---|
| 75 | +#define OBEXFTP_UNICODE_H |
---|
| 76 | + |
---|
| 77 | +#include <inttypes.h> |
---|
| 78 | + |
---|
| 79 | +#ifdef __cplusplus |
---|
| 80 | +extern "C" { |
---|
| 81 | +#endif |
---|
| 82 | + |
---|
| 83 | +int CharToUnicode(uint8_t *uc, const uint8_t *c, int size); |
---|
| 84 | +int UnicodeToChar(uint8_t *c, const uint8_t *uc, int size); |
---|
| 85 | +int Utf8ToChar(uint8_t *c, const uint8_t *uc, int size); |
---|
| 86 | + |
---|
| 87 | +#ifdef __cplusplus |
---|
| 88 | +} |
---|
| 89 | +#endif |
---|
| 90 | + |
---|
| 91 | +#endif /* OBEXFTP_UNICODE_H */ |
---|
| 92 | --- /dev/null 2014-11-11 18:16:49.229711166 -0800 |
---|
| 93 | +++ libbtctl-0.11.1/src/unicode.c 2013-03-05 12:43:50.000000000 -0800 |
---|
| 94 | @@ -0,0 +1,294 @@ |
---|
| 95 | +/** |
---|
| 96 | + \file obexftp/unicode.c |
---|
| 97 | + Unicode charset and encoding conversions. |
---|
| 98 | + ObexFTP library - language bindings for OBEX file transfer. |
---|
| 99 | + |
---|
| 100 | + Copyright (c) 2007 Christian W. Zuckschwerdt <zany@triq.net> |
---|
| 101 | + |
---|
| 102 | + ObexFTP is free software; you can redistribute it and/or modify |
---|
| 103 | + it under the terms of the GNU Lesser General Public License as |
---|
| 104 | + published by the Free Software Foundation; either version 2 of |
---|
| 105 | + the License, or (at your option) any later version. |
---|
| 106 | + |
---|
| 107 | + This program is distributed in the hope that it will be useful, |
---|
| 108 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 109 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 110 | + GNU Lesser General Public License for more details. |
---|
| 111 | + |
---|
| 112 | + You should have received a copy of the GNU Lesser General Public |
---|
| 113 | + License along with ObexFTP. If not, see <http://www.gnu.org/>. |
---|
| 114 | + */ |
---|
| 115 | + |
---|
| 116 | +#ifdef HAVE_CONFIG_H |
---|
| 117 | +#include <config.h> |
---|
| 118 | +#endif |
---|
| 119 | + |
---|
| 120 | +#include <stdio.h> |
---|
| 121 | +#include <stdlib.h> |
---|
| 122 | +#include <string.h> |
---|
| 123 | + |
---|
| 124 | +#ifdef _WIN32 /* no need for iconv */ |
---|
| 125 | +#include <windows.h> /* pulls in Winnls.h */ |
---|
| 126 | +#else |
---|
| 127 | +#ifdef HAVE_ICONV |
---|
| 128 | +#include <iconv.h> |
---|
| 129 | +#include <locale.h> |
---|
| 130 | +#ifndef ICONV_CONST |
---|
| 131 | +#define ICONV_CONST |
---|
| 132 | +#endif |
---|
| 133 | +#ifdef HAVE_LANGINFO_H |
---|
| 134 | +#include <langinfo.h> |
---|
| 135 | +#define locale_charset nl_langinfo(CODESET) |
---|
| 136 | +#else |
---|
| 137 | +#define locale_charset "" |
---|
| 138 | +#endif /* HAVE_LANGINFO_H */ |
---|
| 139 | +#endif /* HAVE_ICONV */ |
---|
| 140 | +#endif /* _WIN32 */ |
---|
| 141 | + |
---|
| 142 | +#include "unicode.h" |
---|
| 143 | + |
---|
| 144 | +#include <common.h> |
---|
| 145 | + |
---|
| 146 | + |
---|
| 147 | +/** |
---|
| 148 | + Convert a string to UTF-16BE, tries to guess charset and encoding. |
---|
| 149 | + |
---|
| 150 | + As a lib we can't be sure what the input charset and encoding is. |
---|
| 151 | + Try to read the input as UTF-8, this will also work for plain ASCII (7bit). |
---|
| 152 | + On errors fall back to the environment locale, which again could be UTF-8. |
---|
| 153 | + As last resort try to copy verbatim, i.e. as ISO-8859-1. |
---|
| 154 | + |
---|
| 155 | + \note This is a quick hack until OpenOBEX is iconv-ready. |
---|
| 156 | + */ |
---|
| 157 | +int CharToUnicode(uint8_t *uc, const uint8_t *c, int size) |
---|
| 158 | +{ |
---|
| 159 | +#ifdef _WIN32 /* no need for iconv */ |
---|
| 160 | + int ret, i; |
---|
| 161 | + char tmp; |
---|
| 162 | + |
---|
| 163 | + return_val_if_fail(uc != NULL, -1); |
---|
| 164 | + return_val_if_fail(c != NULL, -1); |
---|
| 165 | + |
---|
| 166 | + /* ANSI to UTF-16LE */ |
---|
| 167 | + ret = MultiByteToWideChar(CP_ACP, 0, c, -1, (LPWSTR)uc, size); |
---|
| 168 | + /* turn the eggs the right way around now */ |
---|
| 169 | + for (i=0; i < ret; i++) { |
---|
| 170 | + tmp = uc[2*i]; |
---|
| 171 | + uc[2*i] = uc[2*i+1]; |
---|
| 172 | + uc[2*i+1] = tmp; |
---|
| 173 | + } |
---|
| 174 | + return ret * 2; /* 0 on error */ |
---|
| 175 | +#else /* _WIN32 */ |
---|
| 176 | + |
---|
| 177 | +#ifdef HAVE_ICONV |
---|
| 178 | + iconv_t utf16; |
---|
| 179 | + size_t ni, no, nrc; |
---|
| 180 | + /* avoid type-punned dereferecing (breaks strict aliasing) */ |
---|
| 181 | + ICONV_CONST char *cc = (ICONV_CONST char *)c; |
---|
| 182 | + char *ucc = (char *)uc; |
---|
| 183 | + |
---|
| 184 | + return_val_if_fail(uc != NULL, -1); |
---|
| 185 | + return_val_if_fail(c != NULL, -1); |
---|
| 186 | + |
---|
| 187 | + /* try UTF-8 to UTF-16BE */ |
---|
| 188 | + ni = strlen(cc) + 1; |
---|
| 189 | + no = size; |
---|
| 190 | + utf16 = iconv_open("UTF-16BE", "UTF-8"); |
---|
| 191 | + nrc = iconv(utf16, &cc, &ni, &ucc, &no); |
---|
| 192 | + (void)iconv_close(utf16); |
---|
| 193 | + if (nrc == (size_t)(-1)) { |
---|
| 194 | + DEBUG(3, "Iconv from UTF-8 conversion error: '%s'\n", cc); |
---|
| 195 | + } else { |
---|
| 196 | + return size-no; |
---|
| 197 | + } |
---|
| 198 | + |
---|
| 199 | + /* try current locale charset to UTF-16BE */ |
---|
| 200 | + setlocale(LC_CTYPE, ""); |
---|
| 201 | + DEBUG(2, "Iconv from locale \"%s\"\n", locale_charset); |
---|
| 202 | + cc = (ICONV_CONST char *)c; |
---|
| 203 | + ucc = (char *)uc; |
---|
| 204 | + ni = strlen(cc) + 1; |
---|
| 205 | + no = size; |
---|
| 206 | + utf16 = iconv_open("UTF-16BE", locale_charset); |
---|
| 207 | + nrc = iconv(utf16, &cc, &ni, &ucc, &no); |
---|
| 208 | + (void)iconv_close(utf16); |
---|
| 209 | + if (nrc == (size_t)(-1)) { |
---|
| 210 | + DEBUG(3, "Iconv from locale conversion error: '%s'\n", cc); |
---|
| 211 | + } else { |
---|
| 212 | + return size-no; |
---|
| 213 | + } |
---|
| 214 | + |
---|
| 215 | + /* fallback to ISO-8859-1 to UTF-16BE (every byte is valid here) */ |
---|
| 216 | + cc = (ICONV_CONST char *)c; |
---|
| 217 | + ucc = (char *)uc; |
---|
| 218 | + ni = strlen(cc) + 1; |
---|
| 219 | + no = size; |
---|
| 220 | + utf16 = iconv_open("UTF-16BE", "ISO-8859-1"); |
---|
| 221 | + nrc = iconv(utf16, &cc, &ni, &ucc, &no); |
---|
| 222 | + (void)iconv_close(utf16); |
---|
| 223 | + if (nrc == (size_t)(-1)) { |
---|
| 224 | + DEBUG(2, "Iconv internal conversion error: '%s'\n", cc); |
---|
| 225 | + return -1; |
---|
| 226 | + } |
---|
| 227 | + |
---|
| 228 | + return size-no; |
---|
| 229 | +#else /* HAVE_ICONV */ |
---|
| 230 | + int len, n; |
---|
| 231 | + |
---|
| 232 | + if (uc == NULL || c == NULL) |
---|
| 233 | + return -1; |
---|
| 234 | + |
---|
| 235 | + len = n = strlen((char *) c); |
---|
| 236 | + if (n*2+2 > size) |
---|
| 237 | + return -1; |
---|
| 238 | + |
---|
| 239 | + uc[n*2+1] = 0; |
---|
| 240 | + uc[n*2] = 0; |
---|
| 241 | + |
---|
| 242 | + while (n--) { |
---|
| 243 | + uc[n*2+1] = c[n]; |
---|
| 244 | + uc[n*2] = 0; |
---|
| 245 | + } |
---|
| 246 | + |
---|
| 247 | + return (len * 2) + 2; |
---|
| 248 | +#endif /* HAVE_ICONV */ |
---|
| 249 | + |
---|
| 250 | +#endif /* _WIN32 */ |
---|
| 251 | +} |
---|
| 252 | + |
---|
| 253 | + |
---|
| 254 | +/** |
---|
| 255 | + Convert a string from UTF-16BE to locale charset. |
---|
| 256 | + |
---|
| 257 | + Plain ASCII (7bit) and basic ISO-8859-1 will always work. |
---|
| 258 | + This conversion supports UTF-8 and single byte locales. |
---|
| 259 | + |
---|
| 260 | + \note This is a quick hack until OpenOBEX is iconv-ready. |
---|
| 261 | + */ |
---|
| 262 | +int UnicodeToChar(uint8_t *c, const uint8_t *uc, int size) |
---|
| 263 | +{ |
---|
| 264 | +#ifdef _WIN32 /* no need for iconv */ |
---|
| 265 | + int ret, n, i; |
---|
| 266 | + uint8_t *le; |
---|
| 267 | + |
---|
| 268 | + return_val_if_fail(uc != NULL, -1); |
---|
| 269 | + return_val_if_fail(c != NULL, -1); |
---|
| 270 | + |
---|
| 271 | + /* turn the eggs around, pointy side up */ |
---|
| 272 | + for (n=0; uc[2*n] != 0 || uc[2*n+1] != 0; n++); |
---|
| 273 | + le = malloc(2*n+2); |
---|
| 274 | + for (i=0; i <= n; i++) { |
---|
| 275 | + le[2*i] = uc[2*i+1]; |
---|
| 276 | + le[2*i+1] = uc[2*i]; |
---|
| 277 | + } |
---|
| 278 | + /* UTF-16LE to ANSI */ |
---|
| 279 | + ret = WideCharToMultiByte(CP_ACP, 0, le, -1, c, size, NULL, NULL); |
---|
| 280 | + free(le); |
---|
| 281 | + return ret; /* 0 on error */ |
---|
| 282 | +#else /* _WIN32 */ |
---|
| 283 | + |
---|
| 284 | +#ifdef HAVE_ICONV |
---|
| 285 | + iconv_t utf16; |
---|
| 286 | + size_t ni, no, nrc; |
---|
| 287 | + /* avoid type-punned dereferecing (breaks strict aliasing) */ |
---|
| 288 | + char *cc = (char *)c; |
---|
| 289 | + ICONV_CONST char *ucc = (ICONV_CONST char *)uc; |
---|
| 290 | + |
---|
| 291 | + return_val_if_fail(uc != NULL, -1); |
---|
| 292 | + return_val_if_fail(c != NULL, -1); |
---|
| 293 | + |
---|
| 294 | + /* UTF-16BE to current locale charset */ |
---|
| 295 | + setlocale(LC_CTYPE, ""); |
---|
| 296 | + DEBUG(3, "Iconv to locale \"%s\"\n", locale_charset); |
---|
| 297 | + for (ni=0; ucc[2*ni] != 0 || ucc[2*ni+1] != 0; ni++); |
---|
| 298 | + ni = 2*ni+2; |
---|
| 299 | + no = size; |
---|
| 300 | + utf16 = iconv_open(locale_charset, "UTF-16BE"); |
---|
| 301 | + nrc = iconv(utf16, &ucc, &ni, &cc, &no); |
---|
| 302 | + (void)iconv_close(utf16); |
---|
| 303 | + if (nrc == (size_t)(-1)) { |
---|
| 304 | + DEBUG(2, "Iconv from locale conversion error: '%s'\n", cc); |
---|
| 305 | + } |
---|
| 306 | + return size-no; |
---|
| 307 | +#else /* HAVE_ICONV */ |
---|
| 308 | + int n; |
---|
| 309 | + |
---|
| 310 | + if (uc == NULL || c == NULL) |
---|
| 311 | + return -1; |
---|
| 312 | + |
---|
| 313 | + /* Make sure buffer is big enough! */ |
---|
| 314 | + for (n = 0; uc[n*2+1] != 0; n++); |
---|
| 315 | + |
---|
| 316 | + if (n >= size) |
---|
| 317 | + return -1; |
---|
| 318 | + |
---|
| 319 | + for (n = 0; uc[n*2+1] != 0; n++) |
---|
| 320 | + c[n] = uc[n*2+1]; |
---|
| 321 | + c[n] = 0; |
---|
| 322 | + |
---|
| 323 | + return 0; |
---|
| 324 | +#endif /* HAVE_ICONV */ |
---|
| 325 | + |
---|
| 326 | +#endif /* _WIN32 */ |
---|
| 327 | +} |
---|
| 328 | + |
---|
| 329 | + |
---|
| 330 | +/** |
---|
| 331 | + Convert a (xml) string from UTF-8 to locale charset. |
---|
| 332 | + |
---|
| 333 | + Plain ASCII (7bit) and basic ISO-8859-1 will always work. |
---|
| 334 | + This conversion supports UTF-8 and single byte locales. |
---|
| 335 | + |
---|
| 336 | + \note This is a quick hack until OpenOBEX is iconv-ready. |
---|
| 337 | + */ |
---|
| 338 | +int Utf8ToChar(uint8_t *c, const uint8_t *uc, int size) |
---|
| 339 | +{ |
---|
| 340 | +#ifdef _WIN32 /* no need for iconv */ |
---|
| 341 | + int ret, n, i; |
---|
| 342 | + uint8_t *le; |
---|
| 343 | + |
---|
| 344 | + return_val_if_fail(uc != NULL, -1); |
---|
| 345 | + return_val_if_fail(c != NULL, -1); |
---|
| 346 | + |
---|
| 347 | + n = strlen(uc)*2+2; |
---|
| 348 | + le = malloc(n); |
---|
| 349 | + /* UTF-8 to UTF-16LE */ |
---|
| 350 | + ret = MultiByteToWideChar(CP_UTF8, 0, uc, -1, (LPWSTR)le, n); |
---|
| 351 | + |
---|
| 352 | + /* UTF-16LE to ANSI */ |
---|
| 353 | + ret = WideCharToMultiByte(CP_ACP, 0, le, -1, c, size, NULL, NULL); |
---|
| 354 | + free(le); |
---|
| 355 | + return ret; /* 0 on error */ |
---|
| 356 | +#else /* _WIN32 */ |
---|
| 357 | + |
---|
| 358 | +#ifdef HAVE_ICONV |
---|
| 359 | + iconv_t utf8; |
---|
| 360 | + size_t ni, no, nrc; |
---|
| 361 | + /* avoid type-punned dereferecing (breaks strict aliasing) */ |
---|
| 362 | + char *cc = (char *)c; |
---|
| 363 | + ICONV_CONST char *ucc = (ICONV_CONST char *)uc; |
---|
| 364 | + |
---|
| 365 | + return_val_if_fail(uc != NULL, -1); |
---|
| 366 | + return_val_if_fail(c != NULL, -1); |
---|
| 367 | + |
---|
| 368 | + setlocale(LC_CTYPE, ""); |
---|
| 369 | + DEBUG(2, "Iconv to \"%s\"\n", locale_charset); |
---|
| 370 | + ni = strlen(ucc); |
---|
| 371 | + no = size; |
---|
| 372 | + utf8 = iconv_open(locale_charset, "UTF-8"); |
---|
| 373 | + nrc = iconv(utf8, &ucc, &ni, &cc, &no); |
---|
| 374 | + (void)iconv_close(utf8); |
---|
| 375 | + if (nrc != (size_t)(-1)) { |
---|
| 376 | + DEBUG(2, "Iconv from locale conversion error: '%s'\n", cc); |
---|
| 377 | + } |
---|
| 378 | + return size-no; |
---|
| 379 | +#else /* HAVE_ICONV */ |
---|
| 380 | + int n, i; |
---|
| 381 | + n = strlen(uc); |
---|
| 382 | + strncpy(c, uc, size); |
---|
| 383 | + c[size] = '\0'; |
---|
| 384 | + return n; |
---|
| 385 | +#endif /* HAVE_ICONV */ |
---|
| 386 | + |
---|
| 387 | +#endif /* _WIN32 */ |
---|
| 388 | +} |
---|
| 389 | --- /dev/null 2014-11-11 18:16:49.229711166 -0800 |
---|
| 390 | +++ libbtctl-0.11.1/src/common.h 2013-03-05 12:43:50.000000000 -0800 |
---|
| 391 | @@ -0,0 +1,73 @@ |
---|
| 392 | +/** |
---|
| 393 | + \file includes/common.h |
---|
| 394 | + ObexFTP common macros and debugging. |
---|
| 395 | + ObexFTP library - language bindings for OBEX file transfer. |
---|
| 396 | + */ |
---|
| 397 | + |
---|
| 398 | +#ifndef _OBEXFTP_COMMON_H |
---|
| 399 | +#define _OBEXFTP_COMMON_H |
---|
| 400 | + |
---|
| 401 | +#ifdef HAVE_CONFIG_H |
---|
| 402 | +#include "config.h" |
---|
| 403 | +#endif |
---|
| 404 | +#include <stdio.h> |
---|
| 405 | + |
---|
| 406 | +#ifdef UNUSED |
---|
| 407 | +#elif defined(__GNUC__) |
---|
| 408 | +# define UNUSED(x) UNUSED_ ## x __attribute__((unused)) |
---|
| 409 | +#elif defined(__LCLINT__) |
---|
| 410 | +# define UNUSED(x) /*@unused@*/ x |
---|
| 411 | +#else |
---|
| 412 | +# define UNUSED(x) x |
---|
| 413 | +#endif |
---|
| 414 | + |
---|
| 415 | +#ifndef FALSE |
---|
| 416 | +#define FALSE (0) |
---|
| 417 | +#endif |
---|
| 418 | + |
---|
| 419 | +#ifndef TRUE |
---|
| 420 | +#define TRUE (!FALSE) |
---|
| 421 | +#endif |
---|
| 422 | + |
---|
| 423 | +/* these are not asserts! dont define to nothing */ |
---|
| 424 | +#define return_if_fail(expr) do { if (!(expr)) return; } while(0); |
---|
| 425 | +#define return_val_if_fail(expr,val) do { if (!(expr)) return val; } while(0); |
---|
| 426 | + |
---|
| 427 | +#ifdef _WIN32 |
---|
| 428 | +#define snprintf _snprintf |
---|
| 429 | +#endif /* _WIN32 */ |
---|
| 430 | + |
---|
| 431 | +/* use 0 for production, 1 for verification, >2 for debug */ |
---|
| 432 | +#ifndef OBEXFTP_DEBUG |
---|
| 433 | +#define OBEXFTP_DEBUG 0 |
---|
| 434 | +#endif |
---|
| 435 | + |
---|
| 436 | +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L |
---|
| 437 | +#define DEBUG(n, ...) if (OBEXFTP_DEBUG >= (n)) fprintf(stderr, __VA_ARGS__) |
---|
| 438 | +#elif defined (__GNUC__) |
---|
| 439 | +#define DEBUG(n, format...) if (OBEXFTP_DEBUG >= (n)) fprintf (stderr, format) |
---|
| 440 | +#else /* !__GNUC__ */ |
---|
| 441 | +static void |
---|
| 442 | +DEBUG (int n, const char *format, ...) |
---|
| 443 | +{ |
---|
| 444 | + va_list args; |
---|
| 445 | + if (OBEXFTP_DEBUG >= (n)) { |
---|
| 446 | + va_start (args, format); |
---|
| 447 | + fprintf (stderr, format, args); |
---|
| 448 | + va_end (args); |
---|
| 449 | + } |
---|
| 450 | +} |
---|
| 451 | +#endif /* !__GNUC__ */ |
---|
| 452 | + |
---|
| 453 | +#if OBEXFTP_DEBUG > 4 |
---|
| 454 | +#define DEBUGBUFFER(b,l) do { \ |
---|
| 455 | + int i; \ |
---|
| 456 | + for (i=0; i < (l); i++) \ |
---|
| 457 | + fprintf (stderr, "%02x ", ((uint8_t *)(b))[i]); \ |
---|
| 458 | + fprintf (stderr, "\n"); \ |
---|
| 459 | +} while (0) |
---|
| 460 | +#else |
---|
| 461 | +#define DEBUGBUFFER(b,l) do { } while (0) |
---|
| 462 | +#endif |
---|
| 463 | + |
---|
| 464 | +#endif /* _OBEXFTP_COMMON_H */ |
---|