~ubuntu-branches/ubuntu/natty/transmission/natty

« back to all changes in this revision

Viewing changes to libtransmission/utils.h

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Klimonda
  • Date: 2009-12-08 10:49:11 UTC
  • mfrom: (1.1.29 upstream) (2.1.10 sid)
  • Revision ID: james.westby@ubuntu.com-20091208104911-06gio45n2nla3vpg
Tags: 1.80~b1-0ubuntu1
* New upstream release (LP: #460620), rebased on debian unstable
  remaining changes:
  - debian/control:
    + Added replaces & provides clutch (now included as part of transmission).
      Can be removed in lucid+1
    + Added quilt, liblaunchpad-integration-dev and lsb-release to Build-Depends
  - debian/rules:
    + create a po template during package build.
  - debian/patches/01_lpi.patch:
    + integrate transmission with launchpad
  - debian/patches/20_add_x-ubuntu-gettext-domain.diff:
    + add x-ubuntu-gettext-domain to .desktop file.
  - debian/transmission-daemon.default:
    - remove --auth from OPTIONS
* Fixes bugs:
  - tray menu shows wrong status for "main window" when started minimized
    (LP: #451415)
* Refreshed patches:
  - dont_build_libevent.patch
  - 99_autoreconf.patch
* Removed patches:
  - 21_onPortTested.diff, 23_tr_torrentNext.diff and
    24_tr_torrentDeleteLocalData_do_move.diff
* debian/patches/21_fix_inhibition.patch:
  - The right value for suspend inhibition is 4
* debian/control:
  - Build-Depend on libgconf2-dev to enable magnet link registration and on
    libcanberra-gtk-dev for notification sound.
* debian/watch:
  - make it detect beta versions, to be removed after 1.80 is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * This file Copyright (C) 2009 Charles Kerr <charles@transmissionbt.com>
 
2
 * This file Copyright (C) 2009 Mnemosyne LLC
3
3
 *
4
4
 * This file is licensed by the GPL version 2.  Works owned by the
5
5
 * Transmission project are granted a special exemption to clause 2(b)
7
7
 * This exemption does not extend to derived works not owned by
8
8
 * the Transmission project.
9
9
 *
10
 
 * $Id: utils.h 8904 2009-08-12 19:44:32Z charles $
 
10
 * $Id: utils.h 9671 2009-12-05 02:19:24Z charles $
11
11
 */
12
12
 
13
13
#ifndef TR_UTILS_H
19
19
#include <stdio.h> /* FILE* */
20
20
#include <string.h> /* memcpy()* */
21
21
#include <stdlib.h> /* malloc() */
22
 
#include <time.h> /* time_t* */
 
22
#include <time.h> /* time_t */
23
23
 
24
24
#include "transmission.h"
25
25
 
54
54
 
55
55
#ifndef TR_GNUC_PRINTF
56
56
 #ifdef __GNUC__
57
 
  #define TR_GNUC_PRINTF( fmt,\
58
 
                          args ) __attribute__ ( ( format ( printf, fmt,\
59
 
                                                            args ) ) )
 
57
  #define TR_GNUC_PRINTF( fmt, args ) __attribute__ ( ( format ( printf, fmt, args ) ) )
60
58
 #else
61
59
  #define TR_GNUC_PRINTF( fmt, args )
62
60
 #endif
63
61
#endif
64
62
 
 
63
#ifndef TR_GNUC_NONNULL
 
64
 #ifdef __GNUC__
 
65
  #define TR_GNUC_NONNULL( ... ) __attribute__((nonnull (__VA_ARGS__)))
 
66
 #else
 
67
  #define TR_GNUC_NONNULL( ... )
 
68
 #endif
 
69
#endif
 
70
 
65
71
#ifndef TR_GNUC_NULL_TERMINATED
66
 
 #if __GNUC__ >= 4
 
72
 #if __GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 3 )
67
73
  #define TR_GNUC_NULL_TERMINATED __attribute__ ( ( __sentinel__ ) )
 
74
  #define TR_GNUC_HOT __attribute ( ( hot ) )
68
75
 #else
69
76
  #define TR_GNUC_NULL_TERMINATED
 
77
  #define TR_GNUC_HOT
70
78
 #endif
71
79
#endif
72
80
 
115
123
    do { if( ! ( test ) ) tr_assertImpl( __FILE__, __LINE__, #test, fmt, __VA_ARGS__ ); } while( 0 )
116
124
#endif
117
125
 
118
 
int            tr_msgLoggingIsActive( int level );
 
126
void tr_msgInit( void );
 
127
 
 
128
#define TR_MAX_MSG_LOG 10000
 
129
 
 
130
extern int messageLevel;
 
131
 
 
132
static TR_INLINE tr_bool tr_msgLoggingIsActive( int level )
 
133
{
 
134
    return messageLevel >= level;
 
135
}
119
136
 
120
137
void           tr_msg( const char * file,
121
138
                       int          line,
188
205
                           int          line,
189
206
                           const char * name,
190
207
                           const char * fmt,
191
 
                           ... ) TR_GNUC_PRINTF( 4, 5 );
 
208
                           ... ) TR_GNUC_PRINTF( 4, 5 ) TR_GNUC_NONNULL(1,4);
192
209
 
193
210
char*          tr_getLogTimeStr( char * buf,
194
 
                                 int    buflen );
 
211
                                 int    buflen ) TR_GNUC_NONNULL(1);
195
212
 
196
213
 
197
214
int            tr_wildmat( const char * text,
198
 
                           const char * pattern );
 
215
                           const char * pattern ) TR_GNUC_NONNULL(1,2);
