Esempio n. 1
0
//
// use sip:[email protected] or for local net without internet
//  sip.<ipaddr> e.g. sip:192.168.0.1
//
bool QLinPhoneCore::sendMessage(const QString &to, const QString &message)
{
    if (to.isNull() || to.isEmpty()) {
        return false;
    }

    m_chatRoom = linphone_core_create_chat_room(m_lc, to.toLatin1().data());

    /* Sending message */
    linphone_chat_room_send_message(m_chatRoom, message.toLatin1().data());
    linphone_chat_room_destroy(m_chatRoom);

    return true;
}
Esempio n. 2
0
//
// use sip:[email protected] or for local net without internet
//  sip.<ipaddr> e.g. sip:192.168.0.1
//
bool SipClient::sendMessage(const QString &to, const QString &message)
{
	if (to.isNull() || to.isEmpty()) {
		return false;
	}

	m_chatRoom = linphone_core_create_chat_room(lc, to.toLatin1().data());

	/* Sending message */
	linphone_chat_room_send_message(m_chatRoom, message.toLatin1().data());
	//void linphone_chat_room_send_message2(m_chatRoom,	LinphoneChatMessage *msg, on_chat_state_changed, NULL /*void *ud*/);

	linphone_chat_room_destroy(m_chatRoom);

	return true;
}
Esempio n. 3
0
/**
 * function invoked when a file transfer is received.
 **/
static void file_transfer_received(LinphoneChatMessage *message, const LinphoneContent* content, const LinphoneBuffer *buffer){
	FILE* file=NULL;
	if (!linphone_chat_message_get_user_data(message)) {
		/*first chunk, creating file*/
		file = fopen("receive_file.dump","wb");
		linphone_chat_message_set_user_data(message,(void*)file); /*store fd for next chunks*/
	}

	file = (FILE*)linphone_chat_message_get_user_data(message);
	if (linphone_buffer_is_empty(buffer)) {
		printf("File transfert completed\n");
		linphone_chat_room_destroy(linphone_chat_message_get_chat_room(message));
		linphone_chat_message_destroy(message);
		fclose(file);
		running=FALSE;
	} else { /* store content on a file*/
		if (fwrite(linphone_buffer_get_content(buffer),linphone_buffer_get_size(buffer),1,file)==-1){
			ms_warning("file_transfer_received() write failed: %s",strerror(errno));
		}
	}
}
Esempio n. 4
0
void linphone_gtk_chat_destroyed(GtkWidget *w){
	LinphoneChatRoom *cr=(LinphoneChatRoom*)g_object_get_data(G_OBJECT(w),"cr");
	linphone_chat_room_destroy(cr);
}
int main(int argc, char *argv[]){
	LinphoneCoreVTable vtable={0};

	const char* dest_friend=NULL;
	int i;
	const char* big_file_content="big file";
	/*seting dummy file content to something*/
	for (i=0;i<sizeof(big_file);i+=strlen(big_file_content))
		memcpy(big_file+i, big_file_content, strlen(big_file_content));

	big_file[0]=*"S";
	big_file[sizeof(big_file)-1]=*"E";

	signal(SIGINT,stop);
//#define DEBUG
#ifdef DEBUG
	linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/
#endif
	/* 
	 Fill the LinphoneCoreVTable with application callbacks.
	 All are optional. Here we only use the file_transfer_received callback
	 in order to get notifications about incoming file receive, file_transfer_send to feed file to be transfered
	 and file_transfer_progress_indication to print progress.
	 */
	vtable.file_transfer_received=file_transfer_received;
	vtable.file_transfer_send=file_transfer_send;
	vtable.file_transfer_progress_indication=file_transfer_progress_indication;
	vtable.message_received=message_received;


	/*
	 Instantiate a LinphoneCore object given the LinphoneCoreVTable
	*/
	lc=linphone_core_new(&vtable,NULL,NULL,NULL);
	dest_friend = linphone_core_get_primary_contact(lc);
	printf("Send message to me : %s\n", dest_friend);

	/**
	 * Globally configure an http file transfer server.
	 */
	//linphone_core_set_file_transfer_server(lc,"http://npasc.al/lft.php");
	linphone_core_set_file_transfer_server(lc,"https://www.linphone.org:444/lft.php");


	/*Next step is to create a chat room*/
	LinphoneChatRoom* chat_room = linphone_core_create_chat_room(lc,dest_friend);

	LinphoneContent content;
	memset(&content,0,sizeof(content));
	content.type="text";
	content.subtype="plain";
	content.size=sizeof(big_file); /*total size to be transfered*/
	content.name = "bigfile.txt";

	/*now create a chat message with custom content*/
	LinphoneChatMessage* chat_message = linphone_chat_room_create_file_transfer_message(chat_room,&content);
	if (chat_message == NULL) {
		printf("returned message is null\n");
	}

	/*initiating file transfer*/
	linphone_chat_room_send_message2(chat_room, chat_message, linphone_file_transfer_state_changed, NULL);

	/* main loop for receiving incoming messages and doing background linphone core work: */
	while(running){
		linphone_core_iterate(lc);
		ms_usleep(50000);
	}


	printf("Shutting down...\n");
	linphone_chat_room_destroy(chat_room);
	linphone_core_destroy(lc);
	printf("Exited\n");
	return 0;
}