3 /// Barry library tester
7 Copyright (C) 2005-2010, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include <barry/barry.h>
23 #ifdef __BARRY_SYNC_MODE__
24 #include <barry/barrysync.h>
27 #ifdef __BARRY_BACKUP_MODE__
28 #include <barry/barrybackup.h>
44 using namespace std::tr1
;
45 using namespace Barry
;
50 const char *Version
= Barry::Version(major
, minor
);
53 << "btool - Command line USB Blackberry Test Tool\n"
54 << " Copyright 2005-2010, Net Direct Inc. (http://www.netdirect.ca/)\n"
55 << " Using: " << Version
<< "\n"
57 #ifdef __BARRY_BOOST_MODE__
64 << " -b file Filename to save or load a Barry Backup to (tar.gz)\n"
65 << " -B bus Specify which USB bus to search on\n"
66 << " -N dev Specify which system device, using system specific string\n"
68 << " -a db Erase / clear database 'db' FROM device, deleting all\n"
69 << " its records. Can be used multiple times to clear more\n"
71 << " -c dn Convert address book database to LDIF format, using the\n"
72 << " specified baseDN\n"
73 << " -C dnattr LDIF attribute name to use when building the FQDN\n"
74 << " Defaults to 'cn'\n"
75 << " -d db Load database 'db' FROM device and dump to screen\n"
76 << " Can be used multiple times to fetch more than one DB\n"
77 << " -e epp Override endpoint pair detection. 'epp' is a single\n"
78 << " string separated by a comma, holding the read,write\n"
79 << " endpoint pair. Example: -e 83,5\n"
80 << " Note: Endpoints are specified in hex.\n"
81 << " You should never need to use this option.\n"
82 #ifdef __BARRY_BOOST_MODE__
83 << " -f file Filename to save or load handheld data to/from\n"
86 << " -i cs International charset for string conversions\n"
87 << " Valid values here are available with 'iconv --list'\n"
88 << " -I Sort records before output\n"
89 << " -l List devices\n"
90 << " -L List Contact field names\n"
91 << " -m Map LDIF name to Contact field / Unmap LDIF name\n"
92 << " Map: ldif,read,write - maps ldif to read/write Contact fields\n"
93 << " Unmap: ldif name alone\n"
94 << " -M List current LDIF mapping\n"
95 << " -n Use null parser on all databases.\n"
96 << " -p pin PIN of device to talk with\n"
97 << " If only one device is plugged in, this flag is optional\n"
98 << " -P pass Simplistic method to specify device password\n"
99 << " -s db Save database 'db' TO device from data loaded from -f file\n"
100 << " -S Show list of supported database parsers\n"
101 << " -t Show database database table\n"
102 << " -T db Show record state table for given database\n"
103 << " -v Dump protocol data during operation\n"
104 #ifdef __BARRY_SYNC_MODE__
105 << " -V Dump records using MIME vformats where possible\n"
107 << " -X Reset device\n"
108 << " -z Use non-threaded sockets\n"
109 << " -Z Use threaded socket router (default)\n"
111 << " -d Command modifiers: (can be used multiple times for more than 1 record)\n"
113 << " -r # Record index number as seen in the -T state table.\n"
114 << " This overrides the default -d behaviour, and only\n"
115 << " downloads the one specified record, sending to stdout.\n"
116 << " -R # Same as -r, but also clears the record's dirty flags.\n"
117 << " -D # Record index number as seen in the -T state table,\n"
118 << " which indicates the record to delete. Used with the -d\n"
119 << " command to specify the database.\n"
126 Barry::ContactLdif
&ldif
;
128 Contact2Ldif(Barry::ContactLdif
&ldif
) : ldif(ldif
) {}
130 void operator()(const Contact
&rec
)
132 ldif
.DumpLdif(cout
, rec
);
136 template <class Record
>
139 std::vector
<Record
> records
;
140 mutable typename
std::vector
<Record
>::const_iterator rec_it
;
141 std::string filename
;
143 bool immediate_display
;
147 Store(const string
&filename
, bool load
, bool immediate_display
,
149 : rec_it(records
.end()),
152 immediate_display(immediate_display
),
153 vformat_mode(vformat_mode
),
156 #ifdef __BARRY_BOOST_MODE__
159 if( load
&& filename
.size() ) {
160 // filename is available, attempt to load
161 cout
<< "Loading: " << filename
<< endl
;
162 ifstream
ifs(filename
.c_str());
164 getline(ifs
, dbName
);
165 boost::archive::text_iarchive
ia(ifs
);
167 cout
<< records
.size()
168 << " records loaded from '"
169 << filename
<< "'" << endl
;
170 sort(records
.begin(), records
.end());
171 rec_it
= records
.begin();
174 typename
std::vector
<Record
>::const_iterator beg
= records
.begin(), end
= records
.end();
175 for( ; beg
!= end
; beg
++ ) {
176 cout
<< (*beg
) << endl
;
180 } catch( boost::archive::archive_exception
&ae
) {
181 cerr
<< "Archive exception in ~Store(): "
182 << ae
.what() << endl
;
189 if( !immediate_display
) {
190 // not dumped yet, sort then dump
191 sort(records
.begin(), records
.end());
195 cout
<< "Store counted " << dec
<< count
<< " records." << endl
;
196 #ifdef __BARRY_BOOST_MODE__
199 if( !load
&& filename
.size() ) {
200 // filename is available, attempt to save
201 cout
<< "Saving: " << filename
<< endl
;
202 const std::vector
<Record
> &r
= records
;
203 ofstream
ofs(filename
.c_str());
204 ofs
<< Record::GetDBName() << endl
;
205 boost::archive::text_oarchive
oa(ofs
);
207 cout
<< dec
<< r
.size() << " records saved to '"
208 << filename
<< "'" << endl
;
211 } catch( boost::archive::archive_exception
&ae
) {
212 cerr
<< "Archive exception in ~Store(): "
213 << ae
.what() << endl
;
220 typename vector
<Record
>::const_iterator i
= records
.begin();
221 for( ; i
!= records
.end(); ++i
) {
226 void Dump(const Record
&rec
)
229 #ifdef __BARRY_SYNC_MODE__
240 void operator()(const Record
&rec
)
243 if( immediate_display
)
245 records
.push_back(rec
);
248 // retrieval operator
249 bool operator()(Record
&rec
, Builder
&builder
) const
251 if( rec_it
== records
.end() )
259 shared_ptr
<Parser
> GetParser(const string
&name
,
260 const string
&filename
,
262 bool immediate_display
,
266 bool dnow
= immediate_display
;
267 bool vmode
= vformat_mode
;
271 return shared_ptr
<Parser
>( new Barry::HexDumpParser(cout
) );
273 else if( bbackup_mode
) {
274 #ifdef __BARRY_BACKUP_MODE__
275 // Only one backup file per run
276 static shared_ptr
<Parser
> backup
;
277 if( !backup
.get() ) {
278 backup
.reset( new Backup(filename
) );
282 return shared_ptr
<Parser
>( new Barry::HexDumpParser(cout
) );
285 // check for recognized database names
286 else if( name
== Contact::GetDBName() ) {
287 return shared_ptr
<Parser
>(
288 new RecordParser
<Contact
, Store
<Contact
> > (
289 new Store
<Contact
>(filename
, false, dnow
, vmode
)));
291 else if( name
== Message::GetDBName() ) {
292 return shared_ptr
<Parser
>(
293 new RecordParser
<Message
, Store
<Message
> > (
294 new Store
<Message
>(filename
, false, dnow
, vmode
)));
296 else if( name
== Calendar::GetDBName() ) {
297 return shared_ptr
<Parser
>(
298 new RecordParser
<Calendar
, Store
<Calendar
> > (
299 new Store
<Calendar
>(filename
, false, dnow
, vmode
)));
301 else if( name
== CalendarAll::GetDBName() ) {
302 return shared_ptr
<Parser
>(
303 new RecordParser
<CalendarAll
, Store
<CalendarAll
> > (
304 new Store
<CalendarAll
>(filename
, false, dnow
, vmode
)));
306 else if( name
== CallLog::GetDBName() ) {
307 return shared_ptr
<Parser
>(
308 new RecordParser
<CallLog
, Store
<CallLog
> > (
309 new Store
<CallLog
>(filename
, false, dnow
, vmode
)));
311 else if( name
== Bookmark::GetDBName() ) {
312 return shared_ptr
<Parser
>(
313 new RecordParser
<Bookmark
, Store
<Bookmark
> > (
314 new Store
<Bookmark
>(filename
, false, dnow
, vmode
)));
316 else if( name
== ServiceBook::GetDBName() ) {
317 return shared_ptr
<Parser
>(
318 new RecordParser
<ServiceBook
, Store
<ServiceBook
> > (
319 new Store
<ServiceBook
>(filename
, false, dnow
, vmode
)));
322 else if( name
== Memo::GetDBName() ) {
323 return shared_ptr
<Parser
>(
324 new RecordParser
<Memo
, Store
<Memo
> > (
325 new Store
<Memo
>(filename
, false, dnow
, vmode
)));
327 else if( name
== Task::GetDBName() ) {
328 return shared_ptr
<Parser
>(
329 new RecordParser
<Task
, Store
<Task
> > (
330 new Store
<Task
>(filename
, false, dnow
, vmode
)));
332 else if( name
== PINMessage::GetDBName() ) {
333 return shared_ptr
<Parser
>(
334 new RecordParser
<PINMessage
, Store
<PINMessage
> > (
335 new Store
<PINMessage
>(filename
, false, dnow
, vmode
)));
337 else if( name
== SavedMessage::GetDBName() ) {
338 return shared_ptr
<Parser
>(
339 new RecordParser
<SavedMessage
, Store
<SavedMessage
> > (
340 new Store
<SavedMessage
>(filename
, false, dnow
, vmode
)));
342 else if( name
== Sms::GetDBName() ) {
343 return shared_ptr
<Parser
>(
344 new RecordParser
<Sms
, Store
<Sms
> > (
345 new Store
<Sms
>(filename
, false, dnow
, vmode
)));
347 else if( name
== Folder::GetDBName() ) {
348 return shared_ptr
<Parser
>(
349 new RecordParser
<Folder
, Store
<Folder
> > (
350 new Store
<Folder
>(filename
, false, dnow
, vmode
)));
352 else if( name
== Timezone::GetDBName() ) {
353 return shared_ptr
<Parser
>(
354 new RecordParser
<Timezone
, Store
<Timezone
> > (
355 new Store
<Timezone
>(filename
, false, dnow
, vmode
)));
358 // unknown database, use null parser
359 return shared_ptr
<Parser
>( new Barry::HexDumpParser(cout
) );
363 shared_ptr
<Builder
> GetBuilder(const string
&name
, const string
&filename
)
365 // check for recognized database names
366 if( name
== Contact::GetDBName() ) {
367 return shared_ptr
<Builder
>(
368 new RecordBuilder
<Contact
, Store
<Contact
> > (
369 new Store
<Contact
>(filename
, true, true, false)));
371 else if( name
== Calendar::GetDBName() ) {
372 return shared_ptr
<Builder
>(
373 new RecordBuilder
<Calendar
, Store
<Calendar
> > (
374 new Store
<Calendar
>(filename
, true, true, false)));
376 else if( name
== CalendarAll::GetDBName() ) {
377 return shared_ptr
<Builder
>(
378 new RecordBuilder
<CalendarAll
, Store
<CalendarAll
> > (
379 new Store
<CalendarAll
>(filename
, true, true, false)));
381 else if( name
== Memo::GetDBName() ) {
382 return shared_ptr
<Builder
>(
383 new RecordBuilder
<Memo
, Store
<Memo
> > (
384 new Store
<Memo
>(filename
, true, true, false)));
386 else if( name
== Task::GetDBName() ) {
387 return shared_ptr
<Builder
>(
388 new RecordBuilder
<Task
, Store
<Task
> > (
389 new Store
<Task
>(filename
, true, true, false)));
392 else if( name == "Messages" ) {
393 return shared_ptr<Parser>(
394 new RecordParser<Message, Store<Message> > (
395 new Store<Message>(filename, true, true, false)));
397 else if( name == "Service Book" ) {
398 return shared_ptr<Parser>(
399 new RecordParser<ServiceBook, Store<ServiceBook> > (
400 new Store<ServiceBook>(filename, true, true, false)));
404 throw std::runtime_error("No Builder available for database");
410 cout
<< "Supported Database parsers:\n"
412 #ifdef __BARRY_SYNC_MODE__
413 << " (* = can display in vformat MIME mode)\n"
414 #define HANDLE_PARSER(tname) << " " << tname::GetDBName() << (MimeDump<tname>::Supported() ? " *" : "") << "\n"
417 #define HANDLE_PARSER(tname) << " " << tname::GetDBName() << "\n"
420 ALL_KNOWN_PARSER_TYPES
424 << "Supported Database builders:\n"
425 #undef HANDLE_BUILDER
426 #define HANDLE_BUILDER(tname) << " " << tname::GetDBName() << "\n"
427 ALL_KNOWN_BUILDER_TYPES
431 struct StateTableCommand
437 StateTableCommand(char f
, bool c
, unsigned int i
)
438 : flag(f
), clear(c
), index(i
) {}
441 bool SplitMap(const string
&map
, string
&ldif
, string
&read
, string
&write
)
443 string::size_type a
= map
.find(',');
444 if( a
== string::npos
)
447 string::size_type b
= map
.find(',', a
+1);
448 if( b
== string::npos
)
451 ldif
.assign(map
, 0, a
);
452 read
.assign(map
, a
+ 1, b
- a
- 1);
453 write
.assign(map
, b
+ 1, map
.size() - b
- 1);
455 return ldif
.size() && read
.size() && write
.size();
458 void DoMapping(ContactLdif
&ldif
, const vector
<string
> &mapCommands
)
460 for( vector
<string
>::const_iterator i
= mapCommands
.begin();
461 i
!= mapCommands
.end();
464 // single names mean unmapping
465 if( i
->find(',') == string::npos
) {
467 cerr
<< "Unmapping: " << *i
<< endl
;
471 cerr
<< "Mapping: " << *i
<< endl
;
473 // map... extract ldif/read/write names
474 string ldifname
, read
, write
;
475 if( SplitMap(*i
, ldifname
, read
, write
) ) {
476 if( !ldif
.Map(ldifname
, read
, write
) ) {
477 cerr
<< "Read/Write name unknown: " << *i
<< endl
;
481 cerr
<< "Invalid map format: " << *i
<< endl
;
487 bool ParseEpOverride(const char *arg
, Usb::EndpointPair
*epp
)
491 istringstream
iss(arg
);
492 iss
>> hex
>> read
>> comma
>> write
;
500 int main(int argc
, char *argv
[])
504 cout
.sync_with_stdio(true); // leave this on, since libusb uses
505 // stdio for debug messages
510 bool list_only
= false,
512 ldif_contacts
= false,
514 vformat_mode
= false,
515 reset_device
= false,
516 list_contact_fields
= false,
517 list_ldif_map
= false,
518 epp_override
= false,
519 threaded_sockets
= true,
520 record_state_table
= false,
521 clear_database
= false,
523 bbackup_mode
= false,
524 sort_records
= false;
525 string ldifBaseDN
, ldifDnAttr
;
531 vector
<string
> dbNames
, saveDbNames
, mapCommands
, clearDbNames
;
532 vector
<StateTableCommand
> stCommands
;
533 Usb::EndpointPair epOverride
;
535 // process command line options
537 int cmd
= getopt(argc
, argv
, "a:b:B:c:C:d:D:e:f:hi:IlLm:MnN:p:P:r:R:Ss:tT:vVXzZ");
543 case 'a': // Clear Database
544 clear_database
= true;
545 clearDbNames
.push_back(string(optarg
));
548 case 'b': // Barry backup filename (tar.gz)
549 #ifdef __BARRY_BACKUP_MODE__
550 if( filename
.size() == 0 ) {
555 cerr
<< "Do not use -f with -b\n";
559 cerr
<< "-b option not supported - no Barry "
560 "Backup library support available\n";
569 case 'c': // contacts to ldap ldif
570 ldif_contacts
= true;
574 case 'C': // DN Attribute for FQDN
578 case 'd': // show dbname
579 dbNames
.push_back(string(optarg
));
582 case 'D': // delete record
583 stCommands
.push_back(
584 StateTableCommand('D', false, atoi(optarg
)));
587 case 'e': // endpoint override
588 if( !ParseEpOverride(optarg
, &epOverride
) ) {
595 case 'f': // filename
596 #ifdef __BARRY_BOOST_MODE__
597 if( !bbackup_mode
&& filename
.size() == 0 ) {
601 cerr
<< "Do not use -f with -b\n";
605 cerr
<< "-f option not supported - no Boost "
606 "serialization support available\n";
611 case 'i': // international charset (iconv)
612 iconvCharset
= optarg
;
615 case 'I': // sort before dump
619 case 'l': // list only
623 case 'L': // List Contact field names
624 list_contact_fields
= true;
627 case 'm': // Map / Unmap
628 mapCommands
.push_back(string(optarg
));
631 case 'M': // List LDIF map
632 list_ldif_map
= true;
635 case 'n': // use null parser
643 case 'p': // Blackberry PIN
644 pin
= strtoul(optarg
, NULL
, 16);
647 case 'P': // Device password
651 case 'r': // get specific record index
652 stCommands
.push_back(
653 StateTableCommand('r', false, atoi(optarg
)));
656 case 'R': // same as 'r', and clears dirty
657 stCommands
.push_back(
658 StateTableCommand('r', true, atoi(optarg
)));
661 case 's': // save dbname
662 saveDbNames
.push_back(string(optarg
));
665 case 'S': // show supported databases
669 case 't': // display database database
673 case 'T': // show RecordStateTable
674 record_state_table
= true;
675 dbNames
.push_back(string(optarg
));
678 case 'v': // data dump on
682 case 'V': // vformat MIME mode
683 #ifdef __BARRY_SYNC_MODE__
686 cerr
<< "-V option not supported - no Sync "
687 "library support available\n";
692 case 'X': // reset device
696 case 'z': // non-threaded sockets
697 threaded_sockets
= false;
700 case 'Z': // threaded socket router
701 threaded_sockets
= true;
711 // Initialize the barry library. Must be called before
713 Barry::Init(data_dump
);
716 const char *Version
= Barry::Version(major
, minor
);
717 cout
<< Version
<< endl
;
720 // Create an IConverter object if needed
721 auto_ptr
<IConverter
> ic
;
722 if( iconvCharset
.size() ) {
723 ic
.reset( new IConverter(iconvCharset
.c_str(), true) );
726 // LDIF class... only needed if ldif output turned on
727 ContactLdif
ldif(ldifBaseDN
);
728 DoMapping(ldif
, mapCommands
);
729 if( ldifDnAttr
.size() ) {
730 if( !ldif
.SetDNAttr(ldifDnAttr
) ) {
731 cerr
<< "Unable to set DN Attr: " << ldifDnAttr
<< endl
;
735 // Probe the USB bus for Blackberry devices and display.
736 // If user has specified a PIN, search for it in the
737 // available device list here as well
738 Barry::Probe
probe(busname
.c_str(), devname
.c_str(),
739 epp_override
? &epOverride
: 0);
740 int activeDevice
= -1;
742 // show any errors during probe first
743 if( probe
.GetFailCount() ) {
746 cout
<< "Blackberry device errors with errors during probe:" << endl
;
747 for( int i
= 0; i
< probe
.GetFailCount(); i
++ ) {
750 cout
<< probe
.GetFailMsg(i
) << endl
;
754 // show all successfully found devices
757 cout
<< "Blackberry devices found:" << endl
;
758 for( int i
= 0; i
< probe
.GetCount(); i
++ ) {
762 probe
.Get(i
).DumpAll(cout
);
764 cout
<< probe
.Get(i
);
766 if( probe
.Get(i
).m_pin
== pin
)
773 if( activeDevice
== -1 ) {
775 // can we default to single device?
776 if( probe
.GetCount() == 1 )
779 cerr
<< "No device selected" << endl
;
784 cerr
<< "PIN " << setbase(16) << pin
785 << " not found" << endl
;
792 cout
<< "Using device (PIN): "
793 << probe
.Get(activeDevice
).m_pin
.Str() << endl
;
796 Usb::Device
dev(probe
.Get(activeDevice
).m_dev
);
801 // Override device endpoints if user asks
802 Barry::ProbeResult device
= probe
.Get(activeDevice
);
804 device
.m_ep
.read
= epOverride
.read
;
805 device
.m_ep
.write
= epOverride
.write
;
806 device
.m_ep
.type
= 2; // FIXME - override this too?
807 cout
<< "Endpoint pair (read,write) overridden with: "
809 << (unsigned int) device
.m_ep
.read
<< ","
810 << (unsigned int) device
.m_ep
.write
<< endl
;
814 // execute each mode that was turned on
818 // Dump current LDIF mapping
819 if( list_ldif_map
) {
820 cout
<< ldif
<< endl
;
823 // Dump list of Contact field names
824 if( list_contact_fields
) {
825 for( const ContactLdif::NameToFunc
*n
= ldif
.GetFieldNames(); n
->name
; n
++ ) {
827 cout
<< " " << left
<< setw(20) << n
->name
<< ": "
828 << n
->description
<< endl
;
832 // Check if Desktop access is needed
835 record_state_table
||
839 saveDbNames
.size() ) )
843 // Create our controller object
845 // Order is important in the following auto_ptr<> objects,
846 // since Controller must get destroyed before router.
847 // Normally you'd pick one method, and not bother
848 // with auto_ptr<> and so the normal C++ constructor
849 // rules would guarantee this safety for you, but
850 // here we want the user to pick.
852 auto_ptr
<SocketRoutingQueue
> router
;
853 auto_ptr
<Barry::Controller
> pcon
;
854 if( threaded_sockets
) {
855 router
.reset( new SocketRoutingQueue
);
856 router
->SpinoffSimpleReadThread();
857 pcon
.reset( new Barry::Controller(device
, *router
) );
860 pcon
.reset( new Barry::Controller(device
) );
863 Barry::Controller
&con
= *pcon
;
864 Barry::Mode::Desktop
desktop(con
, *ic
);
865 desktop
.Open(password
.c_str());
867 // Dump list of all databases to stdout
869 // open desktop mode socket
870 cout
<< desktop
.GetDBDB() << endl
;
873 // Dump list of contacts to an LDAP LDIF file
874 // This uses the Controller convenience templates
875 if( ldif_contacts
) {
876 // create a storage functor object that accepts
877 // Barry::Contact objects as input
878 Contact2Ldif
storage(ldif
);
880 // load all the Contact records into storage
881 desktop
.LoadDatabaseByType
<Barry::Contact
>(storage
);
884 // Dump record state table to stdout
885 if( record_state_table
) {
886 if( dbNames
.size() == 0 ) {
887 cout
<< "No db names to process" << endl
;
891 vector
<string
>::iterator b
= dbNames
.begin();
892 for( ; b
!= dbNames
.end(); b
++ ) {
893 unsigned int id
= desktop
.GetDBID(*b
);
894 RecordStateTable state
;
895 desktop
.GetRecordStateTable(id
, state
);
896 cout
<< "Record state table for: " << *b
<< endl
;
902 // Get Record mode overrides the default name mode
903 if( stCommands
.size() ) {
904 if( dbNames
.size() != 1 ) {
905 cout
<< "Must have 1 db name to process" << endl
;
909 unsigned int id
= desktop
.GetDBID(dbNames
[0]);
910 shared_ptr
<Parser
> parse
= GetParser(dbNames
[0],filename
,
911 null_parser
, true, vformat_mode
, bbackup_mode
);
913 for( unsigned int i
= 0; i
< stCommands
.size(); i
++ ) {
914 desktop
.GetRecord(id
, stCommands
[i
].index
, *parse
.get());
916 if( stCommands
[i
].flag
== 'r' && stCommands
[i
].clear
) {
917 cout
<< "Clearing record's dirty flags..." << endl
;
918 desktop
.ClearDirty(id
, stCommands
[i
].index
);
921 if( stCommands
[i
].flag
== 'D' ) {
922 desktop
.DeleteRecord(id
, stCommands
[i
].index
);
929 // Dump contents of selected databases to stdout, or
930 // to file if specified.
931 // This is retrieving data from the Blackberry.
932 if( dbNames
.size() ) {
933 vector
<string
>::iterator b
= dbNames
.begin();
935 for( ; b
!= dbNames
.end(); b
++ ) {
936 shared_ptr
<Parser
> parse
= GetParser(*b
,
937 filename
, null_parser
, !sort_records
,
938 vformat_mode
, bbackup_mode
);
939 unsigned int id
= desktop
.GetDBID(*b
);
940 desktop
.LoadDatabase(id
, *parse
.get());
945 if( clear_database
) {
946 if( clearDbNames
.size() == 0 ) {
947 cout
<< "No db names to erase" << endl
;
951 vector
<string
>::iterator b
= clearDbNames
.begin();
953 for( ; b
!= clearDbNames
.end(); b
++ ) {
954 unsigned int id
= desktop
.GetDBID(*b
);
955 cout
<< "Deleting all records from " << (*b
) << "..." << endl
;
956 desktop
.ClearDatabase(id
);
962 // Save contents of file to specified databases
963 // This is writing data to the Blackberry.
964 if( saveDbNames
.size() ) {
965 vector
<string
>::iterator b
= saveDbNames
.begin();
967 for( ; b
!= saveDbNames
.end(); b
++ ) {
968 shared_ptr
<Builder
> build
= GetBuilder(*b
,
970 unsigned int id
= desktop
.GetDBID(*b
);
971 desktop
.SaveDatabase(id
, *build
);
976 catch( Usb::Error
&ue
) {
977 std::cerr
<< "Usb::Error caught: " << ue
.what() << endl
;
980 catch( Barry::Error
&se
) {
981 std::cerr
<< "Barry::Error caught: " << se
.what() << endl
;
984 catch( std::exception
&e
) {
985 std::cerr
<< "std::exception caught: " << e
.what() << endl
;