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 class DataDumpParser
: public Barry::Parser
331 virtual void Clear() {}
333 virtual void SetIds(const std::string
&DbName
,
334 uint8_t RecType
, uint32_t UniqueId
)
339 virtual void ParseHeader(const Data
&, size_t &) {}
341 virtual void ParseFields(const Barry::Data
&data
, size_t &offset
,
342 const IConverter
*ic
)
344 std::cout
<< "Raw record dump for record: "
345 << std::hex
<< m_id
<< std::endl
;
346 std::cout
<< data
<< std::endl
;
349 virtual void Store() {}
352 shared_ptr
<Parser
> GetParser(const string
&name
,
353 const string
&filename
,
355 bool immediate_display
,
359 bool dnow
= immediate_display
;
360 bool vmode
= vformat_mode
;
364 return shared_ptr
<Parser
>( new DataDumpParser
);
366 else if( bbackup_mode
) {
367 #ifdef __BARRY_BACKUP_MODE__
368 // Only one backup file per run
369 static shared_ptr
<Parser
> backup
;
370 if( !backup
.get() ) {
371 backup
.reset( new Backup(filename
) );
375 return shared_ptr
<Parser
>( new DataDumpParser
);
378 // check for recognized database names
379 else if( name
== Contact::GetDBName() ) {
380 return shared_ptr
<Parser
>(
381 new RecordParser
<Contact
, Store
<Contact
> > (
382 new Store
<Contact
>(filename
, false, dnow
, vmode
)));
384 else if( name
== Message::GetDBName() ) {
385 return shared_ptr
<Parser
>(
386 new RecordParser
<Message
, Store
<Message
> > (
387 new Store
<Message
>(filename
, false, dnow
, vmode
)));
389 else if( name
== Calendar::GetDBName() ) {
390 return shared_ptr
<Parser
>(
391 new RecordParser
<Calendar
, Store
<Calendar
> > (
392 new Store
<Calendar
>(filename
, false, dnow
, vmode
)));
394 else if( name
== CalendarAll::GetDBName() ) {
395 return shared_ptr
<Parser
>(
396 new RecordParser
<CalendarAll
, Store
<CalendarAll
> > (
397 new Store
<CalendarAll
>(filename
, false, dnow
, vmode
)));
399 else if( name
== CallLog::GetDBName() ) {
400 return shared_ptr
<Parser
>(
401 new RecordParser
<CallLog
, Store
<CallLog
> > (
402 new Store
<CallLog
>(filename
, false, dnow
, vmode
)));
404 else if( name
== ServiceBook::GetDBName() ) {
405 return shared_ptr
<Parser
>(
406 new RecordParser
<ServiceBook
, Store
<ServiceBook
> > (
407 new Store
<ServiceBook
>(filename
, false, dnow
, vmode
)));
410 else if( name
== Memo::GetDBName() ) {
411 return shared_ptr
<Parser
>(
412 new RecordParser
<Memo
, Store
<Memo
> > (
413 new Store
<Memo
>(filename
, false, dnow
, vmode
)));
415 else if( name
== Task::GetDBName() ) {
416 return shared_ptr
<Parser
>(
417 new RecordParser
<Task
, Store
<Task
> > (
418 new Store
<Task
>(filename
, false, dnow
, vmode
)));
420 else if( name
== PINMessage::GetDBName() ) {
421 return shared_ptr
<Parser
>(
422 new RecordParser
<PINMessage
, Store
<PINMessage
> > (
423 new Store
<PINMessage
>(filename
, false, dnow
, vmode
)));
425 else if( name
== SavedMessage::GetDBName() ) {
426 return shared_ptr
<Parser
>(
427 new RecordParser
<SavedMessage
, Store
<SavedMessage
> > (
428 new Store
<SavedMessage
>(filename
, false, dnow
, vmode
)));
430 else if( name
== Sms::GetDBName() ) {
431 return shared_ptr
<Parser
>(
432 new RecordParser
<Sms
, Store
<Sms
> > (
433 new Store
<Sms
>(filename
, false, dnow
, vmode
)));
435 else if( name
== Folder::GetDBName() ) {
436 return shared_ptr
<Parser
>(
437 new RecordParser
<Folder
, Store
<Folder
> > (
438 new Store
<Folder
>(filename
, false, dnow
, vmode
)));
440 else if( name
== Timezone::GetDBName() ) {
441 return shared_ptr
<Parser
>(
442 new RecordParser
<Timezone
, Store
<Timezone
> > (
443 new Store
<Timezone
>(filename
, false, dnow
, vmode
)));
446 // unknown database, use null parser
447 return shared_ptr
<Parser
>( new DataDumpParser
);
451 shared_ptr
<Builder
> GetBuilder(const string
&name
, const string
&filename
)
453 // check for recognized database names
454 if( name
== Contact::GetDBName() ) {
455 return shared_ptr
<Builder
>(
456 new RecordBuilder
<Contact
, Store
<Contact
> > (
457 new Store
<Contact
>(filename
, true, true, false)));
459 else if( name
== Calendar::GetDBName() ) {
460 return shared_ptr
<Builder
>(
461 new RecordBuilder
<Calendar
, Store
<Calendar
> > (
462 new Store
<Calendar
>(filename
, true, true, false)));
464 else if( name
== CalendarAll::GetDBName() ) {
465 return shared_ptr
<Builder
>(
466 new RecordBuilder
<CalendarAll
, Store
<CalendarAll
> > (
467 new Store
<CalendarAll
>(filename
, true, true, false)));
469 else if( name
== Memo::GetDBName() ) {
470 return shared_ptr
<Builder
>(
471 new RecordBuilder
<Memo
, Store
<Memo
> > (
472 new Store
<Memo
>(filename
, true, true, false)));
474 else if( name
== Task::GetDBName() ) {
475 return shared_ptr
<Builder
>(
476 new RecordBuilder
<Task
, Store
<Task
> > (
477 new Store
<Task
>(filename
, true, true, false)));
480 else if( name == "Messages" ) {
481 return shared_ptr<Parser>(
482 new RecordParser<Message, Store<Message> > (
483 new Store<Message>(filename, true, true, false)));
485 else if( name == "Service Book" ) {
486 return shared_ptr<Parser>(
487 new RecordParser<ServiceBook, Store<ServiceBook> > (
488 new Store<ServiceBook>(filename, true, true, false)));
492 throw std::runtime_error("No Builder available for database");
498 cout
<< "Supported Database parsers:\n"
499 << " (* = can display in vformat MIME mode)\n"
500 << " Address Book *\n"
503 << " Calendar - All *\n"
504 << " Phone Call Logs\n"
509 << " Saved Email Messages\n"
512 << " Time Zones (read only)\n"
514 << "Supported Database builders:\n"
517 << " Calendar - All\n"
523 struct StateTableCommand
529 StateTableCommand(char f
, bool c
, unsigned int i
)
530 : flag(f
), clear(c
), index(i
) {}
533 bool SplitMap(const string
&map
, string
&ldif
, string
&read
, string
&write
)
535 string::size_type a
= map
.find(',');
536 if( a
== string::npos
)
539 string::size_type b
= map
.find(',', a
+1);
540 if( b
== string::npos
)
543 ldif
.assign(map
, 0, a
);
544 read
.assign(map
, a
+ 1, b
- a
- 1);
545 write
.assign(map
, b
+ 1, map
.size() - b
- 1);
547 return ldif
.size() && read
.size() && write
.size();
550 void DoMapping(ContactLdif
&ldif
, const vector
<string
> &mapCommands
)
552 for( vector
<string
>::const_iterator i
= mapCommands
.begin();
553 i
!= mapCommands
.end();
556 // single names mean unmapping
557 if( i
->find(',') == string::npos
) {
559 cerr
<< "Unmapping: " << *i
<< endl
;
563 cerr
<< "Mapping: " << *i
<< endl
;
565 // map... extract ldif/read/write names
566 string ldifname
, read
, write
;
567 if( SplitMap(*i
, ldifname
, read
, write
) ) {
568 if( !ldif
.Map(ldifname
, read
, write
) ) {
569 cerr
<< "Read/Write name unknown: " << *i
<< endl
;
573 cerr
<< "Invalid map format: " << *i
<< endl
;
579 bool ParseEpOverride(const char *arg
, Usb::EndpointPair
*epp
)
583 istringstream
iss(arg
);
584 iss
>> hex
>> read
>> comma
>> write
;
592 int main(int argc
, char *argv
[])
596 cout
.sync_with_stdio(true); // leave this on, since libusb uses
597 // stdio for debug messages
602 bool list_only
= false,
604 ldif_contacts
= false,
606 vformat_mode
= false,
607 reset_device
= false,
608 list_contact_fields
= false,
609 list_ldif_map
= false,
610 epp_override
= false,
611 threaded_sockets
= true,
612 record_state
= false,
613 clear_database
= false,
615 bbackup_mode
= false,
616 sort_records
= false;
617 string ldifBaseDN
, ldifDnAttr
;
623 vector
<string
> dbNames
, saveDbNames
, mapCommands
, clearDbNames
;
624 vector
<StateTableCommand
> stCommands
;
625 Usb::EndpointPair epOverride
;
627 // process command line options
629 int cmd
= getopt(argc
, argv
, "a:b:B:c:C:d:D:e:f:hi:IlLm:MnN:p:P:r:R:Ss:tT:vVXzZ");
635 case 'a': // Clear Database
636 clear_database
= true;
637 clearDbNames
.push_back(string(optarg
));
640 case 'b': // Barry backup filename (tar.gz)
641 #ifdef __BARRY_BACKUP_MODE__
642 if( filename
.size() == 0 ) {
647 cerr
<< "Do not use -f with -b\n";
651 cerr
<< "-b option not supported - no Barry "
652 "Backup library support available\n";
661 case 'c': // contacts to ldap ldif
662 ldif_contacts
= true;
666 case 'C': // DN Attribute for FQDN
670 case 'd': // show dbname
671 dbNames
.push_back(string(optarg
));
674 case 'D': // delete record
675 stCommands
.push_back(
676 StateTableCommand('D', false, atoi(optarg
)));
679 case 'e': // endpoint override
680 if( !ParseEpOverride(optarg
, &epOverride
) ) {
687 case 'f': // filename
688 #ifdef __BARRY_BOOST_MODE__
689 if( !bbackup_mode
&& filename
.size() == 0 ) {
693 cerr
<< "Do not use -f with -b\n";
697 cerr
<< "-f option not supported - no Boost "
698 "serialization support available\n";
703 case 'i': // international charset (iconv)
704 iconvCharset
= optarg
;
707 case 'I': // sort before dump
711 case 'l': // list only
715 case 'L': // List Contact field names
716 list_contact_fields
= true;
719 case 'm': // Map / Unmap
720 mapCommands
.push_back(string(optarg
));
723 case 'M': // List LDIF map
724 list_ldif_map
= true;
727 case 'n': // use null parser
735 case 'p': // Blackberry PIN
736 pin
= strtoul(optarg
, NULL
, 16);
739 case 'P': // Device password
743 case 'r': // get specific record index
744 stCommands
.push_back(
745 StateTableCommand('r', false, atoi(optarg
)));
748 case 'R': // same as 'r', and clears dirty
749 stCommands
.push_back(
750 StateTableCommand('r', true, atoi(optarg
)));
753 case 's': // save dbname
754 saveDbNames
.push_back(string(optarg
));
757 case 'S': // show supported databases
761 case 't': // display database database
765 case 'T': // show RecordStateTable
767 dbNames
.push_back(string(optarg
));
770 case 'v': // data dump on
774 case 'V': // vformat MIME mode
775 #ifdef __BARRY_SYNC_MODE__
778 cerr
<< "-V option not supported - no Sync "
779 "library support available\n";
784 case 'X': // reset device
788 case 'z': // non-threaded sockets
789 threaded_sockets
= false;
792 case 'Z': // threaded socket router
793 threaded_sockets
= true;
803 // Initialize the barry library. Must be called before
805 Barry::Init(data_dump
);
808 const char *Version
= Barry::Version(major
, minor
);
809 cout
<< Version
<< endl
;
812 // Create an IConverter object if needed
813 auto_ptr
<IConverter
> ic
;
814 if( iconvCharset
.size() ) {
815 ic
.reset( new IConverter(iconvCharset
.c_str(), true) );
818 // LDIF class... only needed if ldif output turned on
819 ContactLdif
ldif(ldifBaseDN
);
820 DoMapping(ldif
, mapCommands
);
821 if( ldifDnAttr
.size() ) {
822 if( !ldif
.SetDNAttr(ldifDnAttr
) ) {
823 cerr
<< "Unable to set DN Attr: " << ldifDnAttr
<< endl
;
827 // Probe the USB bus for Blackberry devices and display.
828 // If user has specified a PIN, search for it in the
829 // available device list here as well
830 Barry::Probe
probe(busname
.c_str(), devname
.c_str(),
831 epp_override
? &epOverride
: 0);
832 int activeDevice
= -1;
834 // show any errors during probe first
835 if( probe
.GetFailCount() ) {
838 cout
<< "Blackberry device errors with errors during probe:" << endl
;
839 for( int i
= 0; i
< probe
.GetFailCount(); i
++ ) {
842 cout
<< probe
.GetFailMsg(i
) << endl
;
846 // show all successfully found devices
849 cout
<< "Blackberry devices found:" << endl
;
850 for( int i
= 0; i
< probe
.GetCount(); i
++ ) {
854 probe
.Get(i
).DumpAll(cout
);
856 cout
<< probe
.Get(i
);
858 if( probe
.Get(i
).m_pin
== pin
)
865 if( activeDevice
== -1 ) {
867 // can we default to single device?
868 if( probe
.GetCount() == 1 )
871 cerr
<< "No device selected" << endl
;
876 cerr
<< "PIN " << setbase(16) << pin
877 << " not found" << endl
;
884 cout
<< "Using device (PIN): "
885 << probe
.Get(activeDevice
).m_pin
.str() << endl
;
888 Usb::Device
dev(probe
.Get(activeDevice
).m_dev
);
893 // Override device endpoints if user asks
894 Barry::ProbeResult device
= probe
.Get(activeDevice
);
896 device
.m_ep
.read
= epOverride
.read
;
897 device
.m_ep
.write
= epOverride
.write
;
898 device
.m_ep
.type
= 2; // FIXME - override this too?
899 cout
<< "Endpoint pair (read,write) overridden with: "
901 << (unsigned int) device
.m_ep
.read
<< ","
902 << (unsigned int) device
.m_ep
.write
<< endl
;
906 // Create our controller object
908 // Order is important in the following auto_ptr<> objects,
909 // since Controller must get destroyed before router.
910 // Normally you'd pick one method, and not bother
911 // with auto_ptr<> and so the normal C++ constructor
912 // rules would guarantee this safety for you, but
913 // here we want the user to pick.
915 auto_ptr
<SocketRoutingQueue
> router
;
916 auto_ptr
<Barry::Controller
> pcon
;
917 if( threaded_sockets
) {
918 router
.reset( new SocketRoutingQueue
);
919 router
->SpinoffSimpleReadThread();
920 pcon
.reset( new Barry::Controller(device
, *router
) );
923 pcon
.reset( new Barry::Controller(device
) );
926 Barry::Controller
&con
= *pcon
;
927 Barry::Mode::Desktop
desktop(con
, *ic
);
930 // execute each mode that was turned on
934 // Dump list of all databases to stdout
936 // open desktop mode socket
937 desktop
.Open(password
.c_str());
938 cout
<< desktop
.GetDBDB() << endl
;
941 // Dump list of Contact field names
942 if( list_contact_fields
) {
943 for( const ContactLdif::NameToFunc
*n
= ldif
.GetFieldNames(); n
->name
; n
++ ) {
945 cout
<< " " << left
<< setw(20) << n
->name
<< ": "
946 << n
->description
<< endl
;
950 // Dump current LDIF mapping
951 if( list_ldif_map
) {
952 cout
<< ldif
<< endl
;
955 // Dump list of contacts to an LDAP LDIF file
956 // This uses the Controller convenience templates
957 if( ldif_contacts
) {
958 // make sure we're in desktop mode
959 desktop
.Open(password
.c_str());
961 // create a storage functor object that accepts
962 // Barry::Contact objects as input
963 Contact2Ldif
storage(ldif
);
965 // load all the Contact records into storage
966 desktop
.LoadDatabaseByType
<Barry::Contact
>(storage
);
969 // Dump record state table to stdout
971 if( dbNames
.size() == 0 ) {
972 cout
<< "No db names to process" << endl
;
976 desktop
.Open(password
.c_str());
978 vector
<string
>::iterator b
= dbNames
.begin();
979 for( ; b
!= dbNames
.end(); b
++ ) {
980 unsigned int id
= desktop
.GetDBID(*b
);
981 RecordStateTable state
;
982 desktop
.GetRecordStateTable(id
, state
);
983 cout
<< "Record state table for: " << *b
<< endl
;
989 // Get Record mode overrides the default name mode
990 if( stCommands
.size() ) {
991 if( dbNames
.size() != 1 ) {
992 cout
<< "Must have 1 db name to process" << endl
;
996 desktop
.Open(password
.c_str());
997 unsigned int id
= desktop
.GetDBID(dbNames
[0]);
998 shared_ptr
<Parser
> parse
= GetParser(dbNames
[0],filename
,
999 null_parser
, true, vformat_mode
, bbackup_mode
);
1001 for( unsigned int i
= 0; i
< stCommands
.size(); i
++ ) {
1002 desktop
.GetRecord(id
, stCommands
[i
].index
, *parse
.get());
1004 if( stCommands
[i
].flag
== 'r' && stCommands
[i
].clear
) {
1005 cout
<< "Clearing record's dirty flags..." << endl
;
1006 desktop
.ClearDirty(id
, stCommands
[i
].index
);
1009 if( stCommands
[i
].flag
== 'D' ) {
1010 desktop
.DeleteRecord(id
, stCommands
[i
].index
);
1018 if (clear_database
) {
1019 if( clearDbNames
.size() == 0 ) {
1020 cout
<< "No db names to erase" << endl
;
1024 vector
<string
>::iterator b
= clearDbNames
.begin();
1026 desktop
.Open(password
.c_str());
1028 for( ; b
!= clearDbNames
.end(); b
++ ) {
1029 unsigned int id
= desktop
.GetDBID(*b
);
1030 cout
<< "Deleting all records from " << (*b
) << "..." << endl
;
1031 desktop
.ClearDatabase(id
);
1037 // Dump contents of selected databases to stdout, or
1038 // to file if specified.
1039 // This is retrieving data from the Blackberry.
1040 if( dbNames
.size() ) {
1041 vector
<string
>::iterator b
= dbNames
.begin();
1043 desktop
.Open(password
.c_str());
1044 for( ; b
!= dbNames
.end(); b
++ ) {
1045 shared_ptr
<Parser
> parse
= GetParser(*b
,filename
,
1046 null_parser
, !sort_records
,
1047 vformat_mode
, bbackup_mode
);
1048 unsigned int id
= desktop
.GetDBID(*b
);
1049 desktop
.LoadDatabase(id
, *parse
.get());
1053 // Save contents of file to specified databases
1054 // This is writing data to the Blackberry.
1055 if( saveDbNames
.size() ) {
1056 vector
<string
>::iterator b
= saveDbNames
.begin();
1058 desktop
.Open(password
.c_str());
1059 for( ; b
!= saveDbNames
.end(); b
++ ) {
1060 shared_ptr
<Builder
> build
=
1061 GetBuilder(*b
, filename
);
1062 unsigned int id
= desktop
.GetDBID(*b
);
1063 desktop
.SaveDatabase(id
, *build
);
1068 catch( Usb::Error
&ue
) {
1069 std::cerr
<< "Usb::Error caught: " << ue
.what() << endl
;
1072 catch( Barry::Error
&se
) {
1073 std::cerr
<< "Barry::Error caught: " << se
.what() << endl
;
1076 catch( std::exception
&e
) {
1077 std::cerr
<< "std::exception caught: " << e
.what() << endl
;