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>
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
);
73 << "btool - Command line USB Blackberry Test Tool\n"
74 << " Copyright 2005-2012, Net Direct Inc. (http://www.netdirect.ca/)\n"
75 << " Using: " << Version
<< "\n"
77 #ifdef __BTOOL_BOOST_MODE__
84 << " -b file Filename to save or load a Barry Backup to (tar.gz)\n"
85 << " -B bus Specify which USB bus to search on\n"
86 << " -N dev Specify which system device, using system specific string\n"
88 << " -a db Erase / clear database 'db' FROM device, deleting all\n"
89 << " its records. Can be used multiple times to clear more\n"
91 << " -c dn Convert address book database to LDIF format, using the\n"
92 << " specified baseDN\n"
93 << " -C dnattr LDIF attribute name to use when building the FQDN\n"
94 << " Defaults to 'cn'\n"
95 << " -d db Load database 'db' FROM device and dump to screen\n"
96 << " Can be used multiple times to fetch more than one DB\n"
97 << " -e epp Override endpoint pair detection. 'epp' is a single\n"
98 << " string separated by a comma, holding the read,write\n"
99 << " endpoint pair. Example: -e 83,5\n"
100 << " Note: Endpoints are specified in hex.\n"
101 << " You should never need to use this option.\n"
102 #ifdef __BTOOL_BOOST_MODE__
103 << " -f file Filename to save or load handheld data to/from\n"
105 << " -F sort Field name by which to sort the output. Note that the\n"
106 << " format of this field is special: 'DBName:field1,field2'\n"
107 << " with no spaces unless the spaces are part of the name.\n"
108 << " Can be used multiple times, to match your -d options.\n"
109 << " Example: -F 'Address Book:Company,LastName,FirstName'\n"
111 << " -i cs International charset for string conversions\n"
112 << " Valid values here are available with 'iconv --list'\n"
113 << " -I Sort records before output\n"
114 << " -l List devices\n"
115 << " -L List Contact field names\n"
116 << " -m Map LDIF name to Contact field / Unmap LDIF name\n"
117 << " Map: ldif,read,write - maps ldif to read/write Contact fields\n"
118 << " Unmap: ldif name alone\n"
119 << " -M List current LDIF mapping\n"
120 << " -n Use null parser on all databases.\n"
121 << " -p pin PIN of device to talk with\n"
122 << " If only one device is plugged in, this flag is optional\n"
123 << " -P pass Simplistic method to specify device password\n"
124 << " -s db Save database 'db' TO device from data loaded from -f file\n"
125 << " -S Show list of supported database parsers. Use twice to\n"
126 << " display fields names as well.\n"
127 << " -t Show database database table\n"
128 << " -T db Show record state table for given database\n"
129 << " -v Dump protocol data during operation\n"
130 #ifdef __BARRY_SYNC_MODE__
131 << " -V Dump records using MIME vformats where possible\n"
133 << " -X Reset device\n"
134 << " -z Use non-threaded sockets\n"
135 << " -Z Use threaded socket router (default)\n"
137 << " -d Command modifiers: (can be used multiple times for more than 1 record)\n"
139 << " -r # Record index number as seen in the -T state table.\n"
140 << " This overrides the default -d behaviour, and only\n"
141 << " downloads the one specified record, sending to stdout.\n"
142 << " -R # Same as -r, but also clears the record's dirty flags.\n"
143 << " -D # Record index number as seen in the -T state table,\n"
144 << " which indicates the record to delete. Used with the -d\n"
145 << " command to specify the database.\n"
152 Barry::ContactLdif
&ldif
;
154 Contact2Ldif(Barry::ContactLdif
&ldif
) : ldif(ldif
) {}
156 void operator()(const Contact
&rec
)
158 ldif
.DumpLdif(cout
, rec
);
162 template <class Record
>
165 std::vector
<Record
> records
;
166 mutable typename
std::vector
<Record
>::const_iterator rec_it
;
167 std::string filename
;
169 bool immediate_display
;
171 int from_device_count
;
172 mutable int to_device_count
;
174 Store(const string
&filename
, bool load
, bool immediate_display
,
176 : rec_it(records
.end()),
179 immediate_display(immediate_display
&& !SortKeys
.size()),
180 vformat_mode(vformat_mode
),
181 from_device_count(0),
184 #ifdef __BTOOL_BOOST_MODE__
185 if( load
&& filename
.size() ) {
186 // filename is available, attempt to load
187 cout
<< "Loading: " << filename
<< endl
;
188 string errmsg
, dbName
;
189 if( !LoadBoostFile(filename
, records
, dbName
, errmsg
) ) {
190 cerr
<< errmsg
<< endl
;
192 cout
<< records
.size()
193 << " records loaded from '"
194 << filename
<< "'" << endl
;
195 sort(records
.begin(), records
.end());
196 rec_it
= records
.begin();
199 typename
std::vector
<Record
>::const_iterator beg
= records
.begin(), end
= records
.end();
200 for( ; beg
!= end
; beg
++ ) {
201 cout
<< (*beg
) << endl
;
209 if( !immediate_display
) {
210 // not dumped yet, sort then dump
211 if( SortKeys
.size() && SortKeys
.find(Record::GetDBName()) != SortKeys
.end() ) {
212 sort(records
.begin(), records
.end(),
213 NamedFieldCmp
<Record
>(SortKeys
[Record::GetDBName()]));
216 sort(records
.begin(), records
.end());
221 cout
<< "Store counted " << dec
<< from_device_count
<< " records read from device, and " << dec
<< to_device_count
<< " records written to device." << endl
;
222 #ifdef __BTOOL_BOOST_MODE__
223 if( !load
&& filename
.size() ) {
224 // filename is available, attempt to save
225 cout
<< "Saving: " << filename
<< endl
;
227 if( !SaveBoostFile(filename
, records
, errmsg
) ) {
228 cerr
<< errmsg
<< endl
;
230 cout
<< dec
<< records
.size() << " records saved to '"
231 << filename
<< "'" << endl
;
238 typename vector
<Record
>::const_iterator i
= records
.begin();
239 for( ; i
!= records
.end(); ++i
) {
244 void Dump(const Record
&rec
)
247 #ifdef __BARRY_SYNC_MODE__
258 void operator()(const Record
&rec
)
261 if( immediate_display
)
263 records
.push_back(rec
);
266 // retrieval operator
267 bool operator()(Record
&rec
, Builder
&builder
) const
269 if( rec_it
== records
.end() )
278 shared_ptr
<Parser
> GetParser(const string
&name
,
279 const string
&filename
,
281 bool immediate_display
,
285 bool dnow
= immediate_display
;
286 bool vmode
= vformat_mode
;
290 return shared_ptr
<Parser
>( new Barry::HexDumpParser(cout
) );
292 else if( bbackup_mode
) {
293 #ifdef __BARRY_BACKUP_MODE__
294 // Only one backup file per run
295 static shared_ptr
<Parser
> backup
;
296 if( !backup
.get() ) {
297 backup
.reset( new Backup(filename
) );
301 return shared_ptr
<Parser
>( new Barry::HexDumpParser(cout
) );
304 // check for recognized database names
305 else if( name
== Contact::GetDBName() ) {
306 return shared_ptr
<Parser
>(
307 new RecordParser
<Contact
, Store
<Contact
> > (
308 new Store
<Contact
>(filename
, false, dnow
, vmode
)));
310 else if( name
== Message::GetDBName() ) {
311 return shared_ptr
<Parser
>(
312 new RecordParser
<Message
, Store
<Message
> > (
313 new Store
<Message
>(filename
, false, dnow
, vmode
)));
315 else if( name
== Calendar::GetDBName() ) {
316 return shared_ptr
<Parser
>(
317 new RecordParser
<Calendar
, Store
<Calendar
> > (
318 new Store
<Calendar
>(filename
, false, dnow
, vmode
)));
320 else if( name
== CalendarAll::GetDBName() ) {
321 return shared_ptr
<Parser
>(
322 new RecordParser
<CalendarAll
, Store
<CalendarAll
> > (
323 new Store
<CalendarAll
>(filename
, false, dnow
, vmode
)));
325 else if( name
== CallLog::GetDBName() ) {
326 return shared_ptr
<Parser
>(
327 new RecordParser
<CallLog
, Store
<CallLog
> > (
328 new Store
<CallLog
>(filename
, false, dnow
, vmode
)));
330 else if( name
== Bookmark::GetDBName() ) {
331 return shared_ptr
<Parser
>(
332 new RecordParser
<Bookmark
, Store
<Bookmark
> > (
333 new Store
<Bookmark
>(filename
, false, dnow
, vmode
)));
335 else if( name
== ServiceBook::GetDBName() ) {
336 return shared_ptr
<Parser
>(
337 new RecordParser
<ServiceBook
, Store
<ServiceBook
> > (
338 new Store
<ServiceBook
>(filename
, false, dnow
, vmode
)));
341 else if( name
== Memo::GetDBName() ) {
342 return shared_ptr
<Parser
>(
343 new RecordParser
<Memo
, Store
<Memo
> > (
344 new Store
<Memo
>(filename
, false, dnow
, vmode
)));
346 else if( name
== Task::GetDBName() ) {
347 return shared_ptr
<Parser
>(
348 new RecordParser
<Task
, Store
<Task
> > (
349 new Store
<Task
>(filename
, false, dnow
, vmode
)));
351 else if( name
== PINMessage::GetDBName() ) {
352 return shared_ptr
<Parser
>(
353 new RecordParser
<PINMessage
, Store
<PINMessage
> > (
354 new Store
<PINMessage
>(filename
, false, dnow
, vmode
)));
356 else if( name
== SavedMessage::GetDBName() ) {
357 return shared_ptr
<Parser
>(
358 new RecordParser
<SavedMessage
, Store
<SavedMessage
> > (
359 new Store
<SavedMessage
>(filename
, false, dnow
, vmode
)));
361 else if( name
== Sms::GetDBName() ) {
362 return shared_ptr
<Parser
>(
363 new RecordParser
<Sms
, Store
<Sms
> > (
364 new Store
<Sms
>(filename
, false, dnow
, vmode
)));
366 else if( name
== Folder::GetDBName() ) {
367 return shared_ptr
<Parser
>(
368 new RecordParser
<Folder
, Store
<Folder
> > (
369 new Store
<Folder
>(filename
, false, dnow
, vmode
)));
371 else if( name
== TimeZone::GetDBName() ) {
372 return shared_ptr
<Parser
>(
373 new RecordParser
<TimeZone
, Store
<TimeZone
> > (
374 new Store
<TimeZone
>(filename
, false, dnow
, vmode
)));
376 else if( name
== HandheldAgent::GetDBName() ) {
377 return shared_ptr
<Parser
>(
378 new RecordParser
<HandheldAgent
, Store
<HandheldAgent
> > (
379 new Store
<HandheldAgent
>(filename
, false, dnow
, vmode
)));
382 // unknown database, use null parser
383 return shared_ptr
<Parser
>( new Barry::HexDumpParser(cout
) );
387 shared_ptr
<Builder
> GetBuilder(const string
&name
, const string
&filename
)
389 // check for recognized database names
390 if( name
== Contact::GetDBName() ) {
391 return shared_ptr
<Builder
>(
392 new RecordBuilder
<Contact
, Store
<Contact
> > (
393 new Store
<Contact
>(filename
, true, true, false)));
395 else if( name
== Calendar::GetDBName() ) {
396 return shared_ptr
<Builder
>(
397 new RecordBuilder
<Calendar
, Store
<Calendar
> > (
398 new Store
<Calendar
>(filename
, true, true, false)));
400 else if( name
== CalendarAll::GetDBName() ) {
401 return shared_ptr
<Builder
>(
402 new RecordBuilder
<CalendarAll
, Store
<CalendarAll
> > (
403 new Store
<CalendarAll
>(filename
, true, true, false)));
405 else if( name
== Memo::GetDBName() ) {
406 return shared_ptr
<Builder
>(
407 new RecordBuilder
<Memo
, Store
<Memo
> > (
408 new Store
<Memo
>(filename
, true, true, false)));
410 else if( name
== Task::GetDBName() ) {
411 return shared_ptr
<Builder
>(
412 new RecordBuilder
<Task
, Store
<Task
> > (
413 new Store
<Task
>(filename
, true, true, false)));
416 else if( name == "Messages" ) {
417 return shared_ptr<Parser>(
418 new RecordParser<Message, Store<Message> > (
419 new Store<Message>(filename, true, true, false)));
421 else if( name == "Service Book" ) {
422 return shared_ptr<Parser>(
423 new RecordParser<ServiceBook, Store<ServiceBook> > (
424 new Store<ServiceBook>(filename, true, true, false)));
428 throw std::runtime_error("No Builder available for database");
432 struct StateTableCommand
438 StateTableCommand(char f
, bool c
, unsigned int i
)
439 : flag(f
), clear(c
), index(i
) {}
442 bool SplitMap(const string
&map
, string
&ldif
, string
&read
, string
&write
)
444 string::size_type a
= map
.find(',');
445 if( a
== string::npos
)
448 string::size_type b
= map
.find(',', a
+1);
449 if( b
== string::npos
)
452 ldif
.assign(map
, 0, a
);
453 read
.assign(map
, a
+ 1, b
- a
- 1);
454 write
.assign(map
, b
+ 1, map
.size() - b
- 1);
456 return ldif
.size() && read
.size() && write
.size();
459 void DoMapping(ContactLdif
&ldif
, const vector
<string
> &mapCommands
)
461 for( vector
<string
>::const_iterator i
= mapCommands
.begin();
462 i
!= mapCommands
.end();
465 // single names mean unmapping
466 if( i
->find(',') == string::npos
) {
468 cerr
<< "Unmapping: " << *i
<< endl
;
472 cerr
<< "Mapping: " << *i
<< endl
;
474 // map... extract ldif/read/write names
475 string ldifname
, read
, write
;
476 if( SplitMap(*i
, ldifname
, read
, write
) ) {
477 if( !ldif
.Map(ldifname
, read
, write
) ) {
478 cerr
<< "Read/Write name unknown: " << *i
<< endl
;
482 cerr
<< "Invalid map format: " << *i
<< endl
;
488 bool ParseEpOverride(const char *arg
, Usb::EndpointPair
*epp
)
492 istringstream
iss(arg
);
493 iss
>> hex
>> read
>> comma
>> write
;
501 void ParseSortKey(const std::string
&key
)
503 istringstream
iss(key
);
505 getline(iss
, db
, ':');
506 getline(iss
, spec
, ':');
508 if( db
.size() && spec
.size() )
512 int main(int argc
, char *argv
[])
516 cout
.sync_with_stdio(true); // leave this on, since libusb uses
517 // stdio for debug messages
522 bool list_only
= false,
524 ldif_contacts
= false,
526 vformat_mode
= false,
527 reset_device
= false,
528 list_contact_fields
= false,
529 list_ldif_map
= false,
530 epp_override
= false,
531 threaded_sockets
= true,
532 record_state_table
= false,
533 clear_database
= false,
535 bbackup_mode
= false,
536 sort_records
= false,
537 show_parsers
= false,
539 string ldifBaseDN
, ldifDnAttr
;
545 vector
<string
> dbNames
, saveDbNames
, mapCommands
, clearDbNames
;
546 vector
<StateTableCommand
> stCommands
;
547 Usb::EndpointPair epOverride
;
549 // process command line options
551 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");
557 case 'a': // Clear Database
558 clear_database
= true;
559 clearDbNames
.push_back(string(optarg
));
562 case 'b': // Barry backup filename (tar.gz)
563 #ifdef __BARRY_BACKUP_MODE__
564 if( filename
.size() == 0 ) {
569 cerr
<< "Do not use -f with -b\n";
573 cerr
<< "-b option not supported - no Barry "
574 "Backup library support available\n";
583 case 'c': // contacts to ldap ldif
584 ldif_contacts
= true;
588 case 'C': // DN Attribute for FQDN
592 case 'd': // show dbname
593 dbNames
.push_back(string(optarg
));
596 case 'D': // delete record
597 stCommands
.push_back(
598 StateTableCommand('D', false, atoi(optarg
)));
601 case 'e': // endpoint override
602 if( !ParseEpOverride(optarg
, &epOverride
) ) {
609 case 'f': // filename
610 #ifdef __BTOOL_BOOST_MODE__
611 if( !bbackup_mode
&& filename
.size() == 0 ) {
615 cerr
<< "Do not use -f with -b\n";
619 cerr
<< "-f option not supported - no Boost "
620 "serialization support available\n";
625 case 'F': // sort key
626 ParseSortKey(optarg
);
629 case 'i': // international charset (iconv)
630 iconvCharset
= optarg
;
633 case 'I': // sort before dump
637 case 'l': // list only
641 case 'L': // List Contact field names
642 list_contact_fields
= true;
645 case 'm': // Map / Unmap
646 mapCommands
.push_back(string(optarg
));
649 case 'M': // List LDIF map
650 list_ldif_map
= true;
653 case 'n': // use null parser
661 case 'p': // Blackberry PIN
662 pin
= strtoul(optarg
, NULL
, 16);
665 case 'P': // Device password
669 case 'r': // get specific record index
670 stCommands
.push_back(
671 StateTableCommand('r', false, atoi(optarg
)));
674 case 'R': // same as 'r', and clears dirty
675 stCommands
.push_back(
676 StateTableCommand('r', true, atoi(optarg
)));
679 case 's': // save dbname
680 saveDbNames
.push_back(string(optarg
));
683 case 'S': // show supported databases
690 case 't': // display database database
694 case 'T': // show RecordStateTable
695 record_state_table
= true;
696 dbNames
.push_back(string(optarg
));
699 case 'v': // data dump on
703 case 'V': // vformat MIME mode
704 #ifdef __BARRY_SYNC_MODE__
707 cerr
<< "-V option not supported - no Sync "
708 "library support available\n";
713 case 'X': // reset device
717 case 'z': // non-threaded sockets
718 threaded_sockets
= false;
721 case 'Z': // threaded socket router
722 threaded_sockets
= true;
733 ShowParsers(show_fields
, true);
738 // Initialize the barry library. Must be called before
740 Barry::Init(data_dump
);
742 int logical
, major
, minor
;
743 const char *Version
= Barry::Version(logical
, major
, minor
);
744 cout
<< Version
<< endl
;
747 // Create an IConverter object if needed
748 auto_ptr
<IConverter
> ic
;
749 if( iconvCharset
.size() ) {
750 ic
.reset( new IConverter(iconvCharset
.c_str(), true) );
753 // LDIF class... only needed if ldif output turned on
754 ContactLdif
ldif(ldifBaseDN
);
755 DoMapping(ldif
, mapCommands
);
756 if( ldifDnAttr
.size() ) {
757 if( !ldif
.SetDNAttr(ldifDnAttr
) ) {
758 cerr
<< "Unable to set DN Attr: " << ldifDnAttr
<< endl
;
762 // Probe the USB bus for Blackberry devices and display.
763 // If user has specified a PIN, search for it in the
764 // available device list here as well
765 Barry::Probe
probe(busname
.c_str(), devname
.c_str(),
766 epp_override
? &epOverride
: 0);
767 int activeDevice
= -1;
769 // show any errors during probe first
770 if( probe
.GetFailCount() ) {
773 cout
<< "Blackberry device errors with errors during probe:" << endl
;
774 for( int i
= 0; i
< probe
.GetFailCount(); i
++ ) {
777 cout
<< probe
.GetFailMsg(i
) << endl
;
781 // show all successfully found devices
784 cout
<< "Blackberry devices found:" << endl
;
785 for( int i
= 0; i
< probe
.GetCount(); i
++ ) {
789 probe
.Get(i
).DumpAll(cout
);
791 cout
<< probe
.Get(i
);
793 if( probe
.Get(i
).m_pin
== pin
)
800 if( activeDevice
== -1 ) {
802 // can we default to single device?
803 if( probe
.GetCount() == 1 )
806 cerr
<< "No device selected" << endl
;
811 cerr
<< "PIN " << setbase(16) << pin
812 << " not found" << endl
;
819 cout
<< "Using device (PIN): "
820 << probe
.Get(activeDevice
).m_pin
.Str() << endl
;
823 Usb::Device
dev(probe
.Get(activeDevice
).m_dev
);
828 // Override device endpoints if user asks
829 Barry::ProbeResult device
= probe
.Get(activeDevice
);
831 device
.m_ep
.read
= epOverride
.read
;
832 device
.m_ep
.write
= epOverride
.write
;
833 // FIXME - override this too?
834 device
.m_ep
.type
= Usb::EndpointDescriptor::BulkType
;
835 cout
<< "Endpoint pair (read,write) overridden with: "
837 << (unsigned int) device
.m_ep
.read
<< ","
838 << (unsigned int) device
.m_ep
.write
<< endl
;
842 // execute each mode that was turned on
846 // Dump current LDIF mapping
847 if( list_ldif_map
) {
848 cout
<< ldif
<< endl
;
851 // Dump list of Contact field names
852 if( list_contact_fields
) {
853 for( const ContactLdif::NameToFunc
*n
= ldif
.GetFieldNames(); n
->name
; n
++ ) {
855 cout
<< " " << left
<< setw(20) << n
->name
<< ": "
856 << n
->description
<< endl
;
860 // Check if Desktop access is needed
863 record_state_table
||
867 saveDbNames
.size() ) )
871 // Create our controller object
873 // Order is important in the following auto_ptr<> objects,
874 // since Controller must get destroyed before router.
875 // Normally you'd pick one method, and not bother
876 // with auto_ptr<> and so the normal C++ constructor
877 // rules would guarantee this safety for you, but
878 // here we want the user to pick.
880 auto_ptr
<SocketRoutingQueue
> router
;
881 if( threaded_sockets
) {
882 router
.reset( new SocketRoutingQueue
);
883 router
->SpinoffSimpleReadThread();
886 DesktopConnector
connector(password
.c_str(),
887 iconvCharset
, device
, router
.get());
888 if( !connector
.Connect() ) {
889 // bad password (default action is not to prompt)
890 cerr
<< connector
.GetBadPassword().what() << endl
;
894 Barry::Mode::Desktop
&desktop
= connector
.GetDesktop();
896 // Dump list of all databases to stdout
898 // open desktop mode socket
899 cout
<< desktop
.GetDBDB() << endl
;
902 // Dump list of contacts to an LDAP LDIF file
903 // This uses the Controller convenience templates
904 if( ldif_contacts
) {
905 // create a storage functor object that accepts
906 // Barry::Contact objects as input
907 Contact2Ldif
storage(ldif
);
909 // load all the Contact records into storage
910 desktop
.LoadDatabaseByType
<Barry::Contact
>(storage
);
913 // Dump record state table to stdout
914 if( record_state_table
) {
915 if( dbNames
.size() == 0 ) {
916 cout
<< "No db names to process" << endl
;
920 vector
<string
>::iterator b
= dbNames
.begin();
921 for( ; b
!= dbNames
.end(); b
++ ) {
922 unsigned int id
= desktop
.GetDBID(*b
);
923 RecordStateTable state
;
924 desktop
.GetRecordStateTable(id
, state
);
925 cout
<< "Record state table for: " << *b
<< endl
;
931 // Get Record mode overrides the default name mode
932 if( stCommands
.size() ) {
933 if( dbNames
.size() != 1 ) {
934 cout
<< "Must have 1 db name to process" << endl
;
938 unsigned int id
= desktop
.GetDBID(dbNames
[0]);
939 shared_ptr
<Parser
> parse
= GetParser(dbNames
[0],filename
,
940 null_parser
, true, vformat_mode
, bbackup_mode
);
942 for( unsigned int i
= 0; i
< stCommands
.size(); i
++ ) {
943 desktop
.GetRecord(id
, stCommands
[i
].index
, *parse
.get());
945 if( stCommands
[i
].flag
== 'r' && stCommands
[i
].clear
) {
946 cout
<< "Clearing record's dirty flags..." << endl
;
947 desktop
.ClearDirty(id
, stCommands
[i
].index
);
950 if( stCommands
[i
].flag
== 'D' ) {
951 desktop
.DeleteRecord(id
, stCommands
[i
].index
);
958 // Dump contents of selected databases to stdout, or
959 // to file if specified.
960 // This is retrieving data from the Blackberry.
961 if( dbNames
.size() ) {
962 vector
<string
>::iterator b
= dbNames
.begin();
964 for( ; b
!= dbNames
.end(); b
++ ) {
965 shared_ptr
<Parser
> parse
= GetParser(*b
,
966 filename
, null_parser
, !sort_records
,
967 vformat_mode
, bbackup_mode
);
968 unsigned int id
= desktop
.GetDBID(*b
);
969 desktop
.LoadDatabase(id
, *parse
.get());
974 if( clear_database
) {
975 if( clearDbNames
.size() == 0 ) {
976 cout
<< "No db names to erase" << endl
;
980 vector
<string
>::iterator b
= clearDbNames
.begin();
982 for( ; b
!= clearDbNames
.end(); b
++ ) {
983 unsigned int id
= desktop
.GetDBID(*b
);
984 cout
<< "Deleting all records from " << (*b
) << "..." << endl
;
985 desktop
.ClearDatabase(id
);
991 // Save contents of file to specified databases
992 // This is writing data to the Blackberry.
993 if( saveDbNames
.size() ) {
994 vector
<string
>::iterator b
= saveDbNames
.begin();
996 for( ; b
!= saveDbNames
.end(); b
++ ) {
997 shared_ptr
<Builder
> build
= GetBuilder(*b
,
999 unsigned int id
= desktop
.GetDBID(*b
);
1000 desktop
.SaveDatabase(id
, *build
);
1005 catch( Usb::Error
&ue
) {
1006 std::cerr
<< "Usb::Error caught: " << ue
.what() << endl
;
1009 catch( Barry::Error
&se
) {
1010 std::cerr
<< "Barry::Error caught: " << se
.what() << endl
;
1013 catch( std::exception
&e
) {
1014 std::cerr
<< "std::exception caught: " << e
.what() << endl
;