199
216
 
200
217
/** @brief Portability wrapper for basename() that uses the system implementation if available */
201
218
char* tr_basename( const char * path ) TR_GNUC_MALLOC;
213
230
 * (in which case errno is set appropriately).
214
231
 */
215
232
int            tr_mkdir( const char * path,
216
 
                         int          permissions );
 
233
                         int          permissions ) TR_GNUC_NONNULL(1);
217
234
 
218
235
/**
219
236
 * Like mkdir, but makes parent directories as needed.
221
238
 * @return zero on success, or -1 if an error occurred
222
239
 * (in which case errno is set appropriately).
223
240
 */
224
 
int tr_mkdirp( const char * path, int permissions );
 
241
int tr_mkdirp( const char * path, int permissions ) TR_GNUC_NONNULL(1);
225
242
 
226
243
 
227
244
/**
228
245
 * @brief Loads a file and returns its contents.
229
246
 * On failure, NULL is returned and errno is set.
230
247
 */
231
 
uint8_t* tr_loadFile( const char * filename, size_t * size ) TR_GNUC_MALLOC;
 
248
uint8_t* tr_loadFile( const char * filename, size_t * size ) TR_GNUC_MALLOC TR_GNUC_NONNULL(1);
232
249
 
233
250
 
234
251
/** @brief build a filename from a series of elements using the
246
263
 
247
264
struct event;
248
265
 
249
 
void tr_timerAdd( struct event * timer, int seconds, int milliseconds );
 
266
void tr_timerAdd( struct event * timer, int seconds, int microseconds );
250
267
 
251
268
 
252
269
/** @brief return the current date in milliseconds */
323
340
                   size_t       nmemb,
324
341
                   size_t       size,
325
342
                   int       (* compar)(const void* key, const void* arrayMember),
326
 
                   tr_bool    * exact_match );
 
343
                   tr_bool    * exact_match ) TR_GNUC_HOT TR_GNUC_NONNULL(1,5,6);
327
344
 
328
345
 
329
346
char*       tr_strdup_printf( const char * fmt,
342
359
 
343
360
/** @brief Portability wrapper for snprintf() that uses the system implementation if available */
344
361
int tr_snprintf( char * buf, size_t buflen,
345
 
                 const char * fmt, ... ) TR_GNUC_PRINTF( 3, 4 );
 
362
                 const char * fmt, ... ) TR_GNUC_PRINTF( 3, 4 ) TR_GNUC_NONNULL(1,3);
346
363
 
347
364
const char* tr_strerror( int );
348
365
 
