3 /// Barry library tester
7 Copyright (C) 2005-2012, 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>
42 #include "barrygetopt.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-2012, 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
;
146 int from_device_count
;
147 mutable int to_device_count
;
149 Store(const string
&filename
, bool load
, bool immediate_display
,
151 : rec_it(records
.end()),
154 immediate_display(immediate_display
),
155 vformat_mode(vformat_mode
),
156 from_device_count(0),
159 #ifdef __BARRY_BOOST_MODE__
162 if( load
&& filename
.size() ) {
163 // filename is available, attempt to load
164 cout
<< "Loading: " << filename
<< endl
;
165 ifstream
ifs(filename
.c_str());
167 getline(ifs
, dbName
);
168 boost::archive::text_iarchive
ia(ifs
);
170 cout
<< records
.size()
171 << " records loaded from '"
172 << filename
<< "'" << endl
;
173 sort(records
.begin(), records
.end());
174 rec_it
= records
.begin();
177 typename
std::vector
<Record
>::const_iterator beg
= records
.begin(), end
= records
.end();
178 for( ; beg
!= end
; beg
++ ) {
179 cout
<< (*beg
) << endl
;
183 } catch( boost::archive::archive_exception
&ae
) {
184 cerr
<< "Archive exception in ~Store(): "
185 << ae
.what() << endl
;
192 if( !immediate_display
) {
193 // not dumped yet, sort then dump
194 sort(records
.begin(), records
.end());
198 cout
<< "Store counted " << dec
<< from_device_count
<< " records read from device, and " << dec
<< to_device_count
<< " records written to device." << endl
;
199 #ifdef __BARRY_BOOST_MODE__
202 if( !load
&& filename
.size() ) {
203 // filename is available, attempt to save
204 cout
<< "Saving: " << filename
<< endl
;
205 const std::vector
<Record
> &r
= records
;
206 ofstream
ofs(filename
.c_str());
207 ofs
<< Record::GetDBName() << endl
;
208 boost::archive::text_oarchive
oa(ofs
);
210 cout
<< dec
<< r
.size() << " records saved to '"
211 << filename
<< "'" << endl
;
214 } catch( boost::archive::archive_exception
&ae
) {
215 cerr
<< "Archive exception in ~Store(): "
216 << ae
.what() << endl
;
223 typename vector
<Record
>::const_iterator i
= records
.begin();
224 for( ; i
!= records
.end(); ++i
) {
229 void Dump(const Record
&rec
)
232 #ifdef __BARRY_SYNC_MODE__
243 void operator()(const Record
&rec
)
246 if( immediate_display
)
248 records
.push_back(rec
);
251 // retrieval operator
252 bool operator()(Record
&rec
, Builder
&builder
) const
254 if( rec_it
== records
.end() )
263 shared_ptr
<Parser
> GetParser(const string
&name
,
264 const string
&filename
,
266 bool immediate_display
,
270 bool dnow
= immediate_display
;
271 bool vmode
= vformat_mode
;
275 return shared_ptr
<Parser
>( new Barry::HexDumpParser(cout
) );
277 else if( bbackup_mode
) {
278 #ifdef __BARRY_BACKUP_MODE__
279 // Only one backup file per run
280 static shared_ptr
<Parser
> backup
;
281 if( !backup
.get() ) {
282 backup
.reset( new Backup(filename
) );
286 return shared_ptr
<Parser
>( new Barry::HexDumpParser(cout
) );
289 // check for recognized database names
290 else if( name
== Contact::GetDBName() ) {
291 return shared_ptr
<Parser
>(
292 new RecordParser
<Contact
, Store
<Contact
> > (
293 new Store
<Contact
>(filename
, false, dnow
, vmode
)));
295 else if( name
== Message::GetDBName() ) {
296 return shared_ptr
<Parser
>(
297 new RecordParser
<Message
, Store
<Message
> > (
298 new Store
<Message
>(filename
, false, dnow
, vmode
)));
300 else if( name
== Calendar::GetDBName() ) {
301 return shared_ptr
<Parser
>(
302 new RecordParser
<Calendar
, Store
<Calendar
> > (
303 new Store
<Calendar
>(filename
, false, dnow
, vmode
)));
305 else if( name
== CalendarAll::GetDBName() ) {
306 return shared_ptr
<Parser
>(
307 new RecordParser
<CalendarAll
, Store
<CalendarAll
> > (
308 new Store
<CalendarAll
>(filename
, false, dnow
, vmode
)));
310 else if( name
== CallLog::GetDBName() ) {
311 return shared_ptr
<Parser
>(
312 new RecordParser
<CallLog
, Store
<CallLog
> > (
313 new Store
<CallLog
>(filename
, false, dnow
, vmode
)));
315 else if( name
== Bookmark::GetDBName() ) {
316 return shared_ptr
<Parser
>(
317 new RecordParser
<Bookmark
, Store
<Bookmark
> > (
318 new Store
<Bookmark
>(filename
, false, dnow
, vmode
)));
320 else if( name
== ServiceBook::GetDBName() ) {
321 return shared_ptr
<Parser
>(
322 new RecordParser
<ServiceBook
, Store
<ServiceBook
> > (
323 new Store
<ServiceBook
>(filename
, false, dnow
, vmode
)));
326 else if( name
== Memo::GetDBName() ) {
327 return shared_ptr
<Parser
>(
328 new RecordParser
<Memo
, Store
<Memo
> > (
329 new Store
<Memo
>(filename
, false, dnow
, vmode
)));
331 else if( name
== Task::GetDBName() ) {
332 return shared_ptr
<Parser
>(
333 new RecordParser
<Task
, Store
<Task
> > (
334 new Store
<Task
>(filename
, false, dnow
, vmode
)));
336 else if( name
== PINMessage::GetDBName() ) {
337 return shared_ptr
<Parser
>(
338 new RecordParser
<PINMessage
, Store
<PINMessage
> > (
339 new Store
<PINMessage
>(filename
, false, dnow
, vmode
)));
341 else if( name
== SavedMessage::GetDBName() ) {
342 return shared_ptr
<Parser
>(
343 new RecordParser
<SavedMessage
, Store
<SavedMessage
> > (
344 new Store
<SavedMessage
>(filename
, false, dnow
, vmode
)));
346 else if( name
== Sms::GetDBName() ) {
347 return shared_ptr
<Parser
>(
348 new RecordParser
<Sms
, Store
<Sms
> > (
349 new Store
<Sms
>(filename
, false, dnow
, vmode
)));
351 else if( name
== Folder::GetDBName() ) {
352 return shared_ptr
<Parser
>(
353 new RecordParser
<Folder
, Store
<Folder
> > (
354 new Store
<Folder
>(filename
, false, dnow
, vmode
)));
356 else if( name
== Timezone::GetDBName() ) {
357 return shared_ptr
<Parser
>(
358 new RecordParser
<Timezone
, Store
<Timezone
> > (
359 new Store
<Timezone
>(filename
, false, dnow
, vmode
)));
361 else if( name
== HandheldAgent::GetDBName() ) {
362 return shared_ptr
<Parser
>(
363 new RecordParser
<HandheldAgent
, Store
<HandheldAgent
> > (
364 new Store
<HandheldAgent
>(filename
, false, dnow
, vmode
)));
367 // unknown database, use null parser
368 return shared_ptr
<Parser
>( new Barry::HexDumpParser(cout
) );
372 shared_ptr
<Builder
> GetBuilder(const string
&name
, const string
&filename
)
374 // check for recognized database names
375 if( name
== Contact::GetDBName() ) {
376 return shared_ptr
<Builder
>(
377 new RecordBuilder
<Contact
, Store
<Contact
> > (
378 new Store
<Contact
>(filename
, true, true, false)));
380 else if( name
== Calendar::GetDBName() ) {
381 return shared_ptr
<Builder
>(
382 new RecordBuilder
<Calendar
, Store
<Calendar
> > (
383 new Store
<Calendar
>(filename
, true, true, false)));
385 else if( name
== CalendarAll::GetDBName() ) {
386 return shared_ptr
<Builder
>(
387 new RecordBuilder
<CalendarAll
, Store
<CalendarAll
> > (
388 new Store
<CalendarAll
>(filename
, true, true, false)));
390 else if( name
== Memo::GetDBName() ) {
391 return shared_ptr
<Builder
>(
392 new RecordBuilder
<Memo
, Store
<Memo
> > (
393 new Store
<Memo
>(filename
, true, true, false)));
395 else if( name
== Task::GetDBName() ) {
396 return shared_ptr
<Builder
>(
397 new RecordBuilder
<Task
, Store
<Task
> > (
398 new Store
<Task
>(filename
, true, true, false)));
401 else if( name == "Messages" ) {
402 return shared_ptr<Parser>(
403 new RecordParser<Message, Store<Message> > (
404 new Store<Message>(filename, true, true, false)));
406 else if( name == "Service Book" ) {
407 return shared_ptr<Parser>(
408 new RecordParser<ServiceBook, Store<ServiceBook> > (
409 new Store<ServiceBook>(filename, true, true, false)));
413 throw std::runtime_error("No Builder available for database");
419 cout
<< "Supported Database parsers:\n"
421 #ifdef __BARRY_SYNC_MODE__
422 << " (* = can display in vformat MIME mode)\n"
423 #define HANDLE_PARSER(tname) << " " << tname::GetDBName() << (MimeDump<tname>::Supported() ? " *" : "") << "\n"
426 #define HANDLE_PARSER(tname) << " " << tname::GetDBName() << "\n"
429 ALL_KNOWN_PARSER_TYPES
433 << "Supported Database builders:\n"
434 #undef HANDLE_BUILDER
435 #define HANDLE_BUILDER(tname) << " " << tname::GetDBName() << "\n"
436 ALL_KNOWN_BUILDER_TYPES
440 struct StateTableCommand
446 StateTableCommand(char f
, bool c
, unsigned int i
)
447 : flag(f
), clear(c
), index(i
) {}
450 bool SplitMap(const string
&map
, string
&ldif
, string
&read
, string
&write
)
452 string::size_type a
= map
.find(',');
453 if( a
== string::npos
)
456 string::size_type b
= map
.find(',', a
+1);
457 if( b
== string::npos
)
460 ldif
.assign(map
, 0, a
);
461 read
.assign(map
, a
+ 1, b
- a
- 1);
462 write
.assign(map
, b
+ 1, map
.size() - b
- 1);
464 return ldif
.size() && read
.size() && write
.size();
467 void DoMapping(ContactLdif
&ldif
, const vector
<string
> &mapCommands
)
469 for( vector
<string
>::const_iterator i
= mapCommands
.begin();
470 i
!= mapCommands
.end();
473 // single names mean unmapping
474 if( i
->find(',') == string::npos
) {
476 cerr
<< "Unmapping: " << *i
<< endl
;
480 cerr
<< "Mapping: " << *i
<< endl
;
482 // map... extract ldif/read/write names
483 string ldifname
, read
, write
;
484 if( SplitMap(*i
, ldifname
, read
, write
) ) {
485 if( !ldif
.Map(ldifname
, read
, write
) ) {
486 cerr
<< "Read/Write name unknown: " << *i
<< endl
;
490 cerr
<< "Invalid map format: " << *i
<< endl
;
496 bool ParseEpOverride(const char *arg
, Usb::EndpointPair
*epp
)
500 istringstream
iss(arg
);
501 iss
>> hex
>> read
>> comma
>> write
;
509 int main(int argc
, char *argv
[])
513 cout
.sync_with_stdio(true); // leave this on, since libusb uses
514 // stdio for debug messages
519 bool list_only
= false,
521 ldif_contacts
= false,
523 vformat_mode
= false,
524 reset_device
= false,
525 list_contact_fields
= false,
526 list_ldif_map
= false,
527 epp_override
= false,
528 threaded_sockets
= true,
529 record_state_table
= false,
530 clear_database
= false,
532 bbackup_mode
= false,
533 sort_records
= false;
534 string ldifBaseDN
, ldifDnAttr
;
540 vector
<string
> dbNames
, saveDbNames
, mapCommands
, clearDbNames
;
541 vector
<StateTableCommand
> stCommands
;
542 Usb::EndpointPair epOverride
;
544 // process command line options
546 int cmd
= getopt(argc
, argv
, "a:b:B:c:C:d:D:e:f:hi:IlLm:MnN:p:P:r:R:Ss:tT:vVXzZ");
552 case 'a': // Clear Database
553 clear_database
= true;
554 clearDbNames
.push_back(string(optarg
));
557 case 'b': // Barry backup filename (tar.gz)
558 #ifdef __BARRY_BACKUP_MODE__
559 if( filename
.size() == 0 ) {
564 cerr
<< "Do not use -f with -b\n";
568 cerr
<< "-b option not supported - no Barry "
569 "Backup library support available\n";
578 case 'c': // contacts to ldap ldif
579 ldif_contacts
= true;
583 case 'C': // DN Attribute for FQDN
587 case 'd': // show dbname
588 dbNames
.push_back(string(optarg
));
591 case 'D': // delete record
592 stCommands
.push_back(
593 StateTableCommand('D', false, atoi(optarg
)));
596 case 'e': // endpoint override
597 if( !ParseEpOverride(optarg
, &epOverride
) ) {
604 case 'f': // filename
605 #ifdef __BARRY_BOOST_MODE__
606 if( !bbackup_mode
&& filename
.size() == 0 ) {
610 cerr
<< "Do not use -f with -b\n";
614 cerr
<< "-f option not supported - no Boost "
615 "serialization support available\n";
620 case 'i': // international charset (iconv)
621 iconvCharset
= optarg
;
624 case 'I': // sort before dump
628 case 'l': // list only
632 case 'L': // List Contact field names
633 list_contact_fields
= true;
636 case 'm': // Map / Unmap
637 mapCommands
.push_back(string(optarg
));
640 case 'M': // List LDIF map
641 list_ldif_map
= true;
644 case 'n': // use null parser
652 case 'p': // Blackberry PIN
653 pin
= strtoul(optarg
, NULL
, 16);
656 case 'P': // Device password
660 case 'r': // get specific record index
661 stCommands
.push_back(
662 StateTableCommand('r', false, atoi(optarg
)));
665 case 'R': // same as 'r', and clears dirty
666 stCommands
.push_back(
667 StateTableCommand('r', true, atoi(optarg
)));
670 case 's': // save dbname
671 saveDbNames
.push_back(string(optarg
));
674 case 'S': // show supported databases
678 case 't': // display database database
682 case 'T': // show RecordStateTable
683 record_state_table
= true;
684 dbNames
.push_back(string(optarg
));
687 case 'v': // data dump on
691 case 'V': // vformat MIME mode
692 #ifdef __BARRY_SYNC_MODE__
695 cerr
<< "-V option not supported - no Sync "
696 "library support available\n";
701 case 'X': // reset device
705 case 'z': // non-threaded sockets
706 threaded_sockets
= false;
709 case 'Z': // threaded socket router
710 threaded_sockets
= true;
720 // Initialize the barry library. Must be called before
722 Barry::Init(data_dump
);
724 int logical
, major
, minor
;
725 const char *Version
= Barry::Version(logical
, major
, minor
);
726 cout
<< Version
<< endl
;
729 // Create an IConverter object if needed
730 auto_ptr
<IConverter
> ic
;
731 if( iconvCharset
.size() ) {
732 ic
.reset( new IConverter(iconvCharset
.c_str(), true) );
735 // LDIF class... only needed if ldif output turned on
736 ContactLdif
ldif(ldifBaseDN
);
737 DoMapping(ldif
, mapCommands
);
738 if( ldifDnAttr
.size() ) {
739 if( !ldif
.SetDNAttr(ldifDnAttr
) ) {
740 cerr
<< "Unable to set DN Attr: " << ldifDnAttr
<< endl
;
744 // Probe the USB bus for Blackberry devices and display.
745 // If user has specified a PIN, search for it in the
746 // available device list here as well
747 Barry::Probe
probe(busname
.c_str(), devname
.c_str(),
748 epp_override
? &epOverride
: 0);
749 int activeDevice
= -1;
751 // show any errors during probe first
752 if( probe
.GetFailCount() ) {
755 cout
<< "Blackberry device errors with errors during probe:" << endl
;
756 for( int i
= 0; i
< probe
.GetFailCount(); i
++ ) {
759 cout
<< probe
.GetFailMsg(i
) << endl
;
763 // show all successfully found devices
766 cout
<< "Blackberry devices found:" << endl
;
767 for( int i
= 0; i
< probe
.GetCount(); i
++ ) {
771 probe
.Get(i
).DumpAll(cout
);
773 cout
<< probe
.Get(i
);
775 if( probe
.Get(i
).m_pin
== pin
)
782 if( activeDevice
== -1 ) {
784 // can we default to single device?
785 if( probe
.GetCount() == 1 )
788 cerr
<< "No device selected" << endl
;
793 cerr
<< "PIN " << setbase(16) << pin
794 << " not found" << endl
;
801 cout
<< "Using device (PIN): "
802 << probe
.Get(activeDevice
).m_pin
.Str() << endl
;
805 Usb::Device
dev(probe
.Get(activeDevice
).m_dev
);
810 // Override device endpoints if user asks
811 Barry::ProbeResult device
= probe
.Get(activeDevice
);
813 device
.m_ep
.read
= epOverride
.read
;
814 device
.m_ep
.write
= epOverride
.write
;
815 // FIXME - override this too?
816 device
.m_ep
.type
= Usb::EndpointDescriptor::BulkType
;
817 cout
<< "Endpoint pair (read,write) overridden with: "
819 << (unsigned int) device
.m_ep
.read
<< ","
820 << (unsigned int) device
.m_ep
.write
<< endl
;
824 // execute each mode that was turned on
828 // Dump current LDIF mapping
829 if( list_ldif_map
) {
830 cout
<< ldif
<< endl
;
833 // Dump list of Contact field names
834 if( list_contact_fields
) {
835 for( const ContactLdif::NameToFunc
*n
= ldif
.GetFieldNames(); n
->name
; n
++ ) {
837 cout
<< " " << left
<< setw(20) << n
->name
<< ": "
838 << n
->description
<< endl
;
842 // Check if Desktop access is needed
845 record_state_table
||
849 saveDbNames
.size() ) )
853 // Create our controller object
855 // Order is important in the following auto_ptr<> objects,
856 // since Controller must get destroyed before router.
857 // Normally you'd pick one method, and not bother
858 // with auto_ptr<> and so the normal C++ constructor
859 // rules would guarantee this safety for you, but
860 // here we want the user to pick.
862 auto_ptr
<SocketRoutingQueue
> router
;
863 if( threaded_sockets
) {
864 router
.reset( new SocketRoutingQueue
);
865 router
->SpinoffSimpleReadThread();
868 DesktopConnector
connector(password
.c_str(),
869 iconvCharset
, device
, router
.get());
870 if( !connector
.Connect() ) {
871 // bad password (default action is not to prompt)
872 cerr
<< connector
.GetBadPassword().what() << endl
;
876 Barry::Mode::Desktop
&desktop
= connector
.GetDesktop();
878 // Dump list of all databases to stdout
880 // open desktop mode socket
881 cout
<< desktop
.GetDBDB() << endl
;
884 // Dump list of contacts to an LDAP LDIF file
885 // This uses the Controller convenience templates
886 if( ldif_contacts
) {
887 // create a storage functor object that accepts
888 // Barry::Contact objects as input
889 Contact2Ldif
storage(ldif
);
891 // load all the Contact records into storage
892 desktop
.LoadDatabaseByType
<Barry::Contact
>(storage
);
895 // Dump record state table to stdout
896 if( record_state_table
) {
897 if( dbNames
.size() == 0 ) {
898 cout
<< "No db names to process" << endl
;
902 vector
<string
>::iterator b
= dbNames
.begin();
903 for( ; b
!= dbNames
.end(); b
++ ) {
904 unsigned int id
= desktop
.GetDBID(*b
);
905 RecordStateTable state
;
906 desktop
.GetRecordStateTable(id
, state
);
907 cout
<< "Record state table for: " << *b
<< endl
;
913 // Get Record mode overrides the default name mode
914 if( stCommands
.size() ) {
915 if( dbNames
.size() != 1 ) {
916 cout
<< "Must have 1 db name to process" << endl
;
920 unsigned int id
= desktop
.GetDBID(dbNames
[0]);
921 shared_ptr
<Parser
> parse
= GetParser(dbNames
[0],filename
,
922 null_parser
, true, vformat_mode
, bbackup_mode
);
924 for( unsigned int i
= 0; i
< stCommands
.size(); i
++ ) {
925 desktop
.GetRecord(id
, stCommands
[i
].index
, *parse
.get());
927 if( stCommands
[i
].flag
== 'r' && stCommands
[i
].clear
) {
928 cout
<< "Clearing record's dirty flags..." << endl
;
929 desktop
.ClearDirty(id
, stCommands
[i
].index
);
932 if( stCommands
[i
].flag
== 'D' ) {
933 desktop
.DeleteRecord(id
, stCommands
[i
].index
);
940 // Dump contents of selected databases to stdout, or
941 // to file if specified.
942 // This is retrieving data from the Blackberry.
943 if( dbNames
.size() ) {
944 vector
<string
>::iterator b
= dbNames
.begin();
946 for( ; b
!= dbNames
.end(); b
++ ) {
947 shared_ptr
<Parser
> parse
= GetParser(*b
,
948 filename
, null_parser
, !sort_records
,
949 vformat_mode
, bbackup_mode
);
950 unsigned int id
= desktop
.GetDBID(*b
);
951 desktop
.LoadDatabase(id
, *parse
.get());
956 if( clear_database
) {
957 if( clearDbNames
.size() == 0 ) {
958 cout
<< "No db names to erase" << endl
;
962 vector
<string
>::iterator b
= clearDbNames
.begin();
964 for( ; b
!= clearDbNames
.end(); b
++ ) {
965 unsigned int id
= desktop
.GetDBID(*b
);
966 cout
<< "Deleting all records from " << (*b
) << "..." << endl
;
967 desktop
.ClearDatabase(id
);
973 // Save contents of file to specified databases
974 // This is writing data to the Blackberry.
975 if( saveDbNames
.size() ) {
976 vector
<string
>::iterator b
= saveDbNames
.begin();
978 for( ; b
!= saveDbNames
.end(); b
++ ) {
979 shared_ptr
<Builder
> build
= GetBuilder(*b
,
981 unsigned int id
= desktop
.GetDBID(*b
);
982 desktop
.SaveDatabase(id
, *build
);
987 catch( Usb::Error
&ue
) {
988 std::cerr
<< "Usb::Error caught: " << ue
.what() << endl
;
991 catch( Barry::Error
&se
) {
992 std::cerr
<< "Barry::Error caught: " << se
.what() << endl
;
995 catch( std::exception
&e
) {
996 std::cerr
<< "std::exception caught: " << e
.what() << endl
;