Changeset 1141
- Timestamp:
- 03/06/10 11:35:37 (2 years ago)
- Location:
- trunk/libtorrent
- Files:
-
- 8 modified
-
src/protocol/extensions.cc (modified) (2 diffs)
-
src/protocol/extensions.h (modified) (2 diffs)
-
src/torrent/object_raw_bencode.h (modified) (1 diff)
-
src/torrent/object_stream.cc (modified) (11 diffs)
-
test/Makefile.am (modified) (2 diffs)
-
test/torrent/object_static_map_test.cc (modified) (6 diffs)
-
test/torrent/object_static_map_test.h (modified) (4 diffs)
-
test/torrent/object_stream_test.cc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtorrent/src/protocol/extensions.cc
r1140 r1141 46 46 #include "protocol/peer_connection_base.h" 47 47 #include "torrent/connection_manager.h" 48 #include "torrent/object.h"49 48 #include "torrent/object_stream.h" 50 49 #include "torrent/peer/connection_list.h" 51 50 #include "torrent/peer/peer_info.h" 52 #include "torrent/object_static_map.h"53 51 #include "manager.h" 54 52 … … 56 54 57 55 namespace torrent { 58 59 enum ext_handshake_keys {60 key_e,61 key_m_utPex,62 key_p,63 key_reqq,64 key_v,65 key_handshake_LAST66 };67 68 enum ext_pex_keys {69 key_pex_added,70 key_pex_LAST71 };72 73 typedef static_map_type<ext_handshake_keys, key_handshake_LAST> ExtHandshakeMessage;74 typedef static_map_type<ext_pex_keys, key_pex_LAST> ExtPEXMessage;75 56 76 57 template <> -
trunk/libtorrent/src/protocol/extensions.h
r1138 r1141 41 41 #include <vector> 42 42 43 #include <torrent/exceptions.h> 44 #include <torrent/object.h> 43 #include "torrent/exceptions.h" 44 #include "torrent/object.h" 45 #include "torrent/object_static_map.h" 45 46 46 47 #include "download/download_info.h" … … 156 157 char* m_readPos; 157 158 }; 159 160 // 161 // 162 // 163 164 enum ext_handshake_keys { 165 key_e, 166 key_m_utPex, 167 key_p, 168 key_reqq, 169 key_v, 170 key_handshake_LAST 171 }; 172 173 enum ext_pex_keys { 174 key_pex_added, 175 key_pex_LAST 176 }; 177 178 typedef static_map_type<ext_handshake_keys, key_handshake_LAST> ExtHandshakeMessage; 179 typedef static_map_type<ext_pex_keys, key_pex_LAST> ExtPEXMessage; 180 181 // 182 // 183 // 158 184 159 185 inline -
trunk/libtorrent/src/torrent/object_raw_bencode.h
r1138 r1141 38 38 #define LIBTORRENT_OBJECT_RAW_BENCODE_H 39 39 40 #include <algorithm> 40 41 #include <string> 41 42 #include <cstring> -
trunk/libtorrent/src/torrent/object_stream.cc
r1140 r1141 39 39 #include <iterator> 40 40 #include <iostream> 41 #include <cmath> 42 #include <limits> 41 43 #include <rak/algorithm.h> 42 44 #include <rak/functional.h> … … 212 214 first = object_read_bencode_c_value(first + 1, last, object->as_value()); 213 215 214 if (first == NULL || first ==last || *first++ != 'e')216 if (first == last || *first++ != 'e') 215 217 break; 216 218 … … 224 226 *object = Object::create_list(); 225 227 226 while (first != NULL && first !=last) {228 while (first != last) { 227 229 if (*first == 'e') 228 230 return first + 1; … … 249 251 Object::string_type prev; 250 252 251 while (first != NULL && first !=last) {253 while (first != last) { 252 254 if (*first == 'e') 253 255 return first + 1; … … 348 350 first = object_read_bencode_skip_c(first, last); 349 351 350 if (first == NULL)351 return first;352 353 352 raw_bencode obj = raw_bencode(tmp, std::distance(tmp, first)); 354 353 355 if (obj.is_empty())356 return NULL;354 // if (obj.is_empty()) 355 // throw torrent::bencode_error("Invalid bencode data."); 357 356 358 357 switch (type) { … … 644 643 // sprintf(buffer, "Verified wrong, %u, '%u', '%s'.", std::distance(first, last), (unsigned int)*first, escaped.c_str()); 645 644 646 // throw torrent:: bencode_error("Invalid bencode data.");645 // throw torrent::internal_error("Invalid bencode data."); 647 646 // } 648 647 // } … … 657 656 char current_key[static_map_mapping_type::max_key_size + 2] = ""; 658 657 659 while (first != last && first != NULL) {658 while (first != last) { 660 659 // End a dictionary/list or the whole stream. 661 660 if (*first == 'e') { … … 666 665 667 666 stack_itr--; 667 continue; 668 668 } 669 669 … … 717 717 // The bencode object isn't a list. This should either skip it 718 718 // or produce an error. 719 if (*first++ != 'd') 720 throw torrent::bencode_error("Invalid bencode data."); 719 if (*first++ != 'd') { 720 first = object_read_bencode_skip_c(first - 1, last); 721 break; 722 } 721 723 722 724 stack_itr++; … … 734 736 // The bencode object isn't a list. This should either skip it 735 737 // or produce an error. 736 if (*first++ != 'l') 737 throw torrent::bencode_error("Invalid bencode data."); 738 if (*first++ != 'l') { 739 first = object_read_bencode_skip_c(first - 1, last); 740 break; 741 } 738 742 739 743 first_key = key_search.first; … … 746 750 747 751 if (first_key->key[key_search.second + 2] == '*') { 748 if ((first = object_read_bencode_raw_c(first, last, 749 &entry_values[first_key->index].object, 750 key_search.first->key[key_search.second + 1])) == NULL) 751 break; 752 first = object_read_bencode_raw_c(first, last, 753 &entry_values[first_key->index].object, 754 key_search.first->key[key_search.second + 1]); 752 755 } else { 753 if ((first = object_read_bencode_c(first, last, &entry_values[first_key->index].object)) == NULL) 754 break; 756 first = object_read_bencode_c(first, last, &entry_values[first_key->index].object); 755 757 } 756 758 -
trunk/libtorrent/test/Makefile.am
r1137 r1141 1 1 TESTS = LibTorrentTest 2 2 check_PROGRAMS = $(TESTS) 3 LibTorrentTest_LDADD = \ 4 ../src/libtorrent.la 5 3 6 LibTorrentTest_SOURCES = \ 4 7 rak/allocators_test.cc \ … … 14 17 main.cc 15 18 16 LibTorrentTest_LDADD = \17 ../src/libtorrent.la18 19 19 LibTorrentTest_CXXFLAGS = $(CPPUNIT_CFLAGS) 20 20 LibTorrentTest_LDFLAGS = $(CPPUNIT_LIBS) -ldl -
trunk/libtorrent/test/torrent/object_static_map_test.cc
r1140 r1141 4 4 #include <torrent/object_stream.h> 5 5 #include "torrent/object_static_map.h" 6 #include "protocol/extensions.h" 6 7 7 8 #import "object_test_utils.h" … … 150 151 151 152 CPPUNIT_ASSERT(static_map_read_bencode(test_skip_map, test_read_skip_bencode)); 153 } 154 155 template <> 156 const torrent::ExtHandshakeMessage::key_list_type torrent::ExtHandshakeMessage::keys = { 157 { key_e, "e" }, 158 { key_m_utPex, "m::ut_pex" }, 159 { key_p, "p" }, 160 { key_reqq, "reqq" }, 161 { key_v, "v" }, 162 }; 163 164 void 165 ObjectStaticMapTest::test_read_extensions() { 166 torrent::ExtHandshakeMessage test_ext; 167 168 CPPUNIT_ASSERT(static_map_read_bencode(test_ext, "d1:ai1ee")); 169 170 CPPUNIT_ASSERT(static_map_read_bencode(test_ext, "d1:mi1ee")); 171 CPPUNIT_ASSERT(static_map_read_bencode(test_ext, "d1:mdee")); 172 CPPUNIT_ASSERT(static_map_read_bencode(test_ext, "d6:ut_pexi0ee")); 173 CPPUNIT_ASSERT(static_map_read_bencode(test_ext, "d1:md6:ut_pexi0eee")); 152 174 } 153 175 … … 176 198 enum keys_raw_types { key_raw_types_empty, key_raw_types_list, key_raw_types_map, key_raw_types_str, key_raw_types_LAST}; 177 199 enum keys_multiple { key_multiple_a, key_multiple_b, key_multiple_c, key_multiple_LAST }; 200 enum keys_dict { key_dict_a_b, key_dict_LAST }; 178 201 179 202 typedef torrent::static_map_type<keys_empty, key_empty_LAST> test_empty_type; … … 182 205 typedef torrent::static_map_type<keys_raw_types, key_raw_types_LAST> test_raw_types_type; 183 206 typedef torrent::static_map_type<keys_multiple, key_multiple_LAST> test_multiple_type; 207 typedef torrent::static_map_type<keys_dict, key_dict_LAST> test_dict_type; 184 208 185 209 template <> const test_empty_type::key_list_type … … 196 220 template <> const test_multiple_type::key_list_type 197 221 test_multiple_type::keys = { { key_multiple_a, "a" }, { key_multiple_b, "b*" }, { key_multiple_c, "c" } }; 222 template <> const test_dict_type::key_list_type 223 test_dict_type::keys = { { key_dict_a_b, "a::b" } }; 198 224 199 225 void … … 290 316 291 317 void 318 ObjectStaticMapTest::test_read_dict() { 319 test_dict_type map_normal; 320 321 CPPUNIT_ASSERT(static_map_read_bencode(map_normal, "d1:ai1ee")); 322 CPPUNIT_ASSERT(map_normal[key_dict_a_b].is_empty()); 323 324 CPPUNIT_ASSERT(static_map_read_bencode(map_normal, "d1:adee")); 325 CPPUNIT_ASSERT(map_normal[key_dict_a_b].is_empty()); 326 327 CPPUNIT_ASSERT(static_map_read_bencode(map_normal, "d1:ad1:bi1eee")); 328 CPPUNIT_ASSERT(map_normal[key_dict_a_b].as_value() == 1); 329 } 330 331 void 292 332 ObjectStaticMapTest::test_write_empty() { 293 333 test_empty_type map_normal; -
trunk/libtorrent/test/torrent/object_static_map_test.h
r1138 r1141 8 8 CPPUNIT_TEST(test_write); 9 9 CPPUNIT_TEST(test_read); 10 CPPUNIT_TEST(test_read_extensions); 10 11 11 12 CPPUNIT_TEST(test_read_empty); … … 14 15 CPPUNIT_TEST(test_read_raw_types); 15 16 CPPUNIT_TEST(test_read_multiple); 17 CPPUNIT_TEST(test_read_dict); 16 18 17 19 CPPUNIT_TEST(test_write_empty); … … 29 31 void test_read(); 30 32 33 void test_read_extensions(); 34 31 35 // Proper unit tests: 32 36 void test_read_empty(); … … 35 39 void test_read_raw_types(); 36 40 void test_read_multiple(); 41 void test_read_dict(); 37 42 38 43 void test_write_empty(); -
trunk/libtorrent/test/torrent/object_stream_test.cc
r1140 r1141 125 125 CPPUNIT_ASSERT(object_stream_read_skip("d1:ali1eee")); 126 126 CPPUNIT_ASSERT(object_stream_read_skip("d1:ad1:bi1eee")); 127 128 CPPUNIT_ASSERT(object_stream_read_skip("d1:md6:ut_pexi0eee")); 127 129 } 128 130
