diff options
author | Kevin Krammer <kevin.krammer@gmx.at> | 2006-03-17 17:52:29 +0000 |
---|---|---|
committer | Kevin Krammer <kevin.krammer@gmx.at> | 2006-03-17 17:52:29 +0000 |
commit | 390026ca043fbf3212548281c87e47ce63a763d8 (patch) | |
tree | c52d0d454e771b0538a7b6e7e1c14931ffc08990 | |
parent | 895d07489d9f99871fab5068edb4f0906d0ae757 (diff) |
Added API for working with a user's addressbook.
Added KDE specific implementation for this API calls.
Added test application using all those calls.
-rw-r--r-- | doc/API.txt | 61 | ||||
-rw-r--r-- | kde/daemon/Makefile.am | 4 | ||||
-rw-r--r-- | kde/daemon/handler.cpp | 184 | ||||
-rw-r--r-- | kde/daemon/handler.h | 8 | ||||
-rw-r--r-- | kde/daemon/kabchandler.cpp | 159 | ||||
-rw-r--r-- | kde/daemon/kabchandler.h | 77 | ||||
-rw-r--r-- | kde/gen/callbacks_generated.c | 158 | ||||
-rw-r--r-- | kde/gen/callbacks_generated.h | 18 | ||||
-rw-r--r-- | kde/gen/calls_generated.c | 127 | ||||
-rw-r--r-- | kde/gen/calls_generated.h | 7 | ||||
-rw-r--r-- | kde/gen/comm_generated.c | 177 | ||||
-rw-r--r-- | kde/gen/comm_generated.h | 47 | ||||
-rw-r--r-- | kde/gen/gen.txt | 87 | ||||
-rw-r--r-- | tests/Makefile.am | 6 | ||||
-rw-r--r-- | tests/test_addressbook.c | 150 |
15 files changed, 1263 insertions, 7 deletions
diff --git a/doc/API.txt b/doc/API.txt index bc73023..8ccf254 100644 --- a/doc/API.txt +++ b/doc/API.txt @@ -10,7 +10,7 @@ contain any information specific to any language bindings. Conventions: ============ -All strings, filenames, urls, etc. are UTF8-encoded, unless specified +All strings, filenames, urls, etc. are UTF8-encoded, unless specified otherwise. All filenames and paths must be absolute. @@ -155,3 +155,62 @@ haven't been created by LocalFile. local: filename of a temporary file to be removed ok: if false, the removal failed + +AddressBookList() -> ( stringlist contact_ids, bool ok ) +---------------------------------------------------------- + +Lists all identifiers for contacts in the user's addressbook. The content of such +an identifier can vary between daemon implementations. + +contact_ids: a list of string IDs, one entry for each contact in the addressbook +ok: false if listing is not possible or has failed + +AddressBookOwner() -> ( string contact_id, bool ok ) +---------------------------------------------------- + +Returns the identifier of the user's own contact if available. + +contact_id: a string identifying the user herself +ok: true if owner contact is available, otherwise false + +AddressBookFindByName( string name ) -> ( stringlist contact_ids, bool ok ) +----------------------------------------------------------------------------- + +Finds all contacts in the user's addressbook where the given string is part +of at least one of the contact's name fields. + +name: a string containing the name or part of a name to search for +contact_ids: a list of string IDs, one entry for each matching contact in + the addressbook +ok: false if no match is found + +AddressBookGetName( string contact_id ) -> ( string givenname, string familyname, string fullname, bool ok ) +------------------------------------------------------------------------------------------------------------ + +Gets the name of a specific contact from the user's addressbook. +The contact is identified through a backend specific string which is returned by +query functions such as AddressBookList or AddressBookFindByName. + +contact_id: the identifier of the contact to get the name from +givenname: the given or first name of the contact +familyname: the family name of the contact +fullname: a name string containing all avilable name parts, e.g. name plus title +ok: false if the contact_id is unknown + +AddressBookGetEmails( string contact_id ) -> ( stringlist emails, bool ok ) +----------------------------------------------------------------------------- + +Gets all emails for the contact with the given identifier. + +contact_id: the identifier of the contact to get the email addresses from +emails: a list of strings, one entry for each email address of the contact +ok: false if the contact_id is unknown + +AddressBookGetVCard30( string contact_id ) -> ( string vcard, bool ok) +---------------------------------------------------------------------- + +Gets the full contact information as a VCard version 3.0. + +contact_id: the identifier of the contact to get the vcard for +vcard: a string with the vcard data +ok: true if contact exists and conversion successfull, otherwise false diff --git a/kde/daemon/Makefile.am b/kde/daemon/Makefile.am index 5dad4d7..bbdc52c 100644 --- a/kde/daemon/Makefile.am +++ b/kde/daemon/Makefile.am @@ -1,7 +1,7 @@ bin_PROGRAMS = dapi_kde -dapi_kde_SOURCES = main.cpp handler.cpp -dapi_kde_LDADD = $(LIB_KIO) $(LIB_DAPI) +dapi_kde_SOURCES = main.cpp handler.cpp kabchandler.cpp +dapi_kde_LDADD = $(LIB_KABC) $(LIB_KIO) $(LIB_DAPI) dapi_kde_LDFLAGS = $(all_libraries) METASOURCES = AUTO diff --git a/kde/daemon/handler.cpp b/kde/daemon/handler.cpp index 511f516..cd8c564 100644 --- a/kde/daemon/handler.cpp +++ b/kde/daemon/handler.cpp @@ -3,6 +3,8 @@ #include "handler.h" #include "handler.moc" +#include "kabchandler.h" + #include <dcopref.h> #include <qsocketnotifier.h> #include <kapplication.h> @@ -22,6 +24,7 @@ KDapiHandler::KDapiHandler() { setupSocket(); + kabchandler = new KABCHandler(this); } KDapiHandler::~KDapiHandler() @@ -63,7 +66,7 @@ void KDapiHandler::processSocketData( int sock ) break; } } - + void KDapiHandler::processCommand( ConnectionData& conn ) { int command; @@ -108,6 +111,24 @@ void KDapiHandler::processCommand( ConnectionData& conn ) case DAPI_COMMAND_REMOVETEMPORARYLOCALFILE: processCommandRemoveTemporaryLocalFile( conn, seq ); return; + case DAPI_COMMAND_ADDRESSBOOKLIST: + processCommandAddressBookList( conn, seq ); + return; + case DAPI_COMMAND_ADDRESSBOOKGETNAME: + processCommandAddressBookGetName( conn, seq ); + return; + case DAPI_COMMAND_ADDRESSBOOKGETEMAILS: + processCommandAddressBookGetEmails( conn, seq ); + return; + case DAPI_COMMAND_ADDRESSBOOKFINDBYNAME: + processCommandAddressBookFindByName( conn, seq ); + return; + case DAPI_COMMAND_ADDRESSBOOKOWNER: + processCommandAddressBookOwner( conn, seq ); + return; + case DAPI_COMMAND_ADDRESSBOOKGETVCARD30: + processCommandAddressBookGetVCard30( conn, seq ); + return; } } @@ -138,7 +159,7 @@ void KDapiHandler::processCommandInit( ConnectionData& conn, int seq ) /* TODO */ static int caps[] = - { + { DAPI_COMMAND_INIT, DAPI_COMMAND_CAPABILITIES, DAPI_COMMAND_OPENURL, @@ -425,6 +446,165 @@ void KDapiHandler::processCommandRemoveTemporaryLocalFile( ConnectionData& conn, free( file ); } +void KDapiHandler::processCommandAddressBookList( ConnectionData& conn, int seq ) + { + if( !dapi_readCommandAddressBookList( conn.conn ) ) + { + closeSocket( conn ); + return; + } + + QStringList kabcUIDs = kabchandler->listUIDs(); + + stringarr idList; + idList.data = 0; + idList.count = 0; + if (kabcUIDs.count() > 0) + { + idList.data = (char**) malloc( sizeof( char* ) * (kabcUIDs.count() + 1 ) ); + QStringList::const_iterator it = kabcUIDs.begin(); + QStringList::const_iterator endIt = kabcUIDs.end(); + for ( uint i = 0; it != endIt; ++it, ++i ) + { + QCString string = (*it).utf8(); + idList.data[i] = strndup( string.data(), string.count() ); + } + idList.data[kabcUIDs.count()] = NULL; + idList.count = kabcUIDs.count(); + } + + dapi_writeReplyAddressBookList( conn.conn, seq, idList, kabcUIDs.count() ); + + dapi_freestringarr( idList ); + } + +void KDapiHandler::processCommandAddressBookGetName( ConnectionData& conn, int seq ) + { + char* id; + if( !dapi_readCommandAddressBookGetName( conn.conn, &id ) ) + { + closeSocket( conn ); + return; + } + + QCString firstname; + QCString lastname; + QCString fullname; + + bool ok = kabchandler->getNames( QString::fromUtf8( id ), + firstname, lastname, fullname ); + free( id ); + + dapi_writeReplyAddressBookGetName( conn.conn, seq, firstname.data(), lastname.data(), + fullname.data(), ok ); + + } + +void KDapiHandler::processCommandAddressBookGetEmails( ConnectionData& conn, int seq ) + { + char* id; + if( !dapi_readCommandAddressBookGetEmails( conn.conn, &id ) ) + { + closeSocket( conn ); + return; + } + + QStringList emails; + bool ok = kabchandler->getEmails( QString::fromUtf8( id ), emails ); + + free( id ); + + stringarr emailList; + emailList.data = 0; + emailList.count = 0; + if (emails.count() > 0) + { + emailList.data = (char**) malloc( sizeof( char* ) * ( emails.count() + 1 ) ); + QStringList::const_iterator it = emails.begin(); + QStringList::const_iterator endIt = emails.end(); + for ( uint i = 0; it != endIt; ++it, ++i ) + { + QCString string = (*it).utf8(); + emailList.data[i] = strdup( string.data() ); + } + emailList.data[emails.count()] = NULL; + emailList.count = emails.count(); + } + + dapi_writeReplyAddressBookGetEmails( conn.conn, seq, emailList, ok ); + + dapi_freestringarr( emailList ); + } + +void KDapiHandler::processCommandAddressBookFindByName( ConnectionData& conn, int seq ) + { + char* id; + if( !dapi_readCommandAddressBookFindByName( conn.conn, &id ) ) + { + closeSocket( conn ); + return; + } + + QStringList kabcUIDs = kabchandler->findByName( QString::fromUtf8( id ) ); + + free( id ); + + stringarr idList; + idList.data = 0; + idList.count = 0; + if (kabcUIDs.count() > 0) + { + idList.data = (char**) malloc( sizeof( char* ) * (kabcUIDs.count() + 1 ) ); + QStringList::const_iterator it = kabcUIDs.begin(); + QStringList::const_iterator endIt = kabcUIDs.end(); + for ( uint i = 0; it != endIt; ++it, ++i ) + { + QCString string = (*it).utf8(); + idList.data[i] = strndup( string.data(), string.count() ); + } + idList.data[kabcUIDs.count()] = NULL; + idList.count = kabcUIDs.count(); + } + + dapi_writeReplyAddressBookFindByName( conn.conn, seq, idList, kabcUIDs.count() ); + + dapi_freestringarr( idList ); + } + +void KDapiHandler::processCommandAddressBookOwner( ConnectionData& conn, int seq ) + { + if( !dapi_readCommandAddressBookOwner( conn.conn ) ) + { + closeSocket( conn ); + return; + } + + QString ownerUID = kabchandler->owner(); + + bool ok = !ownerUID.isEmpty(); + + dapi_writeReplyAddressBookOwner( conn.conn, seq, (ok ? ownerUID.utf8().data() : 0), ok ); + } + +void KDapiHandler::processCommandAddressBookGetVCard30( ConnectionData& conn, int seq ) + { + char* id; + if( !dapi_readCommandAddressBookGetVCard30( conn.conn, &id ) ) + { + closeSocket( conn ); + return; + } + + QString vcard = kabchandler->vcard30( QString::fromUtf8( id ) ); + + free( id ); + + bool ok = !vcard.isEmpty(); + + dapi_writeReplyAddressBookGetVCard30( conn.conn, seq, (ok ? vcard.utf8().data() : 0), ok ); + + } + QCString KDapiHandler::makeStartupInfo( const DapiWindowInfo& winfo ) { WId window = winfo.window; diff --git a/kde/daemon/handler.h b/kde/daemon/handler.h index f995a8e..516b517 100644 --- a/kde/daemon/handler.h +++ b/kde/daemon/handler.h @@ -8,6 +8,7 @@ #include <dapi/comm.h> +class KABCHandler; class QSocketNotifier; class KDapiHandler @@ -41,11 +42,18 @@ class KDapiHandler void processCommandLocalFile( ConnectionData& conn, int seq ); void processCommandUploadFile( ConnectionData& conn, int seq ); void processCommandRemoveTemporaryLocalFile( ConnectionData& conn, int seq ); + void processCommandAddressBookList( ConnectionData& conn, int seq ); + void processCommandAddressBookGetName( ConnectionData& conn, int seq ); + void processCommandAddressBookGetEmails( ConnectionData& conn, int seq ); + void processCommandAddressBookFindByName( ConnectionData& conn, int seq ); + void processCommandAddressBookOwner( ConnectionData& conn, int seq ); + void processCommandAddressBookGetVCard30( ConnectionData& conn, int seq ); void updateScreensaving(); static QCString makeStartupInfo( const DapiWindowInfo& winfo ); int mainsocket; typedef QValueList< ConnectionData > ConnectionList; ConnectionList connections; + KABCHandler* kabchandler; }; class KDapiFakeWidget diff --git a/kde/daemon/kabchandler.cpp b/kde/daemon/kabchandler.cpp new file mode 100644 index 0000000..2016c53 --- /dev/null +++ b/kde/daemon/kabchandler.cpp @@ -0,0 +1,159 @@ +/****************************************************************************** + Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at> + All Rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +// local includes +#include "kabchandler.h" + +// KABC includes +#include <kabc/addressee.h> +#include <kabc/addresseelist.h> +#include <kabc/stdaddressbook.h> +#include <kabc/vcardconverter.h> + +using namespace KABC; + +/////////////////////////////////////////////////////////////////////////////// + +KABCHandler::KABCHandler(QObject* parent, const char* name) + : QObject(parent, name), + m_addressBook(0), + m_vcardConverter(0) +{ + m_addressBook = StdAddressBook::self(true); + QObject::connect(m_addressBook, SIGNAL(addressBookChanged(AddressBook*)), + this, SLOT(slotAddressBookChanged())); + + m_vcardConverter = new VCardConverter(); +} + +/////////////////////////////////////////////////////////////////////////////// + +KABCHandler::~KABCHandler() +{ + delete m_vcardConverter; +} + +/////////////////////////////////////////////////////////////////////////////// + +QStringList KABCHandler::listUIDs() const +{ + AddressBook::ConstIterator it = m_addressBook->begin(); + AddressBook::ConstIterator endIt = m_addressBook->end(); + + QStringList uids; + for (; it != endIt; ++it) + { + uids << (*it).uid(); + } + + return uids; +} + +/////////////////////////////////////////////////////////////////////////////// + +bool KABCHandler::getNames(const QString& uid, QCString& givenName, + QCString& familyName, QCString& fullName) const +{ + Addressee contact = m_addressBook->findByUid(uid); + + if (contact.isEmpty()) return false; + + givenName = contact.givenName().utf8(); + familyName = contact.familyName().utf8(); + fullName = contact.assembledName().utf8(); + + return true; +} + +/////////////////////////////////////////////////////////////////////////////// + +bool KABCHandler::getEmails(const QString& uid, QStringList& emails) const +{ + Addressee contact = m_addressBook->findByUid(uid); + + if (contact.isEmpty()) return false; + + emails = contact.emails(); + + return true; +} + +/////////////////////////////////////////////////////////////////////////////// + +QStringList KABCHandler::findByName(const QString& name) const +{ + AddressBook::ConstIterator it = m_addressBook->begin(); + AddressBook::ConstIterator endIt = m_addressBook->end(); + + QStringList uids; + for (; it != endIt; ++it) + { + if (hasNameMatch(*it, name.lower())) + uids << (*it).uid(); + } + + return uids; +} + +/////////////////////////////////////////////////////////////////////////////// + +QString KABCHandler::owner() const +{ + return m_addressBook->whoAmI().uid(); +} + +/////////////////////////////////////////////////////////////////////////////// + +QString KABCHandler::vcard30(const QString& uid) const +{ + Addressee contact = m_addressBook->findByUid(uid); + + if (contact.isEmpty()) return QString::null; + + return m_vcardConverter->createVCard(contact, VCardConverter::v3_0); +} + +/////////////////////////////////////////////////////////////////////////////// + +bool KABCHandler::hasNameMatch(const KABC::Addressee& contact, const QString& name) +{ + if (contact.assembledName().lower().find(name) != -1) return true; + + if (contact.formattedName().lower().find(name) != -1) return true; + + return false; +} + +/////////////////////////////////////////////////////////////////////////////// + +void KABCHandler::slotAddressBookChanged() +{ + qDebug("AddressBook changed"); +} + +#include "kabchandler.moc" + +// End of File diff --git a/kde/daemon/kabchandler.h b/kde/daemon/kabchandler.h new file mode 100644 index 0000000..edd9f68 --- /dev/null +++ b/kde/daemon/kabchandler.h @@ -0,0 +1,77 @@ +/****************************************************************************** + Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at> + All Rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef KABCHANDLER_H +#define KABCHANDLER_H + +// Qt includes +#include <qobject.h> + +// forward declarations +namespace KABC +{ + class Addressee; + class StdAddressBook; + class VCardConverter; +}; +class QStringList; + +class KABCHandler : public QObject +{ + Q_OBJECT + +public: + KABCHandler(QObject* parent = 0, const char* name = 0); + virtual ~KABCHandler(); + + QStringList listUIDs() const; + + bool getNames(const QString& uid, QCString& givenName, QCString& familyName, + QCString& fullName) const; + + bool getEmails(const QString& uid, QStringList& emails) const; + + QStringList findByName(const QString& uid) const; + + QString owner() const; + + QString vcard30(const QString& uid) const; + +private: + KABC::StdAddressBook* m_addressBook; + + KABC::VCardConverter* m_vcardConverter; + +private: + static bool hasNameMatch(const KABC::Addressee& contact, const QString& name); + +private slots: + void slotAddressBookChanged(); +}; + +#endif + +// End of File diff --git a/kde/gen/callbacks_generated.c b/kde/gen/callbacks_generated.c index c8d12b8..6152566 100644 --- a/kde/gen/callbacks_generated.c +++ b/kde/gen/callbacks_generated.c @@ -204,6 +204,114 @@ int dapi_callbackRemoveTemporaryLocalFile( DapiConnection* conn, const char* loc return seq; } +int dapi_callbackAddressBookList( DapiConnection* conn, dapi_AddressBookList_callback callback ) + { + int seq; + DapiCallbackData* call; + seq = dapi_writeCommandAddressBookList( conn ); + if( seq == 0 ) + return 0; + call = malloc( sizeof( *call )); + if( call == NULL ) + return 0; + call->seq = seq; + call->callback = callback; + call->command = DAPI_COMMAND_ADDRESSBOOKLIST; + call->next = conn->callbacks; + conn->callbacks = call; + return seq; + } + +int dapi_callbackAddressBookGetName( DapiConnection* conn, const char* id, dapi_AddressBookGetName_callback callback ) + { + int seq; + DapiCallbackData* call; + seq = dapi_writeCommandAddressBookGetName( conn, id ); + if( seq == 0 ) + return 0; + call = malloc( sizeof( *call )); + if( call == NULL ) + return 0; + call->seq = seq; + call->callback = callback; + call->command = DAPI_COMMAND_ADDRESSBOOKGETNAME; + call->next = conn->callbacks; + conn->callbacks = call; + return seq; + } + +int dapi_callbackAddressBookGetEmails( DapiConnection* conn, const char* id, dapi_AddressBookGetEmails_callback callback ) + { + int seq; + DapiCallbackData* call; + seq = dapi_writeCommandAddressBookGetEmails( conn, id ); + if( seq == 0 ) + return 0; + call = malloc( sizeof( *call )); + if( call == NULL ) + return 0; + call->seq = seq; + call->callback = callback; + call->command = DAPI_COMMAND_ADDRESSBOOKGETEMAILS; + call->next = conn->callbacks; + conn->callbacks = call; + return seq; + } + +int dapi_callbackAddressBookFindByName( DapiConnection* conn, const char* name, dapi_AddressBookFindByName_callback callback ) + { + int seq; + DapiCallbackData* call; + seq = dapi_writeCommandAddressBookFindByName( conn, name ); + if( seq == 0 ) + return 0; + call = malloc( sizeof( *call )); + if( call == NULL ) + return 0; + call->seq = seq; + call->callback = callback; + call->command = DAPI_COMMAND_ADDRESSBOOKFINDBYNAME; + call->next = conn->callbacks; + conn->callbacks = call; + return seq; + } + +int dapi_callbackAddressBookOwner( DapiConnection* conn, dapi_AddressBookOwner_callback callback ) + { + int seq; + DapiCallbackData* call; + seq = dapi_writeCommandAddressBookOwner( conn ); + if( seq == 0 ) + return 0; + call = malloc( sizeof( *call )); + if( call == NULL ) + return 0; + call->seq = seq; + call->callback = callback; + call->command = DAPI_COMMAND_ADDRESSBOOKOWNER; + call->next = conn->callbacks; + conn->callbacks = call; + return seq; + } + +int dapi_callbackAddressBookGetVCard30( DapiConnection* conn, const char* id, dapi_AddressBookGetVCard30_callback callback ) + { + int seq; + DapiCallbackData* call; + seq = dapi_writeCommandAddressBookGetVCard30( conn, id ); + if( seq == 0 ) + return 0; + call = malloc( sizeof( *call )); + if( call == NULL ) + return 0; + call->seq = seq; + call->callback = callback; + call->command = DAPI_COMMAND_ADDRESSBOOKGETVCARD30; + call->next = conn->callbacks; + conn->callbacks = call; + return seq; + } + static void genericCallbackDispatch( DapiConnection* conn, DapiCallbackData* data, int command, int seq ) { switch( command ) @@ -286,6 +394,56 @@ static void genericCallbackDispatch( DapiConnection* conn, DapiCallbackData* dat (( dapi_RemoveTemporaryLocalFile_callback ) data->callback )( conn, data->seq, ok ); break; } + case DAPI_REPLY_ADDRESSBOOKLIST: + { + stringarr idlist; + int ok; + dapi_readReplyAddressBookList( conn, &idlist, &ok ); + (( dapi_AddressBookList_callback ) data->callback )( conn, data->seq, idlist, ok ); + break; + } + case DAPI_REPLY_ADDRESSBOOKGETNAME: + { + char* givenname; + char* familyname; + char* fullname; + int ok; + dapi_readReplyAddressBookGetName( conn, &givenname, &familyname, &fullname, &ok ); + (( dapi_AddressBookGetName_callback ) data->callback )( conn, data->seq, givenname, familyname, fullname, ok ); + break; + } + case DAPI_REPLY_ADDRESSBOOKGETEMAILS: + { + stringarr emaillist; + int ok; + dapi_readReplyAddressBookGetEmails( conn, &emaillist, &ok ); + (( dapi_AddressBookGetEmails_callback ) data->callback )( conn, data->seq, emaillist, ok ); + break; + } + case DAPI_REPLY_ADDRESSBOOKFINDBYNAME: + { + stringarr idlist; + int ok; + dapi_readReplyAddressBookFindByName( conn, &idlist, &ok ); + (( dapi_AddressBookFindByName_callback ) data->callback )( conn, data->seq, idlist, ok ); + break; + } + case DAPI_REPLY_ADDRESSBOOKOWNER: + { + char* id; + int ok; + dapi_readReplyAddressBookOwner( conn, &id, &ok ); + (( dapi_AddressBookOwner_callback ) data->callback )( conn, data->seq, id, ok ); + break; + } + case DAPI_REPLY_ADDRESSBOOKGETVCARD30: + { + char* vcard; + int ok; + dapi_readReplyAddressBookGetVCard30( conn, &vcard, &ok ); + (( dapi_AddressBookGetVCard30_callback ) data->callback )( conn, data->seq, vcard, ok ); + break; + } } } int dapi_callbackOpenUrl_Window( DapiConnection* conn, const char* url, long winfo, diff --git a/kde/gen/callbacks_generated.h b/kde/gen/callbacks_generated.h index 48212e0..2421f23 100644 --- a/kde/gen/callbacks_generated.h +++ b/kde/gen/callbacks_generated.h @@ -44,3 +44,21 @@ typedef void( * dapi_RemoveTemporaryLocalFile_callback )( DapiConnection* conn, int ok ); int dapi_callbackRemoveTemporaryLocalFile( DapiConnection* conn, const char* local, dapi_RemoveTemporaryLocalFile_callback callback ); +typedef void( * dapi_AddressBookList_callback )( DapiConnection* conn, int seq, stringarr idlist, + int ok ); +int dapi_callbackAddressBookList( DapiConnection* conn, dapi_AddressBookList_callback callback ); +typedef void( * dapi_AddressBookGetName_callback )( DapiConnection* conn, int seq, + const char* givenname, const char* familyname, const char* fullname, int ok ); +int dapi_callbackAddressBookGetName( DapiConnection* conn, const char* id, dapi_AddressBookGetName_callback callback ); +typedef void( * dapi_AddressBookGetEmails_callback )( DapiConnection* conn, int seq, + stringarr emaillist, int ok ); +int dapi_callbackAddressBookGetEmails( DapiConnection* conn, const char* id, dapi_AddressBookGetEmails_callback callback ); +typedef void( * dapi_AddressBookFindByName_callback )( DapiConnection* conn, int seq, + stringarr idlist, int ok ); +int dapi_callbackAddressBookFindByName( DapiConnection* conn, const char* name, dapi_AddressBookFindByName_callback callback ); +typedef void( * dapi_AddressBookOwner_callback )( DapiConnection* conn, int seq, const char* id, + int ok ); +int dapi_callbackAddressBookOwner( DapiConnection* conn, dapi_AddressBookOwner_callback callback ); +typedef void( * dapi_AddressBookGetVCard30_callback )( DapiConnection* conn, int seq, + const char* vcard, int ok ); +int dapi_callbackAddressBookGetVCard30( DapiConnection* conn, const char* id, dapi_AddressBookGetVCard30_callback callback ); diff --git a/kde/gen/calls_generated.c b/kde/gen/calls_generated.c index cf93c1b..0b86660 100644 --- a/kde/gen/calls_generated.c +++ b/kde/gen/calls_generated.c @@ -237,6 +237,133 @@ int dapi_RemoveTemporaryLocalFile( DapiConnection* conn, const char* local ) return ret; } +int dapi_AddressBookList( DapiConnection* conn, stringarr* idlist ) + { + int seq; + int ret; + seq = dapi_writeCommandAddressBookList( conn ); + if( seq == 0 ) + return 0; + for(;;) + { + int comm, seq2; + if( !dapi_readCommand( conn, &comm, &seq2 )) + return 0; + if( seq2 == seq && comm == DAPI_REPLY_ADDRESSBOOKLIST ) + break; /* --> */ + conn->generic_callback( conn, comm, seq2 ); + } + if( !dapi_readReplyAddressBookList( conn, idlist, &ret )) + return 0; + return ret; + } + +int dapi_AddressBookGetName( DapiConnection* conn, const char* id, char** givenname, + char** familyname, char** fullname ) + { + int seq; + int ret; + seq = dapi_writeCommandAddressBookGetName( conn, id ); + if( seq == 0 ) + return 0; + for(;;) + { + int comm, seq2; + if( !dapi_readCommand( conn, &comm, &seq2 )) + return 0; + if( seq2 == seq && comm == DAPI_REPLY_ADDRESSBOOKGETNAME ) + break; /* --> */ + conn->generic_callback( conn, comm, seq2 ); + } + if( !dapi_readReplyAddressBookGetName( conn, givenname, familyname, fullname, &ret )) + return 0; + return ret; + } + +int dapi_AddressBookGetEmails( DapiConnection* conn, const char* id, stringarr* emaillist ) + { + int seq; + int ret; + seq = dapi_writeCommandAddressBookGetEmails( conn, id ); + if( seq == 0 ) + return 0; + for(;;) + { + int comm, seq2; + if( !dapi_readCommand( conn, &comm, &seq2 )) + return 0; + if( seq2 == seq && comm == DAPI_REPLY_ADDRESSBOOKGETEMAILS ) + break; /* --> */ + conn->generic_callback( conn, comm, seq2 ); + } + if( !dapi_readReplyAddressBookGetEmails( conn, emaillist, &ret )) + return 0; + return ret; + } + +int dapi_AddressBookFindByName( DapiConnection* conn, const char* name, stringarr* idlist ) + { + int seq; + int ret; + seq = dapi_writeCommandAddressBookFindByName( conn, name ); + if( seq == 0 ) + return 0; + for(;;) + { + int comm, seq2; + if( !dapi_readCommand( conn, &comm, &seq2 )) + return 0; + if( seq2 == seq && comm == DAPI_REPLY_ADDRESSBOOKFINDBYNAME ) + break; /* --> */ + conn->generic_callback( conn, comm, seq2 ); + } + if( !dapi_readReplyAddressBookFindByName( conn, idlist, &ret )) + return 0; + return ret; + } + +int dapi_AddressBookOwner( DapiConnection* conn, char** id ) + { + int seq; + int ret; + seq = dapi_writeCommandAddressBookOwner( conn ); + if( seq == 0 ) + return 0; + for(;;) + { + int comm, seq2; + if( !dapi_readCommand( conn, &comm, &seq2 )) + return 0; + if( seq2 == seq && comm == DAPI_REPLY_ADDRESSBOOKOWNER ) + break; /* --> */ + conn->generic_callback( conn, comm, seq2 ); + } + if( !dapi_readReplyAddressBookOwner( conn, id, &ret )) + return 0; + return ret; + } + +int dapi_AddressBookGetVCard30( DapiConnection* conn, const char* id, char** vcard ) + { + int seq; + int ret; + seq = dapi_writeCommandAddressBookGetVCard30( conn, id ); + if( seq == 0 ) + return 0; + for(;;) + { + int comm, seq2; + if( !dapi_readCommand( conn, &comm, &seq2 )) + return 0; + if( seq2 == seq && comm == DAPI_REPLY_ADDRESSBOOKGETVCARD30 ) + break; /* --> */ + conn->generic_callback( conn, comm, seq2 ); + } + if( !dapi_readReplyAddressBookGetVCard30( conn, vcard, &ret )) + return 0; + return ret; + } + int dapi_OpenUrl_Window( DapiConnection* conn, const char* url, long winfo ) { DapiWindowInfo winfo_; diff --git a/kde/gen/calls_generated.h b/kde/gen/calls_generated.h index 451e275..8a86b5b 100644 --- a/kde/gen/calls_generated.h +++ b/kde/gen/calls_generated.h @@ -22,3 +22,10 @@ int dapi_UploadFile( DapiConnection* conn, const char* local, const char* file, int dapi_UploadFile_Window( DapiConnection* conn, const char* local, const char* file, int remove_local, long winfo ); int dapi_RemoveTemporaryLocalFile( DapiConnection* conn, const char* local ); +int dapi_AddressBookList( DapiConnection* conn, stringarr* idlist ); +int dapi_AddressBookGetName( DapiConnection* conn, const char* id, char** givenname, + char** familyname, char** fullname ); +int dapi_AddressBookGetEmails( DapiConnection* conn, const char* id, stringarr* emaillist ); +int dapi_AddressBookFindByName( DapiConnection* conn, const char* name, stringarr* idlist ); +int dapi_AddressBookOwner( DapiConnection* conn, char** id ); +int dapi_AddressBookGetVCard30( DapiConnection* conn, const char* id, char** vcard ); diff --git a/kde/gen/comm_generated.c b/kde/gen/comm_generated.c index c192668..32a8767 100644 --- a/kde/gen/comm_generated.c +++ b/kde/gen/comm_generated.c @@ -81,6 +81,40 @@ int dapi_readCommandRemoveTemporaryLocalFile( DapiConnection* conn, char** local return 1; } +int dapi_readCommandAddressBookList( DapiConnection* conn ) + { + return 1; + } + +int dapi_readCommandAddressBookGetName( DapiConnection* conn, char** id ) + { + *id = readString( conn ); + return 1; + } + +int dapi_readCommandAddressBookGetEmails( DapiConnection* conn, char** id ) + { + *id = readString( conn ); + return 1; + } + +int dapi_readCommandAddressBookFindByName( DapiConnection* conn, char** name ) + { + *name = readString( conn ); + return 1; + } + +int dapi_readCommandAddressBookOwner( DapiConnection* conn ) + { + return 1; + } + +int dapi_readCommandAddressBookGetVCard30( DapiConnection* conn, char** id ) + { + *id = readString( conn ); + return 1; + } + int dapi_readReplyInit( DapiConnection* conn, int* ok ) { readSocket( conn, ok, sizeof( *ok )); @@ -148,6 +182,53 @@ int dapi_readReplyRemoveTemporaryLocalFile( DapiConnection* conn, int* ok ) return 1; } +int dapi_readReplyAddressBookList( DapiConnection* conn, stringarr* idlist, int* ok ) + { + *idlist = readstringarr( conn ); + readSocket( conn, ok, sizeof( *ok )); + return 1; + } + +int dapi_readReplyAddressBookGetName( DapiConnection* conn, char** givenname, char** familyname, + char** fullname, int* ok ) + { + *givenname = readString( conn ); + *familyname = readString( conn ); + *fullname = readString( conn ); + readSocket( conn, ok, sizeof( *ok )); + return 1; + } + +int dapi_readReplyAddressBookGetEmails( DapiConnection* conn, stringarr* emaillist, + int* ok ) + { + *emaillist = readstringarr( conn ); + readSocket( conn, ok, sizeof( *ok )); + return 1; + } + +int dapi_readReplyAddressBookFindByName( DapiConnection* conn, stringarr* idlist, + int* ok ) + { + *idlist = readstringarr( conn ); + readSocket( conn, ok, sizeof( *ok )); + return 1; + } + +int dapi_readReplyAddressBookOwner( DapiConnection* conn, char** id, int* ok ) + { + *id = readString( conn ); + readSocket( conn, ok, sizeof( *ok )); + return 1; + } + +int dapi_readReplyAddressBookGetVCard30( DapiConnection* conn, char** vcard, int* ok ) + { + *vcard = readString( conn ); + readSocket( conn, ok, sizeof( *ok )); + return 1; + } + int dapi_writeCommandInit( DapiConnection* conn ) { int seq = getNextSeq( conn ); @@ -253,6 +334,52 @@ int dapi_writeCommandRemoveTemporaryLocalFile( DapiConnection* conn, const char* return seq; } +int dapi_writeCommandAddressBookList( DapiConnection* conn ) + { + int seq = getNextSeq( conn ); + writeCommand( conn, DAPI_COMMAND_ADDRESSBOOKLIST, seq ); + return seq; + } + +int dapi_writeCommandAddressBookGetName( DapiConnection* conn, const char* id ) + { + int seq = getNextSeq( conn ); + writeCommand( conn, DAPI_COMMAND_ADDRESSBOOKGETNAME, seq ); + writeString( conn, id ); + return seq; + } + +int dapi_writeCommandAddressBookGetEmails( DapiConnection* conn, const char* id ) + { + int seq = getNextSeq( conn ); + writeCommand( conn, DAPI_COMMAND_ADDRESSBOOKGETEMAILS, seq ); + writeString( conn, id ); + return seq; + } + +int dapi_writeCommandAddressBookFindByName( DapiConnection* conn, const char* name ) + { + int seq = getNextSeq( conn ); + writeCommand( conn, DAPI_COMMAND_ADDRESSBOOKFINDBYNAME, seq ); + writeString( conn, name ); + return seq; + } + +int dapi_writeCommandAddressBookOwner( DapiConnection* conn ) + { + int seq = getNextSeq( conn ); + writeCommand( conn, DAPI_COMMAND_ADDRESSBOOKOWNER, seq ); + return seq; + } + +int dapi_writeCommandAddressBookGetVCard30( DapiConnection* conn, const char* id ) + { + int seq = getNextSeq( conn ); + writeCommand( conn, DAPI_COMMAND_ADDRESSBOOKGETVCARD30, seq ); + writeString( conn, id ); + return seq; + } + void dapi_writeReplyInit( DapiConnection* conn, int seq, int ok ) { writeCommand( conn, DAPI_REPLY_INIT, seq ); @@ -321,6 +448,56 @@ void dapi_writeReplyRemoveTemporaryLocalFile( DapiConnection* conn, int seq, int writeSocket( conn, &ok, sizeof( ok )); } +void dapi_writeReplyAddressBookList( DapiConnection* conn, int seq, stringarr idlist, + int ok ) + { + writeCommand( conn, DAPI_REPLY_ADDRESSBOOKLIST, seq ); + writestringarr( conn, idlist ); + writeSocket( conn, &ok, sizeof( ok )); + } + +void dapi_writeReplyAddressBookGetName( DapiConnection* conn, int seq, const char* givenname, + const char* familyname, const char* fullname, int ok ) + { + writeCommand( conn, DAPI_REPLY_ADDRESSBOOKGETNAME, seq ); + writeString( conn, givenname ); + writeString( conn, familyname ); + writeString( conn, fullname ); + writeSocket( conn, &ok, sizeof( ok )); + } + +void dapi_writeReplyAddressBookGetEmails( DapiConnection* conn, int seq, stringarr emaillist, + int ok ) + { + writeCommand( conn, DAPI_REPLY_ADDRESSBOOKGETEMAILS, seq ); + writestringarr( conn, emaillist ); + writeSocket( conn, &ok, sizeof( ok )); + } + +void dapi_writeReplyAddressBookFindByName( DapiConnection* conn, int seq, stringarr idlist, + int ok ) + { + writeCommand( conn, DAPI_REPLY_ADDRESSBOOKFINDBYNAME, seq ); + writestringarr( conn, idlist ); + writeSocket( conn, &ok, sizeof( ok )); + } + +void dapi_writeReplyAddressBookOwner( DapiConnection* conn, int seq, const char* id, + int ok ) + { + writeCommand( conn, DAPI_REPLY_ADDRESSBOOKOWNER, seq ); + writeString( conn, id ); + writeSocket( conn, &ok, sizeof( ok )); + } + +void dapi_writeReplyAddressBookGetVCard30( DapiConnection* conn, int seq, const char* vcard, + int ok ) + { + writeCommand( conn, DAPI_REPLY_ADDRESSBOOKGETVCARD30, seq ); + writeString( conn, vcard ); + writeSocket( conn, &ok, sizeof( ok )); + } + int dapi_writeCommandOpenUrl_Window( DapiConnection* conn, const char* url, long winfo ) { DapiWindowInfo winfo_; diff --git a/kde/gen/comm_generated.h b/kde/gen/comm_generated.h index aa28087..ecd2920 100644 --- a/kde/gen/comm_generated.h +++ b/kde/gen/comm_generated.h @@ -62,6 +62,39 @@ int dapi_readCommandRemoveTemporaryLocalFile( DapiConnection* conn, char** local int dapi_writeCommandRemoveTemporaryLocalFile( DapiConnection* conn, const char* local ); int dapi_readReplyRemoveTemporaryLocalFile( DapiConnection* conn, int* ok ); void dapi_writeReplyRemoveTemporaryLocalFile( DapiConnection* conn, int seq, int ok ); +int dapi_readCommandAddressBookList( DapiConnection* conn ); +int dapi_writeCommandAddressBookList( DapiConnection* conn ); +int dapi_readReplyAddressBookList( DapiConnection* conn, stringarr* idlist, int* ok ); +void dapi_writeReplyAddressBookList( DapiConnection* conn, int seq, stringarr idlist, + int ok ); +int dapi_readCommandAddressBookGetName( DapiConnection* conn, char** id ); +int dapi_writeCommandAddressBookGetName( DapiConnection* conn, const char* id ); +int dapi_readReplyAddressBookGetName( DapiConnection* conn, char** givenname, char** familyname, + char** fullname, int* ok ); +void dapi_writeReplyAddressBookGetName( DapiConnection* conn, int seq, const char* givenname, + const char* familyname, const char* fullname, int ok ); +int dapi_readCommandAddressBookGetEmails( DapiConnection* conn, char** id ); +int dapi_writeCommandAddressBookGetEmails( DapiConnection* conn, const char* id ); +int dapi_readReplyAddressBookGetEmails( DapiConnection* conn, stringarr* emaillist, + int* ok ); +void dapi_writeReplyAddressBookGetEmails( DapiConnection* conn, int seq, stringarr emaillist, + int ok ); +int dapi_readCommandAddressBookFindByName( DapiConnection* conn, char** name ); +int dapi_writeCommandAddressBookFindByName( DapiConnection* conn, const char* name ); +int dapi_readReplyAddressBookFindByName( DapiConnection* conn, stringarr* idlist, + int* ok ); +void dapi_writeReplyAddressBookFindByName( DapiConnection* conn, int seq, stringarr idlist, + int ok ); +int dapi_readCommandAddressBookOwner( DapiConnection* conn ); +int dapi_writeCommandAddressBookOwner( DapiConnection* conn ); +int dapi_readReplyAddressBookOwner( DapiConnection* conn, char** id, int* ok ); +void dapi_writeReplyAddressBookOwner( DapiConnection* conn, int seq, const char* id, + int ok ); +int dapi_readCommandAddressBookGetVCard30( DapiConnection* conn, char** id ); +int dapi_writeCommandAddressBookGetVCard30( DapiConnection* conn, const char* id ); +int dapi_readReplyAddressBookGetVCard30( DapiConnection* conn, char** vcard, int* ok ); +void dapi_writeReplyAddressBookGetVCard30( DapiConnection* conn, int seq, const char* vcard, + int ok ); enum { DAPI_COMMAND_INIT, @@ -85,5 +118,17 @@ enum DAPI_COMMAND_UPLOADFILE, DAPI_REPLY_UPLOADFILE, DAPI_COMMAND_REMOVETEMPORARYLOCALFILE, - DAPI_REPLY_REMOVETEMPORARYLOCALFILE + DAPI_REPLY_REMOVETEMPORARYLOCALFILE, + DAPI_COMMAND_ADDRESSBOOKLIST, + DAPI_REPLY_ADDRESSBOOKLIST, + DAPI_COMMAND_ADDRESSBOOKGETNAME, + DAPI_REPLY_ADDRESSBOOKGETNAME, + DAPI_COMMAND_ADDRESSBOOKGETEMAILS, + DAPI_REPLY_ADDRESSBOOKGETEMAILS, + DAPI_COMMAND_ADDRESSBOOKFINDBYNAME, + DAPI_REPLY_ADDRESSBOOKFINDBYNAME, + DAPI_COMMAND_ADDRESSBOOKOWNER, + DAPI_REPLY_ADDRESSBOOKOWNER, + DAPI_COMMAND_ADDRESSBOOKGETVCARD30, + DAPI_REPLY_ADDRESSBOOKGETVCARD30 }; diff --git a/kde/gen/gen.txt b/kde/gen/gen.txt index a507dcf..66bb5a6 100644 --- a/kde/gen/gen.txt +++ b/kde/gen/gen.txt @@ -150,3 +150,90 @@ FUNCTION RemoveTemporaryLocalFile RETURN ENDARG ENDFUNCTION + +FUNCTION AddressBookList + ARG idlist + TYPE string[] + OUT + ENDARG + ARG ok + TYPE bool + RETURN + ENDARG +ENDFUNCTION + +FUNCTION AddressBookGetName + ARG id + TYPE string + ENDARG + ARG givenname + TYPE string + OUT + ENDARG + ARG familyname + TYPE string + OUT + ENDARG + ARG fullname + TYPE string + OUT + ENDARG + ARG ok + TYPE bool + RETURN + ENDARG +ENDFUNCTION + +FUNCTION AddressBookGetEmails + ARG id + TYPE string + ENDARG + ARG emaillist + TYPE string[] + OUT + ENDARG + ARG ok + TYPE bool + RETURN + ENDARG +ENDFUNCTION + +FUNCTION AddressBookFindByName + ARG name + TYPE string + ENDARG + ARG idlist + TYPE string[] + OUT + ENDARG + ARG ok + TYPE bool + RETURN + ENDARG +ENDFUNCTION + +FUNCTION AddressBookOwner + ARG id + TYPE string + OUT + ENDARG + ARG ok + TYPE bool + RETURN + ENDARG +ENDFUNCTION + +FUNCTION AddressBookGetVCard30 + ARG id + TYPE string + ENDARG + ARG vcard + TYPE string + OUT + ENDARG + ARG ok + TYPE bool + RETURN + ENDARG +ENDFUNCTION + diff --git a/tests/Makefile.am b/tests/Makefile.am index 49195af..391062a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,5 @@ noinst_PROGRAMS = test_comm test_calls test_runasuser test_screensaving test_mailto test_remotefile test_async \ - test_capabilities test_callbacks test_fallback + test_capabilities test_callbacks test_fallback test_addressbook test_comm_SOURCES = test_comm.c test_comm_LDADD = ../lib/libdapi.la @@ -41,4 +41,8 @@ test_fallback_SOURCES = test_fallback.c test_fallback_LDADD = ../lib/libdapi.la test_fallback_LDFLAGS = $(all_libraries) +test_addressbook_SOURCES = test_addressbook.c +test_addressbook_LDADD = ../lib/libdapi.la +test_addressbook_LDFLAGS = $(all_libraries) + INCLUDES = -I$(top_builddir)/include $(all_includes) diff --git a/tests/test_addressbook.c b/tests/test_addressbook.c new file mode 100644 index 0000000..5b7f192 --- /dev/null +++ b/tests/test_addressbook.c @@ -0,0 +1,150 @@ +/****************************************************************************** + Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at> + All Rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include <stdio.h> +#include <stdlib.h> + +#include <dapi/comm.h> +#include <dapi/calls.h> + +void printContact( DapiConnection* conn, int num, char* id ); +void printVCard( DapiConnection* conn, char* id ); + +int main(int argc, char** argv) + { + DapiConnection* conn = dapi_connectAndInit(); + if( conn == NULL ) + { + fprintf( stderr, "Cannot connect!\n" ); + return 1; + } + + char* ownerID = NULL; + if( dapi_AddressBookOwner( conn, &ownerID ) ) + { + printf( "AddressBookOwner: contact for current user available:\n" ); + printContact( conn, 0, ownerID ); + free( ownerID ); + } + else + printf( "AddressBookOwner: no contact for the current user\n" ); + printf("\n"); + + stringarr idlist; + if( dapi_AddressBookList( conn, &idlist ) ) + printf( "AddressBookList: %d contact IDs\n", idlist.count ); + else + printf( "AddressBookList: call failed\n" ); + + int i; + for( i = 0; i < idlist.count; ++i ) + printContact( conn, i, idlist.data[i] ); + dapi_freestringarr( idlist ); + + if( argc <= 1 ) + printf( "\nNo commandline args, skipping FindByName\n" ); + else + { + for( i = 1; i < argc; ++i ) + { + printf( "\nSearching for '%s'\n", argv[i] ); + + stringarr foundlist; + if( dapi_AddressBookFindByName( conn, argv[i], &foundlist ) ) + { + if ( foundlist.count > 0 ) + { + printf( "Found %d matches\n", foundlist.count ); + + int j; + for ( j = 0; j < foundlist.count; ++j ) + { + printContact( conn, j, foundlist.data[j] ); + printVCard( conn, foundlist.data[j] ); + } + dapi_freestringarr( foundlist ); + } + else + printf( "No matches in addressbook\n" ); + } + else + printf( "AddressBoolFindByName: call failed\n" ); + } + } + + dapi_close( conn ); + + return 0; + } + +void printContact( DapiConnection* conn, int num, char* id ) + { + char* givenname; + char* familyname; + char* fullname; + + if( dapi_AddressBookGetName( conn, id, &givenname, &familyname, &fullname ) ) + { + printf( "Contact %d: '%s', %s', '%s'\n", + num, givenname, familyname, fullname ); + + free( givenname ); + free( familyname ); + free( fullname ); + } + else + printf( "AddressBookGetName: call failed\n" ); + + stringarr emaillist; + if( dapi_AddressBookGetEmails( conn, id, &emaillist ) ) + { + if( emaillist.count > 0 ) + { + int j; + for( j = 0; j < emaillist.count; ++j ) + { + printf( "\temail %d: '%s'\n", j, emaillist.data[j] ); + } + dapi_freestringarr( emaillist ); + } + else + printf( "\tNo emails\n" ); + } + else + printf( "AddressBookGetEmails: call failed\n" ); + } + +void printVCard( DapiConnection* conn, char* id ) + { + char* vcard; + if( dapi_AddressBookGetVCard30( conn, id, &vcard ) ) + { + printf("\n%s\n", vcard); + free( vcard ); + } + else + printf( "AddressBookGetVCard30: call failed" ); + } |