3 /// Barry library tester
7 Copyright (C) 2005-2011, 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>
45 using namespace std::tr1
;
46 using namespace Barry
;
50 int logical
, major
, minor
;
51 const char *Version
= Barry::Version(logical
, major
, minor
);
54 << "btool - Command line USB Blackberry Test Tool\n"
55 << " Copyright 2005-2011, Net Direct Inc. (http://www.netdirect.ca/)\n"
56 << " Using: " << Version
<< "\n"
58 #ifdef __BARRY_BOOST_MODE__
65 << " -b file Filename to save or load a Barry Backup to (tar.gz)\n"
66 << " -B bus Specify which USB bus to search on\n"
67 << " -N dev Specify which system device, using system specific string\n"
69 << " -a db Erase / clear database 'db' FROM device, deleting all\n"
70 << " its records. Can be used multiple times to clear more\n"
72 << " -c dn Convert address book database to LDIF format, using the\n"
73 << " specified baseDN\n"
74 << " -C dnattr LDIF attribute name to use when building the FQDN\n"
75 << " Defaults to 'cn'\n"
76 << " -d db Load database 'db' FROM device and dump to screen\n"
77 << " Can be used multiple times to fetch more than one DB\n"
78 << " -e epp Override endpoint pair detection. 'epp' is a single\n"
79 << " string separated by a comma, holding the read,write\n"
80 << " endpoint pair. Example: -e 83,5\n"
81 << " Note: Endpoints are specified in hex.\n"
82 << " You should never need to use this option.\n"
83 #ifdef __BARRY_BOOST_MODE__
84 << " -f file Filename to save or load handheld data to/from\n"
87 << " -i cs International charset for string conversions\n"
88 << " Valid values here are available with 'iconv --list'\n"
89 << " -I Sort records before output\n"
90 << " -l List devices\n"
91 << " -L List Contact field names\n"
92 << " -m Map LDIF name to Contact field / Unmap LDIF name\n"
93 << " Map: ldif,read,write - maps ldif to read/write Contact fields\n"
94 << " Unmap: ldif name alone\n"
95 << " -M List current LDIF mapping\n"
96 << " -n Use null parser on all databases.\n"
97 << " -p pin PIN of device to talk with\n"
98 << " If only one device is plugged in, this flag is optional\n"
99 << " -P pass Simplistic method to specify device password\n"
100 << " -s db Save database 'db' TO device from data loaded from -f file\n"
101 << " -S Show list of supported database parsers\n"
102 << " -t Show database database table\n"
103 << " -T db Show record state table for given database\n"
104 << " -v Dump protocol data during operation\n"
105 #ifdef __BARRY_SYNC_MODE__
106 << " -V Dump records using MIME vformats where possible\n"
108 << " -X Reset device\n"
109 << " -z Use non-threaded sockets\n"
110 << " -Z Use threaded socket router (default)\n"
112 << " -d Command modifiers: (can be used multiple times for more than 1 record)\n"
114 << " -r # Record index number as seen in the -T state table.\n"
115 << " This overrides the default -d behaviour, and only\n"
116 << " downloads the one specified record, sending to stdout.\n"
117 << " -R # Same as -r, but also clears the record's dirty flags.\n"
118 << " -D # Record index number as seen in the -T state table,\n"
119 << " which indicates the record to delete. Used with the -d\n"
120 << " command to specify the database.\n"
127 Barry::ContactLdif
&ldif
;
129 Contact2Ldif(Barry::ContactLdif
&ldif
) : ldif(ldif
) {}
131 void operator()(const Contact
&rec
)
133 ldif
.DumpLdif(cout
, rec
);
137 template <class Record
>
140 std::vector
<Record
> records
;
141 mutable typename
std::vector
<Record
>::const_iterator rec_it
;
142 std::string filename
;
144 bool immediate_display
;
148 Store(const string
&filename
, bool load
, bool immediate_display
,
150 : rec_it(records
.end()),
153 immediate_display(immediate_display
),
154 vformat_mode(vformat_mode
),
157 #ifdef __BARRY_BOOST_MODE__
160 if( load
&& filename
.size() ) {
161 // filename is available, attempt to load
162 cout
<< "Loading: " << filename
<< endl
;
163 ifstream
ifs(filename
.c_str());
165 getline(ifs
, dbName
);
166 boost::archive::text_iarchive
ia(ifs
);
168 cout
<< records
.size()
169 << " records loaded from '"
170 << filename
<< "'" << endl
;
171 sort(records
.begin(), records
.end());
172 rec_it
= records
.begin();
175 typename
std::vector
<Record
>::const_iterator beg
= records
.begin(), end
= records
.end();
176 for( ; beg
!= end
; beg
++ ) {
177 cout
<< (*beg
) << endl
;
181 } catch( boost::archive::archive_exception
&ae
) {
182 cerr
<< "Archive exception in ~Store(): "
183 << ae
.what() << endl
;
190 if( !immediate_display
) {
191 // not dumped yet, sort then dump
192 sort(records
.begin(), records
.end());
196 cout
<< "Store counted " << dec
<< count
<< " records." << endl
;
197 #ifdef __BARRY_BOOST_MODE__
200 if( !load
&& filename
.size() ) {
201 // filename is available, attempt to save
202 cout
<< "Saving: " << filename
<< endl
;
203 const std::vector
<Record
> &r
= records
;
204 ofstream
ofs(filename
.c_str());
205 ofs
<< Record::GetDBName() << endl
;
206 boost::archive::text_oarchive
oa(ofs
);
208 cout
<< dec
<< r
.size() << " records saved to '"
209 << filename
<< "'" << endl
;
212 } catch( boost::archive::archive_exception
&ae
) {
213 cerr
<< "Archive exception in ~Store(): "
214 << ae
.what() << endl
;
221 typename vector
<Record
>::const_iterator i
= records
.begin();
222 for( ; i
!= records
.end(); ++i
) {
227 void Dump(const Record
&rec
)
230 #ifdef __BARRY_SYNC_MODE__
241 void operator()(const Record
&rec
)
244 if( immediate_display
)
246 records
.push_back(rec
);
249 // retrieval operator
250 bool operator()(Record
&rec
, Builder
&builder
) const
252 if( rec_it
== records
.end() )
260 shared_ptr
<Parser
> GetParser(const string
&name
,
261 const string
&filename
,
263 bool immediate_display
,
267 bool dnow
= immediate_display
;
268 bool vmode
= vformat_mode
;
272 return shared_ptr
<Parser
>( new Barry::HexDumpParser(cout
) );
274 else if( bbackup_mode
) {
275 #ifdef __BARRY_BACKUP_MODE__
276 // Only one backup file per run
277 static shared_ptr
<Parser
> backup
;
278 if( !backup
.get() ) {
279 backup
.reset( new Backup(filename
) );
283 return shared_ptr
<Parser
>( new Barry::HexDumpParser(cout
) );
286 // check for recognized database names
287 else if( name
== Contact::GetDBName() ) {
288 return shared_ptr
<Parser
>(
289 new RecordParser
<Contact
, Store
<Contact
> > (
290 new Store
<Contact
>(filename
, false, dnow
, vmode
)));
292 else if( name
== Message::GetDBName() ) {
293 return shared_ptr
<Parser
>(
294 new RecordParser
<Message
, Store
<Message
> > (
295 new Store
<Message
>(filename
, false, dnow
, vmode
)));
297 else if( name
== Calendar::GetDBName() ) {
298 return shared_ptr
<Parser
>(
299 new RecordParser
<Calendar
, Store
<Calendar
> > (
300 new Store
<Calendar
>(filename
, false, dnow
, vmode
)));
302 else if( name
== CalendarAll::GetDBName() ) {
303 return shared_ptr
<Parser
>(
304 new RecordParser
<CalendarAll
, Store
<CalendarAll
> > (
305 new Store
<CalendarAll
>(filename
, false, dnow
, vmode
)));
307 else if( name
== CallLog::GetDBName() ) {
308 return shared_ptr
<Parser
>(
309 new RecordParser
<CallLog
, Store
<CallLog
> > (
310 new Store
<CallLog
>(filename
, false, dnow
, vmode
)));
312 else if( name
== Bookmark::GetDBName() ) {
313 return shared_ptr
<Parser
>(
314 new RecordParser
<Bookmark
, Store
<Bookmark
> > (
315 new Store
<Bookmark
>(filename
, false, dnow
, vmode
)));
317 else if( name
== ServiceBook::GetDBName() ) {
318 return shared_ptr
<Parser
>(
319 new RecordParser
<ServiceBook
, Store
<ServiceBook
> > (
320 new Store
<ServiceBook
>(filename
, false, dnow
, vmode
)));
323 else if( name
== Memo::GetDBName() ) {
324 return shared_ptr
<Parser
>(
325 new RecordParser
<Memo
, Store
<Memo
> > (
326 new Store
<Memo
>(filename
, false, dnow
, vmode
)));
328 else if( name
== Task::GetDBName() ) {
329 return shared_ptr
<Parser
>(
330 new RecordParser
<Task
, Store
<Task
> > (
331 new Store
<Task
>(filename
, false, dnow
, vmode
)));
333 else if( name
== PINMessage::GetDBName() ) {
334 return shared_ptr
<Parser
>(
335 new RecordParser
<PINMessage
, Store
<PINMessage
> > (
336 new Store
<PINMessage
>(filename
, false, dnow
, vmode
)));
338 else if( name
== SavedMessage::GetDBName() ) {
339 return shared_ptr
<Parser
>(
340 new RecordParser
<SavedMessage
, Store
<SavedMessage
> > (
341 new Store
<SavedMessage
>(filename
, false, dnow
, vmode
)));
343 else if( name
== Sms::GetDBName() ) {
344 return shared_ptr
<Parser
>(
345 new RecordParser
<Sms
, Store
<Sms
> > (
346 new Store
<Sms
>(filename
, false, dnow
, vmode
)));
348 else if( name
== Folder::GetDBName() ) {
349 return shared_ptr
<Parser
>(
350 new RecordParser
<Folder
, Store
<Folder
> > (
351 new Store
<Folder
>(filename
, false, dnow
, vmode
)));
353 else if( name
== Timezone::GetDBName() ) {
354 return shared_ptr
<Parser
>(
355 new RecordParser
<Timezone
, Store
<Timezone
> > (
356 new Store
<Timezone
>(filename
, false, dnow
, vmode
)));
358 else if( name
== HandheldAgent::GetDBName() ) {
359 return shared_ptr
<Parser
>(
360 new RecordParser
<HandheldAgent
, Store
<HandheldAgent
> > (
361 new Store
<HandheldAgent
>(filename
, false, dnow
, vmode
)));
364 // unknown database, use null parser
365 return shared_ptr
<Parser
>( new Barry::HexDumpParser(cout
) );
369 shared_ptr
<Builder
> GetBuilder(const string
&name
, const string
&filename
)
371 // check for recognized database names
372 if( name
== Contact::GetDBName() ) {
373 return shared_ptr
<Builder
>(
374 new RecordBuilder
<Contact
, Store
<Contact
> > (
375 new Store
<Contact
>(filename
, true, true, false)));
377 else if( name
== Calendar::GetDBName() ) {
378 return shared_ptr
<Builder
>(
379 new RecordBuilder
<Calendar
, Store
<Calendar
> > (
380 new Store
<Calendar
>(filename
, true, true, false)));
382 else if( name
== CalendarAll::GetDBName() ) {
383 return shared_ptr
<Builder
>(
384 new RecordBuilder
<CalendarAll
, Store
<CalendarAll
> > (
385 new Store
<CalendarAll
>(filename
, true, true, false)));
387 else if( name
== Memo::GetDBName() ) {
388 return shared_ptr
<Builder
>(
389 new RecordBuilder
<Memo
, Store
<Memo
> > (
390 new Store
<Memo
>(filename
, true, true, false)));
392 else if( name
== Task::GetDBName() ) {
393 return shared_ptr
<Builder
>(
394 new RecordBuilder
<Task
, Store
<Task
> > (
395 new Store
<Task
>(filename
, true, true, false)));
398 else if( name == "Messages" ) {
399 return shared_ptr<Parser>(
400 new RecordParser<Message, Store<Message> > (
401 new Store<Message>(filename, true, true, false)));
403 else if( name == "Service Book" ) {
404 return shared_ptr<Parser>(
405 new RecordParser<ServiceBook, Store<ServiceBook> > (
406 new Store<ServiceBook>(filename, true, true, false)));
410 throw std::runtime_error("No Builder available for database");
416 cout
<< "Supported Database parsers:\n"
418 #ifdef __BARRY_SYNC_MODE__
419 << " (* = can display in vformat MIME mode)\n"
420 #define HANDLE_PARSER(tname) << " " << tname::GetDBName() << (MimeDump<tname>::Supported() ? " *" : "") << "\n"
423 #define HANDLE_PARSER(tname) << " " << tname::GetDBName() << "\n"
426 ALL_KNOWN_PARSER_TYPES
430 << "Supported Database builders:\n"
431 #undef HANDLE_BUILDER
432 #define HANDLE_BUILDER(tname) << " " << tname::GetDBName() << "\n"
433 ALL_KNOWN_BUILDER_TYPES
437 struct StateTableCommand
443 StateTableCommand(char f
, bool c
, unsigned int i
)
444 : flag(f
), clear(c
), index(i
) {}
447 bool SplitMap(const string
&map
, string
&ldif
, string
&read
, string
&write
)
449 string::size_type a
= map
.find(',');
450 if( a
== string::npos
)
453 string::size_type b
= map
.find(',', a
+1);
454 if( b
== string::npos
)
457 ldif
.assign(map
, 0, a
);
458 read
.assign(map
, a
+ 1, b
- a
- 1);
459 write
.assign(map
, b
+ 1, map
.size() - b
- 1);
461 return ldif
.size() && read
.size() && write
.size();
464 void DoMapping(ContactLdif
&ldif
, const vector
<string
> &mapCommands
)
466 for( vector
<string
>::const_iterator i
= mapCommands
.begin();
467 i
!= mapCommands
.end();
470 // single names mean unmapping
471 if( i
->find(',') == string::npos
) {
473 cerr
<< "Unmapping: " << *i
<< endl
;
477 cerr
<< "Mapping: " << *i
<< endl
;
479 // map... extract ldif/read/write names
480 string ldifname
, read
, write
;
481 if( SplitMap(*i
, ldifname
, read
, write
) ) {
482 if( !ldif
.Map(ldifname
, read
, write
) ) {
483 cerr
<< "Read/Write name unknown: " << *i
<< endl
;
487 cerr
<< "Invalid map format: " << *i
<< endl
;
493 bool ParseEpOverride(const char *arg
, Usb::EndpointPair
*epp
)
497 istringstream
iss(arg
);
498 iss
>> hex
>> read
>> comma
>> write
;
506 int main(int argc
, char *argv
[])
510 cout
.sync_with_stdio(true); // leave this on, since libusb uses
511 // stdio for debug messages
516 bool list_only
= false,
518 ldif_contacts
= false,
520 vformat_mode
= false,
521 reset_device
= false,
522 list_contact_fields
= false,
523 list_ldif_map
= false,
524 epp_override
= false,
525 threaded_sockets
= true,
526 record_state_table
= false,
527 clear_database
= false,
529 bbackup_mode
= false,
530 sort_records
= false;
531 string ldifBaseDN
, ldifDnAttr
;
537 vector
<string
> dbNames
, saveDbNames
, mapCommands
, clearDbNames
;
538 vector
<StateTableCommand
> stCommands
;
539 Usb::EndpointPair epOverride
;
541 // process command line options
543 int cmd
= getopt(argc
, argv
, "a:b:B:c:C:d:D:e:f:hi:IlLm:MnN:p:P:r:R:Ss:tT:vVXzZ");
549 case 'a': // Clear Database
550 clear_database
= true;
551 clearDbNames
.push_back(string(optarg
));
554 case 'b': // Barry backup filename (tar.gz)
555 #ifdef __BARRY_BACKUP_MODE__
556 if( filename
.size() == 0 ) {
561 cerr
<< "Do not use -f with -b\n";
565 cerr
<< "-b option not supported - no Barry "
566 "Backup library support available\n";
575 case 'c': // contacts to ldap ldif
576 ldif_contacts
= true;
580 case 'C': // DN Attribute for FQDN
584 case 'd': // show dbname
585 dbNames
.push_back(string(optarg
));
588 case 'D': // delete record
589 stCommands
.push_back(
590 StateTableCommand('D', false, atoi(optarg
)));
593 case 'e': // endpoint override
594 if( !ParseEpOverride(optarg
, &epOverride
) ) {
601 case 'f': // filename
602 #ifdef __BARRY_BOOST_MODE__
603 if( !bbackup_mode
&& filename
.size() == 0 ) {
607 cerr
<< "Do not use -f with -b\n";
611 cerr
<< "-f option not supported - no Boost "
612 "serialization support available\n";
617 case 'i': // international charset (iconv)
618 iconvCharset
= optarg
;
621 case 'I': // sort before dump
625 case 'l': // list only
629 case 'L': // List Contact field names
630 list_contact_fields
= true;
633 case 'm': // Map / Unmap
634 mapCommands
.push_back(string(optarg
));
637 case 'M': // List LDIF map
638 list_ldif_map
= true;
641 case 'n': // use null parser
649 case 'p': // Blackberry PIN
650 pin
= strtoul(optarg
, NULL
, 16);
653 case 'P': // Device password
657 case 'r': // get specific record index
658 stCommands
.push_back(
659 StateTableCommand('r', false, atoi(optarg
)));
662 case 'R': // same as 'r', and clears dirty
663 stCommands
.push_back(
664 StateTableCommand('r', true, atoi(optarg
)));
667 case 's': // save dbname
668 saveDbNames
.push_back(string(optarg
));
671 case 'S': // show supported databases
675 case 't': // display database database
679 case 'T': // show RecordStateTable
680 record_state_table
= true;
681 dbNames
.push_back(string(optarg
));
684 case 'v': // data dump on
688 case 'V': // vformat MIME mode
689 #ifdef __BARRY_SYNC_MODE__
692 cerr
<< "-V option not supported - no Sync "
693 "library support available\n";
698 case 'X': // reset device
702 case 'z': // non-threaded sockets
703 threaded_sockets
= false;
706 case 'Z': // threaded socket router
707 threaded_sockets
= true;
717 // Initialize the barry library. Must be called before
719 Barry::Init(data_dump
);
721 int logical
, major
, minor
;
722 const char *Version
= Barry::Version(logical
, major
, minor
);
723 cout
<< Version
<< endl
;
726 // Create an IConverter object if needed
727 auto_ptr
<IConverter
> ic
;
728 if( iconvCharset
.size() ) {
729 ic
.reset( new IConverter(iconvCharset
.c_str(), true) );
732 // LDIF class... only needed if ldif output turned on
733 ContactLdif
ldif(ldifBaseDN
);
734 DoMapping(ldif
, mapCommands
);
735 if( ldifDnAttr
.size() ) {
736 if( !ldif
.SetDNAttr(ldifDnAttr
) ) {
737 cerr
<< "Unable to set DN Attr: " << ldifDnAttr
<< endl
;
741 // Probe the USB bus for Blackberry devices and display.
742 // If user has specified a PIN, search for it in the
743 // available device list here as well
744 Barry::Probe
probe(busname
.c_str(), devname
.c_str(),
745 epp_override
? &epOverride
: 0);
746 int activeDevice
= -1;
748 // show any errors during probe first
749 if( probe
.GetFailCount() ) {
752 cout
<< "Blackberry device errors with errors during probe:" << endl
;
753 for( int i
= 0; i
< probe
.GetFailCount(); i
++ ) {
756 cout
<< probe
.GetFailMsg(i
) << endl
;
760 // show all successfully found devices
763 cout
<< "Blackberry devices found:" << endl
;
764 for( int i
= 0; i
< probe
.GetCount(); i
++ ) {
768 probe
.Get(i
).DumpAll(cout
);
770 cout
<< probe
.Get(i
);
772 if( probe
.Get(i
).m_pin
== pin
)
779 if( activeDevice
== -1 ) {
781 // can we default to single device?
782 if( probe
.GetCount() == 1 )
785 cerr
<< "No device selected" << endl
;
790 cerr
<< "PIN " << setbase(16) << pin
791 << " not found" << endl
;
798 cout
<< "Using device (PIN): "
799 << probe
.Get(activeDevice
).m_pin
.Str() << endl
;
802 Usb::Device
dev(probe
.Get(activeDevice
).m_dev
);
807 // Override device endpoints if user asks
808 Barry::ProbeResult device
= probe
.Get(activeDevice
);
810 device
.m_ep
.read
= epOverride
.read
;
811 device
.m_ep
.write
= epOverride
.write
;
812 // FIXME - override this too?
813 device
.m_ep
.type
= Usb::EndpointDescriptor::BulkType
;
814 cout
<< "Endpoint pair (read,write) overridden with: "
816 << (unsigned int) device
.m_ep
.read
<< ","
817 << (unsigned int) device
.m_ep
.write
<< endl
;
821 // execute each mode that was turned on
825 // Dump current LDIF mapping
826 if( list_ldif_map
) {
827 cout
<< ldif
<< endl
;
830 // Dump list of Contact field names
831 if( list_contact_fields
) {
832 for( const ContactLdif::NameToFunc
*n
= ldif
.GetFieldNames(); n
->name
; n
++ ) {
834 cout
<< " " << left
<< setw(20) << n
->name
<< ": "
835 << n
->description
<< endl
;
839 // Check if Desktop access is needed
842 record_state_table
||
846 saveDbNames
.size() ) )
850 // Create our controller object
852 // Order is important in the following auto_ptr<> objects,
853 // since Controller must get destroyed before router.
854 // Normally you'd pick one method, and not bother
855 // with auto_ptr<> and so the normal C++ constructor
856 // rules would guarantee this safety for you, but
857 // here we want the user to pick.
859 auto_ptr
<SocketRoutingQueue
> router
;
860 if( threaded_sockets
) {
861 router
.reset( new SocketRoutingQueue
);
862 router
->SpinoffSimpleReadThread();
865 DesktopConnector
connector(password
.c_str(),
866 iconvCharset
, device
, router
.get());
867 if( !connector
.Connect() ) {
868 // bad password (default action is not to prompt)
869 cerr
<< connector
.GetBadPassword().what() << endl
;
873 Barry::Mode::Desktop
&desktop
= connector
.GetDesktop();
875 // Dump list of all databases to stdout
877 // open desktop mode socket
878 cout
<< desktop
.GetDBDB() << endl
;
881 // Dump list of contacts to an LDAP LDIF file
882 // This uses the Controller convenience templates
883 if( ldif_contacts
) {
884 // create a storage functor object that accepts
885 // Barry::Contact objects as input
886 Contact2Ldif
storage(ldif
);
888 // load all the Contact records into storage
889 desktop
.LoadDatabaseByType
<Barry::Contact
>(storage
);
892 // Dump record state table to stdout
893 if( record_state_table
) {
894 if( dbNames
.size() == 0 ) {
895 cout
<< "No db names to process" << endl
;
899 vector
<string
>::iterator b
= dbNames
.begin();
900 for( ; b
!= dbNames
.end(); b
++ ) {
901 unsigned int id
= desktop
.GetDBID(*b
);
902 RecordStateTable state
;
903 desktop
.GetRecordStateTable(id
, state
);
904 cout
<< "Record state table for: " << *b
<< endl
;
910 // Get Record mode overrides the default name mode
911 if( stCommands
.size() ) {
912 if( dbNames
.size() != 1 ) {
913 cout
<< "Must have 1 db name to process" << endl
;
917 unsigned int id
= desktop
.GetDBID(dbNames
[0]);
918 shared_ptr
<Parser
> parse
= GetParser(dbNames
[0],filename
,
919 null_parser
, true, vformat_mode
, bbackup_mode
);
921 for( unsigned int i
= 0; i
< stCommands
.size(); i
++ ) {
922 desktop
.GetRecord(id
, stCommands
[i
].index
, *parse
.get());
924 if( stCommands
[i
].flag
== 'r' && stCommands
[i
].clear
) {
925 cout
<< "Clearing record's dirty flags..." << endl
;
926 desktop
.ClearDirty(id
, stCommands
[i
].index
);
929 if( stCommands
[i
].flag
== 'D' ) {
930 desktop
.DeleteRecord(id
, stCommands
[i
].index
);
937 // Dump contents of selected databases to stdout, or
938 // to file if specified.
939 // This is retrieving data from the Blackberry.
940 if( dbNames
.size() ) {
941 vector
<string
>::iterator b
= dbNames
.begin();
943 for( ; b
!= dbNames
.end(); b
++ ) {
944 shared_ptr
<Parser
> parse
= GetParser(*b
,
945 filename
, null_parser
, !sort_records
,
946 vformat_mode
, bbackup_mode
);
947 unsigned int id
= desktop
.GetDBID(*b
);
948 desktop
.LoadDatabase(id
, *parse
.get());
953 if( clear_database
) {
954 if( clearDbNames
.size() == 0 ) {
955 cout
<< "No db names to erase" << endl
;
959 vector
<string
>::iterator b
= clearDbNames
.begin();
961 for( ; b
!= clearDbNames
.end(); b
++ ) {
962 unsigned int id
= desktop
.GetDBID(*b
);
963 cout
<< "Deleting all records from " << (*b
) << "..." << endl
;
964 desktop
.ClearDatabase(id
);
970 // Save contents of file to specified databases
971 // This is writing data to the Blackberry.
972 if( saveDbNames
.size() ) {
973 vector
<string
>::iterator b
= saveDbNames
.begin();
975 for( ; b
!= saveDbNames
.end(); b
++ ) {
976 shared_ptr
<Builder
> build
= GetBuilder(*b
,
978 unsigned int id
= desktop
.GetDBID(*b
);
979 desktop
.SaveDatabase(id
, *build
);
984 catch( Usb::Error
&ue
) {
985 std::cerr
<< "Usb::Error caught: " << ue
.what() << endl
;
988 catch( Barry::Error
&se
) {
989 std::cerr
<< "Barry::Error caught: " << se
.what() << endl
;
992 catch( std::exception
&e
) {
993 std::cerr
<< "std::exception caught: " << e
.what() << endl
;