Commit 4fd9563e authored by jehan's avatar jehan

test c interface

git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@171 3f6dc0c8-ddfe-455d-9043-3cd528dc4637
parent 47e90f28
......@@ -14,7 +14,7 @@ int main(int argc, char **argv) {
pthread_t th;
printf("starting p2pproxy tester \n");
pthread_create(&th,NULL,thread_starter,NULL);
sleep(3);
sleep(5);
if (p2pproxy_application_get_state() == P2PPROXY_CONNECTED) {
printf("CONNECTED \n");
......@@ -23,6 +23,8 @@ int main(int argc, char **argv) {
};
/* account management */
if (p2pproxy_accountmgt_createAccount("sip:titi@p2p.linphone.org") != P2PPROXY_NO_ERROR) {
printf("cannot create account \n");
}
......@@ -31,7 +33,7 @@ int main(int argc, char **argv) {
if (p2pproxy_accountmgt_isValidAccount("sip:titi@p2p.linphone.org") != P2PPROXY_ACCOUNTMGT_USER_EXIST) {
printf("user not created \n");
}
/* sip proxy */
char string_buffer[256];
if (p2pproxy_resourcemgt_lookup_sip_proxy(string_buffer,256,"p2p.linphone.org") != P2PPROXY_NO_ERROR) {
printf("cannot get proxy\n");
......@@ -46,9 +48,45 @@ int main(int argc, char **argv) {
if (p2pproxy_resourcemgt_lookup_sip_proxy(string_buffer,256,"toto.linphone.org") != P2PPROXY_RESOURCEMGT_SERVER_NOT_FOUND) {
printf("unexpected proxy [%s]\n",string_buffer);
} else {
printf("unknown domaine\n");
printf("cannot find proxy\n");
}
/* media resource mgt */
p2pproxy_resourcemgt_resource_list_t* resource_list;
resource_list = p2pproxy_resourcemgt_new_resource_list();
if (resource_list == 0) {
printf("cannot allocate p2pproxy_resourcemgt_resource_list_t \n");
} else {
if (p2pproxy_resourcemgt_lookup_media_resource(resource_list,"p2p.linphone.org") != P2PPROXY_NO_ERROR) {
printf("cannot get media resource\n");
} else {
int i;
for (i=0;i<resource_list->size;i++) {
printf("media resource is [%s]\n",resource_list->resource_uri[i]);
}
}
if (p2pproxy_resourcemgt_revoke_media_resource(resource_list->resource_uri[0]) != P2PPROXY_NO_ERROR) {
printf("cannot fulsh media resource [%s]\n",resource_list->resource_uri[0]);
}
if (p2pproxy_resourcemgt_lookup_media_resource(resource_list,"p2p.linphone.org") != P2PPROXY_NO_ERROR) {
printf("cannot get media resource\n");
} else {
int i;
for (i=0;i<resource_list->size;i++) {
printf("media resource is [%s]\n",resource_list->resource_uri[i]);
}
}
p2pproxy_resourcemgt_delete_resource_list(resource_list);
}
if (p2pproxy_accountmgt_deleteAccount("sip:titi@p2p.linphone.org") != P2PPROXY_NO_ERROR) {
printf("cannot delete account \n");
}
......
#include <stdio.h>
#include <jni.h>
#include <string.h>
#include <stdlib.h>
#include "p2pproxy.h"
#ifndef P2PPROXY_JMX_PORT
......@@ -194,3 +195,67 @@ int p2pproxy_application_stop() {
}
p2pproxy_resourcemgt_resource_list_t* p2pproxy_resourcemgt_new_resource_list() {
p2pproxy_resourcemgt_resource_list_t* resource_list = malloc(sizeof (p2pproxy_resourcemgt_resource_list_t));
resource_list->size = 0;
return resource_list;
}
void p2pproxy_resourcemgt_delete_resource_list(p2pproxy_resourcemgt_resource_list_t* resource_list) {
int i;
if (resource_list == 0 ) {
return;
}
for (i=0;i<resource_list->size;i++) {
free(resource_list->resource_uri[i]);
}
resource_list->size = 0;
free(resource_list);
}
int p2pproxy_resourcemgt_lookup_media_resource(p2pproxy_resourcemgt_resource_list_t* resource_list, char* domaine) {
jmethodID lLookupMediaResourceMethod;
jarray lJStringResults;
jstring lResourceInstance;
const char* lString;
jboolean lIsCopy;
jstring applicationArg;
int i;
jsize lStringSize;
jsize lArraySize;
GET_JNI_ENV
applicationArg = (*lJniEnv)->NewStringUTF(lJniEnv, domaine);
lLookupMediaResourceMethod = (*lJniEnv)->GetStaticMethodID(lJniEnv, lMainClass, "lookupMediaServerAddress", "(Ljava/lang/String;)[Ljava/lang/String;");
lJStringResults = (*lJniEnv)->CallStaticObjectMethod(lJniEnv, lMainClass, lLookupMediaResourceMethod, applicationArg);
if (lJStringResults == 0) {
return P2PPROXY_RESOURCEMGT_SERVER_NOT_FOUND;
}
lArraySize = (*lJniEnv)->GetArrayLength(lJniEnv, lJStringResults);
for (i=0;i<lArraySize & i<P2PPROXY_MAX_RESOURCE_LIST_SIZE; i++) {
lResourceInstance = (*lJniEnv)->GetObjectArrayElement(lJniEnv,lJStringResults, i);
lString = (*lJniEnv)->GetStringUTFChars(lJniEnv, lResourceInstance, &lIsCopy);
lStringSize = (*lJniEnv)->GetStringLength(lJniEnv, lResourceInstance);
resource_list->resource_uri[i] = malloc(lStringSize);
strcpy(resource_list->resource_uri[i],lString);
resource_list->size=i;
(*lJniEnv)->ReleaseStringUTFChars(lJniEnv, lResourceInstance, lString);
}
(*p2pproxy_application_jvm)->DetachCurrentThread(p2pproxy_application_jvm);
return P2PPROXY_NO_ERROR;
}
int p2pproxy_resourcemgt_revoke_media_resource(char* resource_uri) {
jmethodID revokeMediaResourceMethod;
jstring applicationArg;
GET_JNI_ENV
applicationArg = (*lJniEnv)->NewStringUTF(lJniEnv, resource_uri);
revokeMediaResourceMethod = (*lJniEnv)->GetStaticMethodID(lJniEnv, lMainClass, "revokeMediaServer", "(Ljava/lang/String;)I");
lResult = (*lJniEnv)->CallStaticIntMethod(lJniEnv, lMainClass, revokeMediaResourceMethod,applicationArg);
(*p2pproxy_application_jvm)->DetachCurrentThread(p2pproxy_application_jvm);
return lResult;
}
......@@ -105,15 +105,16 @@ int p2pproxy_accountmgt_deleteAccount(const char* user_name);
* p2pproxy_resourcemgt_new_resource_list and deleted by p2pproxy_resourcemgt_delete_resource_list.
*
*/
struct p2pproxy_resourcemgt_resource_list {
char[]* resource_uri; /* uri list*/
#define P2PPROXY_MAX_RESOURCE_LIST_SIZE 10
typedef struct p2pproxy_resourcemgt_resource_list {
char* resource_uri[P2PPROXY_MAX_RESOURCE_LIST_SIZE]; /* uri list*/
unsigned char size; /*number of element in the list*/
} p2pproxy_resourcemgt_resource_list_t;
/**
* Instanciate a p2pproxy_resourcemgt_resource_list
*/
p2pproxy_resourcemgt_resource_list_t* p2pproxy_resourcemgt_new_resource_list();
p2pproxy_resourcemgt_resource_list_t* p2pproxy_resourcemgt_new_resource_list(void);
/**
* delete a p2pproxy_resourcemgt_resource_list
*/
......@@ -129,7 +130,7 @@ void p2pproxy_resourcemgt_delete_resource_list(p2pproxy_resourcemgt_resource_lis
int p2pproxy_resourcemgt_lookup_sip_proxy(char* proxy_uri,size_t size, char* domaine) ;
/**
* access a media ressource addresses for a given domaine name
* @param [out] p2pproxy_resourcemgt_resource_list_t allocated by the user
* @param [out] p2pproxy_resourcemgt_resource_list_t allocated by the user (size = 0)
* @param [in] domaine name
* @return status code P2PPROXY_NO_ERROR, P2PPROXY_ERROR_RESOURCELOCATOR_SERVER_NOT_FOUND
*/
......
......@@ -424,7 +424,7 @@ public static String[] lookupSipProxiesUri(String aDomaine) {
public static String[] lookupMediaServerAddress(String aDomaine) {
try {
isReady();
return mP2pProxyManagement.getMediaServerList();
return mP2pProxySipProxyRegistrarManagement.getMediaServerList();
} catch (Exception e) {
mLog.error("cannot find media resource",e);
return null;
......@@ -443,7 +443,7 @@ public static int getState() {
public static int revokeSipProxy(String aProxy) {
try {
isReady();
mP2pProxyManagement.revokeSipProxy(aProxy);
mP2pProxySipProxyRegistrarManagement.revokeSipProxy(aProxy);
return P2pProxylauncherConstants.P2PPROXY_NO_ERROR;
} catch (P2pProxyException e) {
return P2pProxylauncherConstants.P2PPROXY_NOT_CONNECTED;
......@@ -452,7 +452,7 @@ public static int revokeSipProxy(String aProxy) {
public static int revokeMediaServer(String aServer) {
try {
isReady();
mP2pProxyManagement.revokeMediaServer(aServer);
mP2pProxySipProxyRegistrarManagement.revokeMediaServer(aServer);
return P2pProxylauncherConstants.P2PPROXY_NO_ERROR;
} catch (P2pProxyException e) {
return P2pProxylauncherConstants.P2PPROXY_NOT_CONNECTED;
......
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