3 /// Barry library tester
7 Copyright (C) 2005-2013, 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.
23 // This define is used in barry/barry.h to signal inclusion of Boost
24 // serialization headers. It is intended to be used by applications,
25 // so we shouldn't mess with it.
27 // But all actual Boost related code is now stuffed into util.cc, safely
28 // locked away from other code. So we don't need the Boost headers, we
29 // just need a flag for our own functionality. So translate this define
30 // into our own, and undef to skip the Boost headers, and the compile speed
31 // slowdown that it creates.
33 #ifdef __BARRY_BOOST_MODE__
34 #define __BTOOL_BOOST_MODE__
36 #undef __BARRY_BOOST_MODE__
38 #include <barry/barry.h>
39 #ifdef __BARRY_SYNC_MODE__
40 #include <barry/barrysync.h>
42 #ifdef __BARRY_BACKUP_MODE__
43 #include <barry/barrybackup.h>
57 #include "boostwrap.h"
59 #include "barrygetopt.h"
62 using namespace std::tr1
;
63 using namespace Barry
;
65 std::map
<std::string
, std::string
> SortKeys
;
69 int logical
, major
, minor
;
70 const char *Version
= Barry::Version(logical
, major
, minor
);
72 #ifdef __BTOOL_BOOST_MODE__
73 string boost_mode
= _("Compiled with Boost support");
74 string boost_opt
= _(" -f file Filename to save or load handheld data to/from");
76 string boost_mode
= _("Compiled without Boost support");
80 #ifdef __BARRY_SYNC_MODE__
81 string sync_mode
= _(" -V Dump records using MIME vformats where possible");
86 cerr
<< string_vprintf(
87 _("btool - Command line USB Blackberry Test Tool\n"
88 " Copyright 2005-2013, Net Direct Inc. (http://www.netdirect.ca/)\n"
92 " -b file Filename to save or load a Barry Backup to (tar.gz)\n"
93 " -B bus Specify which USB bus to search on\n"
94 " -N dev Specify which system device, using system specific string\n"
96 " -a db Erase / clear database 'db' FROM device, deleting all\n"
97 " its records. Can be used multiple times to clear more\n"
99 " -c dn Convert address book database to LDIF format, using the\n"
100 " specified baseDN\n"
101 " -C dnattr LDIF attribute name to use when building the FQDN\n"
102 " Defaults to 'cn'\n"
103 " -d db Load database 'db' FROM device and dump to screen\n"
104 " Can be used multiple times to fetch more than one DB\n"
105 " -e epp Override endpoint pair detection. 'epp' is a single\n"
106 " string separated by a comma, holding the read,write\n"
107 " endpoint pair. Example: -e 83,5\n"
108 " Note: Endpoints are specified in hex.\n"
109 " You should never need to use this option.\n"
111 " -F sort Field name by which to sort the output. Note that the\n"
112 " format of this field is special: 'DBName:field1,field2'\n"
113 " with no spaces unless the spaces are part of the name.\n"
114 " Can be used multiple times, to match your -d options.\n"
115 " Example: -F 'Address Book:Company,LastName,FirstName'\n"
117 " -i cs International charset for string conversions\n"
118 " Valid values here are available with 'iconv --list'\n"
119 " -I Sort records before output\n"
121 " -L List Contact field names\n"
122 " -m Map LDIF name to Contact field / Unmap LDIF name\n"
123 " Map: ldif,read,write - maps ldif to read/write Contact fields\n"
124 " Unmap: ldif name alone\n"
125 " -M List current LDIF mapping\n"
126 " -n Use null parser on all databases.\n"
127 " -p pin PIN of device to talk with\n"
128 " If only one device is plugged in, this flag is optional\n"
129 " -P pass Simplistic method to specify device password\n"
130 " -s db Save database 'db' TO device from data loaded from -f file\n"
131 " -S Show list of supported database parsers. Use twice to\n"
132 " display fields names as well.\n"
133 " -t Show database database table\n"
134 " -T db Show record state table for given database\n"
135 " -v Dump protocol data during operation\n"
138 " -z Use non-threaded sockets\n"
139 " -Z Use threaded socket router (default)\n"
141 " -d Command modifiers: (can be used multiple times for more than 1 record)\n"
143 " -r # Record index number as seen in the -T state table.\n"
144 " This overrides the default -d behaviour, and only\n"
145 " downloads the one specified record, sending to stdout.\n"
146 " -R # Same as -r, but also clears the record's dirty flags.\n"
147 " -D # Record index number as seen in the -T state table,\n"
148 " which indicates the record to delete. Used with the -d\n"
149 " command to specify the database.\n"),
161 Barry::ContactLdif
&ldif
;
163 Contact2Ldif(Barry::ContactLdif
&ldif
) : ldif(ldif
) {}
165 void operator()(const Contact
&rec
)
167 ldif
.DumpLdif(cout
, rec
);
171 template <class Record
>
174 std::vector
<Record
> records
;
175 mutable typename
std::vector
<Record
>::const_iterator rec_it
;
176 std::string filename
;
178 bool immediate_display
;
180 int from_device_count
;
181 mutable int to_device_count
;
183 Store(const string
&filename
, bool load
, bool immediate_display
,
185 : rec_it(records
.end()),
188 immediate_display(immediate_display
&& !SortKeys
.size()),
189 vformat_mode(vformat_mode
),
190 from_device_count(0),
193 #ifdef __BTOOL_BOOST_MODE__
194 if( load
&& filename
.size() ) {
195 // filename is available, attempt to load
196 cout
<< _("Loading: ") << filename
<< endl
;
197 string errmsg
, dbName
;
198 if( !LoadBoostFile(filename
, records
, dbName
, errmsg
) ) {
199 cerr
<< errmsg
<< endl
;
201 cout
<< records
.size()
202 << _(" records loaded from '")
203 << filename
<< "'" << endl
;
204 sort(records
.begin(), records
.end());
205 rec_it
= records
.begin();
208 typename
std::vector
<Record
>::const_iterator beg
= records
.begin(), end
= records
.end();
209 for( ; beg
!= end
; beg
++ ) {
210 cout
<< (*beg
) << endl
;
218 if( !immediate_display
) {
219 // not dumped yet, sort then dump
220 if( SortKeys
.size() && SortKeys
.find(Record::GetDBName()) != SortKeys
.end() ) {
221 sort(records
.begin(), records
.end(),
222 NamedFieldCmp
<Record
>(SortKeys
[Record::GetDBName()]));
225 sort(records
.begin(), records
.end());
230 cout
<< string_vprintf(_("Store counted %d records read from device, and %d records written to device."), from_device_count
, to_device_count
) << endl
;
231 #ifdef __BTOOL_BOOST_MODE__
232 if( !load
&& filename
.size() ) {
233 // filename is available, attempt to save
234 cout
<< _("Saving: ") << filename
<< endl
;
236 if( !SaveBoostFile(filename
, records
, errmsg
) ) {
237 cerr
<< errmsg
<< endl
;
239 cout
<< dec
<< records
.size() << _(" records saved to '")
240 << filename
<< "'" << endl
;
247 typename vector
<Record
>::const_iterator i
= records
.begin();
248 for( ; i
!= records
.end(); ++i
) {
253 void Dump(const Record
&rec
)
256 #ifdef __BARRY_SYNC_MODE__
267 void operator()(const Record
&rec
)
270 if( immediate_display
)
272 records
.push_back(rec
);
275 // retrieval operator
276 bool operator()(Record
&rec
, Builder
&builder
) const
278 if( rec_it
== records
.end() )
287 shared_ptr
<Parser
> GetParser(const string
&name
,
288 const string
&filename
,
290 bool immediate_display
,
294 bool dnow
= immediate_display
;
295 bool vmode
= vformat_mode
;
299 return shared_ptr
<Parser
>( new Barry::HexDumpParser(cout
) );
301 else if( bbackup_mode
) {
302 #ifdef __BARRY_BACKUP_MODE__
303 // Only one backup file per run
304 static shared_ptr
<Parser
> backup
;
305 if( !backup
.get() ) {
306 backup
.reset( new Backup(filename
) );
310 return shared_ptr
<Parser
>( new Barry::HexDumpParser(cout
) );
313 // check for recognized database names
314 else if( name
== Contact::GetDBName() ) {
315 return shared_ptr
<Parser
>(
316 new RecordParser
<Contact
, Store
<Contact
> > (
317 new Store
<Contact
>(filename
, false, dnow
, vmode
)));
319 else if( name
== Message::GetDBName() ) {
320 return shared_ptr
<Parser
>(
321 new RecordParser
<Message
, Store
<Message
> > (
322 new Store
<Message
>(filename
, false, dnow
, vmode
)));
324 else if( name
== Calendar::GetDBName() ) {
325 return shared_ptr
<Parser
>(
326 new RecordParser
<Calendar
, Store
<Calendar
> > (
327 new Store
<Calendar
>(filename
, false, dnow
, vmode
)));
329 else if( name
== CalendarAll::GetDBName() ) {
330 return shared_ptr
<Parser
>(
331 new RecordParser
<CalendarAll
, Store
<CalendarAll
> > (
332 new Store
<CalendarAll
>(filename
, false, dnow
, vmode
)));
334 else if( name
== CallLog::GetDBName() ) {
335 return shared_ptr
<Parser
>(
336 new RecordParser
<CallLog
, Store
<CallLog
> > (
337 new Store
<CallLog
>(filename
, false, dnow
, vmode
)));
339 else if( name
== Bookmark::GetDBName() ) {
340 return shared_ptr
<Parser
>(
341 new RecordParser
<Bookmark
, Store
<Bookmark
> > (
342 new Store
<Bookmark
>(filename
, false, dnow
, vmode
)));
344 else if( name
== ServiceBook::GetDBName() ) {
345 return shared_ptr
<Parser
>(
346 new RecordParser
<ServiceBook
, Store
<ServiceBook
> > (
347 new Store
<ServiceBook
>(filename
, false, dnow
, vmode
)));
350 else if( name
== Memo::GetDBName() ) {
351 return shared_ptr
<Parser
>(
352 new RecordParser
<Memo
, Store
<Memo
> > (
353 new Store
<Memo
>(filename
, false, dnow
, vmode
)));
355 else if( name
== Task::GetDBName() ) {
356 return shared_ptr
<Parser
>(
357 new RecordParser
<Task
, Store
<Task
> > (
358 new Store
<Task
>(filename
, false, dnow
, vmode
)));
360 else if( name
== PINMessage::GetDBName() ) {
361 return shared_ptr
<Parser
>(
362 new RecordParser
<PINMessage
, Store
<PINMessage
> > (
363 new Store
<PINMessage
>(filename
, false, dnow
, vmode
)));
365 else if( name
== SavedMessage::GetDBName() ) {
366 return shared_ptr
<Parser
>(
367 new RecordParser
<SavedMessage
, Store
<SavedMessage
> > (
368 new Store
<SavedMessage
>(filename
, false, dnow
, vmode
)));
370 else if( name
== Sms::GetDBName() ) {
371 return shared_ptr
<Parser
>(
372 new RecordParser
<Sms
, Store
<Sms
> > (
373 new Store
<Sms
>(filename
, false, dnow
, vmode
)));
375 else if( name
== Folder::GetDBName() ) {
376 return shared_ptr
<Parser
>(
377 new RecordParser
<Folder
, Store
<Folder
> > (
378 new Store
<Folder
>(filename
, false, dnow
, vmode
)));
380 else if( name
== TimeZone::GetDBName() ) {
381 return shared_ptr
<Parser
>(
382 new RecordParser
<TimeZone
, Store
<TimeZone
> > (
383 new Store
<TimeZone
>(filename
, false, dnow
, vmode
)));
385 else if( name
== HandheldAgent::GetDBName() ) {
386 return shared_ptr
<Parser
>(
387 new RecordParser
<HandheldAgent
, Store
<HandheldAgent
> > (
388 new Store
<HandheldAgent
>(filename
, false, dnow
, vmode
)));
391 // unknown database, use null parser
392 return shared_ptr
<Parser
>( new Barry::HexDumpParser(cout
) );
396 shared_ptr
<Builder
> GetBuilder(const string
&name
, const string
&filename
)
398 // check for recognized database names
399 if( name
== Contact::GetDBName() ) {
400 return shared_ptr
<Builder
>(
401 new RecordBuilder
<Contact
, Store
<Contact
> > (
402 new Store
<Contact
>(filename
, true, true, false)));
404 else if( name
== Calendar::GetDBName() ) {
405 return shared_ptr
<Builder
>(
406 new RecordBuilder
<Calendar
, Store
<Calendar
> > (
407 new Store
<Calendar
>(filename
, true, true, false)));
409 else if( name
== CalendarAll::GetDBName() ) {
410 return shared_ptr
<Builder
>(
411 new RecordBuilder
<CalendarAll
, Store
<CalendarAll
> > (
412 new Store
<CalendarAll
>(filename
, true, true, false)));
414 else if( name
== Memo::GetDBName() ) {
415 return shared_ptr
<Builder
>(
416 new RecordBuilder
<Memo
, Store
<Memo
> > (
417 new Store
<Memo
>(filename
, true, true, false)));
419 else if( name
== Task::GetDBName() ) {
420 return shared_ptr
<Builder
>(
421 new RecordBuilder
<Task
, Store
<Task
> > (
422 new Store
<Task
>(filename
, true, true, false)));
425 else if( name == "Messages" ) {
426 return shared_ptr<Parser>(
427 new RecordParser<Message, Store<Message> > (
428 new Store<Message>(filename, true, true, false)));
430 else if( name == "Service Book" ) {
431 return shared_ptr<Parser>(
432 new RecordParser<ServiceBook, Store<ServiceBook> > (
433 new Store<ServiceBook>(filename, true, true, false)));
437 throw std::runtime_error(_("No Builder available for database"));
441 struct StateTableCommand
447 StateTableCommand(char f
, bool c
, unsigned int i
)
448 : flag(f
), clear(c
), index(i
) {}
451 bool SplitMap(const string
&map
, string
&ldif
, string
&read
, string
&write
)
453 string::size_type a
= map
.find(',');
454 if( a
== string::npos
)
457 string::size_type b
= map
.find(',', a
+1);
458 if( b
== string::npos
)
461 ldif
.assign(map
, 0, a
);
462 read
.assign(map
, a
+ 1, b
- a
- 1);
463 write
.assign(map
, b
+ 1, map
.size() - b
- 1);
465 return ldif
.size() && read
.size() && write
.size();
468 void DoMapping(ContactLdif
&ldif
, const vector
<string
> &mapCommands
)
470 for( vector
<string
>::const_iterator i
= mapCommands
.begin();
471 i
!= mapCommands
.end();
474 // single names mean unmapping
475 if( i
->find(',') == string::npos
) {
477 cerr
<< _("Unmapping: ") << *i
<< endl
;
481 cerr
<< _("Mapping: ") << *i
<< endl
;
483 // map... extract ldif/read/write names
484 string ldifname
, read
, write
;
485 if( SplitMap(*i
, ldifname
, read
, write
) ) {
486 if( !ldif
.Map(ldifname
, read
, write
) ) {
487 cerr
<< _("Read/Write name unknown: ") << *i
<< endl
;
491 cerr
<< _("Invalid map format: ") << *i
<< endl
;
497 bool ParseEpOverride(const char *arg
, Usb::EndpointPair
*epp
)
501 istringstream
iss(arg
);
502 iss
>> hex
>> read
>> comma
>> write
;
510 void ParseSortKey(const std::string
&key
)
512 istringstream
iss(key
);
514 getline(iss
, db
, ':');
515 getline(iss
, spec
, ':');
517 if( db
.size() && spec
.size() )
521 int main(int argc
, char *argv
[])
525 cout
.sync_with_stdio(true); // leave this on, since libusb uses
526 // stdio for debug messages
531 bool list_only
= false,
533 ldif_contacts
= false,
535 vformat_mode
= false,
536 reset_device
= false,
537 list_contact_fields
= false,
538 list_ldif_map
= false,
539 epp_override
= false,
540 threaded_sockets
= true,
541 record_state_table
= false,
542 clear_database
= false,
544 bbackup_mode
= false,
545 sort_records
= false,
546 show_parsers
= false,
548 string ldifBaseDN
, ldifDnAttr
;
554 vector
<string
> dbNames
, saveDbNames
, mapCommands
, clearDbNames
;
555 vector
<StateTableCommand
> stCommands
;
556 Usb::EndpointPair epOverride
;
558 // process command line options
560 int cmd
= getopt(argc
, argv
, "a:b:B:c:C:d:D:e:f:F:hi:IlLm:MnN:p:P:r:R:Ss:tT:vVXzZ");
566 case 'a': // Clear Database
567 clear_database
= true;
568 clearDbNames
.push_back(string(optarg
));
571 case 'b': // Barry backup filename (tar.gz)
572 #ifdef __BARRY_BACKUP_MODE__
573 if( filename
.size() == 0 ) {
578 cerr
<< "Do not use -f with -b\n";
582 cerr
<< _("-b option not supported - no Barry Backup library support available\n");
591 case 'c': // contacts to ldap ldif
592 ldif_contacts
= true;
596 case 'C': // DN Attribute for FQDN
600 case 'd': // show dbname
601 dbNames
.push_back(string(optarg
));
604 case 'D': // delete record
605 stCommands
.push_back(
606 StateTableCommand('D', false, atoi(optarg
)));
609 case 'e': // endpoint override
610 if( !ParseEpOverride(optarg
, &epOverride
) ) {
617 case 'f': // filename
618 #ifdef __BTOOL_BOOST_MODE__
619 if( !bbackup_mode
&& filename
.size() == 0 ) {
623 cerr
<< "Do not use -f with -b\n";
627 cerr
<< _("-f option not supported - no Boost serialization support available\n");
632 case 'F': // sort key
633 ParseSortKey(optarg
);
636 case 'i': // international charset (iconv)
637 iconvCharset
= optarg
;
640 case 'I': // sort before dump
644 case 'l': // list only
648 case 'L': // List Contact field names
649 list_contact_fields
= true;
652 case 'm': // Map / Unmap
653 mapCommands
.push_back(string(optarg
));
656 case 'M': // List LDIF map
657 list_ldif_map
= true;
660 case 'n': // use null parser
668 case 'p': // Blackberry PIN
669 pin
= strtoul(optarg
, NULL
, 16);
672 case 'P': // Device password
676 case 'r': // get specific record index
677 stCommands
.push_back(
678 StateTableCommand('r', false, atoi(optarg
)));
681 case 'R': // same as 'r', and clears dirty
682 stCommands
.push_back(
683 StateTableCommand('r', true, atoi(optarg
)));
686 case 's': // save dbname
687 saveDbNames
.push_back(string(optarg
));
690 case 'S': // show supported databases
697 case 't': // display database database
701 case 'T': // show RecordStateTable
702 record_state_table
= true;
703 dbNames
.push_back(string(optarg
));
706 case 'v': // data dump on
710 case 'V': // vformat MIME mode
711 #ifdef __BARRY_SYNC_MODE__
714 cerr
<< _("-V option not supported - no Sync library support available\n");
719 case 'X': // reset device
723 case 'z': // non-threaded sockets
724 threaded_sockets
= false;
727 case 'Z': // threaded socket router
728 threaded_sockets
= true;
739 ShowParsers(show_fields
, true);
744 // Initialize the barry library. Must be called before
746 Barry::Init(data_dump
);
748 int logical
, major
, minor
;
749 const char *Version
= Barry::Version(logical
, major
, minor
);
750 cout
<< Version
<< endl
;
753 // Create an IConverter object if needed
754 auto_ptr
<IConverter
> ic
;
755 if( iconvCharset
.size() ) {
756 ic
.reset( new IConverter(iconvCharset
.c_str(), true) );
759 // LDIF class... only needed if ldif output turned on
760 ContactLdif
ldif(ldifBaseDN
);
761 DoMapping(ldif
, mapCommands
);
762 if( ldifDnAttr
.size() ) {
763 if( !ldif
.SetDNAttr(ldifDnAttr
) ) {
764 cerr
<< _("Unable to set DN Attr: ") << ldifDnAttr
<< endl
;
768 // Probe the USB bus for Blackberry devices and display.
769 // If user has specified a PIN, search for it in the
770 // available device list here as well
771 Barry::Probe
probe(busname
.c_str(), devname
.c_str(),
772 epp_override
? &epOverride
: 0);
773 int activeDevice
= -1;
775 // show any errors during probe first
776 if( probe
.GetFailCount() ) {
779 cout
<< _("Blackberry device errors with errors during probe:") << endl
;
780 for( int i
= 0; i
< probe
.GetFailCount(); i
++ ) {
783 cout
<< probe
.GetFailMsg(i
) << endl
;
787 // show all successfully found devices
790 cout
<< _("Blackberry devices found:") << endl
;
791 for( int i
= 0; i
< probe
.GetCount(); i
++ ) {
795 probe
.Get(i
).DumpAll(cout
);
797 cout
<< probe
.Get(i
);
799 if( probe
.Get(i
).m_pin
== pin
)
806 if( activeDevice
== -1 ) {
808 // can we default to single device?
809 if( probe
.GetCount() == 1 )
812 cerr
<< _("No device selected") << endl
;
817 cerr
<< _("PIN not found: ")
818 << setbase(16) << pin
<< endl
;
825 cout
<< _("Using device (PIN): ")
826 << probe
.Get(activeDevice
).m_pin
.Str() << endl
;
829 Usb::Device
dev(probe
.Get(activeDevice
).m_dev
);
834 // Override device endpoints if user asks
835 Barry::ProbeResult device
= probe
.Get(activeDevice
);
837 device
.m_ep
.read
= epOverride
.read
;
838 device
.m_ep
.write
= epOverride
.write
;
839 // FIXME - override this too?
840 device
.m_ep
.type
= Usb::EndpointDescriptor::BulkType
;
841 cout
<< _("Endpoint pair (read,write) overridden with: ")
843 << (unsigned int) device
.m_ep
.read
<< ","
844 << (unsigned int) device
.m_ep
.write
<< endl
;
848 // execute each mode that was turned on
852 // Dump current LDIF mapping
853 if( list_ldif_map
) {
854 cout
<< ldif
<< endl
;
857 // Dump list of Contact field names
858 if( list_contact_fields
) {
859 for( const ContactLdif::NameToFunc
*n
= ldif
.GetFieldNames(); n
->name
; n
++ ) {
861 cout
<< " " << left
<< setw(20) << n
->name
<< ": "
862 << n
->description
<< endl
;
866 // Check if Desktop access is needed
869 record_state_table
||
873 saveDbNames
.size() ) )
877 // Create our controller object
879 // Order is important in the following auto_ptr<> objects,
880 // since Controller must get destroyed before router.
881 // Normally you'd pick one method, and not bother
882 // with auto_ptr<> and so the normal C++ constructor
883 // rules would guarantee this safety for you, but
884 // here we want the user to pick.
886 auto_ptr
<SocketRoutingQueue
> router
;
887 if( threaded_sockets
) {
888 router
.reset( new SocketRoutingQueue
);
889 router
->SpinoffSimpleReadThread();
892 DesktopConnector
connector(password
.c_str(),
893 iconvCharset
, device
, router
.get());
894 if( !connector
.Connect() ) {
895 // bad password (default action is not to prompt)
896 cerr
<< connector
.GetBadPassword().what() << endl
;
900 Barry::Mode::Desktop
&desktop
= connector
.GetDesktop();
902 // Dump list of all databases to stdout
904 // open desktop mode socket
905 cout
<< desktop
.GetDBDB() << endl
;
908 // Dump list of contacts to an LDAP LDIF file
909 // This uses the Controller convenience templates
910 if( ldif_contacts
) {
911 // create a storage functor object that accepts
912 // Barry::Contact objects as input
913 Contact2Ldif
storage(ldif
);
915 // load all the Contact records into storage
916 desktop
.LoadDatabaseByType
<Barry::Contact
>(storage
);
919 // Dump record state table to stdout
920 if( record_state_table
) {
921 if( dbNames
.size() == 0 ) {
922 cout
<< _("No db names to process") << endl
;
926 vector
<string
>::iterator b
= dbNames
.begin();
927 for( ; b
!= dbNames
.end(); b
++ ) {
928 unsigned int id
= desktop
.GetDBID(*b
);
929 RecordStateTable state
;
930 desktop
.GetRecordStateTable(id
, state
);
931 cout
<< _("Record state table for: ") << *b
<< endl
;
937 // Get Record mode overrides the default name mode
938 if( stCommands
.size() ) {
939 if( dbNames
.size() != 1 ) {
940 cout
<< _("Must have 1 db name to process") << endl
;
944 unsigned int id
= desktop
.GetDBID(dbNames
[0]);
945 shared_ptr
<Parser
> parse
= GetParser(dbNames
[0],filename
,
946 null_parser
, true, vformat_mode
, bbackup_mode
);
948 for( unsigned int i
= 0; i
< stCommands
.size(); i
++ ) {
949 desktop
.GetRecord(id
, stCommands
[i
].index
, *parse
.get());
951 if( stCommands
[i
].flag
== 'r' && stCommands
[i
].clear
) {
952 cout
<< _("Clearing record's dirty flags...") << endl
;
953 desktop
.ClearDirty(id
, stCommands
[i
].index
);
956 if( stCommands
[i
].flag
== 'D' ) {
957 desktop
.DeleteRecord(id
, stCommands
[i
].index
);
964 // Dump contents of selected databases to stdout, or
965 // to file if specified.
966 // This is retrieving data from the Blackberry.
967 if( dbNames
.size() ) {
968 vector
<string
>::iterator b
= dbNames
.begin();
970 for( ; b
!= dbNames
.end(); b
++ ) {
971 shared_ptr
<Parser
> parse
= GetParser(*b
,
972 filename
, null_parser
, !sort_records
,
973 vformat_mode
, bbackup_mode
);
974 unsigned int id
= desktop
.GetDBID(*b
);
975 desktop
.LoadDatabase(id
, *parse
.get());
980 if( clear_database
) {
981 if( clearDbNames
.size() == 0 ) {
982 cout
<< _("No db names to erase") << endl
;
986 vector
<string
>::iterator b
= clearDbNames
.begin();
988 for( ; b
!= clearDbNames
.end(); b
++ ) {
989 unsigned int id
= desktop
.GetDBID(*b
);
990 cout
<< _("Deleting all records from ") << (*b
) << "..." << endl
;
991 desktop
.ClearDatabase(id
);
997 // Save contents of file to specified databases
998 // This is writing data to the Blackberry.
999 if( saveDbNames
.size() ) {
1000 vector
<string
>::iterator b
= saveDbNames
.begin();
1002 for( ; b
!= saveDbNames
.end(); b
++ ) {
1003 shared_ptr
<Builder
> build
= GetBuilder(*b
,
1005 unsigned int id
= desktop
.GetDBID(*b
);
1006 desktop
.SaveDatabase(id
, *build
);
1011 catch( Usb::Error
&ue
) {
1012 std::cerr
<< _("Usb::Error caught: ") << ue
.what() << endl
;
1015 catch( Barry::Error
&se
) {
1016 std::cerr
<< _("Barry::Error caught: ") << se
.what() << endl
;
1019 catch( std::exception
&e
) {
1020 std::cerr
<< _("std::exception caught: ") << e
.what() << endl
;