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>
40 using namespace std::tr1
;
41 using namespace Barry
;
46 const char *Version
= Barry::Version(major
, minor
);
49 << "btool - Command line USB Blackberry Test Tool\n"
50 << " Copyright 2005-2010, Net Direct Inc. (http://www.netdirect.ca/)\n"
51 << " Using: " << Version
<< "\n"
53 #ifdef __BARRY_BOOST_MODE__
60 << " -B bus Specify which USB bus to search on\n"
61 << " -N dev Specify which system device, using system specific string\n"
63 << " -a db Erase / clear database 'db' FROM device, deleting all\n"
64 << " its records. Can be used multiple times to clear more\n"
66 << " -c dn Convert address book database to LDIF format, using the\n"
67 << " specified baseDN\n"
68 << " -C dnattr LDIF attribute name to use when building the FQDN\n"
69 << " Defaults to 'cn'\n"
70 << " -d db Load database 'db' FROM device and dump to screen\n"
71 << " Can be used multiple times to fetch more than one DB\n"
72 << " -e epp Override endpoint pair detection. 'epp' is a single\n"
73 << " string separated by a comma, holding the read,write\n"
74 << " endpoint pair. Example: -e 83,5\n"
75 << " Note: Endpoints are specified in hex.\n"
76 << " You should never need to use this option.\n"
77 #ifdef __BARRY_BOOST_MODE__
78 << " -f file Filename to save or load handheld data to/from\n"
81 << " -i cs International charset for string conversions\n"
82 << " Valid values here are available with 'iconv --list'\n"
83 << " -I Sort records before output\n"
84 << " -l List devices\n"
85 << " -L List Contact field names\n"
86 << " -m Map LDIF name to Contact field / Unmap LDIF name\n"
87 << " Map: ldif,read,write - maps ldif to read/write Contact fields\n"
88 << " Unmap: ldif name alone\n"
89 << " -M List current LDIF mapping\n"
90 << " -n Use null parser on all databases.\n"
91 << " -p pin PIN of device to talk with\n"
92 << " If only one device is plugged in, this flag is optional\n"
93 << " -P pass Simplistic method to specify device password\n"
94 << " -s db Save database 'db' TO device from data loaded from -f file\n"
95 << " -S Show list of supported database parsers\n"
96 << " -t Show database database table\n"
97 << " -T db Show record state table for given database\n"
98 << " -v Dump protocol data during operation\n"
99 #ifdef __BARRY_SYNC_MODE__
100 << " -V Dump records using MIME vformats where possible\n"
102 << " -X Reset device\n"
103 << " -z Use non-threaded sockets\n"
104 << " -Z Use threaded socket router (default)\n"
106 << " -d Command modifiers: (can be used multiple times for more than 1 record)\n"
108 << " -r # Record index number as seen in the -T state table.\n"
109 << " This overrides the default -d behaviour, and only\n"
110 << " downloads the one specified record, sending to stdout.\n"
111 << " -R # Same as -r, but also clears the record's dirty flags.\n"
112 << " -D # Record index number as seen in the -T state table,\n"
113 << " which indicates the record to delete. Used with the -d\n"
114 << " command to specify the database.\n"
121 Barry::ContactLdif
&ldif
;
123 Contact2Ldif(Barry::ContactLdif
&ldif
) : ldif(ldif
) {}
125 void operator()(const Contact
&rec
)
127 ldif
.DumpLdif(cout
, rec
);
131 #ifdef __BARRY_SYNC_MODE__
132 template <class Record
>
136 void Dump(std::ostream
&os
, const Record
&rec
)
141 static bool Supported() { return false; }
145 class MimeDump
<Contact
>
148 void Dump(std::ostream
&os
, const Contact
&rec
)
151 os
<< vcard
.ToVCard(rec
) << endl
;
154 static bool Supported() { return true; }
158 class MimeDump
<Calendar
>
161 void Dump(std::ostream
&os
, const Calendar
&rec
)
163 Sync::vTimeConverter vtc
;
164 Sync::vCalendar
vcal(vtc
);
165 os
<< vcal
.ToVCal(rec
) << endl
;
168 static bool Supported() { return true; }
175 void Dump(std::ostream
&os
, const Memo
&rec
)
177 Sync::vJournal vjournal
;
178 os
<< vjournal
.ToMemo(rec
) << endl
;
181 static bool Supported() { return true; }
188 void Dump(std::ostream
&os
, const Task
&rec
)
190 Sync::vTimeConverter vtc
;
191 Sync::vTodo
vtodo(vtc
);
192 os
<< vtodo
.ToTask(rec
) << endl
;
195 static bool Supported() { return true; }
199 template <class Record
>
202 std::vector
<Record
> records
;
203 mutable typename
std::vector
<Record
>::const_iterator rec_it
;
204 std::string filename
;
206 bool immediate_display
;
210 Store(const string
&filename
, bool load
, bool immediate_display
,
212 : rec_it(records
.end()),
215 immediate_display(immediate_display
),
216 vformat_mode(vformat_mode
),
219 #ifdef __BARRY_BOOST_MODE__
222 if( load
&& filename
.size() ) {
223 // filename is available, attempt to load
224 cout
<< "Loading: " << filename
<< endl
;
225 ifstream
ifs(filename
.c_str());
227 getline(ifs
, dbName
);
228 boost::archive::text_iarchive
ia(ifs
);
230 cout
<< records
.size()
231 << " records loaded from '"
232 << filename
<< "'" << endl
;
233 sort(records
.begin(), records
.end());
234 rec_it
= records
.begin();
237 typename
std::vector
<Record
>::const_iterator beg
= records
.begin(), end
= records
.end();
238 for( ; beg
!= end
; beg
++ ) {
239 cout
<< (*beg
) << endl
;
243 } catch( boost::archive::archive_exception
&ae
) {
244 cerr
<< "Archive exception in ~Store(): "
245 << ae
.what() << endl
;
252 if( !immediate_display
) {
253 // not dumped yet, sort then dump
254 sort(records
.begin(), records
.end());
258 cout
<< "Store counted " << dec
<< count
<< " records." << endl
;
259 #ifdef __BARRY_BOOST_MODE__
262 if( !load
&& filename
.size() ) {
263 // filename is available, attempt to save
264 cout
<< "Saving: " << filename
<< endl
;
265 const std::vector
<Record
> &r
= records
;
266 ofstream
ofs(filename
.c_str());
267 ofs
<< Record::GetDBName() << endl
;
268 boost::archive::text_oarchive
oa(ofs
);
270 cout
<< dec
<< r
.size() << " records saved to '"
271 << filename
<< "'" << endl
;
274 } catch( boost::archive::archive_exception
&ae
) {
275 cerr
<< "Archive exception in ~Store(): "
276 << ae
.what() << endl
;
283 typename vector
<Record
>::const_iterator i
= records
.begin();
284 for( ; i
!= records
.end(); ++i
) {
289 void Dump(const Record
&rec
)
292 #ifdef __BARRY_SYNC_MODE__
303 void operator()(const Record
&rec
)
306 if( immediate_display
)
308 records
.push_back(rec
);
311 // retrieval operator
312 bool operator()(Record
&rec
, Builder
&builder
) const
314 if( rec_it
== records
.end() )
322 class DataDumpParser
: public Barry::Parser
327 virtual void Clear() {}
329 virtual void SetIds(const std::string
&DbName
,
330 uint8_t RecType
, uint32_t UniqueId
)
335 virtual void ParseHeader(const Data
&, size_t &) {}
337 virtual void ParseFields(const Barry::Data
&data
, size_t &offset
,
338 const IConverter
*ic
)
340 std::cout
<< "Raw record dump for record: "
341 << std::hex
<< m_id
<< std::endl
;
342 std::cout
<< data
<< std::endl
;
345 virtual void Store() {}
348 shared_ptr
<Parser
> GetParser(const string
&name
,
349 const string
&filename
,
351 bool immediate_display
,
354 bool dnow
= immediate_display
;
355 bool vmode
= vformat_mode
;
359 return shared_ptr
<Parser
>( new DataDumpParser
);
361 // check for recognized database names
362 else if( name
== Contact::GetDBName() ) {
363 return shared_ptr
<Parser
>(
364 new RecordParser
<Contact
, Store
<Contact
> > (
365 new Store
<Contact
>(filename
, false, dnow
, vmode
)));
367 else if( name
== Message::GetDBName() ) {
368 return shared_ptr
<Parser
>(
369 new RecordParser
<Message
, Store
<Message
> > (
370 new Store
<Message
>(filename
, false, dnow
, vmode
)));
372 else if( name
== Calendar::GetDBName() ) {
373 return shared_ptr
<Parser
>(
374 new RecordParser
<Calendar
, Store
<Calendar
> > (
375 new Store
<Calendar
>(filename
, false, dnow
, vmode
)));
377 else if( name
== CalendarAll::GetDBName() ) {
378 return shared_ptr
<Parser
>(
379 new RecordParser
<CalendarAll
, Store
<CalendarAll
> > (
380 new Store
<CalendarAll
>(filename
, false, dnow
, vmode
)));
382 else if( name
== CallLog::GetDBName() ) {
383 return shared_ptr
<Parser
>(
384 new RecordParser
<CallLog
, Store
<CallLog
> > (
385 new Store
<CallLog
>(filename
, false, dnow
, vmode
)));
387 else if( name
== ServiceBook::GetDBName() ) {
388 return shared_ptr
<Parser
>(
389 new RecordParser
<ServiceBook
, Store
<ServiceBook
> > (
390 new Store
<ServiceBook
>(filename
, false, dnow
, vmode
)));
393 else if( name
== Memo::GetDBName() ) {
394 return shared_ptr
<Parser
>(
395 new RecordParser
<Memo
, Store
<Memo
> > (
396 new Store
<Memo
>(filename
, false, dnow
, vmode
)));
398 else if( name
== Task::GetDBName() ) {
399 return shared_ptr
<Parser
>(
400 new RecordParser
<Task
, Store
<Task
> > (
401 new Store
<Task
>(filename
, false, dnow
, vmode
)));
403 else if( name
== PINMessage::GetDBName() ) {
404 return shared_ptr
<Parser
>(
405 new RecordParser
<PINMessage
, Store
<PINMessage
> > (
406 new Store
<PINMessage
>(filename
, false, dnow
, vmode
)));
408 else if( name
== SavedMessage::GetDBName() ) {
409 return shared_ptr
<Parser
>(
410 new RecordParser
<SavedMessage
, Store
<SavedMessage
> > (
411 new Store
<SavedMessage
>(filename
, false, dnow
, vmode
)));
413 else if( name
== Sms::GetDBName() ) {
414 return shared_ptr
<Parser
>(
415 new RecordParser
<Sms
, Store
<Sms
> > (
416 new Store
<Sms
>(filename
, false, dnow
, vmode
)));
418 else if( name
== Folder::GetDBName() ) {
419 return shared_ptr
<Parser
>(
420 new RecordParser
<Folder
, Store
<Folder
> > (
421 new Store
<Folder
>(filename
, false, dnow
, vmode
)));
423 else if( name
== Timezone::GetDBName() ) {
424 return shared_ptr
<Parser
>(
425 new RecordParser
<Timezone
, Store
<Timezone
> > (
426 new Store
<Timezone
>(filename
, false, dnow
, vmode
)));
429 // unknown database, use null parser
430 return shared_ptr
<Parser
>( new DataDumpParser
);
434 shared_ptr
<Builder
> GetBuilder(const string
&name
, const string
&filename
)
436 // check for recognized database names
437 if( name
== Contact::GetDBName() ) {
438 return shared_ptr
<Builder
>(
439 new RecordBuilder
<Contact
, Store
<Contact
> > (
440 new Store
<Contact
>(filename
, true, true, false)));
442 else if( name
== Calendar::GetDBName() ) {
443 return shared_ptr
<Builder
>(
444 new RecordBuilder
<Calendar
, Store
<Calendar
> > (
445 new Store
<Calendar
>(filename
, true, true, false)));
447 else if( name
== CalendarAll::GetDBName() ) {
448 return shared_ptr
<Builder
>(
449 new RecordBuilder
<CalendarAll
, Store
<CalendarAll
> > (
450 new Store
<CalendarAll
>(filename
, true, true, false)));
452 else if( name
== Memo::GetDBName() ) {
453 return shared_ptr
<Builder
>(
454 new RecordBuilder
<Memo
, Store
<Memo
> > (
455 new Store
<Memo
>(filename
, true, true, false)));
457 else if( name
== Task::GetDBName() ) {
458 return shared_ptr
<Builder
>(
459 new RecordBuilder
<Task
, Store
<Task
> > (
460 new Store
<Task
>(filename
, true, true, false)));
463 else if( name == "Messages" ) {
464 return shared_ptr<Parser>(
465 new RecordParser<Message, Store<Message> > (
466 new Store<Message>(filename, true, true, false)));
468 else if( name == "Service Book" ) {
469 return shared_ptr<Parser>(
470 new RecordParser<ServiceBook, Store<ServiceBook> > (
471 new Store<ServiceBook>(filename, true, true, false)));
475 throw std::runtime_error("No Builder available for database");
481 cout
<< "Supported Database parsers:\n"
482 << " (* = can display in vformat MIME mode)\n"
483 << " Address Book *\n"
486 << " Calendar - All *\n"
487 << " Phone Call Logs\n"
492 << " Saved Email Messages\n"
495 << " Time Zones (read only)\n"
497 << "Supported Database builders:\n"
500 << " Calendar - All\n"
506 struct StateTableCommand
512 StateTableCommand(char f
, bool c
, unsigned int i
)
513 : flag(f
), clear(c
), index(i
) {}
516 bool SplitMap(const string
&map
, string
&ldif
, string
&read
, string
&write
)
518 string::size_type a
= map
.find(',');
519 if( a
== string::npos
)
522 string::size_type b
= map
.find(',', a
+1);
523 if( b
== string::npos
)
526 ldif
.assign(map
, 0, a
);
527 read
.assign(map
, a
+ 1, b
- a
- 1);
528 write
.assign(map
, b
+ 1, map
.size() - b
- 1);
530 return ldif
.size() && read
.size() && write
.size();
533 void DoMapping(ContactLdif
&ldif
, const vector
<string
> &mapCommands
)
535 for( vector
<string
>::const_iterator i
= mapCommands
.begin();
536 i
!= mapCommands
.end();
539 // single names mean unmapping
540 if( i
->find(',') == string::npos
) {
542 cerr
<< "Unmapping: " << *i
<< endl
;
546 cerr
<< "Mapping: " << *i
<< endl
;
548 // map... extract ldif/read/write names
549 string ldifname
, read
, write
;
550 if( SplitMap(*i
, ldifname
, read
, write
) ) {
551 if( !ldif
.Map(ldifname
, read
, write
) ) {
552 cerr
<< "Read/Write name unknown: " << *i
<< endl
;
556 cerr
<< "Invalid map format: " << *i
<< endl
;
562 bool ParseEpOverride(const char *arg
, Usb::EndpointPair
*epp
)
566 istringstream
iss(arg
);
567 iss
>> hex
>> read
>> comma
>> write
;
575 int main(int argc
, char *argv
[])
579 cout
.sync_with_stdio(true); // leave this on, since libusb uses
580 // stdio for debug messages
585 bool list_only
= false,
587 ldif_contacts
= false,
589 vformat_mode
= false,
590 reset_device
= false,
591 list_contact_fields
= false,
592 list_ldif_map
= false,
593 epp_override
= false,
594 threaded_sockets
= true,
595 record_state
= false,
596 clear_database
= false,
598 sort_records
= false;
599 string ldifBaseDN
, ldifDnAttr
;
605 vector
<string
> dbNames
, saveDbNames
, mapCommands
, clearDbNames
;
606 vector
<StateTableCommand
> stCommands
;
607 Usb::EndpointPair epOverride
;
609 // process command line options
611 int cmd
= getopt(argc
, argv
, "a:B:c:C:d:D:e:f:hi:IlLm:MnN:p:P:r:R:Ss:tT:vVXzZ");
617 case 'a': // Clear Database
618 clear_database
= true;
619 clearDbNames
.push_back(string(optarg
));
626 case 'c': // contacts to ldap ldif
627 ldif_contacts
= true;
631 case 'C': // DN Attribute for FQDN
635 case 'd': // show dbname
636 dbNames
.push_back(string(optarg
));
639 case 'D': // delete record
640 stCommands
.push_back(
641 StateTableCommand('D', false, atoi(optarg
)));
644 case 'e': // endpoint override
645 if( !ParseEpOverride(optarg
, &epOverride
) ) {
652 case 'f': // filename
653 #ifdef __BARRY_BOOST_MODE__
656 cerr
<< "-f option not supported - no Boost "
657 "serialization support available\n";
662 case 'i': // international charset (iconv)
663 iconvCharset
= optarg
;
666 case 'I': // sort before dump
670 case 'l': // list only
674 case 'L': // List Contact field names
675 list_contact_fields
= true;
678 case 'm': // Map / Unmap
679 mapCommands
.push_back(string(optarg
));
682 case 'M': // List LDIF map
683 list_ldif_map
= true;
686 case 'n': // use null parser
694 case 'p': // Blackberry PIN
695 pin
= strtoul(optarg
, NULL
, 16);
698 case 'P': // Device password
702 case 'r': // get specific record index
703 stCommands
.push_back(
704 StateTableCommand('r', false, atoi(optarg
)));
707 case 'R': // same as 'r', and clears dirty
708 stCommands
.push_back(
709 StateTableCommand('r', true, atoi(optarg
)));
712 case 's': // save dbname
713 saveDbNames
.push_back(string(optarg
));
716 case 'S': // show supported databases
720 case 't': // display database database
724 case 'T': // show RecordStateTable
726 dbNames
.push_back(string(optarg
));
729 case 'v': // data dump on
733 case 'V': // vformat MIME mode
734 #ifdef __BARRY_SYNC_MODE__
737 cerr
<< "-V option not supported - no Sync "
738 "library support available\n";
743 case 'X': // reset device
747 case 'z': // non-threaded sockets
748 threaded_sockets
= false;
751 case 'Z': // threaded socket router
752 threaded_sockets
= true;
762 // Initialize the barry library. Must be called before
764 Barry::Init(data_dump
);
767 const char *Version
= Barry::Version(major
, minor
);
768 cout
<< Version
<< endl
;
771 // Create an IConverter object if needed
772 auto_ptr
<IConverter
> ic
;
773 if( iconvCharset
.size() ) {
774 ic
.reset( new IConverter(iconvCharset
.c_str(), true) );
777 // LDIF class... only needed if ldif output turned on
778 ContactLdif
ldif(ldifBaseDN
);
779 DoMapping(ldif
, mapCommands
);
780 if( ldifDnAttr
.size() ) {
781 if( !ldif
.SetDNAttr(ldifDnAttr
) ) {
782 cerr
<< "Unable to set DN Attr: " << ldifDnAttr
<< endl
;
786 // Probe the USB bus for Blackberry devices and display.
787 // If user has specified a PIN, search for it in the
788 // available device list here as well
789 Barry::Probe
probe(busname
.c_str(), devname
.c_str(),
790 epp_override
? &epOverride
: 0);
791 int activeDevice
= -1;
793 // show any errors during probe first
794 if( probe
.GetFailCount() ) {
797 cout
<< "Blackberry device errors with errors during probe:" << endl
;
798 for( int i
= 0; i
< probe
.GetFailCount(); i
++ ) {
801 cout
<< probe
.GetFailMsg(i
) << endl
;
805 // show all successfully found devices
808 cout
<< "Blackberry devices found:" << endl
;
809 for( int i
= 0; i
< probe
.GetCount(); i
++ ) {
813 probe
.Get(i
).DumpAll(cout
);
815 cout
<< probe
.Get(i
);
817 if( probe
.Get(i
).m_pin
== pin
)
824 if( activeDevice
== -1 ) {
826 // can we default to single device?
827 if( probe
.GetCount() == 1 )
830 cerr
<< "No device selected" << endl
;
835 cerr
<< "PIN " << setbase(16) << pin
836 << " not found" << endl
;
843 cout
<< "Using device (PIN): "
844 << probe
.Get(activeDevice
).m_pin
.str() << endl
;
847 Usb::Device
dev(probe
.Get(activeDevice
).m_dev
);
852 // Override device endpoints if user asks
853 Barry::ProbeResult device
= probe
.Get(activeDevice
);
855 device
.m_ep
.read
= epOverride
.read
;
856 device
.m_ep
.write
= epOverride
.write
;
857 device
.m_ep
.type
= 2; // FIXME - override this too?
858 cout
<< "Endpoint pair (read,write) overridden with: "
860 << (unsigned int) device
.m_ep
.read
<< ","
861 << (unsigned int) device
.m_ep
.write
<< endl
;
865 // Create our controller object
867 // Order is important in the following auto_ptr<> objects,
868 // since Controller must get destroyed before router.
869 // Normally you'd pick one method, and not bother
870 // with auto_ptr<> and so the normal C++ constructor
871 // rules would guarantee this safety for you, but
872 // here we want the user to pick.
874 auto_ptr
<SocketRoutingQueue
> router
;
875 auto_ptr
<Barry::Controller
> pcon
;
876 if( threaded_sockets
) {
877 router
.reset( new SocketRoutingQueue
);
878 router
->SpinoffSimpleReadThread();
879 pcon
.reset( new Barry::Controller(device
, *router
) );
882 pcon
.reset( new Barry::Controller(device
) );
885 Barry::Controller
&con
= *pcon
;
886 Barry::Mode::Desktop
desktop(con
, *ic
);
889 // execute each mode that was turned on
893 // Dump list of all databases to stdout
895 // open desktop mode socket
896 desktop
.Open(password
.c_str());
897 cout
<< desktop
.GetDBDB() << endl
;
900 // Dump list of Contact field names
901 if( list_contact_fields
) {
902 for( const ContactLdif::NameToFunc
*n
= ldif
.GetFieldNames(); n
->name
; n
++ ) {
904 cout
<< " " << left
<< setw(20) << n
->name
<< ": "
905 << n
->description
<< endl
;
909 // Dump current LDIF mapping
910 if( list_ldif_map
) {
911 cout
<< ldif
<< endl
;
914 // Dump list of contacts to an LDAP LDIF file
915 // This uses the Controller convenience templates
916 if( ldif_contacts
) {
917 // make sure we're in desktop mode
918 desktop
.Open(password
.c_str());
920 // create a storage functor object that accepts
921 // Barry::Contact objects as input
922 Contact2Ldif
storage(ldif
);
924 // load all the Contact records into storage
925 desktop
.LoadDatabaseByType
<Barry::Contact
>(storage
);
928 // Dump record state table to stdout
930 if( dbNames
.size() == 0 ) {
931 cout
<< "No db names to process" << endl
;
935 desktop
.Open(password
.c_str());
937 vector
<string
>::iterator b
= dbNames
.begin();
938 for( ; b
!= dbNames
.end(); b
++ ) {
939 unsigned int id
= desktop
.GetDBID(*b
);
940 RecordStateTable state
;
941 desktop
.GetRecordStateTable(id
, state
);
942 cout
<< "Record state table for: " << *b
<< endl
;
948 // Get Record mode overrides the default name mode
949 if( stCommands
.size() ) {
950 if( dbNames
.size() != 1 ) {
951 cout
<< "Must have 1 db name to process" << endl
;
955 desktop
.Open(password
.c_str());
956 unsigned int id
= desktop
.GetDBID(dbNames
[0]);
957 shared_ptr
<Parser
> parse
= GetParser(dbNames
[0],filename
,
958 null_parser
, true, vformat_mode
);
960 for( unsigned int i
= 0; i
< stCommands
.size(); i
++ ) {
961 desktop
.GetRecord(id
, stCommands
[i
].index
, *parse
.get());
963 if( stCommands
[i
].flag
== 'r' && stCommands
[i
].clear
) {
964 cout
<< "Clearing record's dirty flags..." << endl
;
965 desktop
.ClearDirty(id
, stCommands
[i
].index
);
968 if( stCommands
[i
].flag
== 'D' ) {
969 desktop
.DeleteRecord(id
, stCommands
[i
].index
);
977 if (clear_database
) {
978 if( clearDbNames
.size() == 0 ) {
979 cout
<< "No db names to erase" << endl
;
983 vector
<string
>::iterator b
= clearDbNames
.begin();
985 desktop
.Open(password
.c_str());
987 for( ; b
!= clearDbNames
.end(); b
++ ) {
988 unsigned int id
= desktop
.GetDBID(*b
);
989 cout
<< "Deleting all records from " << (*b
) << "..." << endl
;
990 desktop
.ClearDatabase(id
);
996 // Dump contents of selected databases to stdout, or
997 // to file if specified.
998 // This is retrieving data from the Blackberry.
999 if( dbNames
.size() ) {
1000 vector
<string
>::iterator b
= dbNames
.begin();
1002 desktop
.Open(password
.c_str());
1003 for( ; b
!= dbNames
.end(); b
++ ) {
1004 shared_ptr
<Parser
> parse
= GetParser(*b
,filename
,
1005 null_parser
, !sort_records
,
1007 unsigned int id
= desktop
.GetDBID(*b
);
1008 desktop
.LoadDatabase(id
, *parse
.get());
1012 // Save contents of file to specified databases
1013 // This is writing data to the Blackberry.
1014 if( saveDbNames
.size() ) {
1015 vector
<string
>::iterator b
= saveDbNames
.begin();
1017 desktop
.Open(password
.c_str());
1018 for( ; b
!= saveDbNames
.end(); b
++ ) {
1019 shared_ptr
<Builder
> build
=
1020 GetBuilder(*b
, filename
);
1021 unsigned int id
= desktop
.GetDBID(*b
);
1022 desktop
.SaveDatabase(id
, *build
);
1027 catch( Usb::Error
&ue
) {
1028 std::cerr
<< "Usb::Error caught: " << ue
.what() << endl
;
1031 catch( Barry::Error
&se
) {
1032 std::cerr
<< "Barry::Error caught: " << se
.what() << endl
;
1035 catch( std::exception
&e
) {
1036 std::cerr
<< "std::exception caught: " << e
.what() << endl
;