360
377
 
361
378
typedef void ( tr_set_func )( void * element, void * userData );
362
379
 
363
 
void        tr_set_compare( const void * a,
364
 
                            size_t aCount,
365
 
                            const void * b,
366
 
                            size_t bCount,
 
380
void        tr_set_compare( const void * a, size_t aCount,
 
381
                            const void * b, size_t bCount,
367
382
                            int compare( const void * a, const void * b ),
368
383
                            size_t elementSize,
369
384
                            tr_set_func in_a_cb,
371
386
                            tr_set_func in_both_cb,
372
387
                            void * userData );
373
388
 
374
 
void tr_sha1_to_hex( char *          out,
375
 
                     const uint8_t * sha1 );
376
 
 
377
 
 
378
 
tr_bool tr_httpIsValidURL( const char * url );
 
389
void tr_sha1_to_hex( char * out,
 
390
                     const uint8_t * sha1 ) TR_GNUC_NONNULL(1,2);
 
391
 
 
392
void tr_hex_to_sha1( uint8_t * out,
 
393
                     const char * hex ) TR_GNUC_NONNULL(1,2);
 
394
 
 
395
 
 
396
tr_bool tr_httpIsValidURL( const char * url ) TR_GNUC_NONNULL(1);
379
397
 
380
398
int  tr_httpParseURL( const char * url,
381
399
                      int          url_len,
382
400
                      char **      setme_host,
383
401
                      int *        setme_port,
384
 
                      char **      setme_path );
 
402
                      char **      setme_path ) TR_GNUC_NONNULL(1);
385
403
 
386
404
double tr_getRatio( double numerator, double denominator );
387
405
 
388
 
int* tr_parseNumberRange( const char * str, int str_len, int * setmeCount ) TR_GNUC_MALLOC;
389
 
 
390
 
 
391
 
int tr_ptr2int( void* );
392
 
 
393
 
void* tr_int2ptr( int );
 
406
int* tr_parseNumberRange( const char * str, int str_len, int * setmeCount ) TR_GNUC_MALLOC TR_GNUC_NONNULL(1);
 
407
 
394
408
 
395
409
/* truncate a double value at a given number of decimal places.
396
410
   this can be used to prevent a printf() call from rounding up:
412
426
 * @param ratio the ratio to convert to a string
413
427
 * @param the string represntation of "infinity"
414
428
 */
415
 
char* tr_strratio( char * buf, size_t buflen, double ratio, const char * infinity );
 
429
char* tr_strratio( char * buf, size_t buflen, double ratio, const char * infinity ) TR_GNUC_NONNULL(1,4);
416
430
 
417
431
/** @brief Portability wrapper for localtime_r() that uses the system implementation if available */
418
432
struct tm * tr_localtime_r( const time_t *_clock, struct tm *_result );
419
433
 
420
434
 
421
435
/** on success, return 0.  on failure, return -1 and set errno */
422
 
int tr_moveFile( const char * oldpath, const char * newpath );
423
 
 
 
436
int tr_moveFile( const char * oldpath, const char * newpath,
 
437
                 tr_bool * renamed ) TR_GNUC_NONNULL(1,2);
 
438
 
 
439
static TR_INLINE void tr_removeElementFromArray( void   * array,
 
440
                                                 int      index_to_remove,
 
441
                                                 size_t   sizeof_element,
 
442
                                                 size_t   nmemb )
 
443
{
 
444
    char * a = (char*) array;
 
445
 
 
446
    memmove( a + sizeof_element * index_to_remove,
 
447
             a + sizeof_element * ( index_to_remove  + 1 ),
 
448
             sizeof_element * ( --nmemb - index_to_remove ) );
 
449
}
 
450
 
 
451
/***
 
452
****
 
453
***/
 
454
 
 
455
extern time_t transmission_now;
 
456
 
 
457
static TR_INLINE time_t tr_time( void ) { return transmission_now; }
 
458
 
 
459
void tr_timeUpdate( time_t now );
 
460
 
 
461
/***
 
462
****
 
463
***/
424
464
 
425
465
#ifdef __cplusplus
426
466
}