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>
26 #ifdef __BARRY_BACKUP_MODE__
27 #include <barry/barrybackup.h>
43 using namespace std::tr1
;
44 using namespace Barry
;
49 const char *Version
= Barry::Version(major
, minor
);
52 << "btool - Command line USB Blackberry Test Tool\n"
53 << " Copyright 2005-2010, Net Direct Inc. (http://www.netdirect.ca/)\n"
54 << " Using: " << Version
<< "\n"
56 #ifdef __BARRY_BOOST_MODE__
63 << " -b file Filename to save or load a Barry Backup to (tar.gz)\n"
64 << " -B bus Specify which USB bus to search on\n"
65 << " -N dev Specify which system device, using system specific string\n"
67 << " -a db Erase / clear database 'db' FROM device, deleting all\n"
68 << " its records. Can be used multiple times to clear more\n"
70 << " -c dn Convert address book database to LDIF format, using the\n"
71 << " specified baseDN\n"
72 << " -C dnattr LDIF attribute name to use when building the FQDN\n"
73 << " Defaults to 'cn'\n"
74 << " -d db Load database 'db' FROM device and dump to screen\n"
75 << " Can be used multiple times to fetch more than one DB\n"
76 << " -e epp Override endpoint pair detection. 'epp' is a single\n"
77 << " string separated by a comma, holding the read,write\n"
78 << " endpoint pair. Example: -e 83,5\n"
79 << " Note: Endpoints are specified in hex.\n"
80 << " You should never need to use this option.\n"
81 #ifdef __BARRY_BOOST_MODE__
82 << " -f file Filename to save or load handheld data to/from\n"
85 << " -i cs International charset for string conversions\n"
86 << " Valid values here are available with 'iconv --list'\n"
87 << " -I Sort records before output\n"
88 << " -l List devices\n"
89 << " -L List Contact field names\n"
90 << " -m Map LDIF name to Contact field / Unmap LDIF name\n"
91 << " Map: ldif,read,write - maps ldif to read/write Contact fields\n"
92 << " Unmap: ldif name alone\n"
93 << " -M List current LDIF mapping\n"
94 << " -n Use null parser on all databases.\n"
95 << " -p pin PIN of device to talk with\n"
96 << " If only one device is plugged in, this flag is optional\n"
97 << " -P pass Simplistic method to specify device password\n"
98 << " -s db Save database 'db' TO device from data loaded from -f file\n"
99 << " -S Show list of supported database parsers\n"
100 << " -t Show database database table\n"
101 << " -T db Show record state table for given database\n"
102 << " -v Dump protocol data during operation\n"
103 #ifdef __BARRY_SYNC_MODE__
104 << " -V Dump records using MIME vformats where possible\n"
106 << " -X Reset device\n"
107 << " -z Use non-threaded sockets\n"
108 << " -Z Use threaded socket router (default)\n"
110 << " -d Command modifiers: (can be used multiple times for more than 1 record)\n"
112 << " -r # Record index number as seen in the -T state table.\n"
113 << " This overrides the default -d behaviour, and only\n"
114 << " downloads the one specified record, sending to stdout.\n"
115 << " -R # Same as -r, but also clears the record's dirty flags.\n"
116 << " -D # Record index number as seen in the -T state table,\n"
117 << " which indicates the record to delete. Used with the -d\n"
118 << " command to specify the database.\n"
125 Barry::ContactLdif
&ldif
;
127 Contact2Ldif(Barry::ContactLdif
&ldif
) : ldif(ldif
) {}
129 void operator()(const Contact
&rec
)
131 ldif
.DumpLdif(cout
, rec
);
135 #ifdef __BARRY_SYNC_MODE__
136 template <class Record
>
140 void Dump(std::ostream
&os
, const Record
&rec
)
145 static bool Supported() { return false; }
149 class MimeDump
<Contact
>
152 void Dump(std::ostream
&os
, const Contact
&rec
)
155 os
<< vcard
.ToVCard(rec
) << endl
;
158 static bool Supported() { return true; }
162 class MimeDump
<Calendar
>
165 void Dump(std::ostream
&os
, const Calendar
&rec
)
167 Sync::vTimeConverter vtc
;
168 Sync::vCalendar
vcal(vtc
);
169 os
<< vcal
.ToVCal(rec
) << endl
;
172 static bool Supported() { return true; }
179 void Dump(std::ostream
&os
, const Memo
&rec
)
181 Sync::vJournal vjournal
;
182 os
<< vjournal
.ToMemo(rec
) << endl
;
185 static bool Supported() { return true; }
192 void Dump(std::ostream
&os
, const Task
&rec
)
194 Sync::vTimeConverter vtc
;
195 Sync::vTodo
vtodo(vtc
);
196 os
<< vtodo
.ToTask(rec
) << endl
;
199 static bool Supported() { return true; }
203 template <class Record
>
206 std::vector
<Record
> records
;
207 mutable typename
std::vector
<Record
>::const_iterator rec_it
;
208 std::string filename
;
210 bool immediate_display
;
214 Store(const string
&filename
, bool load
, bool immediate_display
,
216 : rec_it(records
.end()),
219 immediate_display(immediate_display
),
220 vformat_mode(vformat_mode
),
223 #ifdef __BARRY_BOOST_MODE__
226 if( load
&& filename
.size() ) {
227 // filename is available, attempt to load
228 cout
<< "Loading: " << filename
<< endl
;
229 ifstream
ifs(filename
.c_str());
231 getline(ifs
, dbName
);
232 boost::archive::text_iarchive
ia(ifs
);
234 cout
<< records
.size()
235 << " records loaded from '"
236 << filename
<< "'" << endl
;
237 sort(records
.begin(), records
.end());
238 rec_it
= records
.begin();
241 typename
std::vector
<Record
>::const_iterator beg
= records
.begin(), end
= records
.end();
242 for( ; beg
!= end
; beg
++ ) {
243 cout
<< (*beg
) << endl
;
247 } catch( boost::archive::archive_exception
&ae
) {
248 cerr
<< "Archive exception in ~Store(): "
249 << ae
.what() << endl
;
256 if( !immediate_display
) {
257 // not dumped yet, sort then dump
258 sort(records
.begin(), records
.end());
262 cout
<< "Store counted " << dec
<< count
<< " records." << endl
;
263 #ifdef __BARRY_BOOST_MODE__
266 if( !load
&& filename
.size() ) {
267 // filename is available, attempt to save
268 cout
<< "Saving: " << filename
<< endl
;
269 const std::vector
<Record
> &r
= records
;
270 ofstream
ofs(filename
.c_str());
271 ofs
<< Record::GetDBName() << endl
;
272 boost::archive::text_oarchive
oa(ofs
);
274 cout
<< dec
<< r
.size() << " records saved to '"
275 << filename
<< "'" << endl
;
278 } catch( boost::archive::archive_exception
&ae
) {
279 cerr
<< "Archive exception in ~Store(): "
280 << ae
.what() << endl
;
287 typename vector
<Record
>::const_iterator i
= records
.begin();
288 for( ; i
!= records
.end(); ++i
) {
293 void Dump(const Record
&rec
)
296 #ifdef __BARRY_SYNC_MODE__
307 void operator()(const Record
&rec
)
310 if( immediate_display
)
312 records
.push_back(rec
);
315 // retrieval operator
316 bool operator()(Record
&rec
, Builder
&builder
) const
318 if( rec_it
== records
.end() )
326 shared_ptr
<Parser
> GetParser(const string
&name
,
327 const string
&filename
,
329 bool immediate_display
,
333 bool dnow
= immediate_display
;
334 bool vmode
= vformat_mode
;
338 return shared_ptr
<Parser
>( new Barry::HexDumpParser(cout
) );
340 else if( bbackup_mode
) {
341 #ifdef __BARRY_BACKUP_MODE__
342 // Only one backup file per run
343 static shared_ptr
<Parser
> backup
;
344 if( !backup
.get() ) {
345 backup
.reset( new Backup(filename
) );
349 return shared_ptr
<Parser
>( new Barry::HexDumpParser(cout
) );
352 // check for recognized database names
353 else if( name
== Contact::GetDBName() ) {
354 return shared_ptr
<Parser
>(
355 new RecordParser
<Contact
, Store
<Contact
> > (
356 new Store
<Contact
>(filename
, false, dnow
, vmode
)));
358 else if( name
== Message::GetDBName() ) {
359 return shared_ptr
<Parser
>(
360 new RecordParser
<Message
, Store
<Message
> > (
361 new Store
<Message
>(filename
, false, dnow
, vmode
)));
363 else if( name
== Calendar::GetDBName() ) {
364 return shared_ptr
<Parser
>(
365 new RecordParser
<Calendar
, Store
<Calendar
> > (
366 new Store
<Calendar
>(filename
, false, dnow
, vmode
)));
368 else if( name
== CalendarAll::GetDBName() ) {
369 return shared_ptr
<Parser
>(
370 new RecordParser
<CalendarAll
, Store
<CalendarAll
> > (
371 new Store
<CalendarAll
>(filename
, false, dnow
, vmode
)));
373 else if( name
== CallLog::GetDBName() ) {
374 return shared_ptr
<Parser
>(
375 new RecordParser
<CallLog
, Store
<CallLog
> > (
376 new Store
<CallLog
>(filename
, false, dnow
, vmode
)));
378 else if( name
== Bookmark::GetDBName() ) {
379 return shared_ptr
<Parser
>(
380 new RecordParser
<Bookmark
, Store
<Bookmark
> > (
381 new Store
<Bookmark
>(filename
, false, dnow
, vmode
)));
383 else if( name
== ServiceBook::GetDBName() ) {
384 return shared_ptr
<Parser
>(
385 new RecordParser
<ServiceBook
, Store
<ServiceBook
> > (
386 new Store
<ServiceBook
>(filename
, false, dnow
, vmode
)));
389 else if( name
== Memo::GetDBName() ) {
390 return shared_ptr
<Parser
>(
391 new RecordParser
<Memo
, Store
<Memo
> > (
392 new Store
<Memo
>(filename
, false, dnow
, vmode
)));
394 else if( name
== Task::GetDBName() ) {
395 return shared_ptr
<Parser
>(
396 new RecordParser
<Task
, Store
<Task
> > (
397 new Store
<Task
>(filename
, false, dnow
, vmode
)));
399 else if( name
== PINMessage::GetDBName() ) {
400 return shared_ptr
<Parser
>(
401 new RecordParser
<PINMessage
, Store
<PINMessage
> > (
402 new Store
<PINMessage
>(filename
, false, dnow
, vmode
)));
404 else if( name
== SavedMessage::GetDBName() ) {
405 return shared_ptr
<Parser
>(
406 new RecordParser
<SavedMessage
, Store
<SavedMessage
> > (
407 new Store
<SavedMessage
>(filename
, false, dnow
, vmode
)));
409 else if( name
== Sms::GetDBName() ) {
410 return shared_ptr
<Parser
>(
411 new RecordParser
<Sms
, Store
<Sms
> > (
412 new Store
<Sms
>(filename
, false, dnow
, vmode
)));
414 else if( name
== Folder::GetDBName() ) {
415 return shared_ptr
<Parser
>(
416 new RecordParser
<Folder
, Store
<Folder
> > (
417 new Store
<Folder
>(filename
, false, dnow
, vmode
)));
419 else if( name
== Timezone::GetDBName() ) {
420 return shared_ptr
<Parser
>(
421 new RecordParser
<Timezone
, Store
<Timezone
> > (
422 new Store
<Timezone
>(filename
, false, dnow
, vmode
)));
425 // unknown database, use null parser
426 return shared_ptr
<Parser
>( new Barry::HexDumpParser(cout
) );
430 shared_ptr
<Builder
> GetBuilder(const string
&name
, const string
&filename
)
432 // check for recognized database names
433 if( name
== Contact::GetDBName() ) {
434 return shared_ptr
<Builder
>(
435 new RecordBuilder
<Contact
, Store
<Contact
> > (
436 new Store
<Contact
>(filename
, true, true, false)));
438 else if( name
== Calendar::GetDBName() ) {
439 return shared_ptr
<Builder
>(
440 new RecordBuilder
<Calendar
, Store
<Calendar
> > (
441 new Store
<Calendar
>(filename
, true, true, false)));
443 else if( name
== CalendarAll::GetDBName() ) {
444 return shared_ptr
<Builder
>(
445 new RecordBuilder
<CalendarAll
, Store
<CalendarAll
> > (
446 new Store
<CalendarAll
>(filename
, true, true, false)));
448 else if( name
== Memo::GetDBName() ) {
449 return shared_ptr
<Builder
>(
450 new RecordBuilder
<Memo
, Store
<Memo
> > (
451 new Store
<Memo
>(filename
, true, true, false)));
453 else if( name
== Task::GetDBName() ) {
454 return shared_ptr
<Builder
>(
455 new RecordBuilder
<Task
, Store
<Task
> > (
456 new Store
<Task
>(filename
, true, true, false)));
459 else if( name == "Messages" ) {
460 return shared_ptr<Parser>(
461 new RecordParser<Message, Store<Message> > (
462 new Store<Message>(filename, true, true, false)));
464 else if( name == "Service Book" ) {
465 return shared_ptr<Parser>(
466 new RecordParser<ServiceBook, Store<ServiceBook> > (
467 new Store<ServiceBook>(filename, true, true, false)));
471 throw std::runtime_error("No Builder available for database");
477 cout
<< "Supported Database parsers:\n"
478 << " (* = can display in vformat MIME mode)\n"
479 << " Address Book *\n"
482 << " Calendar - All *\n"
483 << " Phone Call Logs\n"
484 << " Browser Bookmarks\n"
489 << " Saved Email Messages\n"
492 << " Time Zones (read only)\n"
494 << "Supported Database builders:\n"
497 << " Calendar - All\n"
503 struct StateTableCommand
509 StateTableCommand(char f
, bool c
, unsigned int i
)
510 : flag(f
), clear(c
), index(i
) {}
513 bool SplitMap(const string
&map
, string
&ldif
, string
&read
, string
&write
)
515 string::size_type a
= map
.find(',');
516 if( a
== string::npos
)
519 string::size_type b
= map
.find(',', a
+1);
520 if( b
== string::npos
)
523 ldif
.assign(map
, 0, a
);
524 read
.assign(map
, a
+ 1, b
- a
- 1);
525 write
.assign(map
, b
+ 1, map
.size() - b
- 1);
527 return ldif
.size() && read
.size() && write
.size();
530 void DoMapping(ContactLdif
&ldif
, const vector
<string
> &mapCommands
)
532 for( vector
<string
>::const_iterator i
= mapCommands
.begin();
533 i
!= mapCommands
.end();
536 // single names mean unmapping
537 if( i
->find(',') == string::npos
) {
539 cerr
<< "Unmapping: " << *i
<< endl
;
543 cerr
<< "Mapping: " << *i
<< endl
;
545 // map... extract ldif/read/write names
546 string ldifname
, read
, write
;
547 if( SplitMap(*i
, ldifname
, read
, write
) ) {
548 if( !ldif
.Map(ldifname
, read
, write
) ) {
549 cerr
<< "Read/Write name unknown: " << *i
<< endl
;
553 cerr
<< "Invalid map format: " << *i
<< endl
;
559 bool ParseEpOverride(const char *arg
, Usb::EndpointPair
*epp
)
563 istringstream
iss(arg
);
564 iss
>> hex
>> read
>> comma
>> write
;
572 int main(int argc
, char *argv
[])
576 cout
.sync_with_stdio(true); // leave this on, since libusb uses
577 // stdio for debug messages
582 bool list_only
= false,
584 ldif_contacts
= false,
586 vformat_mode
= false,
587 reset_device
= false,
588 list_contact_fields
= false,
589 list_ldif_map
= false,
590 epp_override
= false,
591 threaded_sockets
= true,
592 record_state_table
= false,
593 clear_database
= false,
595 bbackup_mode
= false,
596 sort_records
= false;
597 string ldifBaseDN
, ldifDnAttr
;
603 vector
<string
> dbNames
, saveDbNames
, mapCommands
, clearDbNames
;
604 vector
<StateTableCommand
> stCommands
;
605 Usb::EndpointPair epOverride
;
607 // process command line options
609 int cmd
= getopt(argc
, argv
, "a:b:B:c:C:d:D:e:f:hi:IlLm:MnN:p:P:r:R:Ss:tT:vVXzZ");
615 case 'a': // Clear Database
616 clear_database
= true;
617 clearDbNames
.push_back(string(optarg
));
620 case 'b': // Barry backup filename (tar.gz)
621 #ifdef __BARRY_BACKUP_MODE__
622 if( filename
.size() == 0 ) {
627 cerr
<< "Do not use -f with -b\n";
631 cerr
<< "-b option not supported - no Barry "
632 "Backup library support available\n";
641 case 'c': // contacts to ldap ldif
642 ldif_contacts
= true;
646 case 'C': // DN Attribute for FQDN
650 case 'd': // show dbname
651 dbNames
.push_back(string(optarg
));
654 case 'D': // delete record
655 stCommands
.push_back(
656 StateTableCommand('D', false, atoi(optarg
)));
659 case 'e': // endpoint override
660 if( !ParseEpOverride(optarg
, &epOverride
) ) {
667 case 'f': // filename
668 #ifdef __BARRY_BOOST_MODE__
669 if( !bbackup_mode
&& filename
.size() == 0 ) {
673 cerr
<< "Do not use -f with -b\n";
677 cerr
<< "-f option not supported - no Boost "
678 "serialization support available\n";
683 case 'i': // international charset (iconv)
684 iconvCharset
= optarg
;
687 case 'I': // sort before dump
691 case 'l': // list only
695 case 'L': // List Contact field names
696 list_contact_fields
= true;
699 case 'm': // Map / Unmap
700 mapCommands
.push_back(string(optarg
));
703 case 'M': // List LDIF map
704 list_ldif_map
= true;
707 case 'n': // use null parser
715 case 'p': // Blackberry PIN
716 pin
= strtoul(optarg
, NULL
, 16);
719 case 'P': // Device password
723 case 'r': // get specific record index
724 stCommands
.push_back(
725 StateTableCommand('r', false, atoi(optarg
)));
728 case 'R': // same as 'r', and clears dirty
729 stCommands
.push_back(
730 StateTableCommand('r', true, atoi(optarg
)));
733 case 's': // save dbname
734 saveDbNames
.push_back(string(optarg
));
737 case 'S': // show supported databases
741 case 't': // display database database
745 case 'T': // show RecordStateTable
746 record_state_table
= true;
747 dbNames
.push_back(string(optarg
));
750 case 'v': // data dump on
754 case 'V': // vformat MIME mode
755 #ifdef __BARRY_SYNC_MODE__
758 cerr
<< "-V option not supported - no Sync "
759 "library support available\n";
764 case 'X': // reset device
768 case 'z': // non-threaded sockets
769 threaded_sockets
= false;
772 case 'Z': // threaded socket router
773 threaded_sockets
= true;
783 // Initialize the barry library. Must be called before
785 Barry::Init(data_dump
);
788 const char *Version
= Barry::Version(major
, minor
);
789 cout
<< Version
<< endl
;
792 // Create an IConverter object if needed
793 auto_ptr
<IConverter
> ic
;
794 if( iconvCharset
.size() ) {
795 ic
.reset( new IConverter(iconvCharset
.c_str(), true) );
798 // LDIF class... only needed if ldif output turned on
799 ContactLdif
ldif(ldifBaseDN
);
800 DoMapping(ldif
, mapCommands
);
801 if( ldifDnAttr
.size() ) {
802 if( !ldif
.SetDNAttr(ldifDnAttr
) ) {
803 cerr
<< "Unable to set DN Attr: " << ldifDnAttr
<< endl
;
807 // Probe the USB bus for Blackberry devices and display.
808 // If user has specified a PIN, search for it in the
809 // available device list here as well
810 Barry::Probe
probe(busname
.c_str(), devname
.c_str(),
811 epp_override
? &epOverride
: 0);
812 int activeDevice
= -1;
814 // show any errors during probe first
815 if( probe
.GetFailCount() ) {
818 cout
<< "Blackberry device errors with errors during probe:" << endl
;
819 for( int i
= 0; i
< probe
.GetFailCount(); i
++ ) {
822 cout
<< probe
.GetFailMsg(i
) << endl
;
826 // show all successfully found devices
829 cout
<< "Blackberry devices found:" << endl
;
830 for( int i
= 0; i
< probe
.GetCount(); i
++ ) {
834 probe
.Get(i
).DumpAll(cout
);
836 cout
<< probe
.Get(i
);
838 if( probe
.Get(i
).m_pin
== pin
)
845 if( activeDevice
== -1 ) {
847 // can we default to single device?
848 if( probe
.GetCount() == 1 )
851 cerr
<< "No device selected" << endl
;
856 cerr
<< "PIN " << setbase(16) << pin
857 << " not found" << endl
;
864 cout
<< "Using device (PIN): "
865 << probe
.Get(activeDevice
).m_pin
.str() << endl
;
868 Usb::Device
dev(probe
.Get(activeDevice
).m_dev
);
873 // Override device endpoints if user asks
874 Barry::ProbeResult device
= probe
.Get(activeDevice
);
876 device
.m_ep
.read
= epOverride
.read
;
877 device
.m_ep
.write
= epOverride
.write
;
878 device
.m_ep
.type
= 2; // FIXME - override this too?
879 cout
<< "Endpoint pair (read,write) overridden with: "
881 << (unsigned int) device
.m_ep
.read
<< ","
882 << (unsigned int) device
.m_ep
.write
<< endl
;
886 // execute each mode that was turned on
890 // Dump current LDIF mapping
891 if( list_ldif_map
) {
892 cout
<< ldif
<< endl
;
895 // Dump list of Contact field names
896 if( list_contact_fields
) {
897 for( const ContactLdif::NameToFunc
*n
= ldif
.GetFieldNames(); n
->name
; n
++ ) {
899 cout
<< " " << left
<< setw(20) << n
->name
<< ": "
900 << n
->description
<< endl
;
904 // Check if Desktop access is needed
907 record_state_table
||
911 saveDbNames
.size() ) )
915 // Create our controller object
917 // Order is important in the following auto_ptr<> objects,
918 // since Controller must get destroyed before router.
919 // Normally you'd pick one method, and not bother
920 // with auto_ptr<> and so the normal C++ constructor
921 // rules would guarantee this safety for you, but
922 // here we want the user to pick.
924 auto_ptr
<SocketRoutingQueue
> router
;
925 auto_ptr
<Barry::Controller
> pcon
;
926 if( threaded_sockets
) {
927 router
.reset( new SocketRoutingQueue
);
928 router
->SpinoffSimpleReadThread();
929 pcon
.reset( new Barry::Controller(device
, *router
) );
932 pcon
.reset( new Barry::Controller(device
) );
935 Barry::Controller
&con
= *pcon
;
936 Barry::Mode::Desktop
desktop(con
, *ic
);
937 desktop
.Open(password
.c_str());
939 // Dump list of all databases to stdout
941 // open desktop mode socket
942 cout
<< desktop
.GetDBDB() << endl
;
945 // Dump list of contacts to an LDAP LDIF file
946 // This uses the Controller convenience templates
947 if( ldif_contacts
) {
948 // create a storage functor object that accepts
949 // Barry::Contact objects as input
950 Contact2Ldif
storage(ldif
);
952 // load all the Contact records into storage
953 desktop
.LoadDatabaseByType
<Barry::Contact
>(storage
);
956 // Dump record state table to stdout
957 if( record_state_table
) {
958 if( dbNames
.size() == 0 ) {
959 cout
<< "No db names to process" << endl
;
963 vector
<string
>::iterator b
= dbNames
.begin();
964 for( ; b
!= dbNames
.end(); b
++ ) {
965 unsigned int id
= desktop
.GetDBID(*b
);
966 RecordStateTable state
;
967 desktop
.GetRecordStateTable(id
, state
);
968 cout
<< "Record state table for: " << *b
<< endl
;
974 // Get Record mode overrides the default name mode
975 if( stCommands
.size() ) {
976 if( dbNames
.size() != 1 ) {
977 cout
<< "Must have 1 db name to process" << endl
;
981 unsigned int id
= desktop
.GetDBID(dbNames
[0]);
982 shared_ptr
<Parser
> parse
= GetParser(dbNames
[0],filename
,
983 null_parser
, true, vformat_mode
, bbackup_mode
);
985 for( unsigned int i
= 0; i
< stCommands
.size(); i
++ ) {
986 desktop
.GetRecord(id
, stCommands
[i
].index
, *parse
.get());
988 if( stCommands
[i
].flag
== 'r' && stCommands
[i
].clear
) {
989 cout
<< "Clearing record's dirty flags..." << endl
;
990 desktop
.ClearDirty(id
, stCommands
[i
].index
);
993 if( stCommands
[i
].flag
== 'D' ) {
994 desktop
.DeleteRecord(id
, stCommands
[i
].index
);
1001 // Dump contents of selected databases to stdout, or
1002 // to file if specified.
1003 // This is retrieving data from the Blackberry.
1004 if( dbNames
.size() ) {
1005 vector
<string
>::iterator b
= dbNames
.begin();
1007 for( ; b
!= dbNames
.end(); b
++ ) {
1008 shared_ptr
<Parser
> parse
= GetParser(*b
,
1009 filename
, null_parser
, !sort_records
,
1010 vformat_mode
, bbackup_mode
);
1011 unsigned int id
= desktop
.GetDBID(*b
);
1012 desktop
.LoadDatabase(id
, *parse
.get());
1017 if( clear_database
) {
1018 if( clearDbNames
.size() == 0 ) {
1019 cout
<< "No db names to erase" << endl
;
1023 vector
<string
>::iterator b
= clearDbNames
.begin();
1025 for( ; b
!= clearDbNames
.end(); b
++ ) {
1026 unsigned int id
= desktop
.GetDBID(*b
);
1027 cout
<< "Deleting all records from " << (*b
) << "..." << endl
;
1028 desktop
.ClearDatabase(id
);
1034 // Save contents of file to specified databases
1035 // This is writing data to the Blackberry.
1036 if( saveDbNames
.size() ) {
1037 vector
<string
>::iterator b
= saveDbNames
.begin();
1039 for( ; b
!= saveDbNames
.end(); b
++ ) {
1040 shared_ptr
<Builder
> build
= GetBuilder(*b
,
1042 unsigned int id
= desktop
.GetDBID(*b
);
1043 desktop
.SaveDatabase(id
, *build
);
1048 catch( Usb::Error
&ue
) {
1049 std::cerr
<< "Usb::Error caught: " << ue
.what() << endl
;
1052 catch( Barry::Error
&se
) {
1053 std::cerr
<< "Barry::Error caught: " << se
.what() << endl
;
1056 catch( std::exception
&e
) {
1057 std::cerr
<< "std::exception caught: " << e
.what() << endl
;