00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00036 #ifndef _common_h_
00037 #define _common_h_
00038
00039 #include "config.h"
00040
00041
00042
00043
00044
00045 #define GTA_VERSION 0
00046 #define GTA_SUBVERSION 96
00047 #define GTA_PATCHLEVEL 1
00048 #define GTA_REVISION "unstable"
00049 #define GTA_REVCHAR "u"
00050 #define GTA_RELEASE "2006-02-03"
00051 #define GTA_WEBSITE "http://gtk-gnutella.sourceforge.net/"
00052
00053 #if defined(USE_GTK1)
00054 #define GTA_INTERFACE "GTK1"
00055 #elif defined(USE_GTK2)
00056 #define GTA_INTERFACE "GTK2"
00057 #elif defined(USE_TOPLESS)
00058 #define GTA_INTERFACE "Topless"
00059 #else
00060 #define GTA_INTERFACE "X11"
00061 #endif
00062
00063 #ifndef HAS_LIBXML2
00064 #error "You need libxml2 (http://www.xmlsoft.org/) to compile Gtk-Gnutella"
00065 #endif
00066
00067
00068
00069
00070
00071 #include <errno.h>
00072 #include <stdlib.h>
00073 #include <stdio.h>
00074 #include <signal.h>
00075 #include <unistd.h>
00076 #include <sys/types.h>
00077
00078 #ifdef I_SYS_TIME
00079 #include <sys/time.h>
00080 #endif
00081 #ifdef I_SYS_TIME_KERNEL
00082 #define KERNEL
00083 #include <sys/time.h>
00084 #undef KERNEL
00085 #endif
00086
00087
00088 #ifdef MINGW32
00089 #include <ws2tcpip.h>
00090 #include <winsock.h>
00091 #define ECONNRESET WSAECONNRESET
00092 #define ECONNREFUSED WSAECONNREFUSED
00093 #define ECONNABORTED WSAECONNABORTED
00094 #define ENETUNREACH WSAENETUNREACH
00095 #define EHOSTUNREACH WSAEHOSTUNREACH
00096 #define ETIMEDOUT WSAETIMEDOUT
00097 #define EINPROGRESS WSAEINPROGRESS
00098 #define ENOTCONN WSAENOTCONN
00099 #define ENOBUFS WSAENOBUFS
00100 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
00101 #define ENETRESET WSAENETRESET
00102 #define ENETDOWN WSAENETDOWN
00103 #define EHOSTDOWN WSAEHOSTDOWN
00104 #define ENOPROTOOPT WSAENOPROTOOPT
00105 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
00106
00107 #define SHUT_RD SD_RECEIVE
00108 #define SHUT_WR SD_SEND
00109 #define SHUT_RDWR SD_BOTH
00110
00111 #define S_IXGRP _S_IEXEC
00112 #define S_IWGRP _S_IWRITE
00113 #define S_IRGRP _S_IREAD
00114
00115 #define S_IRWXG _S_IREAD
00116 #define S_IRWXO _S_IREAD
00117
00118 #else
00119
00120 #include <sys/resource.h>
00121 #include <sys/socket.h>
00122 #endif
00123
00124 #include <sys/stat.h>
00125
00126 #ifdef MINGW32
00127 struct iovec
00128 {
00129 char *iov_base;
00130 int iov_len;
00131 };
00132
00133 struct passwd
00134 {
00135 char *pw_name;
00136 char *pw_passwd;
00137 #if 0
00138 __uid_t pw_uid;
00139 __gid_t pw_gid;
00140 char *pw_gecos;
00141 char *pw_dir;
00142 char *pw_shell;
00143 #endif
00144 };
00145
00146 #else
00147
00148 #include <sys/uio.h>
00149 #include <netinet/in.h>
00150 #include <netinet/tcp.h>
00151 #include <arpa/inet.h>
00152
00153 #endif
00154
00155 #include <ctype.h>
00156 #include <fcntl.h>
00157 #include <string.h>
00158 #include <dirent.h>
00159 #include <setjmp.h>
00160
00161 #ifdef I_TIME
00162 #include <time.h>
00163 #endif
00164
00165 #ifdef I_SYS_PARAM
00166 #include <sys/param.h>
00167 #endif
00168 #ifdef I_SYS_SYSCTL
00169 #include <sys/sysctl.h>
00170 #endif
00171 #ifdef I_INVENT
00172 #include <invent.h>
00173 #endif
00174
00175 #ifdef I_INTTYPES
00176 #include <inttypes.h>
00177 #endif
00178
00179 #include <sys/mman.h>
00180
00181 #ifndef MAP_FAILED
00182 #define MAP_FAILED ((void *) -1)
00183 #endif
00184
00185 #ifdef I_SYS_SENDFILE
00186 #include <sys/sendfile.h>
00187 #else
00188 #ifdef HAS_SENDFILE
00189 #define USE_BSD_SENDFILE
00190 #else
00191
00192
00193
00194
00195 #if defined(__STDC_VERSION__)
00196 #define USE_MMAP 1
00197 #endif
00198
00199 #endif
00200 #endif
00201
00202 #if defined(USE_IP_TOS) && defined(I_NETINET_IP)
00203 #include <netinet/in_systm.h>
00204 #include <netinet/ip.h>
00205 #endif
00206
00207
00208
00209 #ifdef USE_LINT
00210 #undef G_GNUC_INTERNAL
00211 #define G_GNUC_INTERNAL
00212 #undef G_INLINE_FUNC
00213 #define G_INLINE_FUNC
00214 #define inline
00215 #endif
00216
00217
00218
00219
00220
00221 #if defined(IOV_MAX)
00222 #define MAX_IOV_COUNT IOV_MAX
00223 #elif defined(MAXIOV)
00224 #define MAX_IOV_COUNT MAXIOV
00225 #elif defined(UIO_MAXIOV)
00226 #define MAX_IOV_COUNT UIO_MAXIOV
00227 #elif defined(_XOPEN_IOV_MAX)
00228 #define MAX_IOV_COUNT _XOPEN_IOV_MAX
00229 #else
00230 #define MAX_IOV_COUNT 16
00231 #endif
00232
00233 #include <glib.h>
00234
00235 #ifdef USE_LINT
00236 #undef G_GNUC_INTERNAL
00237 #define G_GNUC_INTERNAL
00238 #undef G_INLINE_FUNC
00239 #define G_INLINE_FUNC
00240 #define inline
00241 #endif
00242
00243 typedef guint64 filesize_t;
00245 #include <stdarg.h>
00246 #include <regex.h>
00247
00248 #include <zlib.h>
00249
00250 #ifdef USE_GLIB1
00251 typedef void (*GCallback) (void);
00252 #define G_STRLOC __FILE__ ":" STRINGIFY(__LINE__)
00253 #endif
00254 #ifdef USE_GLIB2
00255 #include <glib-object.h>
00256 #endif
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267 #ifdef va_copy
00268 #define VA_COPY(dest, src) va_copy(dest, src)
00269 #elif defined(__va_copy)
00270 #define VA_COPY(dest, src) __va_copy(dest, src)
00271 #else
00272 #define VA_COPY(dest, src) (dest) = (src)
00273 #endif
00274
00275
00276
00277
00278
00279 #ifndef STDIN_FILENO
00280 #define STDIN_FILENO 0
00281 #endif
00282
00283 #ifndef STDOUT_FILENO
00284 #define STDOUT_FILENO 1
00285 #endif
00286
00287 #ifndef STDERR_FILENO
00288 #define STDERR_FILENO 2
00289 #endif
00290
00291
00292
00293
00294
00295
00296 #define SRC_PREFIX "src/"
00298
00299
00300
00301
00302
00303 #ifdef CURDIR
00304 #define _WHERE_ STRINGIFY(CURDIR) "/" __FILE__
00305 #else
00306 #define _WHERE_ __FILE__
00307 #endif
00308
00309
00310
00311
00312
00313 #ifdef OFFICIAL_BUILD
00314 #undef PACKAGE_EXTRA_SOURCE_DIR
00315 #else
00316 #define PACKAGE_EXTRA_SOURCE_DIR \
00317 PACKAGE_SOURCE_DIR G_DIR_SEPARATOR_S "extra_files"
00318 #endif
00319
00325 #define G_FREE_NULL(p) \
00326 G_STMT_START { \
00327 if (p) { \
00328 g_free(p); \
00329 p = NULL; \
00330 } \
00331 } G_STMT_END
00332
00340 #define RCSID(x) \
00341 static inline const char * \
00342 get_rcsid(void) \
00343 { \
00344 static const char rcsid[] = "@(#) " x; \
00345 const char *s = rcsid; \
00346 while (*s != '\0') { \
00347 if (*s++ == '$') \
00348 break; \
00349 } \
00350 return s; \
00351 }
00352
00353 #if defined(__GNUC__) && defined(__GNUC_MINOR__)
00354 #define HAVE_GCC(major, minor) \
00355 ((__GNUC__ > (major)) || \
00356 (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
00357 #else
00358 #define HAVE_GCC(major, minor) 0
00359 #endif
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369 #if HAVE_GCC(3, 3)
00370 #define NON_NULL_PARAM(x) __attribute__((nonnull x))
00371 #else
00372 #define NON_NULL_PARAM(x)
00373 #endif
00374
00379 #if HAVE_GCC(3, 0)
00380 #define PRINTF_FUNC_PTR(x, y) __attribute__((format(printf, (x), (y))))
00381 #else
00382 #define PRINTF_FUNC_PTR(x, y)
00383 #endif
00384
00385
00386
00387 #if HAVE_GCC(3, 4)
00388 #define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
00389 #else
00390 #define WARN_UNUSED_RESULT
00391 #endif
00392
00393
00394
00395 #if HAVE_GCC(4, 0)
00396 #define WARN_NEED_SENTINEL __attribute__((sentinel))
00397 #else
00398 #define WARN_NEED_SENTINEL
00399 #endif
00400
00401
00402
00403
00404 #ifndef G_LIKELY
00405 #if HAVE_GCC(3, 4)
00406 #define G_LIKELY(x) (__builtin_expect(x, 1))
00407 #define G_UNLIKELY(x) (__builtin_expect(x, 0))
00408 #else
00409 #define G_LIKELY(x) (x)
00410 #define G_UNLIKELY(x) (x)
00411 #endif
00412 #endif
00413
00417 #define CMP(a, b) ((a) == (b) ? 0 : (a) > (b) ? 1 : (-1))
00418
00432 #define STATIC_ASSERT(x) \
00433 do { switch (0) { case ((x) ? 1 : 0): case 0: break; } } while(0)
00434
00435 #if defined(GTA_PATCHLEVEL) && (GTA_PATCHLEVEL != 0)
00436 #define GTA_VERSION_NUMBER \
00437 STRINGIFY(GTA_VERSION) "." \
00438 STRINGIFY(GTA_SUBVERSION) "." \
00439 STRINGIFY(GTA_PATCHLEVEL) GTA_REVCHAR
00440 #else
00441 #define GTA_VERSION_NUMBER \
00442 STRINGIFY(GTA_VERSION) "." STRINGIFY(GTA_SUBVERSION) GTA_REVCHAR
00443 #endif
00444
00445 #define GTA_PORT 6346
00446 #define MAX_HOSTLEN 256
00448
00449 #define SHA1_BASE32_SIZE 32
00450 #define SHA1_RAW_SIZE 20
00452 #define BITPRINT_BASE32_SIZE 72
00454 #define BITPRINT_RAW_SIZE 44
00457
00458
00459
00460
00461 #define g_snprintf DONT_CALL_g_snprintf
00462 #define g_vsnprintf DONT_CALL_g_vsnprintf
00464
00465
00466
00467
00468 typedef gboolean (*reclaim_fd_t)(void);
00469
00470
00471
00472
00473
00474 #ifdef ENABLE_NLS
00475 # include <libintl.h>
00476 # undef _
00477 # define _(String) dgettext(PACKAGE, String)
00478 # define Q_(String) g_strip_context ((String), gettext (String))
00479 # ifdef gettext_noop
00480 # define N_(String) gettext_noop(String)
00481 # else
00482 # define N_(String) (String)
00483 # endif
00484
00485
00486 #else
00487 # define textdomain(String) (String)
00488 # define gettext(String) (String)
00489 # define dgettext(Domain,Message) (Message)
00490 # define dcgettext(Domain,Message,Type) (Message)
00491 # define bindtextdomain(Domain,Directory) (Domain)
00492 # define ngettext(Single, Plural, Number) ((Number) == 1 ? (Single) : (Plural))
00493 # define _(String) (String)
00494 # define N_(String) (String)
00495 # define Q_(String) g_strip_context ((String), (String))
00496 #endif
00497
00498 static inline const gchar *
00499 ngettext_(const gchar *msg1, const gchar *msg2, gulong n)
00500 G_GNUC_FORMAT(1) G_GNUC_FORMAT(2);
00501
00502 static inline const gchar *
00503 ngettext_(const gchar *msg1, const gchar *msg2, gulong n)
00504 {
00505 return ngettext(msg1, msg2, n);
00506 }
00507
00511 #define NG_(Single, Plural, Number) ngettext_((Single), (Plural), (Number))
00512
00513 #endif
00514
00515