Commit e6488438 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

PUT/DELETE queries added to CardDAV (update not tested yet)

parent 8f493e0c
......@@ -976,12 +976,11 @@ typedef struct {
unsigned char node[6];
} sal_uuid_t;
int sal_create_uuid(Sal*ctx, char *uuid, size_t len){
int sal_generate_uuid(char *uuid, size_t len) {
sal_uuid_t uuid_struct;
int i;
int written;
if (len==0) return -1;
/*create an UUID as described in RFC4122, 4.4 */
belle_sip_random_bytes((unsigned char*)&uuid_struct, sizeof(sal_uuid_t));
......@@ -1000,10 +999,17 @@ int sal_create_uuid(Sal*ctx, char *uuid, size_t len){
for (i = 0; i < 6; i++)
written+=snprintf(uuid+written,len-written,"%2.2x", uuid_struct.node[i]);
uuid[len-1]='\0';
sal_set_uuid(ctx,uuid);
return 0;
}
int sal_create_uuid(Sal*ctx, char *uuid, size_t len) {
if (sal_generate_uuid(uuid, len) == 0) {
sal_set_uuid(ctx, uuid);
return 0;
}
return -1;
}
static void make_supported_header(Sal *sal){
MSList *it;
char *alltags=NULL;
......
This diff is collapsed.
......@@ -23,22 +23,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifdef __cplusplus
extern "C" {
#endif
/**
* @addtogroup carddav_vcard
* @{
*/
typedef struct _LinphoneCardDavContext LinphoneCardDavContext;
typedef enum _LinphoneCardDavQueryType {
LinphoneCardDavQueryTypePropfind,
LinphoneCardDavQueryTypeAddressbookQuery,
LinphoneCardDavQueryTypeAddressbookMultiget
LinphoneCardDavQueryTypeAddressbookMultiget,
LinphoneCardDavQueryTypePut,
LinphoneCardDavQueryTypeDelete
} LinphoneCardDavQueryType;
typedef enum _LinphoneCardDavQueryStatus {
LinphoneCardDavQueryStatusIdle,
LinphoneCardDavQueryStatusPending,
LinphoneCardDavQueryStatusOk,
LinphoneCardDavQueryStatusFailed
} LinphoneCardDavQueryStatus;
typedef struct _LinphoneCardDavQuery LinphoneCardDavQuery;
typedef struct _LinphoneCardDavResponse LinphoneCardDavResponse;
......@@ -157,6 +157,10 @@ void linphone_carddav_fetch_vcards(LinphoneCardDavContext *cdc);
*/
void linphone_carddav_pull_vcards(LinphoneCardDavContext *cdc, MSList *vcards_to_pull);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
......
......@@ -1244,8 +1244,9 @@ struct _LinphoneCardDavQuery {
const char *method;
const char *body;
const char *depth;
const char *ifmatch;
void *user_data;
LinphoneCardDavQueryType type;
LinphoneCardDavQueryStatus status;
};
struct _LinphoneCardDavResponse {
......
......@@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "vcard.h"
#include "belcard/belcard.hpp"
#include "belcard/belcard_parser.hpp"
#include "sal/sal.h"
struct _LinphoneVCard {
shared_ptr<belcard::BelCard> belCard;
......@@ -27,20 +28,24 @@ struct _LinphoneVCard {
const char *url;
};
extern "C" LinphoneVCard* linphone_vcard_new(void) {
#ifdef __cplusplus
extern "C" {
#endif
LinphoneVCard* linphone_vcard_new(void) {
LinphoneVCard* vCard = (LinphoneVCard*) ms_new0(LinphoneVCard, 1);
vCard->belCard = belcard::BelCardGeneric::create<belcard::BelCard>();
return vCard;
}
extern "C" void linphone_vcard_free(LinphoneVCard *vCard) {
void linphone_vcard_free(LinphoneVCard *vCard) {
if (!vCard) return;
vCard->belCard.reset();
ms_free(vCard);
}
extern "C" MSList* linphone_vcard_list_from_vcard4_file(const char *filename) {
MSList* linphone_vcard_list_from_vcard4_file(const char *filename) {
MSList *result = NULL;
if (filename && ortp_file_exist(filename) == 0) {
belcard::BelCardParser parser = belcard::BelCardParser::getInstance();
......@@ -57,7 +62,7 @@ extern "C" MSList* linphone_vcard_list_from_vcard4_file(const char *filename) {
return result;
}
extern "C" MSList* linphone_vcard_list_from_vcard4_buffer(const char *buffer) {
MSList* linphone_vcard_list_from_vcard4_buffer(const char *buffer) {
MSList *result = NULL;
if (buffer) {
belcard::BelCardParser parser = belcard::BelCardParser::getInstance();
......@@ -74,7 +79,7 @@ extern "C" MSList* linphone_vcard_list_from_vcard4_buffer(const char *buffer) {
return result;
}
extern "C" LinphoneVCard* linphone_vcard_new_from_vcard4_buffer(const char *buffer) {
LinphoneVCard* linphone_vcard_new_from_vcard4_buffer(const char *buffer) {
LinphoneVCard *vCard = NULL;
if (buffer) {
belcard::BelCardParser parser = belcard::BelCardParser::getInstance();
......@@ -89,13 +94,13 @@ extern "C" LinphoneVCard* linphone_vcard_new_from_vcard4_buffer(const char *buff
return vCard;
}
extern "C" const char * linphone_vcard_as_vcard4_string(LinphoneVCard *vCard) {
const char * linphone_vcard_as_vcard4_string(LinphoneVCard *vCard) {
if (!vCard) return NULL;
return vCard->belCard->toFoldedString().c_str();
}
extern "C" void linphone_vcard_set_full_name(LinphoneVCard *vCard, const char *name) {
void linphone_vcard_set_full_name(LinphoneVCard *vCard, const char *name) {
if (!vCard || !name) return;
shared_ptr<belcard::BelCardFullName> fn = belcard::BelCardGeneric::create<belcard::BelCardFullName>();
......@@ -103,14 +108,14 @@ extern "C" void linphone_vcard_set_full_name(LinphoneVCard *vCard, const char *n
vCard->belCard->setFullName(fn);
}
extern "C" const char* linphone_vcard_get_full_name(const LinphoneVCard *vCard) {
const char* linphone_vcard_get_full_name(const LinphoneVCard *vCard) {
if (!vCard) return NULL;
const char *result = vCard->belCard->getFullName() ? vCard->belCard->getFullName()->getValue().c_str() : NULL;
return result;
}
extern "C" void linphone_vcard_add_sip_address(LinphoneVCard *vCard, const char *sip_address) {
void linphone_vcard_add_sip_address(LinphoneVCard *vCard, const char *sip_address) {
if (!vCard || !sip_address) return;
shared_ptr<belcard::BelCardImpp> impp = belcard::BelCardGeneric::create<belcard::BelCardImpp>();
......@@ -118,7 +123,7 @@ extern "C" void linphone_vcard_add_sip_address(LinphoneVCard *vCard, const char
vCard->belCard->addImpp(impp);
}
extern "C" void linphone_vcard_remove_sip_address(LinphoneVCard *vCard, const char *sip_address) {
void linphone_vcard_remove_sip_address(LinphoneVCard *vCard, const char *sip_address) {
if (!vCard) return;
for (auto it = vCard->belCard->getImpp().begin(); it != vCard->belCard->getImpp().end(); ++it) {
......@@ -130,7 +135,7 @@ extern "C" void linphone_vcard_remove_sip_address(LinphoneVCard *vCard, const ch
}
}
extern "C" void linphone_vcard_edit_main_sip_address(LinphoneVCard *vCard, const char *sip_address) {
void linphone_vcard_edit_main_sip_address(LinphoneVCard *vCard, const char *sip_address) {
if (!vCard || !sip_address) return;
if (vCard->belCard->getImpp().size() > 0) {
......@@ -143,7 +148,7 @@ extern "C" void linphone_vcard_edit_main_sip_address(LinphoneVCard *vCard, const
}
}
extern "C" MSList* linphone_vcard_get_sip_addresses(const LinphoneVCard *vCard) {
MSList* linphone_vcard_get_sip_addresses(const LinphoneVCard *vCard) {
MSList *result = NULL;
if (!vCard) return NULL;
......@@ -156,27 +161,56 @@ extern "C" MSList* linphone_vcard_get_sip_addresses(const LinphoneVCard *vCard)
return result;
}
extern "C" const char* linphone_vcard_get_uid(const LinphoneVCard *vCard) {
bool_t linphone_vcard_generate_unique_id(LinphoneVCard *vCard) {
char uuid[64];
if (vCard) {
if (linphone_vcard_get_uid(vCard)) {
return FALSE;
}
if (sal_generate_uuid(uuid, sizeof(uuid)) == 0) {
char vcard_uuid[sizeof(uuid)+4];
snprintf(vcard_uuid, sizeof(vcard_uuid), "urn:%s", uuid);
linphone_vcard_set_uid(vCard, ms_strdup(vcard_uuid));
return TRUE;
}
}
return FALSE;
}
void linphone_vcard_set_uid(LinphoneVCard *vCard, const char *uid) {
if (!vCard || !uid) return;
shared_ptr<belcard::BelCardUniqueId> uniqueId = belcard::BelCardGeneric::create<belcard::BelCardUniqueId>();
uniqueId->setValue(uid);
vCard->belCard->setUniqueId(uniqueId);
}
const char* linphone_vcard_get_uid(const LinphoneVCard *vCard) {
if (vCard && vCard->belCard->getUniqueId()) {
return vCard->belCard->getUniqueId()->getValue().c_str();
}
return NULL;
}
extern "C" void linphone_vcard_set_etag(LinphoneVCard *vCard, const char * etag) {
void linphone_vcard_set_etag(LinphoneVCard *vCard, const char * etag) {
vCard->etag = ms_strdup(etag);
}
extern "C" const char* linphone_vcard_get_etag(const LinphoneVCard *vCard) {
const char* linphone_vcard_get_etag(const LinphoneVCard *vCard) {
if (!vCard) return NULL;
return vCard->etag;
}
extern "C" void linphone_vcard_set_url(LinphoneVCard *vCard, const char * url) {
void linphone_vcard_set_url(LinphoneVCard *vCard, const char * url) {
vCard->url = ms_strdup(url);
}
extern "C" const char* linphone_vcard_get_url(const LinphoneVCard *vCard) {
const char* linphone_vcard_get_url(const LinphoneVCard *vCard) {
if (!vCard) return NULL;
return vCard->url;
}
\ No newline at end of file
}
#ifdef __cplusplus
}
#endif
\ No newline at end of file
......@@ -32,7 +32,7 @@ extern "C"
#endif
/**
* @addtogroup buddy_list
* @addtogroup carddav_vcard
* @{
*/
......@@ -119,12 +119,54 @@ LINPHONE_PUBLIC void linphone_vcard_edit_main_sip_address(LinphoneVCard *vCard,
*/
LINPHONE_PUBLIC MSList* linphone_vcard_get_sip_addresses(const LinphoneVCard *vCard);
/**
* Generates a random unique id for the vCard.
* If is required to be able to synchronize the vCard with a CardDAV server
* @param[in] vCard the LinphoneVCard
* @return TRUE if operation is successful, otherwise FALSE (for example if it already has an unique ID)
*/
LINPHONE_PUBLIC bool_t linphone_vcard_generate_unique_id(LinphoneVCard *vCard);
/**
* Sets the unique ID of the vCard
* @param[in] vCard the LinphoneVCard
* @param[in] uid the unique id
*/
void linphone_vcard_set_uid(LinphoneVCard *vCard, const char *uid);
/**
* Gets the UID of the vCard
* @param[in] vCard the LinphoneVCard
* @return the UID of the vCard, otherwise NULL
*/
const char* linphone_vcard_get_uid(const LinphoneVCard *vCard);
/**
* Sets the eTAG of the vCard
* @param[in] vCard the LinphoneVCard
* @param[in] etag the eTAG
*/
void linphone_vcard_set_etag(LinphoneVCard *vCard, const char * etag);
/**
* Gets the eTag of the vCard
* @param[in] vCard the LinphoneVCard
* @return the eTag of the vCard in the CardDAV server, otherwise NULL
*/
const char* linphone_vcard_get_etag(const LinphoneVCard *vCard);
/**
* Sets the URL of the vCard
* @param[in] vCard the LinphoneVCard
* @param[in] url the URL
*/
void linphone_vcard_set_url(LinphoneVCard *vCard, const char * url);
/**
* Gets the URL of the vCard
* @param[in] vCard the LinphoneVCard
* @return the URL of the vCard in the CardDAV server, otherwise NULL
*/
const char* linphone_vcard_get_url(const LinphoneVCard *vCard);
/**
......
......@@ -71,6 +71,14 @@ MSList* linphone_vcard_get_sip_addresses(const LinphoneVCard *vCard) {
return NULL;
}
bool_t linphone_vcard_generate_unique_id(LinphoneVCard *vCard) {
return FALSE;
}
void linphone_vcard_set_uid(LinphoneVCard *vCard, const char *uid) {
}
const char* linphone_vcard_get_uid(const LinphoneVCard *vCard) {
return NULL;
}
......
......@@ -618,6 +618,7 @@ void sal_verify_server_certificates(Sal *ctx, bool_t verify);
void sal_verify_server_cn(Sal *ctx, bool_t verify);
void sal_set_uuid(Sal*ctx, const char *uuid);
int sal_create_uuid(Sal*ctx, char *uuid, size_t len);
int sal_generate_uuid(char *uuid, size_t len);
LINPHONE_PUBLIC void sal_enable_test_features(Sal*ctx, bool_t enabled);
void sal_use_no_initial_route(Sal *ctx, bool_t enabled);
......
......@@ -200,7 +200,6 @@ typedef struct _LinphoneCardDAVStats {
static void carddav_sync_done(LinphoneCardDavContext *c, bool_t success, const char *message) {
LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_carddav_get_user_data(c);
BC_ASSERT_TRUE(success);
linphone_carddav_destroy(c);
stats->sync_done_count++;
}
......@@ -250,6 +249,7 @@ static void carddav_sync(void) {
BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");
ms_free(stats);
linphone_carddav_destroy(c);
linphone_core_manager_destroy(manager);
}
......@@ -288,6 +288,7 @@ static void carddav_sync_2(void) {
ms_free(stats);
unlink(friends_db);
ms_free(friends_db);
linphone_carddav_destroy(c);
linphone_core_manager_destroy(manager);
}
......@@ -325,6 +326,40 @@ static void carddav_sync_3(void) {
ms_free(stats);
unlink(friends_db);
ms_free(friends_db);
linphone_carddav_destroy(c);
linphone_core_manager_destroy(manager);
}
static void carddav_sync_4(void) {
LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE);
LinphoneCardDavContext *c = linphone_core_create_carddav_context(manager->lc);
LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1);
LinphoneVCard *lvc = linphone_vcard_new_from_vcard4_buffer("BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Margaux Clerc\r\nIMPP;TYPE=work:sip:margaux@sip.linphone.org\r\nEND:VCARD\r\n");
LinphoneFriend *lf = linphone_friend_new_from_vcard(lvc);
BC_ASSERT_PTR_NOT_NULL_FATAL(c);
BC_ASSERT_PTR_NOT_NULL(c->server_url);
BC_ASSERT_PTR_NOT_NULL(c->username);
BC_ASSERT_PTR_NOT_NULL(c->ha1);
linphone_carddav_set_user_data(c, stats);
linphone_carddav_set_synchronization_done_callback(c, carddav_sync_done);
BC_ASSERT_PTR_NULL(linphone_vcard_get_uid(lvc));
BC_ASSERT_TRUE(linphone_vcard_generate_unique_id(lvc));
BC_ASSERT_PTR_NOT_NULL(linphone_vcard_get_uid(lvc));
linphone_carddav_put_vcard(c, lf);
wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, 2000);
BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");
linphone_carddav_delete_vcard(c, lf);
wait_for_until(manager->lc, NULL, &stats->sync_done_count, 2, 2000);
BC_ASSERT_EQUAL(stats->sync_done_count, 2, int, "%i");
linphone_friend_unref(lf);
ms_free(stats);
linphone_carddav_destroy(c);
linphone_core_manager_destroy(manager);
}
......@@ -346,6 +381,7 @@ test_t vcard_tests[] = {
{ "CardDAV synchronization", carddav_sync },
{ "CardDAV synchronization 2", carddav_sync_2 },
{ "CardDAV synchronization 3", carddav_sync_3 },
{ "CardDAV synchronization 4", carddav_sync_4 },
#else
{ "Dummy test", dummy_test }
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment