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.
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>
43 #ifdef __BARRY_BACKUP_MODE__
44 #include <barry/barrybackup.h>
58 #include "boostwrap.h"
60 #include "barrygetopt.h"
63 using namespace std::tr1
;
64 using namespace Barry
;
66 std::map
<std::string
, std::string
> SortKeys
;
70 int logical
, major
, minor
;
71 const char *Version
= Barry::Version(logical
, major
, minor
);
74 << "btool - Command line USB Blackberry Test Tool\n"
75 << " Copyright 2005-2012, Net Direct Inc. (http://www.netdirect.ca/)\n"
76 << " Using: " << Version
<< "\n"
78 #ifdef __BTOOL_BOOST_MODE__
85 << " -b file Filename to save or load a Barry Backup to (tar.gz)\n"
86 << " -B bus Specify which USB bus to search on\n"
87 << " -N dev Specify which system device, using system specific string\n"
89 << " -a db Erase / clear database 'db' FROM device, deleting all\n"
90 << " its records. Can be used multiple times to clear more\n"
92 << " -c dn Convert address book database to LDIF format, using the\n"
93 << " specified baseDN\n"
94 << " -C dnattr LDIF attribute name to use when building the FQDN\n"
95 << " Defaults to 'cn'\n"
96 << " -d db Load database 'db' FROM device and dump to screen\n"
97 << " Can be used multiple times to fetch more than one DB\n"
98 << " -e epp Override endpoint pair detection. 'epp' is a single\n"
99 << " string separated by a comma, holding the read,write\n"
100 << " endpoint pair. Example: -e 83,5\n"
101 << " Note: Endpoints are specified in hex.\n"
102 << " You should never need to use this option.\n"
103 #ifdef __BTOOL_BOOST_MODE__
104 << " -f file Filename to save or load handheld data to/from\n"
106 << " -F sort Field name by which to sort the output. Note that the\n"
107 << " format of this field is special: 'DBName:field1,field2'\n"
108 << " with no spaces unless the spaces are part of the name.\n"
109 << " Can be used multiple times, to match your -d options.\n"
110 << " Example: -F 'Address Book:Company,LastName,FirstName'\n"
112 << " -i cs International charset for string conversions\n"
113 << " Valid values here are available with 'iconv --list'\n"
114 << " -I Sort records before output\n"
115 << " -l List devices\n"
116 << " -L List Contact field names\n"
117 << " -m Map LDIF name to Contact field / Unmap LDIF name\n"
118 << " Map: ldif,read,write - maps ldif to read/write Contact fields\n"
119 << " Unmap: ldif name alone\n"
120 << " -M List current LDIF mapping\n"
121 << " -n Use null parser on all databases.\n"
122 << " -p pin PIN of device to talk with\n"
123 << " If only one device is plugged in, this flag is optional\n"
124 << " -P pass Simplistic method to specify device password\n"
125 << " -s db Save database 'db' TO device from data loaded from -f file\n"
126 << " -S Show list of supported database parsers. Use twice to\n"
127 << " display fields names as well.\n"
128 << " -t Show database database table\n"
129 << " -T db Show record state table for given database\n"
130 << " -v Dump protocol data during operation\n"
131 #ifdef __BARRY_SYNC_MODE__
132 << " -V Dump records using MIME vformats where possible\n"
134 << " -X Reset device\n"
135 << " -z Use non-threaded sockets\n"
136 << " -Z Use threaded socket router (default)\n"
138 << " -d Command modifiers: (can be used multiple times for more than 1 record)\n"
140 << " -r # Record index number as seen in the -T state table.\n"
141 << " This overrides the default -d behaviour, and only\n"
142 << " downloads the one specified record, sending to stdout.\n"
143 << " -R # Same as -r, but also clears the record's dirty flags.\n"
144 << " -D # Record index number as seen in the -T state table,\n"
145 << " which indicates the record to delete. Used with the -d\n"
146 << " command to specify the database.\n"
153 Barry::ContactLdif
&ldif
;
155 Contact2Ldif(Barry::ContactLdif
&ldif
) : ldif(ldif
) {}
157 void operator()(const Contact
&rec
)
159 ldif
.DumpLdif(cout
, rec
);
163 template <class Record
>
166 std::vector
<Record
> records
;
167 mutable typename
std::vector
<Record
>::const_iterator rec_it
;
168 std::string filename
;
170 bool immediate_display
;
172 int from_device_count
;
173 mutable int to_device_count
;
175 Store(const string
&filename
, bool load
, bool immediate_display
,
177 : rec_it(records
.end()),
180 immediate_display(immediate_display
&& !SortKeys
.size()),
181 vformat_mode(vformat_mode
),
182 from_device_count(0),
185 #ifdef __BTOOL_BOOST_MODE__
186 if( load
&& filename
.size() ) {
187 // filename is available, attempt to load
188 cout
<< "Loading: " << filename
<< endl
;
189 string errmsg
, dbName
;
190 if( !LoadBoostFile(filename
, records
, dbName
, errmsg
) ) {
191 cerr
<< errmsg
<< endl
;
193 cout
<< records
.size()
194 << " records loaded from '"
195 << filename
<< "'" << endl
;
196 sort(records
.begin(), records
.end());
197 rec_it
= records
.begin();
200 typename
std::vector
<Record
>::const_iterator beg
= records
.begin(), end
= records
.end();
201 for( ; beg
!= end
; beg
++ ) {
202 cout
<< (*beg
) << endl
;
210 if( !immediate_display
) {
211 // not dumped yet, sort then dump
212 if( SortKeys
.size() && SortKeys
.find(Record::GetDBName()) != SortKeys
.end() ) {
213 sort(records
.begin(), records
.end(),
214 NamedFieldCmp
<Record
>(SortKeys
[Record::GetDBName()]));
217 sort(records
.begin(), records
.end());
222 cout
<< "Store counted " << dec
<< from_device_count
<< " records read from device, and " << dec
<< to_device_count
<< " records written to device." << endl
;
223 #ifdef __BTOOL_BOOST_MODE__
224 if( !load
&& filename
.size() ) {
225 // filename is available, attempt to save
226 cout
<< "Saving: " << filename
<< endl
;
228 if( !SaveBoostFile(filename
, records
, errmsg
) ) {
229 cerr
<< errmsg
<< endl
;
231 cout
<< dec
<< records
.size() << " records saved to '"
232 << filename
<< "'" << endl
;
239 typename vector
<Record
>::const_iterator i
= records
.begin();
240 for( ; i
!= records
.end(); ++i
) {
245 void Dump(const Record
&rec
)
248 #ifdef __BARRY_SYNC_MODE__
259 void operator()(const Record
&rec
)
262 if( immediate_display
)
264 records
.push_back(rec
);
267 // retrieval operator
268 bool operator()(Record
&rec
, Builder
&builder
) const
270 if( rec_it
== records
.end() )
279 shared_ptr
<Parser
> GetParser(const string
&name
,
280 const string
&filename
,
282 bool immediate_display
,
286 bool dnow
= immediate_display
;
287 bool vmode
= vformat_mode
;
291 return shared_ptr
<Parser
>( new Barry::HexDumpParser(cout
) );
293 else if( bbackup_mode
) {
294 #ifdef __BARRY_BACKUP_MODE__
295 // Only one backup file per run
296 static shared_ptr
<Parser
> backup
;
297 if( !backup
.get() ) {
298 backup
.reset( new Backup(filename
) );
302 return shared_ptr
<Parser
>( new Barry::HexDumpParser(cout
) );
305 // check for recognized database names
306 else if( name
== Contact::GetDBName() ) {
307 return shared_ptr
<Parser
>(
308 new RecordParser
<Contact
, Store
<Contact
> > (
309 new Store
<Contact
>(filename
, false, dnow
, vmode
)));
311 else if( name
== Message::GetDBName() ) {
312 return shared_ptr
<Parser
>(
313 new RecordParser
<Message
, Store
<Message
> > (
314 new Store
<Message
>(filename
, false, dnow
, vmode
)));
316 else if( name
== Calendar::GetDBName() ) {
317 return shared_ptr
<Parser
>(
318 new RecordParser
<Calendar
, Store
<Calendar
> > (
319 new Store
<Calendar
>(filename
, false, dnow
, vmode
)));
321 else if( name
== CalendarAll::GetDBName() ) {
322 return shared_ptr
<Parser
>(
323 new RecordParser
<CalendarAll
, Store
<CalendarAll
> > (
324 new Store
<CalendarAll
>(filename
, false, dnow
, vmode
)));
326 else if( name
== CallLog::GetDBName() ) {
327 return shared_ptr
<Parser
>(
328 new RecordParser
<CallLog
, Store
<CallLog
> > (
329 new Store
<CallLog
>(filename
, false, dnow
, vmode
)));
331 else if( name
== Bookmark::GetDBName() ) {
332 return shared_ptr
<Parser
>(
333 new RecordParser
<Bookmark
, Store
<Bookmark
> > (
334 new Store
<Bookmark
>(filename
, false, dnow
, vmode
)));
336 else if( name
== ServiceBook::GetDBName() ) {
337 return shared_ptr
<Parser
>(
338 new RecordParser
<ServiceBook
, Store
<ServiceBook
> > (
339 new Store
<ServiceBook
>(filename
, false, dnow
, vmode
)));
342 else if( name
== Memo::GetDBName() ) {
343 return shared_ptr
<Parser
>(
344 new RecordParser
<Memo
, Store
<Memo
> > (
345 new Store
<Memo
>(filename
, false, dnow
, vmode
)));
347 else if( name
== Task::GetDBName() ) {
348 return shared_ptr
<Parser
>(
349 new RecordParser
<Task
, Store
<Task
> > (
350 new Store
<Task
>(filename
, false, dnow
, vmode
)));
352 else if( name
== PINMessage::GetDBName() ) {
353 return shared_ptr
<Parser
>(
354 new RecordParser
<PINMessage
, Store
<PINMessage
> > (
355 new Store
<PINMessage
>(filename
, false, dnow
, vmode
)));
357 else if( name
== SavedMessage::GetDBName() ) {
358 return shared_ptr
<Parser
>(
359 new RecordParser
<SavedMessage
, Store
<SavedMessage
> > (
360 new Store
<SavedMessage
>(filename
, false, dnow
, vmode
)));
362 else if( name
== Sms::GetDBName() ) {
363 return shared_ptr
<Parser
>(
364 new RecordParser
<Sms
, Store
<Sms
> > (
365 new Store
<Sms
>(filename
, false, dnow
, vmode
)));
367 else if( name
== Folder::GetDBName() ) {
368 return shared_ptr
<Parser
>(
369 new RecordParser
<Folder
, Store
<Folder
> > (
370 new Store
<Folder
>(filename
, false, dnow
, vmode
)));
372 else if( name
== TimeZone::GetDBName() ) {
373 return shared_ptr
<Parser
>(
374 new RecordParser
<TimeZone
, Store
<TimeZone
> > (
375 new Store
<TimeZone
>(filename
, false, dnow
, vmode
)));
377 else if( name
== HandheldAgent::GetDBName() ) {
378 return shared_ptr
<Parser
>(
379 new RecordParser
<HandheldAgent
, Store
<HandheldAgent
> > (
380 new Store
<HandheldAgent
>(filename
, false, dnow
, vmode
)));
383 // unknown database, use null parser
384 return shared_ptr
<Parser
>( new Barry::HexDumpParser(cout
) );
388 shared_ptr
<Builder
> GetBuilder(const string
&name
, const string
&filename
)
390 // check for recognized database names
391 if( name
== Contact::GetDBName() ) {
392 return shared_ptr
<Builder
>(
393 new RecordBuilder
<Contact
, Store
<Contact
> > (
394 new Store
<Contact
>(filename
, true, true, false)));
396 else if( name
== Calendar::GetDBName() ) {
397 return shared_ptr
<Builder
>(
398 new RecordBuilder
<Calendar
, Store
<Calendar
> > (
399 new Store
<Calendar
>(filename
, true, true, false)));
401 else if( name
== CalendarAll::GetDBName() ) {
402 return shared_ptr
<Builder
>(
403 new RecordBuilder
<CalendarAll
, Store
<CalendarAll
> > (
404 new Store
<CalendarAll
>(filename
, true, true, false)));
406 else if( name
== Memo::GetDBName() ) {
407 return shared_ptr
<Builder
>(
408 new RecordBuilder
<Memo
, Store
<Memo
> > (
409 new Store
<Memo
>(filename
, true, true, false)));
411 else if( name
== Task::GetDBName() ) {
412 return shared_ptr
<Builder
>(
413 new RecordBuilder
<Task
, Store
<Task
> > (
414 new Store
<Task
>(filename
, true, true, false)));
417 else if( name == "Messages" ) {
418 return shared_ptr<Parser>(
419 new RecordParser<Message, Store<Message> > (
420 new Store<Message>(filename, true, true, false)));
422 else if( name == "Service Book" ) {
423 return shared_ptr<Parser>(
424 new RecordParser<ServiceBook, Store<ServiceBook> > (
425 new Store<ServiceBook>(filename, true, true, false)));
429 throw std::runtime_error("No Builder available for database");
433 struct StateTableCommand
439 StateTableCommand(char f
, bool c
, unsigned int i
)
440 : flag(f
), clear(c
), index(i
) {}
443 bool SplitMap(const string
&map
, string
&ldif
, string
&read
, string
&write
)
445 string::size_type a
= map
.find(',');
446 if( a
== string::npos
)
449 string::size_type b
= map
.find(',', a
+1);
450 if( b
== string::npos
)
453 ldif
.assign(map
, 0, a
);
454 read
.assign(map
, a
+ 1, b
- a
- 1);
455 write
.assign(map
, b
+ 1, map
.size() - b
- 1);
457 return ldif
.size() && read
.size() && write
.size();
460 void DoMapping(ContactLdif
&ldif
, const vector
<string
> &mapCommands
)
462 for( vector
<string
>::const_iterator i
= mapCommands
.begin();
463 i
!= mapCommands
.end();
466 // single names mean unmapping
467 if( i
->find(',') == string::npos
) {
469 cerr
<< "Unmapping: " << *i
<< endl
;
473 cerr
<< "Mapping: " << *i
<< endl
;
475 // map... extract ldif/read/write names
476 string ldifname
, read
, write
;
477 if( SplitMap(*i
, ldifname
, read
, write
) ) {
478 if( !ldif
.Map(ldifname
, read
, write
) ) {
479 cerr
<< "Read/Write name unknown: " << *i
<< endl
;
483 cerr
<< "Invalid map format: " << *i
<< endl
;
489 bool ParseEpOverride(const char *arg
, Usb::EndpointPair
*epp
)
493 istringstream
iss(arg
);
494 iss
>> hex
>> read
>> comma
>> write
;
502 void ParseSortKey(const std::string
&key
)
504 istringstream
iss(key
);
506 getline(iss
, db
, ':');
507 getline(iss
, spec
, ':');
509 if( db
.size() && spec
.size() )
513 int main(int argc
, char *argv
[])
517 cout
.sync_with_stdio(true); // leave this on, since libusb uses
518 // stdio for debug messages
523 bool list_only
= false,
525 ldif_contacts
= false,
527 vformat_mode
= false,
528 reset_device
= false,
529 list_contact_fields
= false,
530 list_ldif_map
= false,
531 epp_override
= false,
532 threaded_sockets
= true,
533 record_state_table
= false,
534 clear_database
= false,
536 bbackup_mode
= false,
537 sort_records
= false,
538 show_parsers
= false,
540 string ldifBaseDN
, ldifDnAttr
;
546 vector
<string
> dbNames
, saveDbNames
, mapCommands
, clearDbNames
;
547 vector
<StateTableCommand
> stCommands
;
548 Usb::EndpointPair epOverride
;
550 // process command line options
552 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");
558 case 'a': // Clear Database
559 clear_database
= true;
560 clearDbNames
.push_back(string(optarg
));
563 case 'b': // Barry backup filename (tar.gz)
564 #ifdef __BARRY_BACKUP_MODE__
565 if( filename
.size() == 0 ) {
570 cerr
<< "Do not use -f with -b\n";
574 cerr
<< "-b option not supported - no Barry "
575 "Backup library support available\n";
584 case 'c': // contacts to ldap ldif
585 ldif_contacts
= true;
589 case 'C': // DN Attribute for FQDN
593 case 'd': // show dbname
594 dbNames
.push_back(string(optarg
));
597 case 'D': // delete record
598 stCommands
.push_back(
599 StateTableCommand('D', false, atoi(optarg
)));
602 case 'e': // endpoint override
603 if( !ParseEpOverride(optarg
, &epOverride
) ) {
610 case 'f': // filename
611 #ifdef __BTOOL_BOOST_MODE__
612 if( !bbackup_mode
&& filename
.size() == 0 ) {
616 cerr
<< "Do not use -f with -b\n";
620 cerr
<< "-f option not supported - no Boost "
621 "serialization support available\n";
626 case 'F': // sort key
627 ParseSortKey(optarg
);
630 case 'i': // international charset (iconv)
631 iconvCharset
= optarg
;
634 case 'I': // sort before dump
638 case 'l': // list only
642 case 'L': // List Contact field names
643 list_contact_fields
= true;
646 case 'm': // Map / Unmap
647 mapCommands
.push_back(string(optarg
));
650 case 'M': // List LDIF map
651 list_ldif_map
= true;
654 case 'n': // use null parser
662 case 'p': // Blackberry PIN
663 pin
= strtoul(optarg
, NULL
, 16);
666 case 'P': // Device password
670 case 'r': // get specific record index
671 stCommands
.push_back(
672 StateTableCommand('r', false, atoi(optarg
)));
675 case 'R': // same as 'r', and clears dirty
676 stCommands
.push_back(
677 StateTableCommand('r', true, atoi(optarg
)));
680 case 's': // save dbname
681 saveDbNames
.push_back(string(optarg
));
684 case 'S': // show supported databases
691 case 't': // display database database
695 case 'T': // show RecordStateTable
696 record_state_table
= true;
697 dbNames
.push_back(string(optarg
));
700 case 'v': // data dump on
704 case 'V': // vformat MIME mode
705 #ifdef __BARRY_SYNC_MODE__
708 cerr
<< "-V option not supported - no Sync "
709 "library support available\n";
714 case 'X': // reset device
718 case 'z': // non-threaded sockets
719 threaded_sockets
= false;
722 case 'Z': // threaded socket router
723 threaded_sockets
= true;
734 ShowParsers(show_fields
, true);
739 // Initialize the barry library. Must be called before
741 Barry::Init(data_dump
);
743 int logical
, major
, minor
;
744 const char *Version
= Barry::Version(logical
, major
, minor
);
745 cout
<< Version
<< endl
;
748 // Create an IConverter object if needed
749 auto_ptr
<IConverter
> ic
;
750 if( iconvCharset
.size() ) {
751 ic
.reset( new IConverter(iconvCharset
.c_str(), true) );
754 // LDIF class... only needed if ldif output turned on
755 ContactLdif
ldif(ldifBaseDN
);
756 DoMapping(ldif
, mapCommands
);
757 if( ldifDnAttr
.size() ) {
758 if( !ldif
.SetDNAttr(ldifDnAttr
) ) {
759 cerr
<< "Unable to set DN Attr: " << ldifDnAttr
<< endl
;
763 // Probe the USB bus for Blackberry devices and display.
764 // If user has specified a PIN, search for it in the
765 // available device list here as well
766 Barry::Probe
probe(busname
.c_str(), devname
.c_str(),
767 epp_override
? &epOverride
: 0);
768 int activeDevice
= -1;
770 // show any errors during probe first
771 if( probe
.GetFailCount() ) {
774 cout
<< "Blackberry device errors with errors during probe:" << endl
;
775 for( int i
= 0; i
< probe
.GetFailCount(); i
++ ) {
778 cout
<< probe
.GetFailMsg(i
) << endl
;
782 // show all successfully found devices
785 cout
<< "Blackberry devices found:" << endl
;
786 for( int i
= 0; i
< probe
.GetCount(); i
++ ) {
790 probe
.Get(i
).DumpAll(cout
);
792 cout
<< probe
.Get(i
);
794 if( probe
.Get(i
).m_pin
== pin
)
801 if( activeDevice
== -1 ) {
803 // can we default to single device?
804 if( probe
.GetCount() == 1 )
807 cerr
<< "No device selected" << endl
;
812 cerr
<< "PIN " << setbase(16) << pin
813 << " not found" << endl
;
820 cout
<< "Using device (PIN): "
821 << probe
.Get(activeDevice
).m_pin
.Str() << endl
;
824 Usb::Device
dev(probe
.Get(activeDevice
).m_dev
);
829 // Override device endpoints if user asks
830 Barry::ProbeResult device
= probe
.Get(activeDevice
);
832 device
.m_ep
.read
= epOverride
.read
;
833 device
.m_ep
.write
= epOverride
.write
;
834 // FIXME - override this too?
835 device
.m_ep
.type
= Usb::EndpointDescriptor::BulkType
;
836 cout
<< "Endpoint pair (read,write) overridden with: "
838 << (unsigned int) device
.m_ep
.read
<< ","
839 << (unsigned int) device
.m_ep
.write
<< endl
;
843 // execute each mode that was turned on
847 // Dump current LDIF mapping
848 if( list_ldif_map
) {
849 cout
<< ldif
<< endl
;
852 // Dump list of Contact field names
853 if( list_contact_fields
) {
854 for( const ContactLdif::NameToFunc
*n
= ldif
.GetFieldNames(); n
->name
; n
++ ) {
856 cout
<< " " << left
<< setw(20) << n
->name
<< ": "
857 << n
->description
<< endl
;
861 // Check if Desktop access is needed
864 record_state_table
||
868 saveDbNames
.size() ) )
872 // Create our controller object
874 // Order is important in the following auto_ptr<> objects,
875 // since Controller must get destroyed before router.
876 // Normally you'd pick one method, and not bother
877 // with auto_ptr<> and so the normal C++ constructor
878 // rules would guarantee this safety for you, but
879 // here we want the user to pick.
881 auto_ptr
<SocketRoutingQueue
> router
;
882 if( threaded_sockets
) {
883 router
.reset( new SocketRoutingQueue
);
884 router
->SpinoffSimpleReadThread();
887 DesktopConnector
connector(password
.c_str(),
888 iconvCharset
, device
, router
.get());
889 if( !connector
.Connect() ) {
890 // bad password (default action is not to prompt)
891 cerr
<< connector
.GetBadPassword().what() << endl
;
895 Barry::Mode::Desktop
&desktop
= connector
.GetDesktop();
897 // Dump list of all databases to stdout
899 // open desktop mode socket
900 cout
<< desktop
.GetDBDB() << endl
;
903 // Dump list of contacts to an LDAP LDIF file
904 // This uses the Controller convenience templates
905 if( ldif_contacts
) {
906 // create a storage functor object that accepts
907 // Barry::Contact objects as input
908 Contact2Ldif
storage(ldif
);
910 // load all the Contact records into storage
911 desktop
.LoadDatabaseByType
<Barry::Contact
>(storage
);
914 // Dump record state table to stdout
915 if( record_state_table
) {
916 if( dbNames
.size() == 0 ) {
917 cout
<< "No db names to process" << endl
;
921 vector
<string
>::iterator b
= dbNames
.begin();
922 for( ; b
!= dbNames
.end(); b
++ ) {
923 unsigned int id
= desktop
.GetDBID(*b
);
924 RecordStateTable state
;
925 desktop
.GetRecordStateTable(id
, state
);
926 cout
<< "Record state table for: " << *b
<< endl
;
932 // Get Record mode overrides the default name mode
933 if( stCommands
.size() ) {
934 if( dbNames
.size() != 1 ) {
935 cout
<< "Must have 1 db name to process" << endl
;
939 unsigned int id
= desktop
.GetDBID(dbNames
[0]);
940 shared_ptr
<Parser
> parse
= GetParser(dbNames
[0],filename
,
941 null_parser
, true, vformat_mode
, bbackup_mode
);
943 for( unsigned int i
= 0; i
< stCommands
.size(); i
++ ) {
944 desktop
.GetRecord(id
, stCommands
[i
].index
, *parse
.get());
946 if( stCommands
[i
].flag
== 'r' && stCommands
[i
].clear
) {
947 cout
<< "Clearing record's dirty flags..." << endl
;
948 desktop
.ClearDirty(id
, stCommands
[i
].index
);
951 if( stCommands
[i
].flag
== 'D' ) {
952 desktop
.DeleteRecord(id
, stCommands
[i
].index
);
959 // Dump contents of selected databases to stdout, or
960 // to file if specified.
961 // This is retrieving data from the Blackberry.
962 if( dbNames
.size() ) {
963 vector
<string
>::iterator b
= dbNames
.begin();
965 for( ; b
!= dbNames
.end(); b
++ ) {
966 shared_ptr
<Parser
> parse
= GetParser(*b
,
967 filename
, null_parser
, !sort_records
,
968 vformat_mode
, bbackup_mode
);
969 unsigned int id
= desktop
.GetDBID(*b
);
970 desktop
.LoadDatabase(id
, *parse
.get());
975 if( clear_database
) {
976 if( clearDbNames
.size() == 0 ) {
977 cout
<< "No db names to erase" << endl
;
981 vector
<string
>::iterator b
= clearDbNames
.begin();
983 for( ; b
!= clearDbNames
.end(); b
++ ) {
984 unsigned int id
= desktop
.GetDBID(*b
);
985 cout
<< "Deleting all records from " << (*b
) << "..." << endl
;
986 desktop
.ClearDatabase(id
);
992 // Save contents of file to specified databases
993 // This is writing data to the Blackberry.
994 if( saveDbNames
.size() ) {
995 vector
<string
>::iterator b
= saveDbNames
.begin();
997 for( ; b
!= saveDbNames
.end(); b
++ ) {
998 shared_ptr
<Builder
> build
= GetBuilder(*b
,
1000 unsigned int id
= desktop
.GetDBID(*b
);
1001 desktop
.SaveDatabase(id
, *build
);
1006 catch( Usb::Error
&ue
) {
1007 std::cerr
<< "Usb::Error caught: " << ue
.what() << endl
;
1010 catch( Barry::Error
&se
) {
1011 std::cerr
<< "Barry::Error caught: " << se
.what() << endl
;
1014 catch( std::exception
&e
) {
1015 std::cerr
<< "std::exception caught: " << e
.what() << endl
;