~ubuntu-branches/ubuntu/jaunty/transmission/jaunty-security

« back to all changes in this revision

Viewing changes to libtransmission/list.c

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2008-11-28 15:33:48 UTC
  • mfrom: (1.1.19 upstream)
  • Revision ID: james.westby@ubuntu.com-20081128153348-it70trfnxiroblmc
Tags: 1.40-0ubuntu1
* New upstream release (LP: #302672)
  - Tracker communication uses fewer resources
  - More accurate bandwidth limits
  - Reduce disk fragmentation by preallocating files (LP: #287726)
  - Stability, security and performance improvements to the RPC /
    Web UI server (closes LP: #290423)
  - Support compression when serving Web UI and RPC responses
  - Simplify the RPC whitelist
  - Fix bug that prevented handshakes with encrypted BitComet peers
  - Fix 1.3x bug that could re-download some data unnecessarily
    (LP: #295040)
  - Option to automatically update the blocklist weekly
  - Added off-hour bandwidth scheduling
  - Simplify file/priority selection in the details dialog
  - Fix a couple of crashes
  - New / updated translations
  - Don't inhibit hibernation by default (LP: #292929)
  - Use "close" animation when sending to notification area (LP: #130811)
  - Fix resize problems (LP: #269872)
  - Support "--version" option when launching from command line
    (LP: #292011)
  - Correctly parse announce URLs that have leading or trailing
    spaces (LP: #262411)
  - Display an error when "Open Torrent" fails (LP: #281463)
* Dropped 10_fix_crasher_from_upstream.dpatch: Fix is in this
  upstream release.
* debian/control: Don't just build-depend on libcurl-dev, which is
  a virtual package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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)
6
 
 * so that the bulk of its code can remain under the MIT license. 
 
6
 * so that the bulk of its code can remain under the MIT license.
7
7
 * This exemption does not extend to derived works not owned by
8
8
 * the Transmission project.
9
9
 *
10
 
 * $Id: list.c 6425 2008-08-01 16:43:22Z charles $
 
10
 * $Id: list.c 6892 2008-10-13 22:26:02Z charles $
11
11
 */
12
12
 
13
13
#include "transmission.h"
31
31
***/
32
32
 
33
33
void
34
 
tr_list_free( tr_list** list, TrListForeachFunc data_free_func )
 
34
tr_list_free( tr_list**         list,
 
35
              TrListForeachFunc data_free_func )
35
36
{
36
37
    while( *list )
37
38
    {
38
39
        tr_list *node = *list;
39
 
        *list = (*list)->next;
 
40
        *list = ( *list )->next;
40
41
        if( data_free_func )
41
42
            data_free_func( node->data );
42
43
        node_free( node );
44
45
}
45
46
 
46
47
void
47
 
tr_list_prepend( tr_list ** list, void * data )
 
48
tr_list_prepend( tr_list ** list,
 
49
                 void *     data )
48
50
{
49
 
    tr_list * node = node_alloc ();
 
51
    tr_list * node = node_alloc ( );
 
52
 
50
53
    node->data = data;
51
54
    node->next = *list;
52
55
    if( *list )
53
 
        (*list)->prev = node;
 
56
        ( *list )->prev = node;
54
57
    *list = node;
55
58
}
56
59
 
57
60
void
58
 
tr_list_append( tr_list ** list, void * data )
 
61
tr_list_append( tr_list ** list,
 
62
                void *     data )
59
63
{
60
64
    tr_list * node = node_alloc( );
 
65
 
61
66
    node->data = data;
62
67
    if( !*list )
63
68
        *list = node;
64
 
    else {
 
69
    else
 
70
    {
65
71
        tr_list * l = *list;
66
72
        while( l->next )
67
73
            l = l->next;
 
74
 
68
75
        l->next = node;
69
76
        node->prev = l;
70
77
    }
71
78
}
72
79
 
73
80
void
74
 
tr_list_insert_sorted( tr_list ** list,
75
 
                       void       * data,
76
 
                       int          compare(const void*,const void*) )
 
81
tr_list_insert_sorted( tr_list            ** list,
 
82
                       void                * data,
 
83
                       TrListCompareFunc     compare )
77
84
{
78
85
    /* find l, the node that we'll insert this data before */
79
86
    tr_list * l;
80
 
    for( l=*list; l!=NULL; l=l->next ) {
 
87
 
 
88
    for( l = *list; l != NULL; l = l->next )
 
89
    {
81
90
        const int c = (compare)( data, l->data );
82
91
        if( c <= 0 )
83
92
            break;
84
93
    }
85
94
 
86
 
    if( l == NULL)
 
95
    if( l == NULL )
87
96
        tr_list_append( list, data );
88
97
    else if( l == *list )
89
98
        tr_list_prepend( list, data );
90
 
    else {
 
99
    else
 
100
    {
91
101
        tr_list * node = node_alloc( );
92
102
        node->data = data;
93
 
        if( l->prev ) { node->prev = l->prev; node->prev->next = node; }
 
103
        if( l->prev ){ node->prev = l->prev; node->prev->next = node; }
94
104
        node->next = l;
95
105
        l->prev = node;
96
106
    }
97
107
}
98
108
 
99
 
 
100
109
tr_list*
101
 
tr_list_find_data ( tr_list * list, const void * data )
 
110
tr_list_find_data( tr_list *    list,
 
111
                   const void * data )
102
112
{
103
 
    for(; list; list=list->next )
 
113
    for( ; list; list = list->next )
104
114
        if( list->data == data )
105
115
            return list;
106
116
 
108
118
}
109
119
 
110
120
static void*
111
 
tr_list_remove_node ( tr_list ** list, tr_list * node )
 
121
tr_list_remove_node( tr_list ** list,
 
122
                     tr_list *  node )
112
123
{
113
 
    void * data;
 
124
    void *    data;
114
125
    tr_list * prev = node ? node->prev : NULL;
115
126
    tr_list * next = node ? node->next : NULL;
 
127
 
116
128
    if( prev ) prev->next = next;
117
129
    if( next ) next->prev = prev;
118
130
    if( *list == node ) *list = next;
125
137
tr_list_pop_front( tr_list ** list )
126
138
{
127
139
    void * ret = NULL;
 
140
 
128
141
    if( *list )
129
142
    {
130
 
        ret = (*list)->data;
 
143
        ret = ( *list )->data;
131
144
        tr_list_remove_node( list, *list );
132
145
    }
133
146
    return ret;
134
147
}
135
148
 
136
149
void*
137
 
tr_list_remove_data ( tr_list ** list, const void * data )
 
150
tr_list_remove_data( tr_list **   list,
 
151
                     const void * data )
138
152
{
139
153
    return tr_list_remove_node( list, tr_list_find_data( *list, data ) );
140
154
}
141
155
 
142
156
void*
143
 
tr_list_remove( tr_list         ** list,
144
 
                const void       * b,
145
 
                TrListCompareFunc  compare_func )
 
157
tr_list_remove( tr_list **        list,
 
158
                const void *      b,
 
159
                TrListCompareFunc compare_func )
146
160
{
147
161
    return tr_list_remove_node( list, tr_list_find( *list, b, compare_func ) );
148
162
}
149
163
 
150
 
 
151
164
tr_list*
152
 
tr_list_find ( tr_list * list , const void * b, TrListCompareFunc func )
 
165
tr_list_find( tr_list *         list,
 
166
              const void *      b,
 
167
              TrListCompareFunc func )
153
168
{
154
 
    for( ; list; list=list->next )
 
169
    for( ; list; list = list->next )
155
170
        if( !func( list->data, b ) )
156
171
            return list;
157
172
 
159
174
}
160
175
 
161
176
void
162
 
tr_list_foreach( tr_list * list, TrListForeachFunc func )
 
177
tr_list_foreach( tr_list *         list,
 
178
                 TrListForeachFunc func )
163
179
{
164
 
    while( list ) {
 
180
    while( list )
 
181
    {
165
182
        func( list->data );
166
183
        list = list->next;
167
184
    }
171
188
tr_list_size( const tr_list * list )
172
189
{
173
190
    int size = 0;
174
 
    while( list ) {
 
191
 
 
192
    while( list )
 
193
    {
175
194
        ++size;
176
195
        list = list->next;
177
196
    }
 
197
 
178
198
    return size;
179
199
}
 
200