fi
AC_ARG_ENABLE(msg-storage,
- [AS_HELP_STRING([--enable-msg-storage=[yes/no]], [Turn on compilation of message storage (default=yes)])],
+ [AS_HELP_STRING([--enable-msg-storage=[yes/no]], [Turn on compilation of message storage (default=auto)])],
[case "${enableval}" in
yes) enable_msg_storage=true ;;
no) enable_msg_storage=false ;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-msg-storage) ;;
esac],
- [enable_msg_storage=true]
+ [enable_msg_storage=auto]
)
+
+echo "enable_msg_storage = $enable_msg_storage"
+
AM_CONDITIONAL(BUILD_MSG_STORAGE, test x$enable_msg_storage = xtrue)
-if test x$enable_msg_storage = xtrue; then
- PKG_CHECK_MODULES(SQLITE3,[ sqlite3 >= 3.7.0],[],[
- AC_MSG_ERROR([sqlite3 required for message storage not found.])] )
- SQLITE3_CFLAGS+="-DMSG_STORAGE_ENABLED"
- AC_SUBST(SQLITE3_CFLAGS)
- AC_SUBST(SQLITE3_LIBS)
+if test x$enable_msg_storage != xfalse; then
+ PKG_CHECK_MODULES(SQLITE3,[ sqlite3 >= 3.7.0],[
+ SQLITE3_CFLAGS+="-DMSG_STORAGE_ENABLED"
+ AC_SUBST(SQLITE3_CFLAGS)
+ AC_SUBST(SQLITE3_LIBS)
+ enable_msg_storage=true
+ ],[
+ if test x$enable_msg_storage = xtrue; then
+ AC_MSG_ERROR([sqlite3 required for message storage not found.])
+ fi
+ enable_msg_storage=false
+ ] )
+
fi
LinphoneChatMessage *chat_msg=(LinphoneChatMessage* )sal_op_get_user_pointer(op);
const MSList* calls = linphone_core_get_calls(chat_msg->chat_room->lc);
- linphone_core_set_message_state(chat_msg->chat_room,chat_msg->message,chatStatusSal2Linphone(status),chat_msg->time);
+ chat_msg->state=chatStatusSal2Linphone(status);
+ linphone_chat_message_store_state(chat_msg);
if (chat_msg && chat_msg->cb) {
chat_msg->cb(chat_msg
- ,chatStatusSal2Linphone(status)
+ ,chat_msg->state
,chat_msg->cb_ud);
}
linphone_chat_message_destroy(chat_msg);
ms_free(cr->peer);
}
-#ifdef WIN32
-static inline char *my_ctime_r(const time_t *t, char *buf){
- strcpy(buf,ctime(t));
- return buf;
-}
-
-#else
-#define my_ctime_r ctime_r
-#endif
static void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage* msg){
const char *route=NULL;
LinphoneCall *call;
char* content_type;
time_t t=time(NULL);
- char buf[26];
- char *to;
if (lp_config_get_int(cr->lc->config,"sip","chat_use_call_dialogs",0)){
if((call = linphone_core_get_call_by_remote_address(cr->lc,cr->peer))!=NULL){
}
if (msg->external_body_url) {
content_type=ms_strdup_printf("message/external-body; access-type=URL; URL=\"%s\"",msg->external_body_url);
- sal_message_send(op,identity,cr->peer,content_type, NULL,my_ctime_r(&t,buf));
+ sal_message_send(op,identity,cr->peer,content_type, NULL);
ms_free(content_type);
} else {
- sal_text_send(op, identity, cr->peer,msg->message,my_ctime_r(&t,buf));
+ sal_text_send(op, identity, cr->peer,msg->message);
}
- to=linphone_address_as_string_uri_only (cr->peer_url);
- linphone_core_set_history_message(cr,identity,to,OUTGOING,msg->message,
- my_ctime_r(&t,buf),READ,LinphoneChatMessageStateInProgress);
- ms_free(to);
+ msg->dir=LinphoneChatMessageOutgoing;
+ msg->from=linphone_address_new(identity);
+ linphone_chat_message_store(msg);
}
/**
}
-void linphone_core_message_received(LinphoneCore *lc, SalOp *op, const SalMessage *sal_msg){
+/**
+ * Retrieve an existing chat room whose peer is the supplied address, if exists.
+ * @param lc the linphone core
+ * @param add a linphone address.
+ * @returns the matching chatroom, or NULL if no such chatroom exists.
+**/
+LinphoneChatRoom *linphone_core_get_chat_room(LinphoneCore *lc, const LinphoneAddress *addr){
+ LinphoneChatRoom *cr=NULL;
MSList *elem;
+ for(elem=lc->chatrooms;elem!=NULL;elem=ms_list_next(elem)){
+ cr=(LinphoneChatRoom*)elem->data;
+ if (linphone_chat_room_matches(cr,addr)){
+ break;
+ }
+ cr=NULL;
+ }
+ return cr;
+}
+
+void linphone_core_message_received(LinphoneCore *lc, SalOp *op, const SalMessage *sal_msg){
+
LinphoneChatRoom *cr=NULL;
LinphoneAddress *addr;
char *cleanfrom;
- const char *to;
char *from;
LinphoneChatMessage* msg;
const SalCustomHeader *ch;
- char buf[26];
addr=linphone_address_new(sal_msg->from);
linphone_address_clean(addr);
- for(elem=lc->chatrooms;elem!=NULL;elem=ms_list_next(elem)){
- cr=(LinphoneChatRoom*)elem->data;
- if (linphone_chat_room_matches(cr,addr)){
- break;
- }
- cr=NULL;
- }
- to=linphone_core_get_identity(lc);
+ cr=linphone_core_get_chat_room(lc,addr);
cleanfrom=linphone_address_as_string(addr);
from=linphone_address_as_string_uri_only(addr);
if (cr==NULL){
}
msg = linphone_chat_room_create_message(cr, sal_msg->text);
linphone_chat_message_set_from(msg, cr->peer_url);
+
+ {
+ LinphoneAddress *to;
+ to=sal_op_get_to(op) ? linphone_address_new(sal_op_get_to(op)) : linphone_address_new(linphone_core_get_identity(lc));
+ msg->to=to;
+ }
+
msg->time=sal_msg->time;
msg->state=LinphoneChatMessageStateDelivered;
+ msg->is_read=FALSE;
ch=sal_op_get_custom_header(op);
if (ch) msg->custom_headers=sal_custom_header_clone(ch);
linphone_chat_message_set_external_body_url(msg, sal_msg->url);
}
linphone_address_destroy(addr);
- linphone_core_set_history_message(cr,to,from,INCOMING,
- msg->message,my_ctime_r(&msg->time,buf),NOT_READ,
- LinphoneChatMessageStateDelivered);
+ linphone_chat_message_store(msg);
linphone_chat_room_message_received(cr,lc,msg);
ms_free(cleanfrom);
ms_free(from);
LinphoneChatMessage* msg = ms_new0(LinphoneChatMessage,1);
msg->chat_room=(LinphoneChatRoom*)cr;
msg->message=message?ms_strdup(message):NULL;
+ msg->is_read=TRUE;
return msg;
}
*@param message #LinphoneChatMessage obj
*@return #LinphoneAddress
*/
-LinphoneAddress* linphone_chat_message_get_from(const LinphoneChatMessage* message) {
+const LinphoneAddress* linphone_chat_message_get_from(const LinphoneChatMessage* message) {
return message->from;
}
+/**
+ * Get destination of the message
+ *@param message #LinphoneChatMessage obj
+ *@return #LinphoneAddress
+ */
+const LinphoneAddress* linphone_chat_message_get_to(const LinphoneChatMessage* message){
+ if (message->to) return message->to;
+ if (message->dir==LinphoneChatMessageOutgoing){
+ return message->chat_room->peer_url;
+ }
+ return NULL;
+}
+
+/**
+ * Returns the origin address of a message if it was a outgoing message, or the destination address if it was an incoming message.
+ *@param message #LinphoneChatMessage obj
+ *@return #LinphoneAddress
+ */
+LinphoneAddress *linphone_chat_message_get_local_address(const LinphoneChatMessage* message){
+ return message->dir==LinphoneChatMessageOutgoing ? message->from : message->to;
+}
+
/**
* Get the time the message was sent.
*/
#ifdef TUNNEL_ENABLED
lc->tunnel=linphone_core_tunnel_new(lc);
if (lc->tunnel) linphone_tunnel_configure(lc->tunnel);
-#endif
-#ifdef MSG_STORAGE_ENABLED
- lc->db=linphone_message_storage_init();
#endif
if (lc->vtable.display_status)
lc->vtable.display_status(lc,_("Ready"));
}
linphone_core_free_payload_types(lc);
+
+ linphone_core_message_storage_close(lc);
ortp_exit();
linphone_core_set_state(lc,LinphoneGlobalOff,"Off");
#ifdef TUNNEL_ENABLED
int linphone_core_get_video_dscp(const LinphoneCore *lc){
return lp_config_get_int(lc->config,"rtp","video_dscp",0x2e);
}
+
+
+/**
+ * Sets the database filename where chat messages will be stored.
+ * If the file does not exist, it will be created.
+ * @ingroup initializing
+ * @param lc the linphone core
+ * @param path filesystem path
+**/
+void linphone_core_set_chat_database_path(LinphoneCore *lc, const char *path){
+ if (lc->chat_db_file){
+ ms_free(lc->chat_db_file);
+ lc->chat_db_file=NULL;
+ }
+ if (path) {
+ lc->chat_db_file=ms_strdup(path);
+ linphone_core_message_storage_init(lc);
+ }
+}
+
+
*/
typedef void (*LinphoneChatMessageStateChangeCb)(LinphoneChatMessage* msg,LinphoneChatMessageState state,void* ud);
+void linphone_core_set_chat_database_path(LinphoneCore *lc, const char *path);
LinphoneChatRoom * linphone_core_create_chat_room(LinphoneCore *lc, const char *to);
+LinphoneChatRoom *linphone_core_get_chat_room(LinphoneCore *lc, const LinphoneAddress *addr);
void linphone_chat_room_destroy(LinphoneChatRoom *cr);
LinphoneChatMessage* linphone_chat_room_create_message(LinphoneChatRoom *cr,const char* message);
const LinphoneAddress* linphone_chat_room_get_peer_address(LinphoneChatRoom *cr);
void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg);
void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage* msg,LinphoneChatMessageStateChangeCb status_cb,void* ud);
+MSList *linphone_chat_room_get_history(LinphoneChatRoom *cr,int nb_message);
+void linphone_chat_room_mark_as_read(LinphoneChatRoom *cr);
+void linphone_chat_room_delete_history(LinphoneChatRoom *cr);
LinphoneCore* linphone_chat_room_get_lc(LinphoneChatRoom *cr);
void linphone_chat_room_set_user_data(LinphoneChatRoom *cr, void * ud);
void * linphone_chat_room_get_user_data(LinphoneChatRoom *cr);
const char* linphone_chat_message_state_to_string(const LinphoneChatMessageState state);
LinphoneChatMessage* linphone_chat_message_clone(const LinphoneChatMessage* message);
void linphone_chat_message_set_from(LinphoneChatMessage* message, const LinphoneAddress* from);
-LinphoneAddress* linphone_chat_message_get_from(const LinphoneChatMessage* message);
+const LinphoneAddress* linphone_chat_message_get_from(const LinphoneChatMessage* message);
+const LinphoneAddress* linphone_chat_message_get_to(const LinphoneChatMessage* message);
const char* linphone_chat_message_get_external_body_url(const LinphoneChatMessage* message);
void linphone_chat_message_set_external_body_url(LinphoneChatMessage* message,const char* url);
const char * linphone_chat_message_get_text(const LinphoneChatMessage* message);
void linphone_chat_message_set_user_data(LinphoneChatMessage* message,void*);
LinphoneChatRoom* linphone_chat_message_get_chat_room(LinphoneChatMessage *msg);
const LinphoneAddress* linphone_chat_message_get_peer_address(LinphoneChatMessage *msg);
+LinphoneAddress *linphone_chat_message_get_local_address(const LinphoneChatMessage* message);
void linphone_chat_message_add_custom_header(LinphoneChatMessage* message, const char *header_name, const char *header_value);
const char * linphone_chat_message_get_custom_header(LinphoneChatMessage* message, const char *header_name);
void linphone_core_set_video_dscp(LinphoneCore *lc, int dscp);
int linphone_core_get_video_dscp(const LinphoneCore *lc);
-MSList *linphone_chat_room_get_history(const char *to,LinphoneChatRoom *cr,int nb_message);
-void linphone_core_set_messages_flag_read(LinphoneChatRoom *cr,const char *from, int read);
-void linphone_core_delete_history(LinphoneCore *lc,const char *from);
+
#ifdef __cplusplus
}
static const char *days[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};\r
static const char *months[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};\r
\r
-#define CONFIG_FILE ".linphone-history.db"\r
-\r
-char *linphone_message_storage_get_config_file(const char *filename){\r
- const int path_max=1024;\r
- char *config_file=(char *)malloc(path_max*sizeof(char));\r
- if (filename==NULL) filename=CONFIG_FILE;\r
- /*try accessing a local file first if exists*/\r
- if (access(CONFIG_FILE,F_OK)==0){\r
- snprintf(config_file,path_max,"%s",filename);\r
- }else{\r
-#ifdef WIN32\r
- const char *appdata=getenv("APPDATA");\r
- if (appdata){\r
- snprintf(config_file,path_max,"%s\\%s",appdata,LINPHONE_CONFIG_DIR);\r
- CreateDirectory(config_file,NULL);\r
- snprintf(config_file,path_max,"%s\\%s\\%s",appdata,LINPHONE_CONFIG_DIR,filename);\r
- }\r
-#else\r
- const char *home=getenv("HOME");\r
- if (home==NULL) home=".";\r
- snprintf(config_file,path_max,"%s/%s",home,filename);\r
-#endif\r
- }\r
- return config_file;\r
-}\r
\r
-void create_chat_message(char **argv, void *data){\r
+static void create_chat_message(char **argv, void *data){\r
LinphoneChatRoom *cr = (LinphoneChatRoom *)data;\r
LinphoneChatMessage* new_message = linphone_chat_room_create_message(cr,argv[4]);\r
+ LinphoneAddress *from;\r
struct tm ret={0};\r
char tmp1[80]={0};\r
char tmp2[80]={0};\r
\r
- if(atoi(argv[3])==INCOMING){\r
- linphone_chat_message_set_from(new_message,linphone_address_new(argv[2]));\r
+ if(atoi(argv[3])==LinphoneChatMessageIncoming){\r
+ from=linphone_address_new(argv[2]);\r
} else {\r
- linphone_chat_message_set_from(new_message,linphone_address_new(argv[1]));\r
+ from=linphone_address_new(argv[1]);\r
}\r
+ linphone_chat_message_set_from(new_message,from);\r
+ linphone_address_destroy(from);\r
\r
if(argv[5]!=NULL){\r
int i,j;\r
}\r
new_message->time=argv[5]!=NULL ? mktime(&ret) : time(NULL);\r
new_message->state=atoi(argv[7]);\r
- cr->messages_hist=ms_list_prepend(cr->messages_hist,(void *)new_message);\r
+ cr->messages_hist=ms_list_prepend(cr->messages_hist,new_message);\r
}\r
\r
static int callback(void *data, int argc, char **argv, char **colName){\r
return 0;\r
}\r
\r
-void linphone_sql_request_message(sqlite3 *db,const char *stmt,void *data){\r
+void linphone_sql_request_message(sqlite3 *db,const char *stmt,LinphoneChatRoom *cr){\r
char* errmsg;\r
int ret;\r
- ret=sqlite3_exec(db,stmt,callback,data,&errmsg);\r
+ ret=sqlite3_exec(db,stmt,callback,cr,&errmsg);\r
if(ret != SQLITE_OK) {\r
printf("Error in creation: %s.\n", errmsg);\r
}\r
}\r
\r
void linphone_sql_request(sqlite3* db,const char *stmt){\r
- char* errmsg;\r
+ char* errmsg=NULL;\r
int ret;\r
ret=sqlite3_exec(db,stmt,0,0,&errmsg);\r
if(ret != SQLITE_OK) {\r
- printf("Error in creation: %s.\n", errmsg);\r
+ ms_error("linphone_sql_request: error sqlite3_exec(): %s.\n", errmsg);\r
+ sqlite3_free(errmsg);\r
}\r
}\r
\r
-void linphone_core_set_history_message(LinphoneChatRoom *cr,const char *local_contact,const char *remote_contact, \r
- int direction, const char *message,const char *date, int read, int state){\r
- LinphoneCore *lc=linphone_chat_room_get_lc(cr);\r
- char *buf=sqlite3_mprintf("insert into history values(NULL,%Q,%Q,%i,%Q,%Q,%i,%i);",\r
- local_contact,remote_contact,direction,message,date,read,state);\r
- linphone_sql_request(lc->db,buf);\r
+void linphone_chat_message_store(LinphoneChatMessage *msg){\r
+ LinphoneCore *lc=linphone_chat_room_get_lc(msg->chat_room);\r
+ if (lc->db){\r
+ const char *peer=msg->chat_room->peer;\r
+ char *local_contact=linphone_address_as_string_uri_only(linphone_chat_message_get_local_address(msg));\r
+ char datebuf[26];\r
+ char *buf=sqlite3_mprintf("insert into history values(NULL,%Q,%Q,%i,%Q,%Q,%i,%i);",\r
+ local_contact,peer,msg->dir,msg->message,my_ctime_r(&msg->time,datebuf),msg->is_read,msg->state);\r
+ linphone_sql_request(lc->db,buf);\r
+ sqlite3_free(buf);\r
+ ms_free(local_contact);\r
+ }\r
}\r
\r
-void linphone_core_set_message_state(LinphoneChatRoom *cr,const char *message, int state, time_t date){\r
- LinphoneCore *lc=linphone_chat_room_get_lc(cr);\r
- char time_str[26];\r
- char *buf=sqlite3_mprintf("update history set status=%i where message = %Q and time = %Q;",\r
- state,message,my_ctime_r(&date,time_str));\r
- linphone_sql_request(lc->db,buf);\r
+void linphone_chat_message_store_state(LinphoneChatMessage *msg){\r
+ LinphoneCore *lc=msg->chat_room->lc;\r
+ if (lc->db){\r
+ char time_str[26];\r
+ char *buf=sqlite3_mprintf("update history set status=%i where message = %Q and time = %Q;",\r
+ msg->state,msg->message,my_ctime_r(&msg->time,time_str));\r
+ linphone_sql_request(lc->db,buf);\r
+ sqlite3_free(buf);\r
+ }\r
}\r
\r
-void linphone_core_set_messages_flag_read(LinphoneChatRoom *cr,const char *from, int read){\r
+void linphone_chat_room_mark_as_read(LinphoneChatRoom *cr){\r
LinphoneCore *lc=linphone_chat_room_get_lc(cr);\r
+ int read=1;\r
+ \r
+ if (lc->db==NULL) return ;\r
+\r
char *buf=sqlite3_mprintf("update history set read=%i where remoteContact = %Q;",\r
- read,from);\r
+ read,cr->peer);\r
linphone_sql_request(lc->db,buf);\r
+ sqlite3_free(buf);\r
}\r
\r
-void linphone_core_delete_history(LinphoneCore *lc,const char *from){\r
- char *buf=sqlite3_mprintf("delete from history where remoteContact = %Q;",from);\r
+void linphone_chat_room_delete_history(LinphoneChatRoom *cr){\r
+ LinphoneCore *lc=cr->lc;\r
+ \r
+ if (lc->db==NULL) return ;\r
+ char *buf=sqlite3_mprintf("delete from history where remoteContact = %Q;",cr->peer);\r
linphone_sql_request(lc->db,buf);\r
+ sqlite3_free(buf);\r
}\r
\r
-MSList *linphone_chat_room_get_history(const char *to,LinphoneChatRoom *cr,int nb_message){\r
+MSList *linphone_chat_room_get_history(LinphoneChatRoom *cr,int nb_message){\r
LinphoneCore *lc=linphone_chat_room_get_lc(cr);\r
+ MSList *ret;\r
+ \r
+ if (lc->db==NULL) return NULL;\r
+ \r
cr->messages_hist = NULL;\r
- char *buf=sqlite3_mprintf("select * from history where remoteContact = %Q order by id DESC limit %i ;",to,nb_message);\r
- linphone_sql_request_message(lc->db,buf,(void *)cr);\r
- return cr->messages_hist;\r
+ char *buf=sqlite3_mprintf("select * from history where remoteContact = %Q order by id DESC limit %i ;",cr->peer,nb_message);\r
+ linphone_sql_request_message(lc->db,buf,cr);\r
+ sqlite3_free(buf);\r
+ ret=cr->messages_hist;\r
+ cr->messages_hist=NULL;\r
+ return ret;\r
}\r
\r
void linphone_close_storage(sqlite3* db){\r
}\r
}\r
\r
-sqlite3 * linphone_message_storage_init(){\r
+void linphone_core_message_storage_init(LinphoneCore *lc){\r
int ret;\r
- char *errmsg;\r
+ char *errmsg=NULL;\r
sqlite3 *db;\r
- char *filename;\r
- filename=linphone_message_storage_get_config_file(NULL);\r
- ret=sqlite3_open(filename,&db);\r
+ ret=sqlite3_open(lc->chat_db_file,&db);\r
if(ret != SQLITE_OK) {\r
printf("Error in the opening: %s.\n", errmsg);\r
sqlite3_close(db);\r
+ sqlite3_free(errmsg);\r
}\r
linphone_create_table(db);\r
- return db;\r
+ lc->db=db;\r
+}\r
+\r
+void linphone_core_message_storage_close(LinphoneCore *lc){\r
+ if (lc->db){\r
+ sqlite3_close(lc->db);\r
+ lc->db=NULL;\r
+ }\r
}\r
+\r
#else \r
\r
-void linphone_core_set_history_message(LinphoneChatRoom *cr,const char *local_contact,const char *remote_contact, \r
- int direction, const char *message,const char *date, int read, int state){\r
+void linphone_chat_message_store(LinphoneChatMessage *cr){\r
}\r
\r
-void linphone_core_set_message_state(LinphoneChatRoom *cr,const char *message, int state, time_t date){\r
+void linphone_chat_message_store_state(LinphoneChatMessage *cr){\r
}\r
\r
-void linphone_core_set_messages_flag_read(LinphoneChatRoom *cr,const char *from, int read){\r
+void linphone_chat_room_mark_as_read(LinphoneChatRoom *cr){\r
}\r
\r
-MSList *linphone_chat_room_get_history(const char *to,LinphoneChatRoom *cr,int nb_message){\r
+MSList *linphone_chat_room_get_history(LinphoneChatRoom *cr,int nb_message){\r
return NULL;\r
}\r
\r
-void linphone_core_delete_history(LinphoneCore *lc,const char *from){\r
+void linphone_chat_room_delete_history(LinphoneChatRoom *cr){\r
+}\r
+\r
+void linphone_core_message_storage_init(LinphoneCore *lc){\r
}\r
-#endif
\ No newline at end of file
+\r
+void linphone_core_message_storage_close(LinphoneCore *lc){\r
+}\r
+\r
+#endif\r
static const int linphone_call_magic=0x3343;
+typedef enum _LinphoneChatMessageDir{
+ LinphoneChatMessageIncoming,
+ LinphoneChatMessageOutgoing
+} LinphoneChatMessageDir;
+
struct _LinphoneChatMessage {
- char* message;
LinphoneChatRoom* chat_room;
+ LinphoneChatMessageDir dir;
+ char* message;
LinphoneChatMessageStateChangeCb cb;
void* cb_ud;
void* message_userdata;
char* external_body_url;
- LinphoneAddress* from;
+ LinphoneAddress *from;
+ LinphoneAddress *to;
time_t time;
SalCustomHeader *custom_headers;
LinphoneChatMessageState state;
+ bool_t is_read;
};
typedef struct StunCandidate{
LinphoneTunnel *tunnel;
char* device_id;
MSList *last_recv_msg_ids;
+ char *chat_db_file;
#ifdef MSG_STORAGE_ENABLED
sqlite3 *db;
#endif
int linphone_upnp_init(LinphoneCore *lc);
void linphone_upnp_destroy(LinphoneCore *lc);
-#define OUTGOING 0
-#define INCOMING 1
-
-#define NOT_READ 0
-#define READ 1
-
#ifdef MSG_STORAGE_ENABLED
sqlite3 * linphone_message_storage_init();
#endif
-void linphone_core_set_history_message(LinphoneChatRoom *cr,const char *local_contact,const char *remote_contact,
- int direction, const char *message,const char *date, int read, int state);
-void linphone_core_set_message_state(LinphoneChatRoom *cr,const char *message, int state,time_t date);
-
+void linphone_chat_message_store(LinphoneChatMessage *msg);
+void linphone_chat_message_store_state(LinphoneChatMessage *msg);
+void linphone_core_message_storage_init(LinphoneCore *lc);
+void linphone_core_message_storage_close(LinphoneCore *lc);
#ifdef __cplusplus
}
int sal_unregister(SalOp *h);
/*Messaging */
-int sal_text_send(SalOp *op, const char *from, const char *to, const char *text, const char*t);
-int sal_message_send(SalOp *op, const char *from, const char *to, const char* content_type, const char *msg, const char*t);
+int sal_text_send(SalOp *op, const char *from, const char *to, const char *text);
+int sal_message_send(SalOp *op, const char *from, const char *to, const char* content_type, const char *msg);
/*presence Subscribe/notify*/
int sal_subscribe_presence(SalOp *op, const char *from, const char *to);
sal->in_subscribes=ms_list_remove(sal->in_subscribes,op);
}
-int sal_message_send(SalOp *op, const char *from, const char *to, const char* content_type, const char *msg, const char *t){
+#ifdef WIN32
+
+static inline char *my_ctime_r(const time_t *t, char *buf){
+ strcpy(buf,ctime(t));
+ return buf;
+}
+
+#else
+#define my_ctime_r ctime_r
+#endif
+
+int sal_message_send(SalOp *op, const char *from, const char *to, const char* content_type, const char *msg){
osip_message_t *sip=NULL;
+ char t[26];
+ time_t curtime=time(NULL);
+
+ my_ctime_r(&curtime,t);
if(op->cid == -1)
{
eXosip_unlock();
return -1;
}
+ sal_exosip_add_custom_headers(sip,op->base.custom_headers);
+ osip_message_set_date(sip,t);
osip_message_set_content_type(sip,content_type);
if (msg) osip_message_set_body(sip,msg,strlen(msg));
eXosip_call_send_request(op->did,sip);
return 0;
}
-int sal_text_send(SalOp *op, const char *from, const char *to, const char *msg,const char *t) {
- return sal_message_send(op,from,to,"text/plain",msg,t);
+int sal_text_send(SalOp *op, const char *from, const char *to, const char *msg) {
+ return sal_message_send(op,from,to,"text/plain",msg);
}
/*presence Subscribe/notify*/
int sal_subscribe_presence(SalOp *op, const char *from, const char *to){
#define NB_MSG_HIST 250
+#define CONFIG_FILE ".linphone-history.db"
+
+const char *linphone_gtk_message_storage_get_db_file(const char *filename){
+ const int path_max=1024;
+ static char *db_file=NULL;
+
+ if (db_file) return db_file;
+
+ db_file=(char *)malloc(path_max*sizeof(char));
+ if (filename==NULL) filename=CONFIG_FILE;
+ /*try accessing a local file first if exists*/
+ if (access(CONFIG_FILE,F_OK)==0){
+ snprintf(db_file,path_max,"%s",filename);
+ }else{
+#ifdef WIN32
+ const char *appdata=getenv("APPDATA");
+ if (appdata){
+ snprintf(db_file,path_max,"%s\\%s",appdata,LINPHONE_CONFIG_DIR);
+ CreateDirectory(db_file,NULL);
+ snprintf(db_file,path_max,"%s\\%s\\%s",appdata,LINPHONE_CONFIG_DIR,filename);
+ }
+#else
+ const char *home=getenv("HOME");
+ if (home==NULL) home=".";
+ snprintf(db_file,path_max,"%s/%s",home,filename);
+#endif
+ }
+ return db_file;
+}
+
+
void linphone_gtk_quit_chatroom(LinphoneChatRoom *cr) {
GtkWidget *main_window=linphone_gtk_get_main_window ();
GtkWidget *nb=linphone_gtk_get_widget(main_window,"viewswitch");
void linphone_gtk_push_text(GtkWidget *w, const LinphoneAddress *from,
gboolean me,LinphoneChatRoom *cr,LinphoneChatMessage *msg, gboolean hist){
- GtkTextView *text=GTK_TEXT_VIEW(linphone_gtk_get_widget(w,"textview"));
- GtkTextBuffer *buffer=gtk_text_view_get_buffer(text);
- GtkTextIter iter,begin;
+ GtkTextView *text=GTK_TEXT_VIEW(linphone_gtk_get_widget(w,"textview"));
+ GtkTextBuffer *buffer=gtk_text_view_get_buffer(text);
+ GtkTextIter iter,begin;
int off;
char *from_str=linphone_address_as_string_uri_only(from);
char *from_message=(char *)g_object_get_data(G_OBJECT(w),"from_message");
GList *list=g_object_get_data(G_OBJECT(w),"list");
time_t t;
- gtk_text_buffer_get_start_iter(buffer,&begin);
+ gtk_text_buffer_get_start_iter(buffer,&begin);
gtk_text_buffer_get_end_iter(buffer,&iter);
off=gtk_text_iter_get_offset(&iter);
if(g_strcmp0(from_message,from_str)!=0){
gtk_text_buffer_get_end_iter(buffer,&iter);
gtk_text_buffer_insert(buffer,&iter,"\n",-1);
GtkTextMark *mark=gtk_text_buffer_create_mark(buffer,NULL,&iter,FALSE);
- gtk_text_view_scroll_mark_onscreen(text,mark);
+ gtk_text_view_scroll_mark_onscreen(text,mark);
}
const LinphoneAddress* linphone_gtk_get_used_identity(){
}
void update_chat_state_message(LinphoneChatMessageState state,LinphoneChatMessage *msg){
- GtkWidget *main_window=linphone_gtk_get_main_window();
- GtkWidget *friendlist=linphone_gtk_get_widget(main_window,"contact_list");
+ GtkWidget *main_window=linphone_gtk_get_main_window();
+ GtkWidget *friendlist=linphone_gtk_get_widget(main_window,"contact_list");
GtkWidget *page=(GtkWidget*)g_object_get_data(G_OBJECT(friendlist),"chatview");
GList *list=g_object_get_data(G_OBJECT(page),"list");
colorb.blue = 61952;
with_str=linphone_address_as_string_uri_only(with);
- linphone_core_set_messages_flag_read(cr,with_str,1);
+ linphone_chat_room_mark_as_read(cr);
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text),GTK_WRAP_WORD_CHAR);
gtk_text_view_set_editable(GTK_TEXT_VIEW(text),FALSE);
gtk_notebook_append_page(notebook,chat_view,create_tab_chat_header(cr,with));
"margin","indent",10,NULL);
gtk_text_buffer_create_tag(gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)),
"bg","paragraph-background-gdk",&colorb,NULL);
- messages = linphone_chat_room_get_history(with_str,cr,NB_MSG_HIST);
+ messages = linphone_chat_room_get_history(cr,NB_MSG_HIST);
display_history_message(chat_view,messages,with);
button = linphone_gtk_get_widget(chat_view,"send");
g_signal_connect_swapped(G_OBJECT(button),"clicked",(GCallback)linphone_gtk_send_text,NULL);
LinphoneChatRoom *cr2=(LinphoneChatRoom *)g_object_get_data(G_OBJECT(chat_view),"cr");
char *from_str=linphone_address_as_string(linphone_chat_room_get_peer_address (cr2));
char *uri_str=linphone_address_as_string(uri);
- char *uri_only=linphone_address_as_string_uri_only(uri);
MSList *messages=NULL;
- linphone_core_set_messages_flag_read(cr,uri_only,1);
- if(g_strcmp0(from_str,uri_str)!=0){
- GtkTextView *text_view=GTK_TEXT_VIEW(linphone_gtk_get_widget(chat_view,"textview"));
- GtkTextIter start;
- GtkTextIter end;
+ linphone_chat_room_mark_as_read(cr);
+ if(g_strcmp0(from_str,uri_str)!=0){
+ GtkTextView *text_view=GTK_TEXT_VIEW(linphone_gtk_get_widget(chat_view,"textview"));
+ GtkTextIter start;
+ GtkTextIter end;
GtkTextBuffer *text_buffer;
- text_buffer=gtk_text_view_get_buffer(text_view);
- gtk_text_buffer_get_bounds(text_buffer, &start, &end);
- gtk_text_buffer_delete (text_buffer, &start, &end);
+ text_buffer=gtk_text_view_get_buffer(text_view);
+ gtk_text_buffer_get_bounds(text_buffer, &start, &end);
+ gtk_text_buffer_delete (text_buffer, &start, &end);
udpate_tab_chat_header(chat_view,uri,cr);
g_object_set_data(G_OBJECT(chat_view),"cr",cr);
g_object_set_data(G_OBJECT(linphone_gtk_get_widget(main_window,"contact_list")),"chatview",(gpointer)chat_view);
- messages = linphone_chat_room_get_history(uri_only,cr,NB_MSG_HIST);
+ messages = linphone_chat_room_get_history(cr,NB_MSG_HIST);
g_object_set_data(G_OBJECT(chat_view),"from_message",uri_str);
display_history_message(chat_view,messages,uri);
}
select = gtk_tree_view_get_selection(GTK_TREE_VIEW(linphone_gtk_get_widget(w,"contact_list")));
if (gtk_tree_selection_get_selected (select, &model, &iter))
{
+ LinphoneChatRoom *cr;
gtk_tree_model_get (model, &iter,FRIEND_ID , &lf, -1);
- linphone_core_delete_history(linphone_gtk_get_core(),linphone_address_as_string_uri_only(linphone_friend_get_address(lf)));
+ cr=linphone_core_get_chat_room(linphone_gtk_get_core(),linphone_friend_get_address(lf));
+ linphone_chat_room_delete_history(cr);
linphone_gtk_show_friends();
}
}
GtkWidget *linphone_gtk_get_widget(GtkWidget *window, const char *name);
GtkWidget *linphone_gtk_create_widget(const char *filename, const char *widget_name);
+
+const char *linphone_gtk_message_storage_get_db_file(const char *filename);
void linphone_gtk_show_assistant(void);
void linphone_gtk_close_assistant(void);
}
static void linphone_gtk_init_liblinphone(const char *config_file,
- const char *factory_config_file) {
+ const char *factory_config_file, const char *db_file) {
LinphoneCoreVTable vtable={0};
gchar *secrets_file=linphone_gtk_get_config_file(SECRETS_FILE);
_linphone_gtk_enable_video(FALSE);
linphone_gtk_set_ui_config_int("videoselfview",0);
}
+ if (db_file) linphone_core_set_chat_database_path(the_core,db_file);
}
LinphoneCore *linphone_gtk_get_core(void){
GdkPixbuf *pbuf;
const char *app_name="Linphone";
LpConfig *factory;
+ const char *db_file;
#if !GLIB_CHECK_VERSION(2, 31, 0)
g_thread_init(NULL);
linphone_gtk_create_log_window();
linphone_core_enable_logs_with_cb(linphone_gtk_log_handler);
- linphone_gtk_init_liblinphone(config_file, factory_config_file);
+ db_file=linphone_gtk_message_storage_get_db_file(NULL);
+ linphone_gtk_init_liblinphone(config_file, factory_config_file, db_file);
g_set_application_name(app_name);
pbuf=create_pixbuf(linphone_gtk_get_ui_config("icon",LINPHONE_ICON));