/* linphone Copyright (C) 2000 - 2010 Simon MORLAT (simon.morlat@linphone.org) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef LINPHONECORE_H #define LINPHONECORE_H #include "ortp/ortp.h" #include "ortp/payloadtype.h" #include "mediastreamer2/mscommon.h" #include "mediastreamer2/msvideo.h" #ifdef IN_LINPHONE #include "sipsetup.h" #else #include "linphone/sipsetup.h" #endif #define LINPHONE_IPADDR_SIZE 64 #define LINPHONE_HOSTNAME_SIZE 128 #ifdef __cplusplus extern "C" { #endif struct _MSSndCard; struct _LinphoneCore; struct SalOp; struct _LpConfig; struct _LCSipTransports{ int udp_port; int tcp_port; int dtls_port; int tls_port; }; typedef struct _LCSipTransports LCSipTransports; /** * Object that represents a SIP address. * * The LinphoneAddress is an opaque object to represents SIP addresses, ie * the content of SIP's 'from' and 'to' headers. * A SIP address is made of display name, username, domain name, port, and various * uri headers (such as tags). It looks like 'Alice '. * The LinphoneAddress has methods to extract and manipulate all parts of the address. * When some part of the address (for example the username) is empty, the accessor methods * return NULL. * * @ingroup linphone_address * @var LinphoneAddress */ typedef struct SalAddress LinphoneAddress; LinphoneAddress * linphone_address_new(const char *uri); LinphoneAddress * linphone_address_clone(const LinphoneAddress *uri); const char *linphone_address_get_scheme(const LinphoneAddress *u); const char *linphone_address_get_display_name(const LinphoneAddress* u); const char *linphone_address_get_username(const LinphoneAddress *u); const char *linphone_address_get_domain(const LinphoneAddress *u); /** * Get port number as an integer value. * */ int linphone_address_get_port_int(const LinphoneAddress *u); /** * Get port number, null if not present. */ const char* linphone_address_get_port(const LinphoneAddress *u); void linphone_address_set_display_name(LinphoneAddress *u, const char *display_name); void linphone_address_set_username(LinphoneAddress *uri, const char *username); void linphone_address_set_domain(LinphoneAddress *uri, const char *host); void linphone_address_set_port(LinphoneAddress *uri, const char *port); void linphone_address_set_port_int(LinphoneAddress *uri, int port); /*remove tags, params etc... so that it is displayable to the user*/ void linphone_address_clean(LinphoneAddress *uri); char *linphone_address_as_string(const LinphoneAddress *u); char *linphone_address_as_string_uri_only(const LinphoneAddress *u); bool_t linphone_address_weak_equal(const LinphoneAddress *a1, const LinphoneAddress *a2); void linphone_address_destroy(LinphoneAddress *u); struct _SipSetupContext; /** * Enum representing the direction of a call. * @ingroup call_logs **/ enum _LinphoneCallDir { LinphoneCallOutgoing, /**< outgoing calls*/ LinphoneCallIncoming /**< incoming calls*/ }; /** * Typedef for enum * @ingroup call_logs **/ typedef enum _LinphoneCallDir LinphoneCallDir; /** * Enum representing the status of a call * @ingroup call_logs **/ typedef enum _LinphoneCallStatus { LinphoneCallSuccess, /**< The call was sucessful*/ LinphoneCallAborted, /**< The call was aborted */ LinphoneCallMissed /**< The call was missed (unanswered)*/ } LinphoneCallStatus; /** * Structure representing a call log. * * @ingroup call_logs * **/ typedef struct _LinphoneCallLog{ LinphoneCallDir dir; /**< The direction of the call*/ LinphoneCallStatus status; /**< The status of the call*/ LinphoneAddress *from; /** Use by linphone_friend_set_inc_subscribe_policy() */ typedef enum { /** * Does not automatically accept an incoming subscription request. * */ LinphoneSPWait, /** * Rejects incoming subscription request. */ LinphoneSPDeny, /** * Automatically accepts a subscription request. */ LinphoneSPAccept }LinphoneSubscribePolicy; /** * @ingroup buddy_list */ typedef enum _LinphoneOnlineStatus{ LinphoneStatusOffline, LinphoneStatusOnline, LinphoneStatusBusy, LinphoneStatusBeRightBack, LinphoneStatusAway, LinphoneStatusOnThePhone, LinphoneStatusOutToLunch, LinphoneStatusDoNotDisturb, LinphoneStatusMoved, LinphoneStatusAltService, LinphoneStatusPending, LinphoneStatusEnd }LinphoneOnlineStatus; /** * @ingroup buddy_list * return humain readable presence status * @param ss */ const char *linphone_online_status_to_string(LinphoneOnlineStatus ss); /** * @addtogroup buddy_list * @{ */ struct _LinphoneFriend; /** * Represents a buddy, all presence actions like subscription and status change notification are performed on this object */ typedef struct _LinphoneFriend LinphoneFriend; /** * Contructor * @return a new empty #LinphoneFriend */ LinphoneFriend * linphone_friend_new(); /** * Contructor same as linphone_friend_new() + linphone_friend_set_sip_addr() * @param addr a buddy address, must be a sip uri like sip:joe@sip.linphone.org * @return a new #LinphoneFriend with \link linphone_friend_get_address() address initialized \endlink */ LinphoneFriend *linphone_friend_new_with_addr(const char *addr); /** * Configure #LinphoneFriend with a new address. * @param uri a buddy address, must be a sip uri like sip:joe@sip.linphone.org * @return 0 if succeed */ int linphone_friend_set_sip_addr(LinphoneFriend *fr, const char *uri); /** * modify friend nickname * @param fr #LinphoneFriend object * @param new name * @return 0 if succeed * */ int linphone_friend_set_name(LinphoneFriend *fr, const char *name); /** * Configure #LinphoneFriend to subscribe to presence information * @param fr #LinphoneFriend object * @param val if TRUE this friend will receive subscription message */ int linphone_friend_enable_subscribes(LinphoneFriend *fr, bool_t val); #define linphone_friend_send_subscribe linphone_friend_enable_subscribes /** * Configure incoming subscription policy for this friend. * @param fr #LinphoneFriend object * @param pol #LinphoneSubscribePolicy policy to apply. */ int linphone_friend_set_inc_subscribe_policy(LinphoneFriend *fr, LinphoneSubscribePolicy pol); /** * Starts editing a friend configuration. * * Because friend configuration must be consistent, applications MUST * call linphone_friend_edit() before doing any attempts to modify * friend configuration (such as \link linphone_friend_set_name() nick name \endlink , \link linphone_friend_set_sip_addr() address \endlink and so on). * Once the modifications are done, then the application must call * linphone_friend_done() to commit the changes. **/ void linphone_friend_edit(LinphoneFriend *fr); /** * Commits modification made to the friend configuration. * @param fr #LinphoneFriend object **/ void linphone_friend_done(LinphoneFriend *fr); /** * Destructor * @param fr #LinphoneFriend object */ void linphone_friend_destroy(LinphoneFriend *lf); /** * get address of this friend * @param lf #LinphoneFriend object * @return #LinphoneAddress */ const LinphoneAddress *linphone_friend_get_address(const LinphoneFriend *lf); /** * get subscription flag value * @param lf #LinphoneFriend object * @return returns true is subscription is activated for this friend * */ bool_t linphone_friend_subscribes_enabled(const LinphoneFriend *lf); #define linphone_friend_get_send_subscribe linphone_friend_subscribes_enabled /** * get current subscription policy for this #LinphoneFriend * @param lf #LinphoneFriend object * @return #LinphoneSubscribePolicy * */ LinphoneSubscribePolicy linphone_friend_get_inc_subscribe_policy(const LinphoneFriend *lf); /** * get friend status * @return #LinphoneOnlineStatus */ LinphoneOnlineStatus linphone_friend_get_status(const LinphoneFriend *lf); BuddyInfo * linphone_friend_get_info(const LinphoneFriend *lf); void linphone_friend_set_ref_key(LinphoneFriend *lf, const char *key); const char *linphone_friend_get_ref_key(const LinphoneFriend *lf); bool_t linphone_friend_in_list(const LinphoneFriend *lf); #define linphone_friend_url(lf) ((lf)->url) /** * @} */ /** * @addtogroup proxies * @{ **/ /** * The LinphoneProxyConfig object represents a proxy configuration to be used * by the LinphoneCore object. * Its fields must not be used directly in favour of the accessors methods. * Once created and filled properly the LinphoneProxyConfig can be given to * LinphoneCore with linphone_core_add_proxy_config(). * This will automatically triggers the registration, if enabled. * * The proxy configuration are persistent to restarts because they are saved * in the configuration file. As a consequence, after linphone_core_new() there * might already be a list of configured proxy that can be examined with * linphone_core_get_proxy_config_list(). * * The default proxy (see linphone_core_set_default_proxy() ) is the one of the list * that is used by default for calls. **/ typedef struct _LinphoneProxyConfig LinphoneProxyConfig; /** * LinphoneRegistrationState describes proxy registration states. **/ typedef enum _LinphoneRegistrationState{ LinphoneRegistrationNone, LinphoneRegistrationProgress, LinphoneRegistrationOk, LinphoneRegistrationCleared, LinphoneRegistrationFailed }LinphoneRegistrationState; /** * Human readable version of the #LinphoneRegistrationState * @param cs sate */ const char *linphone_registration_state_to_string(LinphoneRegistrationState cs); LinphoneProxyConfig *linphone_proxy_config_new(void); int linphone_proxy_config_set_server_addr(LinphoneProxyConfig *obj, const char *server_addr); int linphone_proxy_config_set_identity(LinphoneProxyConfig *obj, const char *identity); int linphone_proxy_config_set_route(LinphoneProxyConfig *obj, const char *route); void linphone_proxy_config_expires(LinphoneProxyConfig *obj, int expires); /** * Indicates either or not, REGISTRATION must be issued for this #LinphoneProxyConfig . *
In case this #LinphoneProxyConfig has been added to #LinphoneCore, follows the linphone_proxy_config_edit() rule. * @param obj object pointer * @param val if true, registration will be engaged */ void linphone_proxy_config_enable_register(LinphoneProxyConfig *obj, bool_t val); #define linphone_proxy_config_enableregister linphone_proxy_config_enable_register void linphone_proxy_config_edit(LinphoneProxyConfig *obj); int linphone_proxy_config_done(LinphoneProxyConfig *obj); void linphone_proxy_config_enable_publish(LinphoneProxyConfig *obj, bool_t val); void linphone_proxy_config_set_dial_escape_plus(LinphoneProxyConfig *cfg, bool_t val); void linphone_proxy_config_set_dial_prefix(LinphoneProxyConfig *cfg, const char *prefix); LinphoneRegistrationState linphone_proxy_config_get_state(const LinphoneProxyConfig *obj); bool_t linphone_proxy_config_is_registered(const LinphoneProxyConfig *obj); const char *linphone_proxy_config_get_domain(const LinphoneProxyConfig *cfg); const char *linphone_proxy_config_get_route(const LinphoneProxyConfig *obj); const char *linphone_proxy_config_get_identity(const LinphoneProxyConfig *obj); bool_t linphone_proxy_config_publish_enabled(const LinphoneProxyConfig *obj); const char *linphone_proxy_config_get_addr(const LinphoneProxyConfig *obj); int linphone_proxy_config_get_expires(const LinphoneProxyConfig *obj); bool_t linphone_proxy_config_register_enabled(const LinphoneProxyConfig *obj); struct _LinphoneCore * linphone_proxy_config_get_core(const LinphoneProxyConfig *obj); bool_t linphone_proxy_config_get_dial_escape_plus(const LinphoneProxyConfig *cfg); const char * linphone_proxy_config_get_dial_prefix(const LinphoneProxyConfig *cfg); LinphoneError linphone_proxy_config_get_error(const LinphoneProxyConfig *cfg); /* destruction is called automatically when removing the proxy config */ void linphone_proxy_config_destroy(LinphoneProxyConfig *cfg); void linphone_proxy_config_set_sip_setup(LinphoneProxyConfig *cfg, const char *type); SipSetupContext *linphone_proxy_config_get_sip_setup_context(LinphoneProxyConfig *cfg); SipSetup *linphone_proxy_config_get_sip_setup(LinphoneProxyConfig *cfg); /** * normalize a human readable phone number into a basic string. 888-444-222 becomes 888444222 */ int linphone_proxy_config_normalize_number(LinphoneProxyConfig *proxy, const char *username, char *result, size_t result_len); /* * attached a user data to a proxy config */ void linphone_proxy_config_set_user_data(LinphoneProxyConfig *cr, void * ud); /* * get user data to a proxy config. return null if any */ void * linphone_proxy_config_get_user_data(LinphoneProxyConfig *cr); /** * @} **/ typedef struct _LinphoneAccountCreator{ struct _LinphoneCore *lc; struct _SipSetupContext *ssctx; char *username; char *password; char *domain; bool_t succeeded; }LinphoneAccountCreator; LinphoneAccountCreator *linphone_account_creator_new(struct _LinphoneCore *core, const char *type); void linphone_account_creator_set_username(LinphoneAccountCreator *obj, const char *username); void linphone_account_creator_set_password(LinphoneAccountCreator *obj, const char *password); void linphone_account_creator_set_domain(LinphoneAccountCreator *obj, const char *domain); const char * linphone_account_creator_get_username(LinphoneAccountCreator *obj); const char * linphone_account_creator_get_domain(LinphoneAccountCreator *obj); int linphone_account_creator_test_existence(LinphoneAccountCreator *obj); LinphoneProxyConfig * linphone_account_creator_validate(LinphoneAccountCreator *obj); void linphone_account_creator_destroy(LinphoneAccountCreator *obj); struct _LinphoneAuthInfo; /** * @ingroup authentication * Object holding authentication information. * * @note The object's fields should not be accessed directly. Prefer using * the accessor methods. * * In most case, authentication information consists of a username and password. * Sometimes, a userid is required by proxy, and realm can be useful to discriminate * different SIP domains. * * Once created and filled, a LinphoneAuthInfo must be added to the LinphoneCore in * order to become known and used automatically when needed. * Use linphone_core_add_auth_info() for that purpose. * * The LinphoneCore object can take the initiative to request authentication information * when needed to the application through the auth_info_requested callback of the * LinphoneCoreVTable structure. * * The application can respond to this information request later using * linphone_core_add_auth_info(). This will unblock all pending authentication * transactions and retry them with authentication headers. * **/ typedef struct _LinphoneAuthInfo LinphoneAuthInfo; LinphoneAuthInfo *linphone_auth_info_new(const char *username, const char *userid, const char *passwd, const char *ha1,const char *realm); void linphone_auth_info_set_passwd(LinphoneAuthInfo *info, const char *passwd); void linphone_auth_info_set_username(LinphoneAuthInfo *info, const char *username); void linphone_auth_info_set_userid(LinphoneAuthInfo *info, const char *userid); const char *linphone_auth_info_get_username(const LinphoneAuthInfo *i); const char *linphone_auth_info_get_passwd(const LinphoneAuthInfo *i); const char *linphone_auth_info_get_userid(const LinphoneAuthInfo *i); /* you don't need those function*/ void linphone_auth_info_destroy(LinphoneAuthInfo *info); LinphoneAuthInfo * linphone_auth_info_new_from_config_file(struct _LpConfig *config, int pos); struct _LinphoneChatRoom; typedef struct _LinphoneChatRoom LinphoneChatRoom; LinphoneChatRoom * linphone_core_create_chat_room(struct _LinphoneCore *lc, const char *to); void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg); void linphone_chat_room_destroy(LinphoneChatRoom *cr); void linphone_chat_room_set_user_data(LinphoneChatRoom *cr, void * ud); void * linphone_chat_room_get_user_data(LinphoneChatRoom *cr); typedef enum _LinphoneGlobalState{ LinphoneGlobalOff, LinphoneGlobalStartup, LinphoneGlobalOn, LinphoneGlobalShutdown }LinphoneGlobalState; const char *linphone_global_state_to_string(LinphoneGlobalState gs); /** * @addtogroup initializing * @{ **/ /**Call state notification callback prototype*/ typedef void (*LinphoneGlobalStateCb)(struct _LinphoneCore *lc, LinphoneGlobalState gstate, const char *message); /**Call state notification callback prototype*/ typedef void (*LinphoneCallStateCb)(struct _LinphoneCore *lc, LinphoneCall *call, LinphoneCallState cstate, const char *message); /** @ingroup Proxies * Registration state notification callback prototype * */ typedef void (*LinphoneRegistrationStateCb)(struct _LinphoneCore *lc, LinphoneProxyConfig *cfg, LinphoneRegistrationState cstate, const char *message); /** Callback prototype */ typedef void (*ShowInterfaceCb)(struct _LinphoneCore *lc); /** Callback prototype */ typedef void (*DisplayStatusCb)(struct _LinphoneCore *lc, const char *message); /** Callback prototype */ typedef void (*DisplayMessageCb)(struct _LinphoneCore *lc, const char *message); /** Callback prototype */ typedef void (*DisplayUrlCb)(struct _LinphoneCore *lc, const char *message, const char *url); /** Callback prototype */ typedef void (*LinphoneCoreCbFunc)(struct _LinphoneCore *lc,void * user_data); /** Callback prototype */ typedef void (*NotifyReceivedCb)(struct _LinphoneCore *lc, LinphoneCall *call, const char *from, const char *event); /** * Report status change for a friend previously \link linphone_core_add_friend() added \endlink to #LinphoneCore. * @param lc #LinphoneCore object . * @param fr Updated #LinphoneFriend . */ typedef void (*NotifyPresenceReceivedCb)(struct _LinphoneCore *lc, LinphoneFriend * fr); /** Callback prototype */ typedef void (*NewUnknownSubscriberCb)(struct _LinphoneCore *lc, LinphoneFriend *lf, const char *url); /** Callback prototype */ typedef void (*AuthInfoRequested)(struct _LinphoneCore *lc, const char *realm, const char *username); /** Callback prototype */ typedef void (*CallLogUpdated)(struct _LinphoneCore *lc, struct _LinphoneCallLog *newcl); /** Callback prototype */ typedef void (*TextMessageReceived)(struct _LinphoneCore *lc, LinphoneChatRoom *room, const char *from, const char *message); /** Callback prototype */ typedef void (*DtmfReceived)(struct _LinphoneCore* lc, LinphoneCall *call, int dtmf); /** Callback prototype */ typedef void (*ReferReceived)(struct _LinphoneCore *lc, const char *refer_to); /** Callback prototype */ typedef void (*BuddyInfoUpdated)(struct _LinphoneCore *lc, LinphoneFriend *lf); /** * This structure holds all callbacks that the application should implement. * None is mandatory. **/ typedef struct _LinphoneVTable{ LinphoneGlobalStateCb global_state_changed; /**