| 1 | /* |
|---|
| 2 |  * phapi  phone api |
|---|
| 3 | Â * |
|---|
| 4 | Â * Copyright (C) 2004Â Â Â Â Vadim Lebedev <vadim@mbdsys.com> |
|---|
| 5 | Â * |
|---|
| 6 | Â * This is free software; you can redistribute it and/or modify |
|---|
| 7 | Â * it under the terms of the GNU General Public License as |
|---|
| 8 | Â * published by the Free Software F undation; either version 2, |
|---|
| 9 | Â * or (at your option) any later version. |
|---|
| 10 | Â * |
|---|
| 11 | Â * This is distributed in the hope that it will be useful, but |
|---|
| 12 | Â * WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | Â * GNU General Public License for more details. |
|---|
| 15 | Â * |
|---|
| 16 | Â * You should have received a copy of the GNU General Public |
|---|
| 17 | Â * License along with dpkg; if not, write to the Free Software |
|---|
| 18 | Â * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 19 | Â */ |
|---|
| 20 | |
|---|
| 21 | /** |
|---|
| 22 | Â * @file phapi.c |
|---|
| 23 |  * @brief softphone API |
|---|
| 24 | Â * |
|---|
| 25 | Â * phapi is a library providing simplified api to create VOIP sessions |
|---|
| 26 | Â * using eXosip library oSIP stack and oRTP stack |
|---|
| 27 | Â * <P> |
|---|
| 28 | Â */ |
|---|
| 29 | |
|---|
| 30 | #include "phglobal.h" |
|---|
| 31 | #ifdef OS_WIN32 |
|---|
| 32 | #include <winsock2.h> |
|---|
| 33 | #include <windows.h> |
|---|
| 34 | #endif |
|---|
| 35 | #include <stdio.h> |
|---|
| 36 | #include <string.h> |
|---|
| 37 | #include <stdlib.h> |
|---|
| 38 | #include <sys/stat.h> |
|---|
| 39 | #include <sys/types.h> |
|---|
| 40 | #include <errno.h> |
|---|
| 41 | #include <limits.h> |
|---|
| 42 | #include <ctype.h> |
|---|
| 43 | #include <assert.h> |
|---|
| 44 | #include <time.h> |
|---|
| 45 | |
|---|
| 46 | #if !defined(OS_WIN32) && !defined(_WIN32_WCE) |
|---|
| 47 | //#include "config.h" |
|---|
| 48 | #include <sys/wait.h> |
|---|
| 49 | #include <unistd.h> |
|---|
| 50 | #include <dirent.h> |
|---|
| 51 | #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
|---|
| 52 | #include <sys/soundcard.h> |
|---|
| 53 | #endif |
|---|
| 54 | #include <sys/ioctl.h> |
|---|
| 55 | #include <fcntl.h> |
|---|
| 56 | #else /* WIN32 */ |
|---|
| 57 | #define snprintf _snprintf |
|---|
| 58 | #ifndef _WIN32_WCE |
|---|
| 59 | #define strncasecmp strnicmp |
|---|
| 60 | #endif /* !_WIN32_WCE */ |
|---|
| 61 | # if !defined(strcasecmp) |
|---|
| 62 | #Â define strcasecmp stricmp |
|---|
| 63 | # endif |
|---|
| 64 | #define usleep(usecs) Sleep((usecs)/1000) |
|---|
| 65 | #define random rand |
|---|
| 66 | #define osip_free_func osip_free |
|---|
| 67 | #endif |
|---|
| 68 | |
|---|
| 69 | #ifdef HAVE_NETINET_IN_H |
|---|
| 70 | #include <netinet/in.h> |
|---|
| 71 | #endif |
|---|
| 72 | #include <osipparser2/osip_list.h> |
|---|
| 73 | #include <osipparser2/osip_port.h> |
|---|
| 74 | #include <osip2/osip_dialog.h> |
|---|
| 75 | #include <osip2/osip_mt.h> |
|---|
| 76 | #include <osip2/osip.h> |
|---|
| 77 | #include <eXosip2/eXosip.h> |
|---|
| 78 | #include <ortp/stun.h> |
|---|
| 79 | #include <ortp/ortp.h> |
|---|
| 80 | #include <ortp/payloadtype.h> |
|---|
| 81 | |
|---|
| 82 | #include "phapi-config.h" |
|---|
| 83 | |
|---|
| 84 | #include "phdebug.h" |
|---|
| 85 | #include "phapi.h" |
|---|
| 86 | #include "phcall.h" |
|---|
| 87 | #include "phrpc.h" |
|---|
| 88 | |
|---|
| 89 | #include "phms.h" |
|---|
| 90 | #include "phms_audiostream.h" |
|---|
| 91 | #include "sdphandler.h" |
|---|
| 92 | |
|---|
| 93 | #ifdef USE_HTTP_TUNNEL |
|---|
| 94 | #include "httptunnel.h" |
|---|
| 95 | #endif |
|---|
| 96 | |
|---|
| 97 | #if 1 |
|---|
| 98 | |
|---|
| 99 | #ifdef PHAPI_VIDEO_SUPPORT |
|---|
| 100 | #include <libavcodec/avcodec.h> |
|---|
| 101 | #include "phms_videostream.h" |
|---|
| 102 | #endif |
|---|
| 103 | |
|---|
| 104 | #ifdef USE_UPNP |
|---|
| 105 | #include <miniupnpc/upnpcommands.h> |
|---|
| 106 | #include <miniupnpc/miniupnpc.h> |
|---|
| 107 | |
|---|
| 108 | static struct UPNPUrls ph_upnp_urls; |
|---|
| 109 | static struct IGDdatas ph_upnp_data; |
|---|
| 110 | static struct UPNPDev * ph_upnp_devlist; |
|---|
| 111 | #endif |
|---|
| 112 | |
|---|
| 113 | static struct osip_thread *phapithread = NULL; |
|---|
| 114 | |
|---|
| 115 | phcall_t *ph_locate_call(eXosip_event_t *je, int creatit); |
|---|
| 116 | phcall_t *ph_allocate_call(int cid); |
|---|
| 117 | phcall_t *ph_locate_call_for_refer(eXosip_event_t *je); |
|---|
| 118 | |
|---|
| 119 | void ph_wegot_dtmf(void *ctx, int dtmfEvent); |
|---|
| 120 | static int ph_event_get(); |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | static char *ph_get_call_(phcall_t *ca); |
|---|
| 124 | static void set_customized_header(osip_message_t *req, const char *h, const char *v); |
|---|
| 125 | static char *ph_get_call_contact(phcall_t *ca); |
|---|
| 126 | |
|---|
| 127 | //#define MEDIA_SUSPEND |
|---|
| 128 | |
|---|
| 129 | /*#ifndef PH_STREAM_AUDIO |
|---|
| 130 | #define PH_STREAM_AUDIO (1 << 0) |
|---|
| 131 | #define PH_STREAM_VIDEO_RX (1 << 1) |
|---|
| 132 | #define PH_STREAM_VIDEO_TX (1 << 2) |
|---|
| 133 | #endif*/ |
|---|
| 134 | |
|---|
| 135 | #define PH_STREAM_CNG (1 << 30) |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | static int ph_call_retrieve_payloads(phcall_t *ca, int flags); |
|---|
| 139 | static int ph_call_media_start(phcall_t *ca, eXosip_event_t *je, int flags, int resumeflag); |
|---|
| 140 | static char *ph_ipv4tostr(char *buf, size_t s, const StunAddress4 addr); |
|---|
| 141 | static void ph_release_stream_ports(phcall_t *ca); |
|---|
| 142 | |
|---|
| 143 | void ph_release_call(phcall_t *ca); |
|---|
| 144 | static int timeout = 10; |
|---|
| 145 | |
|---|
| 146 | static int ph_resend_offset = 30; |
|---|
| 147 | |
|---|
| 148 | #define PORT_STRING_LEN 16 |
|---|
| 149 | static char ph_nat_router_addr[32]; |
|---|
| 150 | static char ph_nat_port_str[PORT_STRING_LEN]; |
|---|
| 151 | |
|---|
| 152 | #ifdef PHAPI_VIDEO_SUPPORT |
|---|
| 153 | static char ph_nat_video_port_str[16]; |
|---|
| 154 | #endif |
|---|
| 155 | |
|---|
| 156 | static char ph_nat_sip_port_str[16]; |
|---|
| 157 | |
|---|
| 158 | static char vcontact[256]; |
|---|
| 159 | |
|---|
| 160 | typedef enum phNatType |
|---|
| 161 | { |
|---|
| 162 | Â Â Â Â OPEN, |
|---|
| 163 | Â Â Â Â UPNP, |
|---|
| 164 | Â Â Â Â STUN, |
|---|
| 165 | Â Â Â Â TUNNEL |
|---|
| 166 | }phNatType; |
|---|
| 167 | |
|---|
| 168 | static phNatType ph_nat_type = OPEN; |
|---|
| 169 | static NatType ph_stun_nat_type = StunTypeOpen; |
|---|
| 170 | |
|---|
| 171 | static size_t ph_generate_rfc5626_probe(int rid, const void *addr, int addrlen, char* buf, size_t bsize); |
|---|
| 172 | static char * _get_local_sip_port(); |
|---|
| 173 | static void _get_local_video_sdp_port(char buf[]); |
|---|
| 174 | static void _get_local_audio_sdp_port(char buf[]); |
|---|
| 175 | |
|---|
| 176 | static char* _get_public_sip_port(); |
|---|
| 177 | |
|---|
| 178 | static void ph_connection_lost(const char *host, int port); |
|---|
| 179 | static int ph_is_connection_lost; |
|---|
| 180 | static char* ph_is_connection_lost_host; |
|---|
| 181 | static int ph_is_connection_lost_port; |
|---|
| 182 | |
|---|
| 183 | void ph_message_progress(eXosip_event_t *je); |
|---|
| 184 | static void ph_keep_refreshing(); |
|---|
| 185 | static void ph_call_requestfailure(eXosip_event_t *je); |
|---|
| 186 | |
|---|
| 187 | static void ph_frame_display_cbk(void *ctx, void *event); |
|---|
| 188 | static void ph_qos_info_cbk(void *ctx, void *info); |
|---|
| 189 | |
|---|
| 190 | static int ph_call_media_stop(phcall_t * ca); |
|---|
| 191 | static int ph_call_media_suspend(phcall_t *ca, int localhold); |
|---|
| 192 | |
|---|
| 193 | enum ph_direction |
|---|
| 194 | { |
|---|
| 195 | Â Â Â Â sendrecv, |
|---|
| 196 | Â Â Â Â sendonly, |
|---|
| 197 | Â Â Â Â recvonly, |
|---|
| 198 | Â Â Â Â inactive |
|---|
| 199 | }; |
|---|
| 200 | |
|---|
| 201 | enum ph_direction ph_get_media_direction( sdp_message_t * sdp, const char * media_type); |
|---|
| 202 | enum ph_direction ph_get_local_media_direction( phcall_t *ca, const char * media_type); |
|---|
| 203 | int ph_set_media_direction( sdp_message_t * sdp, const char *media_type, enum ph_direction direction); |
|---|
| 204 | const char * ph_get_str_direction( enum ph_direction direction); |
|---|
| 205 | |
|---|
| 206 | #define nonempty(x)Â ((x) && (x)[0]) |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | #define USE_VLINES 1 |
|---|
| 210 | #ifndef PH_MAX_VLINES |
|---|
| 211 | #define PH_MAX_VLINES 16 |
|---|
| 212 | #endif |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | struct vline |
|---|
| 216 | { |
|---|
| 217 |     char *displayname; |
|---|
| 218 |     char *nrusername;  /* username for non-REGISTER requests */ |
|---|
| 219 |     char *rusername;  /* username for REGISTER requests */ |
|---|
| 220 |     char *server; |
|---|
| 221 |     int  port; |
|---|
| 222 |     char *proxy; |
|---|
| 223 |     char *contact; |
|---|
| 224 |     time_t  regTimeout; |
|---|
| 225 |     time_t  lastRegTime; |
|---|
| 226 |     int  rid; |
|---|
| 227 | #define VL_USED 1 |
|---|
| 228 | #define VL_DELETING 2 |
|---|
| 229 |     int  used; |
|---|
| 230 |     int  busy; |
|---|
| 231 |     char *followme; |
|---|
| 232 |     int  mobility; |
|---|
| 233 | Â Â Â Â struct |
|---|
| 234 | Â Â Â Â { |
|---|
| 235 |         time_t timeout; |
|---|
| 236 |         time_t last; |
|---|
| 237 |         char  *etag; |
|---|
| 238 |         char  *uri; |
|---|
| 239 |         char  *evt; |
|---|
| 240 |         char  *ctt; |
|---|
| 241 |         char  *body; |
|---|
| 242 | Â Â Â Â }Â pub; |
|---|
| 243 | }; |
|---|
| 244 | |
|---|
| 245 | |
|---|
| 246 | struct vline ph_vlines[PH_MAX_VLINES]; |
|---|
| 247 | |
|---|
| 248 | #ifdef ENABLE_SOCKS |
|---|
| 249 | #define TUNNEL_MAX 16 |
|---|
| 250 | struct tunnel_info { |
|---|
| 251 |     char tunnel_proto[16]; |
|---|
| 252 |     char tunnel_server[64]; |
|---|
| 253 |     char tunnel_port[8]; |
|---|
| 254 | }; |
|---|
| 255 | |
|---|
| 256 | static struct tunnel_info sip_tunnel_set[TUNNEL_MAX]; |
|---|
| 257 | static int sip_tunnel_count; |
|---|
| 258 | |
|---|
| 259 | static struct tunnel_info rtp_tunnel_set[TUNNEL_MAX]; |
|---|
| 260 | static int rtp_tunnel_count; |
|---|
| 261 | |
|---|
| 262 | static void copyfield(char *dst, const char* src, const char *eos, int M) |
|---|
| 263 | { |
|---|
| 264 |     int L = eos - src; |
|---|
| 265 | |
|---|
| 266 |     osip_strncpy(dst, src, M); |
|---|
| 267 |     if (L < M) |
|---|
| 268 | Â Â Â Â Â Â Â Â dst[L]Â =Â 0; |
|---|
| 269 | |
|---|
| 270 | } |
|---|
| 271 | /* |
|---|
| 272 | Â *Â parse proto://addr:port |
|---|
| 273 | Â *Â return 0 in case of success |
|---|
| 274 | Â */ |
|---|
| 275 | int ph_parse_tunnel_info(struct tunnel_info *tun, const char *uri) |
|---|
| 276 | { |
|---|
| 277 |     const char *addr, *port; |
|---|
| 278 |     const char *eos; |
|---|
| 279 | |
|---|
| 280 |     addr = strstr(uri, "://"); |
|---|
| 281 |     if (!addr) |
|---|
| 282 |         return -1; |
|---|
| 283 | |
|---|
| 284 |     port = strstr(addr+3, ":"); |
|---|
| 285 |     if (!port) |
|---|
| 286 |         return -1; |
|---|
| 287 | |
|---|
| 288 | Â Â Â Â eos =Â port+1; |
|---|
| 289 | Â Â Â Â while(*eos &&Â isdigit(*eos)) |
|---|
| 290 | Â Â Â Â Â Â Â Â eos++; |
|---|
| 291 | |
|---|
| 292 | Â Â Â Â while(*uri &&Â isspace(*uri)) |
|---|
| 293 | Â Â Â Â Â Â Â Â uri++; |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 |     copyfield(tun->tunnel_proto, uri, addr, sizeof(tun->tunnel_proto)-1); |
|---|
| 297 |     copyfield(tun->tunnel_server, addr+3, port, sizeof(tun->tunnel_server)-1); |
|---|
| 298 |     copyfield(tun->tunnel_port, port+1, eos, sizeof(tun->tunnel_port)-1); |
|---|
| 299 | |
|---|
| 300 |     return 0; |
|---|
| 301 | |
|---|
| 302 | } |
|---|
| 303 | |
|---|
| 304 | /* |
|---|
| 305 | Â * parse proto1://addr1:port1,proto2://addr2:port2,..... |
|---|
| 306 | Â * return number of parsed elements |
|---|
| 307 | Â */ |
|---|
| 308 | int ph_parse_tunnel_list(struct tunnel_info *tinfo, const char* urilist, int N) |
|---|
| 309 | { |
|---|
| 310 |     int i = 0; |
|---|
| 311 |     struct tunnel_info *tun = tinfo; |
|---|
| 312 |     const char *p = urilist; |
|---|
| 313 | |
|---|
| 314 | Â Â Â Â while(p &&Â (i++Â <Â N))Â { |
|---|
| 315 |         if (ph_parse_tunnel_info(tun, p)) |
|---|
| 316 | Â Â Â Â Â Â Â Â Â Â Â Â break; |
|---|
| 317 |         p = strchr(p, ','); |
|---|
| 318 |         if (p) |
|---|
| 319 | Â Â Â Â Â Â Â Â Â Â Â Â p++; |
|---|
| 320 | Â Â Â Â } |
|---|
| 321 | |
|---|
| 322 |     return i; |
|---|
| 323 | } |
|---|
| 324 | |
|---|
| 325 | struct tunnel_info *ph_select_tunnel(struct tunnel_info *tinfo, int N) |
|---|
| 326 | { |
|---|
| 327 |     return tinfo + random() % N; |
|---|
| 328 | |
|---|
| 329 | } |
|---|
| 330 | |
|---|
| 331 | RtpTransport * rtp_socks_transport_new(const char *peer, int pport); |
|---|
| 332 | |
|---|
| 333 | static RtpTransport * |
|---|
| 334 | ph_create_rtp_tunnel(struct tunnel_info *t, const char* ip, int port) |
|---|
| 335 | { |
|---|
| 336 |     rtp_set_tunnel_server(t->tunnel_server, t->tunnel_port); |
|---|
| 337 |     return rtp_socks_transport_new(ip, port); |
|---|
| 338 | } |
|---|
| 339 | |
|---|
| 340 | #endif |
|---|
| 341 | |
|---|
| 342 | |
|---|
| 343 | static int |
|---|
| 344 | ph_build_cname(char *buf, int n, struct vline *vl); |
|---|
| 345 | |
|---|
| 346 | |
|---|
| 347 | static int |
|---|
| 348 | ph_req_set_body(osip_message_t *msg, const char *body, const char *mime); |
|---|
| 349 | static char * |
|---|
| 350 | ph_req_get_body(osip_message_t *msg); |
|---|
| 351 | |
|---|
| 352 | |
|---|
| 353 | static |
|---|
| 354 | void ph_msession_free(struct ph_msession_s *s); |
|---|
| 355 | static |
|---|
| 356 | void ph_msession_use(struct ph_msession_s *s); |
|---|
| 357 | |
|---|
| 358 | static struct vline *vline_alloc(); |
|---|
| 359 | static void vline_free(struct vline *vl); |
|---|
| 360 | #define PHM_IGNORE_PORT 1 |
|---|
| 361 | #define PHM_IGNORE_HOST 2 |
|---|
| 362 | static struct vline *ph_find_matching_vline(const char *userid, int ignore); |
|---|
| 363 | static struct vline *ph_find_matching_vline2(const char *username, const char* host, int ignore); |
|---|
| 364 | static struct vline *ph_find_matching_vline3(const char *username, const char* host, int port, int ignore); |
|---|
| 365 | static struct vline *ph_find_vline_by_rid(int rid); |
|---|
| 366 | |
|---|
| 367 | static char *ph_get_proxy(const char *from); |
|---|
| 368 | static int  ph_get_vline_id(const char *userid, const char *altid); |
|---|
| 369 | static enum phNatType ph_get_nat_type() |
|---|
| 370 | { |
|---|
| 371 |     return ph_nat_type; |
|---|
| 372 | } |
|---|
| 373 | |
|---|
| 374 | int getPublicPort(char *local_voice_port, char *local_video_port, char *public_voice_port, char *public_video_port); |
|---|
| 375 | |
|---|
| 376 | |
|---|
| 377 | |
|---|
| 378 | #define ph_vlid2vline(vlid) (ph_vlines + (vlid) - 1) |
|---|
| 379 | #define ph_vline2vlid(vl) ((vl) - ph_vlines + 1) |
|---|
| 380 | |
|---|
| 381 | #define clear(x) memset(&x, 0, sizeof(x)) |
|---|
| 382 | |
|---|
| 383 | static struct vline * |
|---|
| 384 | ph_valid_vlid(int vlid) |
|---|
| 385 | { |
|---|
| 386 |     struct vline *vl = 0; |
|---|
| 387 | |
|---|
| 388 |     if (vlid > 0 && vlid <= PH_MAX_VLINES) |
|---|
| 389 | Â Â Â Â { |
|---|
| 390 | Â Â Â Â Â Â Â Â vl =Â ph_vlid2vline(vlid); |
|---|
| 391 |         if (!vl->used || vl->used == VL_DELETING) |
|---|
| 392 | Â Â Â Â Â Â Â Â Â Â Â Â vl =Â 0; |
|---|
| 393 | Â Â Â Â } |
|---|
| 394 |     return vl; |
|---|
| 395 | } |
|---|
| 396 | |
|---|
| 397 | PHAPI_EXPORT phCallbacks_t *phcb; |
|---|
| 398 | |
|---|
| 399 | PHAPI_EXPORT int phIsInitialized; |
|---|
| 400 | |
|---|
| 401 | PHAPI_EXPORT int phDebugLevel = 0; |
|---|
| 402 | PHAPI_EXPORT char *phLogFileName = 0; |
|---|
| 403 | |
|---|
| 404 | static char ph_follow_me_addr[256]; |
|---|
| 405 | |
|---|
| 406 | unsigned short phCallBackPort = PH_CALLBACK_PORT; |
|---|
| 407 | PHAPI_EXPORT unsigned short phServerPort = PH_SERVER_PORT; |
|---|
| 408 | |
|---|
| 409 | static int ph_busyFlag; |
|---|
| 410 | |
|---|
| 411 | |
|---|
| 412 | static FILE *ph_log_file; |
|---|
| 413 | |
|---|
| 414 | void * |
|---|
| 415 | ph_api_thread(void *arg); |
|---|
| 416 | |
|---|
| 417 | // mutex for ph_start_call |
|---|
| 418 | ph_mutex_t *ph_media_start_mutex; |
|---|
| 419 | |
|---|
| 420 | // mutex for ph_release_call |
|---|
| 421 | ph_mutex_t *ph_media_stop_mutex; |
|---|
| 422 | |
|---|
| 423 | ph_mutex_t *ph_custom_mutex; |
|---|
| 424 | |
|---|
| 425 | osip_list_t ph_custom_headers; |
|---|
| 426 | int ph_custom_idx; |
|---|
| 427 | |
|---|
| 428 | #define ph_custom_lock() osip_mutex_lock(ph_custom_mutex) |
|---|
| 429 | #define ph_custom_unlock() osip_mutex_unlock(ph_custom_mutex) |
|---|
| 430 | static void ph_apply_header_monitor(osip_message_t* msg, struct ph_hdr_list *hlist); |
|---|
| 431 | |
|---|
| 432 | |
|---|
| 433 | ph_mutex_t *ph_hdrmon_mutex; |
|---|
| 434 | int ph_hdrmon_idx; |
|---|
| 435 | osip_list_t ph_hdrmon_list; |
|---|
| 436 | |
|---|
| 437 | #define ph_hdrmon_lock() osip_mutex_lock(ph_hdrmon_mutex) |
|---|
| 438 | #define ph_hdrmon_unlock() osip_mutex_unlock(ph_hdrmon_mutex) |
|---|
| 439 | |
|---|
| 440 | |
|---|
| 441 | |
|---|
| 442 | struct ph_custom_hdr |
|---|
| 443 | { |
|---|
| 444 |     char   *matchrequests; |
|---|
| 445 |     char *hdrname; |
|---|
| 446 |     char *hdrvalue; |
|---|
| 447 |     int  idx; |
|---|
| 448 |     int  enabled; |
|---|
| 449 | |
|---|
| 450 | }; |
|---|
| 451 | |
|---|
| 452 | |
|---|
| 453 | |
|---|
| 454 | static char *presencenames[] = |
|---|
| 455 | { |
|---|
| 456 | Â Â Â Â Â Â Â Â "presence", |
|---|
| 457 | Â Â Â Â Â Â Â Â "presence.winfo", |
|---|
| 458 | Â Â Â Â Â Â Â Â "presence.list", |
|---|
| 459 | Â Â Â Â Â Â Â Â "conflist", |
|---|
| 460 | Â Â Â Â Â Â Â Â "sipprofile", |
|---|
| 461 | Â Â Â Â Â Â Â Â "addressbook.query" |
|---|
| 462 | }; |
|---|
| 463 | |
|---|
| 464 | #define name(x) #x |
|---|
| 465 | |
|---|
| 466 | static char *evtnames[] = |
|---|
| 467 | { |
|---|
| 468 |         name(EXOSIP_REGISTRATION_NEW),      /**< announce new registration.    */ |
|---|
| 469 |         name(EXOSIP_REGISTRATION_SUCCESS),    /**< user is successfully registred. */ |
|---|
| 470 |         name(EXOSIP_REGISTRATION_FAILURE),    /**< user is not registred.      */ |
|---|
| 471 |         name(EXOSIP_REGISTRATION_REFRESHED),   /**< registration has been refreshed. */ |
|---|
| 472 |         name(EXOSIP_REGISTRATION_TERMINATED),  /**< UA is not registred any more.  */ |
|---|
| 473 | |
|---|
| 474 | Â Â Â Â Â Â Â Â /* INVITE related events within calls */ |
|---|
| 475 |         name(EXOSIP_CALL_INVITE),      /**< announce a new call          */ |
|---|
| 476 |         name(EXOSIP_CALL_REINVITE),     /**< announce a new INVITE within call   */ |
|---|
| 477 | |
|---|
| 478 |         name(EXOSIP_CALL_NOANSWER),     /**< announce no answer within the timeout */ |
|---|
| 479 |         name(EXOSIP_CALL_PROCEEDING),    /**< announce processing by a remote app  */ |
|---|
| 480 |         name(EXOSIP_CALL_RINGING),      /**< announce ringback           */ |
|---|
| 481 |         name(EXOSIP_CALL_ANSWERED),     /**< announce start of call        */ |
|---|
| 482 |         name(EXOSIP_CALL_REDIRECTED),    /**< announce a redirection        */ |
|---|
| 483 |         name(EXOSIP_CALL_REQUESTFAILURE),  /**< announce a request failure      */ |
|---|
| 484 |         name(EXOSIP_CALL_SERVERFAILURE),   /**< announce a server failure       */ |
|---|
| 485 |         name(EXOSIP_CALL_GLOBALFAILURE),   /**< announce a global failure       */ |
|---|
| 486 |         name(EXOSIP_CALL_ACK),        /**< ACK received for 200ok to INVITE   */ |
|---|
| 487 | |
|---|
| 488 |         name(EXOSIP_CALL_CANCELLED),     /**< announce that call has been cancelled */ |
|---|
| 489 |         name(EXOSIP_CALL_TIMEOUT),      /**< announce that call has failed     */ |
|---|
| 490 | |
|---|
| 491 | Â Â Â Â Â Â Â Â /* request related events within calls (except INVITE) */ |
|---|
| 492 |         name(EXOSIP_CALL_MESSAGE_NEW),       /**< announce new incoming request. */ |
|---|
| 493 |         name(EXOSIP_CALL_MESSAGE_PROCEEDING),    /**< announce a 1xx for request. */ |
|---|
| 494 |         name(EXOSIP_CALL_MESSAGE_ANSWERED),     /**< announce a 200ok */ |
|---|
| 495 |         name(EXOSIP_CALL_MESSAGE_REDIRECTED),    /**< announce a failure. */ |
|---|
| 496 |         name(EXOSIP_CALL_MESSAGE_REQUESTFAILURE),  /**< announce a failure. */ |
|---|
| 497 |         name(EXOSIP_CALL_MESSAGE_SERVERFAILURE),  /**< announce a failure. */ |
|---|
| 498 |         name(EXOSIP_CALL_MESSAGE_GLOBALFAILURE),  /**< announce a failure. */ |
|---|
| 499 | |
|---|
| 500 |         name(EXOSIP_CALL_CLOSED),      /**< a BYE was received for this call   */ |
|---|
| 501 | |
|---|
| 502 | Â Â Â Â Â Â Â Â /* for both UAS & UAC events */ |
|---|
| 503 |         name(EXOSIP_CALL_RELEASED),       /**< call context is cleared.      */ |
|---|
| 504 | |
|---|
| 505 | Â Â Â Â Â Â Â Â /* response received for request outside calls */ |
|---|
| 506 |         name(EXOSIP_MESSAGE_NEW),       /**< announce new incoming request. */ |
|---|
| 507 |         name(EXOSIP_MESSAGE_PROCEEDING),    /**< announce a 1xx for request. */ |
|---|
| 508 |         name(EXOSIP_MESSAGE_ANSWERED),     /**< announce a 200ok */ |
|---|
| 509 |         name(EXOSIP_MESSAGE_REDIRECTED),    /**< announce a failure. */ |
|---|
| 510 |         name(EXOSIP_MESSAGE_REQUESTFAILURE),  /**< announce a failure. */ |
|---|
| 511 |         name(EXOSIP_MESSAGE_SERVERFAILURE),  /**< announce a failure. */ |
|---|
| 512 |         name(EXOSIP_MESSAGE_GLOBALFAILURE),  /**< announce a failure. */ |
|---|
| 513 | |
|---|
| 514 | Â Â Â Â Â Â Â Â /* Presence and Instant Messaging */ |
|---|
| 515 |         name(EXOSIP_SUBSCRIPTION_UPDATE),     /**< announce incoming SUBSCRIBE.   */ |
|---|
| 516 |         name(EXOSIP_SUBSCRIPTION_CLOSED),     /**< announce end of subscription.   */ |
|---|
| 517 | |
|---|
| 518 |         name(EXOSIP_SUBSCRIPTION_NOANSWER),     /**< announce no answer       */ |
|---|
| 519 |         name(EXOSIP_SUBSCRIPTION_PROCEEDING),    /**< announce a 1xx         */ |
|---|
| 520 |         name(EXOSIP_SUBSCRIPTION_ANSWERED),     /**< announce a 200ok        */ |
|---|
| 521 |         name(EXOSIP_SUBSCRIPTION_REDIRECTED),    /**< announce a redirection     */ |
|---|
| 522 |         name(EXOSIP_SUBSCRIPTION_REQUESTFAILURE),  /**< announce a request failure   */ |
|---|
| 523 |         name(EXOSIP_SUBSCRIPTION_SERVERFAILURE),   /**< announce a server failure    */ |
|---|
| 524 |         name(EXOSIP_SUBSCRIPTION_GLOBALFAILURE),   /**< announce a global failure    */ |
|---|
| 525 |         name(EXOSIP_SUBSCRIPTION_NOTIFY),      /**< announce new NOTIFY request   */ |
|---|
| 526 | |
|---|
| 527 |         name(EXOSIP_SUBSCRIPTION_RELEASED),     /**< call context is cleared.    */ |
|---|
| 528 | |
|---|
| 529 |         name(EXOSIP_IN_SUBSCRIPTION_NEW),      /**< announce new incoming SUBSCRIBE.*/ |
|---|
| 530 |         name(EXOSIP_IN_SUBSCRIPTION_RELEASED),    /**< announce end of subscription.  */ |
|---|
| 531 | |
|---|
| 532 |         name(EXOSIP_NOTIFICATION_NOANSWER),     /**< announce no answer       */ |
|---|
| 533 |         name(EXOSIP_NOTIFICATION_PROCEEDING),    /**< announce a 1xx         */ |
|---|
| 534 |         name(EXOSIP_NOTIFICATION_ANSWERED),     /**< announce a 200ok        */ |
|---|
| 535 |         name(EXOSIP_NOTIFICATION_REDIRECTED),    /**< announce a redirection     */ |
|---|
| 536 |         name(EXOSIP_NOTIFICATION_REQUESTFAILURE),  /**< announce a request failure   */ |
|---|
| 537 |         name(EXOSIP_NOTIFICATION_SERVERFAILURE),   /**< announce a server failure    */ |
|---|
| 538 |         name(EXOSIP_NOTIFICATION_GLOBALFAILURE)   /**< announce a global failure    */ |
|---|
| 539 | |
|---|
| 540 | }; |
|---|
| 541 | |
|---|
| 542 | #undef name |
|---|
| 543 | |
|---|
| 544 | |
|---|
| 545 | |
|---|
| 546 | phcall_t ph_calls[PH_MAX_CALLS]; |
|---|
| 547 | |
|---|
| 548 | /* |
|---|
| 549 | //#define FORCE_VADÂ Â 1 |
|---|
| 550 | #define FORCE_CNGÂ Â 1 |
|---|
| 551 | Â */ |
|---|
| 552 | static struct osip_list ph_audio_payloads; |
|---|
| 553 | static struct osip_list ph_video_payloads; |
|---|
| 554 | |
|---|
| 555 | |
|---|
| 556 | ph_config_t phcfg =Â { |
|---|
| 557 | Â Â Â Â Â Â Â Â /* public ip addr */Â "", |
|---|
| 558 | Â Â Â Â Â Â Â Â /* local ip addr */Â "", |
|---|
| 559 | Â Â Â Â Â Â Â Â /* local audio rtp port */"10600", |
|---|
| 560 | Â Â Â Â Â Â Â Â /* local audio rtcp port */Â "10900", |
|---|
| 561 | Â Â Â Â Â Â Â Â /* local audio rtp port */"10700", |
|---|
| 562 | Â Â Â Â Â Â Â Â /* local audio rtcp port */Â "11000", |
|---|
| 563 | Â Â Â Â Â Â Â Â /* local video rtp port */Â "10800", |
|---|
| 564 | Â Â Â Â Â Â Â Â /* local video rtcp port */Â "11100", |
|---|
| 565 |         /* sipport */ "5060", |
|---|
| 566 | Â Â Â Â Â Â Â Â /* public sip port */Â "", |
|---|
| 567 | Â Â Â Â Â Â Â Â /* sip transport */Â IPPROTO_UDP, |
|---|
| 568 | Â Â Â Â Â Â Â Â /* nattype */Â ""Â , |
|---|
| 569 | Â Â Â Â Â Â Â Â /* codecs */Â Â ""Â ,"", |
|---|
| 570 | Â Â Â Â Â Â Â Â /* asyncmode */Â 0, |
|---|
| 571 | Â Â Â Â Â Â Â Â /* audio_dev_in */Â Â ""Â , |
|---|
| 572 | Â Â Â Â Â Â Â Â /* audio_dev_out */Â Â ""Â , |
|---|
| 573 | Â Â Â Â Â Â Â Â /* softboost */Â 0, |
|---|
| 574 | Â Â Â Â Â Â Â Â /* no media */Â 0, |
|---|
| 575 | Â Â Â Â Â Â Â Â /* no aec */Â 0, |
|---|
| 576 | Â Â Â Â Â Â Â Â /* vad */Â 0, |
|---|
| 577 | Â Â Â Â Â Â Â Â /* cng */Â 0, |
|---|
| 578 | Â Â Â Â Â Â Â Â /* hdx mode */Â 0, |
|---|
| 579 | Â Â Â Â Â Â Â Â /* nat_refresh_udp_time */Â 0, |
|---|
| 580 | Â Â Â Â Â Â Â Â /* nat_refresh_tcp_time */Â 0, |
|---|
| 581 | Â Â Â Â Â Â Â Â /* nat_refresh_time_shift */Â 0, |
|---|
| 582 | Â Â Â Â Â Â Â Â /* ptime */Â 0, |
|---|
| 583 | Â Â Â Â Â Â Â Â /* jitterdepth */0, |
|---|
| 584 | Â Â Â Â Â Â Â Â /* stream_timeout */0, |
|---|
| 585 | Â Â Â Â Â Â Â Â /* nodefaultline */0, |
|---|
| 586 | Â Â Â Â Â Â Â Â /* autoredir */0, |
|---|
| 587 | Â Â Â Â Â Â Â Â /* stunserver */Â "80.118.132.74", |
|---|
| 588 | Â Â Â Â Â Â Â Â 0 |
|---|
| 589 | }; |
|---|
| 590 | |
|---|
| 591 | static const char * |
|---|
| 592 | ph_get_event_type_str(int winfo) |
|---|
| 593 | { |
|---|
| 594 |     if (winfo >= sizeof(presencenames)/sizeof(presencenames[0])) |
|---|
| 595 |         return NULL; |
|---|
| 596 |     return presencenames[winfo]; |
|---|
| 597 | }Â |
|---|
| 598 | |
|---|
| 599 | PHAPI_EXPORT ph_config_t *ph_get_config() |
|---|
| 600 | { |
|---|
| 601 |     return &phcfg; |
|---|
| 602 | } |
|---|
| 603 | |
|---|
| 604 | static int _is_video_enabled(int streams) |
|---|
| 605 | { |
|---|
| 606 |     return (streams & (PH_STREAM_VIDEO_RX | PH_STREAM_VIDEO_TX)); |
|---|
| 607 | } |
|---|
| 608 | |
|---|
| 609 | |
|---|
| 610 | static int _is_audio_enabled(int streams) |
|---|
| 611 | { |
|---|
| 612 |     return (streams & PH_STREAM_AUDIO); |
|---|
| 613 | } |
|---|
| 614 | |
|---|
| 615 | static char *ph_ipv4tostr(char *buf, size_t s, const StunAddress4 addr) |
|---|
| 616 | { |
|---|
| 617 |     uint32_t ip = addr.addr; |
|---|
| 618 | |
|---|
| 619 |     snprintf(buf, s, "%d.%d.%d.%d", (ip >> 24) & 255, (ip >> 16) & 255, (ip >> 8) & 255, ip & 255); |
|---|
| 620 | |
|---|
| 621 |     return buf; |
|---|
| 622 | |
|---|
| 623 | } |
|---|
| 624 | |
|---|
| 625 | static int |
|---|
| 626 | ph_port_inuse(int port) |
|---|
| 627 | { |
|---|
| 628 |     int i; |
|---|
| 629 | Â Â Â Â phcall_t *ca; |
|---|
| 630 | |
|---|
| 631 | Â Â Â Â /* scan all active calls and check that the given port is inuse */ |
|---|
| 632 | Â Â Â Â for(i=0;Â i<PH_MAX_CALLS;Â i++) |
|---|
| 633 | Â Â Â Â { |
|---|
| 634 | Â Â Â Â Â Â Â Â ca =Â &ph_calls[i]; |
|---|
| 635 |         if (ca->cid != -1) |
|---|
| 636 | Â Â Â Â Â Â Â Â { |
|---|
| 637 | Â Â Â Â Â Â Â Â Â Â Â Â /* active call */ |
|---|
| 638 | Â Â Â Â Â Â Â Â Â Â Â Â if(ca->loc_sdp_audio_port ==Â port ||Â port ==Â ca->loc_sdp_video_port) |
|---|
| 639 |                 return 1; |
|---|
| 640 | Â Â Â Â Â Â Â Â } |
|---|
| 641 | Â Â Â Â } |
|---|
| 642 | |
|---|
| 643 |     return 0; |
|---|
| 644 | } |
|---|
| 645 | |
|---|
| 646 | static void |
|---|
| 647 | _get_local_audio_sdp_port(char buf[]) |
|---|
| 648 | { |
|---|
| 649 | |
|---|
| 650 | Â Â Â Â /* <MINHPQ> |
|---|
| 651 | Â Â Â Â Â * To get arround the problem of connect in winsock ( connect returns |
|---|
| 652 | Â Â Â Â Â * an error: 10048: Address already in use connect is called an the local address is in used |
|---|
| 653 | Â Â Â Â Â * within the last 2 or 4 minutes), we should not bind the rtp socket to a specific local port. Hence, |
|---|
| 654 | Â Â Â Â Â * we should return "0" here to let the system choose a random port number. |
|---|
| 655 | Â Â Â Â Â */ |
|---|
| 656 | |
|---|
| 657 | Â Â Â Â /* base port number*/ |
|---|
| 658 |     int port = atoi(phcfg.local_audio_rtp_port); |
|---|
| 659 | |
|---|
| 660 | Â Â Â Â buf[0]Â =Â 0; |
|---|
| 661 | |
|---|
| 662 |     if (port <= 0) |
|---|
| 663 | Â Â Â Â Â Â Â Â port =Â 10600Â +Â random()Â %Â 4096; |
|---|
| 664 | |
|---|
| 665 | Â Â Â Â while(1) |
|---|
| 666 | Â Â Â Â { |
|---|
| 667 |         if (!ph_port_inuse(port)) |
|---|
| 668 | Â Â Â Â Â Â Â Â { |
|---|
| 669 |             sprintf(buf, "%d", port); |
|---|
| 670 | Â Â Â Â Â Â Â Â Â Â Â Â return; |
|---|
| 671 | Â Â Â Â Â Â Â Â } |
|---|
| 672 | Â Â Â Â Â Â Â Â else |
|---|
| 673 | Â Â Â Â Â Â Â Â Â Â Â Â port +=Â 2;Â Â /* try next pair */ |
|---|
| 674 | Â Â Â Â } |
|---|
| 675 | } |
|---|
| 676 | |
|---|
| 677 | static void |
|---|
| 678 | _get_local_video_sdp_port(char buf[]) |
|---|
| 679 | { |
|---|
| 680 |     int port = atoi(phcfg.local_video_rtp_port); |
|---|
| 681 | |
|---|
| 682 | Â Â Â Â buf[0]Â =Â 0; |
|---|
| 683 | |
|---|
| 684 |     if (port <= 0) |
|---|
| 685 | Â Â Â Â Â Â Â Â port =Â 10600Â +Â random()Â %Â 4096; |
|---|
| 686 | Â Â Â Â else |
|---|
| 687 | Â Â Â Â Â Â Â Â port +=Â 2; |
|---|
| 688 | |
|---|
| 689 | Â Â Â Â while(1) |
|---|
| 690 | Â Â Â Â { |
|---|
| 691 |         if (!ph_port_inuse(port)) |
|---|
| 692 | Â Â Â Â Â Â Â Â { |
|---|
| 693 |             sprintf(buf, "%d", port); |
|---|
| 694 | Â Â Â Â Â Â Â Â Â Â Â Â return; |
|---|
| 695 | Â Â Â Â Â Â Â Â } |
|---|
| 696 | Â Â Â Â Â Â Â Â else |
|---|
| 697 | Â Â Â Â Â Â Â Â Â Â Â Â port +=Â 2;Â Â /* try next pair */ |
|---|
| 698 | Â Â Â Â } |
|---|
| 699 | } |
|---|
| 700 | |
|---|
| 701 | |
|---|
| 702 | |
|---|
| 703 | static char * |
|---|
| 704 | _get_local_sip_port() |
|---|
| 705 | { |
|---|
| 706 |     return phcfg.sipport; |
|---|
| 707 | } |
|---|
| 708 | |
|---|
| 709 | static char * |
|---|
| 710 | _get_public_sip_port() |
|---|
| 711 | { |
|---|
| 712 |     if (ph_nat_sip_port_str[0]) |
|---|
| 713 |         return ph_nat_sip_port_str; |
|---|
| 714 |     return _get_local_sip_port(); |
|---|
| 715 | } |
|---|
| 716 | |
|---|
| 717 | phcall_t * |
|---|
| 718 | ph_locate_call_by_cid(int cid) |
|---|
| 719 | { |
|---|
| 720 | Â Â Â Â phcall_t *ca; |
|---|
| 721 | |
|---|
| 722 | Â Â Â Â for(ca =Â ph_calls;Â ca <Â &ph_calls[PH_MAX_CALLS];Â ca++) |
|---|
| 723 | Â Â Â Â { |
|---|
| 724 |         if (ca->cid == cid) |
|---|
| 725 |             return ca; |
|---|
| 726 | Â Â Â Â } |
|---|
| 727 |     return 0; |
|---|
| 728 | } |
|---|
| 729 | |
|---|
| 730 | #if 0 |
|---|
| 731 | void phReleaseTerminatedCalls() |
|---|
| 732 | { |
|---|
| 733 | Â Â Â Â phcall_t *ca; |
|---|
| 734 | Â Â Â Â for(ca = ph_calls; ca < &ph_calls[PH_MAX_CALLS];Â ca++) |
|---|
| 735 | Â Â Â Â { |
|---|
| 736 | Â Â Â Â Â Â Â Â if ((ca->cid != -1) && (ph_media_is_stream_stopped(ca) == 1)) |
|---|
| 737 | Â Â Â Â Â Â Â Â Â Â Â Â ph_release_call(ca); |
|---|
| 738 | Â Â Â Â } |
|---|
| 739 | } |
|---|
| 740 | #endif |
|---|
| 741 | |
|---|
| 742 | |
|---|
| 743 | phcall_t * |
|---|
| 744 | ph_locate_call_by_rcid(int cid) |
|---|
| 745 | { |
|---|
| 746 | Â Â Â Â phcall_t *ca; |
|---|
| 747 | |
|---|
| 748 | |
|---|
| 749 | Â Â Â Â for(ca =Â ph_calls;Â ca <Â &ph_calls[PH_MAX_CALLS];Â ca++) |
|---|
| 750 | Â Â Â Â { |
|---|
| 751 |         if (ca->rcid == cid) |
|---|
| 752 |             return ca; |
|---|
| 753 | Â Â Â Â } |
|---|
| 754 | |
|---|
| 755 |     return 0; |
|---|
| 756 | } |
|---|
| 757 | |
|---|
| 758 | phcall_t * |
|---|
| 759 | ph_locate_call_by_rdid(int did) |
|---|
| 760 | { |
|---|
| 761 | Â Â Â Â phcall_t *ca; |
|---|
| 762 | |
|---|
| 763 | |
|---|
| 764 | Â Â Â Â for(ca =Â ph_calls;Â ca <Â &ph_calls[PH_MAX_CALLS];Â ca++) |
|---|
| 765 | Â Â Â Â { |
|---|
| 766 |         if (ca->rdid == did) |
|---|
| 767 |             return ca; |
|---|
| 768 | Â Â Â Â } |
|---|
| 769 | |
|---|
| 770 |     return 0; |
|---|
| 771 | } |
|---|
| 772 | |
|---|
| 773 | |
|---|
| 774 | phcall_t * |
|---|
| 775 | ph_allocate_call(int cid) |
|---|
| 776 | { |
|---|
| 777 | Â Â Â Â phcall_t *ca =Â ph_locate_call_by_cid(-1); |
|---|
| 778 | |
|---|
| 779 |     if (!ca) |
|---|
| 780 |         return 0; |
|---|
| 781 | |
|---|
| 782 | Â Â Â Â ca->redirs =Â 0; |
|---|
| 783 | Â Â Â Â ca->cid =Â cid; |
|---|
| 784 | Â Â Â Â osip_list_init(&ca->audio_payloads); |
|---|
| 785 |     if (osip_list_clone(&ph_audio_payloads, &ca->audio_payloads, sdp_payload_clone)) |
|---|
| 786 |       return 0; |
|---|
| 787 | Â Â Â Â osip_list_init(&ca->video_payloads); |
|---|
| 788 |     if (osip_list_clone(&ph_video_payloads, &ca->video_payloads, sdp_payload_clone)) |
|---|
| 789 |       return 0; |
|---|
| 790 |     return ca; |
|---|
| 791 | } |
|---|
| 792 | |
|---|
| 793 | |
|---|
| 794 | phcall_t * |
|---|
| 795 | ph_locate_call(eXosip_event_t *je, int creatit) |
|---|
| 796 | { |
|---|
| 797 |     phcall_t *ca, *found = 0, *newca = 0; |
|---|
| 798 | Â Â Â Â osip_header_t *hdr =Â 0; |
|---|
| 799 | |
|---|
| 800 | |
|---|
| 801 | Â Â Â Â /* lookup matching call descriptor */ |
|---|
| 802 |     for (ca = ph_calls; ca < &ph_calls[PH_MAX_CALLS]; ca++) |
|---|
| 803 | Â Â Â Â { |
|---|
| 804 |         if (ca->cid == -1 && !newca) |
|---|
| 805 | Â Â Â Â Â Â Â Â Â Â Â Â newca =Â ca; |
|---|
| 806 | |
|---|
| 807 |         if (ca->cid == je->cid) |
|---|
| 808 | Â Â Â Â Â Â Â Â { |
|---|
| 809 | Â Â Â Â Â Â Â Â Â Â Â Â found =Â ca; |
|---|
| 810 | Â Â Â Â Â Â Â Â Â Â Â Â break; |
|---|
| 811 | Â Â Â Â Â Â Â Â } |
|---|
| 812 | Â Â Â Â } |
|---|
| 813 | |
|---|
| 814 | Â Â Â Â ca =Â found; |
|---|
| 815 | |
|---|
| 816 |     if (!ca) /* we didn't find a matching call descriptor */ |
|---|
| 817 | Â Â Â Â { |
|---|
| 818 |         if (creatit) |
|---|
| 819 | Â Â Â Â Â Â Â Â { |
|---|
| 820 | Â Â Â Â Â Â Â Â Â Â Â Â /* allocate a new one */ |
|---|
| 821 |             if (!newca) |
|---|
| 822 |                 return 0; /* !!! BUG !!! */ |
|---|
| 823 | Â Â Â Â Â Â Â Â Â Â Â Â ca =Â newca; |
|---|
| 824 |             memset(ca, 0, sizeof(*ca)); |
|---|
| 825 | Â Â Â Â Â Â Â Â Â Â Â Â ca->cid =Â -2; |
|---|
| 826 | Â Â Â Â Â Â Â Â } |
|---|
| 827 | Â Â Â Â } |
|---|
| 828 | |
|---|
| 829 |     if (!ca) |
|---|
| 830 |         return 0; |
|---|
| 831 | |
|---|
| 832 | |
|---|
| 833 | Â Â Â Â /* update the call information */ |
|---|
| 834 | |
|---|
| 835 |     if (!ca->localrefer) |
|---|
| 836 | Â Â Â Â { |
|---|
| 837 | Â Â Â Â Â Â Â Â ca->cid =Â je->cid; |
|---|
| 838 | Â Â Â Â Â Â Â Â ca->did =Â je->did; |
|---|
| 839 | Â Â Â Â Â Â Â Â ca->tid =Â je->tid; |
|---|
| 840 | Â Â Â Â } |
|---|
| 841 | |
|---|
| 842 |     if (je->response) |
|---|
| 843 | Â Â Â Â { |
|---|
| 844 |         osip_message_header_get_byname(je->response, "Accept-Contact", 0, &hdr); |
|---|
| 845 |         if (hdr && !strcmp(hdr->hvalue, "*;+g.oma.sip-im")) |
|---|
| 846 | Â Â Â Â Â Â Â Â Â Â Â Â ca->nego_mflags =Â PH_STREAM_DATA; |
|---|
| 847 | Â Â Â Â } |
|---|
| 848 | |
|---|
| 849 |     if (creatit) |
|---|
| 850 | Â Â Â Â { |
|---|
| 851 |         if (osip_list_size(&ca->audio_payloads) == 0) { |
|---|
| 852 | Â Â Â Â Â Â Â Â Â Â Â Â osip_list_init(&ca->audio_payloads); |
|---|
| 853 |             osip_list_clone(&ph_audio_payloads, &ca->audio_payloads, sdp_payload_clone); |
|---|
| 854 | Â Â Â Â Â Â Â Â } |
|---|
| 855 |         if (osip_list_size(&ca->video_payloads) == 0) { |
|---|
| 856 | Â Â Â Â Â Â Â Â Â Â Â Â osip_list_init(&ca->video_payloads); |
|---|
| 857 |             osip_list_clone(&ph_video_payloads, &ca->video_payloads, sdp_payload_clone); |
|---|
| 858 | Â Â Â Â Â Â Â Â } |
|---|
| 859 | Â Â Â Â Â Â Â Â osip_list_init(&ca->result_audio_payloads); |
|---|
| 860 | Â Â Â Â Â Â Â Â osip_list_init(&ca->result_video_payloads); |
|---|
| 861 | |
|---|
| 862 |         if (je->request && MSG_IS_INVITE(je->request) && !ca->remote_sdp && !ca->state == PH_CALLER) |
|---|
| 863 | Â Â Â Â Â Â Â Â { |
|---|
| 864 |             char *sdp = ph_req_get_body(je->request); |
|---|
| 865 | |
|---|
| 866 |             if (sdp) |
|---|
| 867 | Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 868 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â sdp_message_init(&ca->remote_sdp); |
|---|
| 869 |                 sdp_message_parse(ca->remote_sdp, sdp); |
|---|
| 870 |                 if (sdp_message_m_attr_has_type(ca->remote_sdp, "audio")) |
|---|
| 871 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ca->nego_mflags |=Â PH_STREAM_AUDIO; |
|---|
| 872 |                 if (sdp_message_m_attr_has_type(ca->remote_sdp, "video")) |
|---|
| 873 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ca->nego_mflags |=Â PH_STREAM_VIDEO; |
|---|
| 874 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â osip_free(sdp); |
|---|
| 875 | Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 876 | Â Â Â Â Â Â Â Â } |
|---|
| 877 | |
|---|
| 878 |         if (je->response && MSG_IS_INVITE(je->response) && !ca->remote_sdp) |
|---|
| 879 | Â Â Â Â Â Â Â Â { |
|---|
| 880 |             char *sdp = ph_req_get_body(je->response); |
|---|
| 881 | |
|---|
| 882 |             if (sdp) |
|---|
| 883 | Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 884 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â sdp_message_init(&ca->remote_sdp); |
|---|
| 885 |                 sdp_message_parse(ca->remote_sdp, sdp); |
|---|
| 886 |                 if (sdp_message_m_attr_has_type(ca->remote_sdp, "audio")) |
|---|
| 887 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ca->nego_mflags |=Â PH_STREAM_AUDIO; |
|---|
| 888 |                 if (sdp_message_m_attr_has_type(ca->remote_sdp, "video")) |
|---|
| 889 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ca->nego_mflags |=Â PH_STREAM_VIDEO; |
|---|
| 890 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â osip_free(sdp); |
|---|
| 891 | Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 892 | Â Â Â Â Â Â Â Â } |
|---|
| 893 | Â Â Â Â } |
|---|
| 894 |     return ca; |
|---|
| 895 | } |
|---|
| 896 | |
|---|
| 897 | static void |
|---|
| 898 | ph_free_stream(struct ph_stream_params *sp) |
|---|
| 899 | { |
|---|
| 900 |     int i; |
|---|
| 901 | |
|---|
| 902 |     if (sp->streamtype) |
|---|
| 903 | Â Â Â Â Â Â Â Â osip_free((void*)sp->streamtype); |
|---|
| 904 |     if (sp->payloads) |
|---|
| 905 | Â Â Â Â Â Â Â Â osip_free((void*)sp->payloads); |
|---|
| 906 |     if (sp->streamaddr) |
|---|
| 907 | Â Â Â Â Â Â Â Â osip_free((void*)sp->streamaddr); |
|---|
| 908 | |
|---|
| 909 | Â Â Â Â for(i =Â 0;Â (i <Â PH_STREAM_MAX_ATTRS)Â &&Â sp->attrs[i];Â i++) |
|---|
| 910 | Â Â Â Â Â Â Â Â osip_free((void*)sp->attrs[i]); |
|---|
| 911 | Â Â Â Â osip_free(sp); |
|---|
| 912 | } |
|---|
| 913 | |
|---|
| 914 | |
|---|
| 915 | static void |
|---|
| 916 | ph_copy_stream(struct ph_stream_params *dp, const struct ph_stream_params *sp) |
|---|
| 917 | { |
|---|
| 918 |     int i; |
|---|
| 919 | |
|---|
| 920 | Â Â Â Â *dp =Â *sp; |
|---|
| 921 |     if (dp->streamtype) |
|---|
| 922 | Â Â Â Â Â Â Â Â dp->streamtype =Â strdup(dp->streamtype); |
|---|
| 923 |     if (dp->payloads) |
|---|
| 924 | Â Â Â Â Â Â Â Â dp->payloads =Â strdup(dp->payloads); |
|---|
| 925 |     if (dp->streamaddr) |
|---|
| 926 | Â Â Â Â Â Â Â Â dp->streamaddr =Â strdup(dp->streamaddr); |
|---|
| 927 | |
|---|
| 928 | Â Â Â Â for(i =Â 0;Â (i <Â PH_STREAM_MAX_ATTRS)Â &&Â dp->attrs[i];Â i++) |
|---|
| 929 | Â Â Â Â Â Â Â Â dp->attrs[i]Â =Â strdup(dp->attrs[i]); |
|---|
| 930 | |
|---|
| 931 | } |
|---|
| 932 | |
|---|
| 933 | static void |
|---|
| 934 | ph_deep_copy_streams(struct ph_stream_params **dp, struct ph_stream_params **sp) |
|---|
| 935 | { |
|---|
| 936 |     int i; |
|---|
| 937 | |
|---|
| 938 | Â Â Â Â for(Â i =Â 0;Â i <Â PH_MAX_STREAMS &&Â sp[i];Â i++) |
|---|
| 939 | Â Â Â Â { |
|---|
| 940 | Â Â Â Â Â Â Â Â dp[i]Â =Â malloc(sizeof(*sp[i])); |
|---|
| 941 |         ph_copy_stream(dp[i], sp[i]); |
|---|
| 942 | Â Â Â Â } |
|---|
| 943 | |
|---|
| 944 |     if (i < PH_MAX_STREAMS) |
|---|
| 945 | Â Â Â Â Â Â Â Â dp[i]Â =Â 0; |
|---|
| 946 | } |
|---|
| 947 | |
|---|
| 948 | |
|---|
| 949 | static void |
|---|
| 950 | ph_free_all_streams(struct ph_stream_params *sp[]) |
|---|
| 951 | { |
|---|
| 952 |     int i; |
|---|
| 953 | |
|---|
| 954 | Â Â Â Â for(Â i =Â 0;Â i <Â PH_MAX_STREAMS &&Â sp[i];Â i++) |
|---|
| 955 | Â Â Â Â { |
|---|
| 956 | Â Â Â Â Â Â Â Â ph_free_stream(sp[i]); |
|---|
| 957 | Â Â Â Â } |
|---|
| 958 | } |
|---|
| 959 | |
|---|
| 960 | static int ph_call_hasaudio(phcall_t *ca) |
|---|
| 961 | { |
|---|
| 962 |     if (ca->mses && (ca->mses->activestreams & (1 << PH_MSTREAM_AUDIO1))) |
|---|
| 963 |         return 1; |
|---|
| 964 |     return 0; |
|---|
| 965 | } |
|---|
| 966 | |
|---|
| 967 | static int ph_call_hasvideo(phcall_t *ca) |
|---|
| 968 | { |
|---|
| 969 |     if (ca->mses && (ca->mses->activestreams & (1 << PH_MSTREAM_VIDEO1))) |
|---|
| 970 |         return 1; |
|---|
| 971 |     return 0; |
|---|
| 972 | } |
|---|
| 973 | |
|---|
| 974 | static int ph_call_stream_alive(phcall_t *ca) |
|---|
| 975 | { |
|---|
| 976 |     if (!ph_call_hasaudio(ca) && !ph_call_hasvideo(ca)) |
|---|
| 977 |         return 0; |
|---|
| 978 |     if (phcfg.stream_timeout <= 0) |
|---|
| 979 |         return 1; |
|---|
| 980 |     return ph_msession_is_stream_alive(ca->mses, phcfg.stream_timeout); |
|---|
| 981 | } |
|---|
| 982 | |
|---|
| 983 | |
|---|
| 984 | static struct ph_stream_params * |
|---|
| 985 | ph_find_stream(struct ph_stream_params **streams, const char *strtype, int maxstrs); |
|---|
| 986 | |
|---|
| 987 | void ph_release_call(phcall_t *ca) |
|---|
| 988 | { |
|---|
| 989 | |
|---|
| 990 | Â Â Â Â DBG_SIP_NEGO("SIP_NEGO: ph_release_call\n"); |
|---|
| 991 | |
|---|
| 992 |     if (ph_call_hasaudio(ca) || ph_call_hasvideo(ca)) |
|---|
| 993 | Â Â Â Â { |
|---|
| 994 | Â Â Â Â Â Â Â Â ph_call_media_stop(ca); |
|---|
| 995 | Â Â Â Â } |
|---|
| 996 | |
|---|
| 997 | |
|---|
| 998 |     if (ca->audiodev_in != phcfg.audio_dev_in) |
|---|
| 999 |         if (ca->audiodev_in) |
|---|
| 1000 | Â Â Â Â Â Â Â Â Â Â Â Â osip_free(ca->audiodev_in); |
|---|
| 1001 | Â Â Â Â |
|---|
| 1002 |     if (ca->audiodev_out != phcfg.audio_dev_out) |
|---|
| 1003 |         if (ca->audiodev_out) |
|---|
| 1004 | Â Â Â Â Â Â Â Â Â Â Â Â osip_free(ca->audiodev_out); |
|---|
| 1005 | |
|---|
| 1006 | Â Â Â Â ph_free_all_streams(ca->streams); |
|---|
| 1007 |     if (ca->sdpctx) |
|---|
| 1008 | Â Â Â Â Â Â Â Â sdp_context_free(ca->sdpctx); |
|---|
| 1009 | |
|---|
| 1010 |     osip_list_special_free(&ca->audio_payloads, sdp_payload_free); |
|---|
| 1011 |     osip_list_special_free(&ca->result_audio_payloads, sdp_payload_free); |
|---|
| 1012 |     osip_list_special_free(&ca->result_video_payloads, sdp_payload_free); |
|---|
| 1013 | |
|---|
| 1014 |     osip_list_special_free(&ca->video_payloads, sdp_payload_free); |
|---|
| 1015 | |
|---|
| 1016 | Â Â Â Â ph_release_stream_ports(ca); |
|---|
| 1017 | |
|---|
| 1018 |     memset(ca, 0, sizeof(phcall_t)); |
|---|
| 1019 | Â Â Â Â ca->cid =Â -1; |
|---|
| 1020 | } |
|---|
| 1021 | |
|---|
| 1022 | int ph_has_active_calls() |
|---|
| 1023 | { |
|---|
| 1024 | Â Â Â Â phcall_t *ca; |
|---|
| 1025 |     int count = 0; |
|---|
| 1026 | |
|---|
| 1027 | Â Â Â Â for(ca =Â ph_calls;Â ca <Â &ph_calls[PH_MAX_CALLS];Â ca++) |
|---|
| 1028 | Â Â Â Â { |
|---|
| 1029 |         if (ca->cid != -1 && (ph_call_hasaudio(ca) || ph_call_hasvideo(ca)) ) |
|---|
| 1030 | Â Â Â Â Â Â Â Â { |
|---|
| 1031 |             if (!ca->remotehold && !ca->localhold) |
|---|
| 1032 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â count++; |
|---|
| 1033 | Â Â Â Â Â Â Â Â } |
|---|
| 1034 | Â Â Â Â } |
|---|
| 1035 | |
|---|
| 1036 |     return count; |
|---|
| 1037 | } |
|---|
| 1038 | |
|---|
| 1039 | void ph_stream_ended(void *ctx, int event) |
|---|
| 1040 | { |
|---|
| 1041 | Â Â Â Â phcall_t *ca =Â (phcall_t *)ctx; |
|---|
| 1042 | |
|---|
| 1043 | Â Â Â Â ca->closereq =Â 1; |
|---|
| 1044 | } |
|---|
| 1045 | |
|---|
| 1046 | void ph_wegot_dtmf(void *ctx, int dtmfEvent) |
|---|
| 1047 | { |
|---|
| 1048 | Â Â Â Â phCallStateInfo_t info; |
|---|
| 1049 | Â Â Â Â phcall_t *ca =Â (phcall_t *)ctx; |
|---|
| 1050 | |
|---|
| 1051 | Â Â Â Â clear(info); |
|---|
| 1052 | |
|---|
| 1053 | Â Â Â Â info.event =Â phDTMF; |
|---|
| 1054 | Â Â Â Â info.dtmfDigit =Â dtmfEvent; |
|---|
| 1055 | Â Â Â Â info.vlid =Â ca->vlid; |
|---|
| 1056 |     phcb->callProgress(ca->cid, &info); |
|---|
| 1057 | |
|---|
| 1058 | } |
|---|
| 1059 | |
|---|
| 1060 | void ph_qos_info_cbk(void *ctx, void * info) |
|---|
| 1061 | { |
|---|
| 1062 | Â Â Â Â phcall_t *ca =Â (phcall_t *)ctx; |
|---|
| 1063 |     phcb->qosEvent(ca->cid, (phQosInfo_t*)info); |
|---|
| 1064 | } |
|---|
| 1065 | |
|---|
| 1066 | void ph_frame_display_cbk(void *ctx, void *event) |
|---|
| 1067 | { |
|---|
| 1068 | Â Â Â Â phcall_t *ca =Â (phcall_t *)Â ctx; |
|---|
| 1069 | |
|---|
| 1070 |     phcb->onFrameReady(ca->cid, event); |
|---|
| 1071 | } |
|---|
| 1072 | |
|---|
| 1073 | int ph_same_str(const char *str1, const char *str2) |
|---|
| 1074 | { |
|---|
| 1075 |     if (str1 == 0) |
|---|
| 1076 |         return str2 == 0; |
|---|
| 1077 | |
|---|
| 1078 |     if (str2 == 0) |
|---|
| 1079 |         return str1 == 0; |
|---|
| 1080 | |
|---|
| 1081 |     return (0 == strcasecmp(str1, str2)); |
|---|
| 1082 | } |
|---|
| 1083 | |
|---|
| 1084 | int ph_same_uri(const char *uristr1, const char *uristr2) |
|---|
| 1085 | { |
|---|
| 1086 |     osip_contact_t *uri1, *uri2; |
|---|
| 1087 |     int ret; |
|---|
| 1088 | |
|---|
| 1089 | Â Â Â Â osip_contact_init(&uri1); |
|---|
| 1090 | Â Â Â Â osip_contact_init(&uri2); |
|---|
| 1091 | |
|---|
| 1092 |     osip_contact_parse(uri1, uristr1); |
|---|
| 1093 |     osip_contact_parse(uri2, uristr2); |
|---|
| 1094 | |
|---|
| 1095 | Â Â Â Â /* if we've got and invalid URI return TRUE */ |
|---|
| 1096 |     if (!uri1 || !uri2 || !uri1->url || !uri2->url) |
|---|
| 1097 | Â Â Â Â Â Â Â Â ret =Â 1; |
|---|
| 1098 | Â Â Â Â else |
|---|
| 1099 |         ret = ph_same_str(uri1->url->username, uri2->url->username) && |
|---|
| 1100 |         ph_same_str(uri1->url->host, uri2->url->host) && |
|---|
| 1101 |         ph_same_str(uri1->url->port, uri2->url->port); |
|---|
| 1102 | |
|---|
| 1103 | Â Â Â Â osip_contact_free(uri1); |
|---|
| 1104 | Â Â Â Â osip_contact_free(uri2); |
|---|
| 1105 | |
|---|
| 1106 |     return ret; |
|---|
| 1107 | } |
|---|
| 1108 | |
|---|
| 1109 | ph_prepare_stream_ports(phcall_t *ca) |
|---|
| 1110 | { |
|---|
| 1111 |      struct tunnel_info *tun; |
|---|
| 1112 | Â Â Â Â Â ca->pub_sdp_audio_port =Â ca->loc_sdp_audio_port; |
|---|
| 1113 | Â Â Â Â Â ca->pub_sdp_audio_rtcp_port =Â ca->loc_sdp_audio_rtcp_port; |
|---|
| 1114 | Â Â Â Â Â ca->pub_sdp_video_port =Â ca->loc_sdp_video_port; |
|---|
| 1115 | Â Â Â Â Â ca->pub_sdp_video_rtcp_port =Â ca->loc_sdp_video_rtcp_port; |
|---|
| 1116 | |
|---|
| 1117 | #ifdef ENABLE_SOCKS |
|---|
| 1118 |      if (phcfg.use_tunnel & PH_RTP_TUNNEL_USE) { |
|---|
| 1119 |          tun = ph_select_tunnel(rtp_tunnel_set, rtp_tunnel_count); |
|---|
| 1120 |          ca->audio_rtptr = ph_create_rtp_tunnel(tun, ca->remote_sdp_audio_ip, ca->remote_sdp_audio_port); |
|---|
| 1121 |          ca->audio_rtcptr = ph_create_rtp_tunnel(tun, ca->remote_sdp_audio_ip, ca->remote_sdp_audio_rtcp_port); |
|---|
| 1122 | |
|---|
| 1123 | #ifdef PHAPI_VIDEO_SUPPORT |
|---|
| 1124 |          if (_is_video_enabled(ca->nego_mflags)) { |
|---|
| 1125 |              ca->video_rtptr = ph_create_rtp_tunnel(tun, ca->remote_sdp_video_ip, ca->remote_sdp_video_port); |
|---|
| 1126 |              ca->video_rtcptr = ph_create_rtp_tunnel(tun, ca->remote_sdp_video_ip, ca->remote_sdp_video_rtcp_port); |
|---|
| 1127 | Â Â Â Â Â Â Â Â Â } |
|---|
| 1128 | #endif |
|---|
| 1129 | Â Â Â Â Â } |
|---|
| 1130 | #endif |
|---|
| 1131 | |
|---|
| 1132 | #ifdef USE_UPNP |
|---|
| 1133 |      if (ph_upnp_devlist) { |
|---|
| 1134 |          struct vline* vl = vlid2vline(ca->vlid); |
|---|
| 1135 |          char localip[16]; |
|---|
| 1136 |          const char* udp = "UDP"; |
|---|
| 1137 | |
|---|
| 1138 |          if (!vl) |
|---|
| 1139 | Â Â Â Â Â Â Â Â Â Â Â Â Â return; |
|---|
| 1140 | |
|---|
| 1141 |          eXosip_guess_localip(AF_INET, local_ip, 16); |
|---|
| 1142 | |
|---|
| 1143 | |
|---|
| 1144 |          if (_is_audio_enabled(ca->nego_mstreams)) { |
|---|
| 1145 |              ph_upnp_redir_port(localip, ca->loc_sdp_audio_port, &ca->pub_sdp_audio_port, udp); |
|---|
| 1146 |              if (!(vl->mobility & PH_NORTCP_ATTR)) |
|---|
| 1147 |                  ph_upnp_redir_port(localip, ca->loc_sdp_audio_rtcp_port, &ca->pub_sdp_audio_rtcp_port, udp); |
|---|
| 1148 | Â Â Â Â Â Â Â Â Â } |
|---|
| 1149 | #ifdef PHAPI_VIDEO_SUPPORT |
|---|
| 1150 |          if (_is_video_enabled(ca->nego_mstreams)) { |
|---|
| 1151 |              ph_upnp_redir_port(localip, ca->loc_sdp_video_port, &ca->pub_sdp_video_port, udp); |
|---|
| 1152 |              if (!(vl->mobility & PH_NORTCP_ATTR)) |
|---|
| 1153 |                  ph_upnp_redir_port(localip, ca->loc_sdp_video_rtcp_port, &ca->pub_sdp_video_rtcp_port, udp); |
|---|
| 1154 | Â Â Â Â Â Â Â Â Â } |
|---|
| 1155 | #endif |
|---|
| 1156 | Â Â Â Â Â } |
|---|
| 1157 | #endif |
|---|
| 1158 | } |
|---|
| 1159 | static void |
|---|
| 1160 | ph_release_stream_ports(phcall_t *ca) |
|---|
| 1161 | { |
|---|
| 1162 | #ifdef USE_UPNP |
|---|
| 1163 |     const char* udp = "UDP"; |
|---|
| 1164 |      if (ph_upnp_devlist) { |
|---|
| 1165 |          struct vline* vl = vlid2vline(ca->vlid); |
|---|
| 1166 | |
|---|
| 1167 |          if (_is_audio_enabled(ca->nego_mstreams)) { |
|---|
| 1168 |              ph_upnp_release_port(ca->pub_sdp_audio_port, udp); |
|---|
| 1169 |              if (!(vl->mobility & PH_NORTCP_ATTR)) |
|---|
| 1170 |                  ph_upnp_relase_port(ca->pub_sdp_audio_rtcp_port, udp); |
|---|
| 1171 | Â Â Â Â Â Â Â Â Â } |
|---|
| 1172 | #ifdef PHAPI_VIDEO_SUPPORT |
|---|
| 1173 |          if (_is_video_enabled(ca->nego_mstreams)) { |
|---|
| 1174 |              ph_upnp_release_port(ca->pub_sdp_video_port, udp); |
|---|
| 1175 |              if (!(vl->mobility & PH_NORTCP_ATTR)) |
|---|
| 1176 |                  ph_upnp_redir_port(ca->pub_sdp_video_rtcp_port, udp); |
|---|
| 1177 | Â Â Â Â Â Â Â Â Â } |
|---|
| 1178 | #endif |
|---|
| 1179 | Â Â Â Â Â } |
|---|
| 1180 | #endif |
|---|
| 1181 | } |
|---|
| 1182 | |
|---|
| 1183 | static int |
|---|
| 1184 | ph_req_set_body(osip_message_t *msg, const char *body, const char *mime) |
|---|
| 1185 | { |
|---|
| 1186 |     char clen[10]; |
|---|
| 1187 | |
|---|
| 1188 |     snprintf(clen, 10, "%li", strlen(body)); |
|---|
| 1189 |     if (mime) |
|---|
| 1190 |         osip_message_set_content_type(msg, mime); |
|---|
| 1191 |     osip_message_set_body(msg, body, strlen(body)); |
|---|
| 1192 |     osip_message_set_content_length(msg, clen); |
|---|
| 1193 | |
|---|
| 1194 |     return 0; |
|---|
| 1195 | } |
|---|
| 1196 | |
|---|
| 1197 | static sdp_payload_t * |
|---|
| 1198 | ph_call_support_payload(const struct osip_list *codec_list, const sdp_payload_t *payload) |
|---|
| 1199 | { |
|---|
| 1200 | Â Â Â Â sdp_payload_t *cur_payload; |
|---|
| 1201 | |
|---|
| 1202 |     int pos = 0; |
|---|
| 1203 | |
|---|
| 1204 |     while (!osip_list_eol(codec_list, pos)) |
|---|
| 1205 | Â Â Â Â { |
|---|
| 1206 |         cur_payload = (sdp_payload_t *) osip_list_get (codec_list, pos); |
|---|
| 1207 | |
|---|
| 1208 |         if (sdp_equal_payload(cur_payload, payload) == 0) |
|---|
| 1209 | Â Â Â Â Â Â Â Â { |
|---|
| 1210 |             return cur_payload; |
|---|
| 1211 | Â Â Â Â Â Â Â Â } |
|---|
| 1212 | Â Â Â Â Â Â Â Â pos++; |
|---|
| 1213 | Â Â Â Â } |
|---|
| 1214 |     return NULL; |
|---|
| 1215 | } |
|---|
| 1216 | |
|---|
| 1217 | int ph_accept_audio_offer(sdp_context_t *ctx, sdp_payload_t *payload) |
|---|
| 1218 | { |
|---|
| 1219 | Â Â Â Â phcall_t *ca =(phcall_t*)sdp_context_get_user_pointer(ctx); |
|---|
| 1220 |     struct ph_stream_params *si; |
|---|
| 1221 |     sdp_payload_t *new_payload, *ca_payload; |
|---|
| 1222 |     struct vline *vl; |
|---|
| 1223 | |
|---|
| 1224 |     if (!_is_audio_enabled(ca->user_mflags) || |
|---|
| 1225 |             !(ca_payload = ph_call_support_payload(&ca->audio_payloads, payload))) |
|---|
| 1226 | Â Â Â Â { |
|---|
| 1227 | Â Â Â Â Â Â Â Â DBG_CODEC_LOOKUP("Refusing audio codec %i (%s)",payload->pt,payload->a_rtpmap); |
|---|
| 1228 |         return -1; |
|---|
| 1229 | Â Â Â Â } |
|---|
| 1230 | |
|---|
| 1231 |     if (!ca->remote_sdp_audio_port) |
|---|
| 1232 | Â Â Â Â { |
|---|
| 1233 | Â Â Â Â Â Â Â Â ca->remote_sdp_audio_port =Â payload->remoteport; |
|---|
| 1234 | Â Â Â Â Â Â Â Â ca->remote_sdp_audio_rtcp_port =Â payload->remotertcpport; |
|---|
| 1235 |         osip_strncpy(ca->remote_sdp_audio_ip, payload->c_addr, sizeof(ca->remote_sdp_audio_ip)-1); |
|---|
| 1236 | Â Â Â Â } |
|---|
| 1237 | |
|---|
| 1238 | Â Â Â Â //maybe si->streamport is useless |
|---|
| 1239 | Â Â Â Â { |
|---|
| 1240 |         si = ph_find_stream(ca->streams, "audio", 16); |
|---|
| 1241 |         if (!si->streamaddr && si->streamport == -1) |
|---|
| 1242 | Â Â Â Â Â Â Â Â { |
|---|
| 1243 | Â Â Â Â Â Â Â Â Â Â Â Â si->streamport =Â ca->loc_sdp_audio_port; |
|---|
| 1244 | Â Â Â Â Â Â Â Â } |
|---|
| 1245 | Â Â Â Â } |
|---|
| 1246 | |
|---|
| 1247 | Â Â Â Â vl =Â ph_valid_vlid(ca->vlid); |
|---|
| 1248 | |
|---|
| 1249 | Â Â Â Â payload->localport =Â ca->pub_sdp_audio_port; |
|---|
| 1250 | Â Â payload->localrtcpport =Â ca->pub_sdp_audio_rtcp_port; |
|---|
| 1251 | |
|---|
| 1252 |     sdp_payload_clone(payload, (void **)&new_payload); |
|---|
| 1253 |     if (new_payload->a_rtpmap) |
|---|
| 1254 | Â Â Â Â Â Â Â Â new_payload->a_rtpmap =Â osip_strdup(ca_payload->a_rtpmap); |
|---|
| 1255 | |
|---|
| 1256 | Â Â Â Â //we replace external payload number by local number |
|---|
| 1257 | Â Â Â Â //new_payload->pt = ca_payload->pt; |
|---|
| 1258 |     if (vl->mobility & PH_NORTCP_ATTR) |
|---|
| 1259 | Â Â Â Â Â Â Â Â new_payload->localrtcpport =Â 0; |
|---|
| 1260 | |
|---|
| 1261 |     osip_list_add(&ca->result_audio_payloads, new_payload, -1); |
|---|
| 1262 | |
|---|
| 1263 |     return 0; |
|---|
| 1264 | } |
|---|
| 1265 | |
|---|
| 1266 | int ph_accept_video_offer(sdp_context_t *ctx, sdp_payload_t *payload) |
|---|
| 1267 | { |
|---|
| 1268 | Â Â Â Â phcall_t *ca =(phcall_t*)sdp_context_get_user_pointer(ctx); |
|---|
| 1269 |     struct ph_stream_params *si; |
|---|
| 1270 |     sdp_payload_t *new_payload, *ca_payload; |
|---|
| 1271 |     struct vline* vl; |
|---|
| 1272 | |
|---|
| 1273 |     if (!_is_video_enabled(ca->user_mflags)) |
|---|
| 1274 | Â Â Â Â { |
|---|
| 1275 | Â Â Â Â Â Â Â Â DBG_CODEC_LOOKUP("Refusing video codec %i (%s)",payload->pt,payload->a_rtpmap); |
|---|
| 1276 |         return -1; |
|---|
| 1277 | Â Â Â Â } |
|---|
| 1278 | |
|---|
| 1279 |     if (!(ca_payload = ph_call_support_payload(&ca->video_payloads, payload))) |
|---|
| 1280 | Â Â Â Â { |
|---|
| 1281 | Â Â Â Â Â Â Â Â DBG_CODEC_LOOKUP("Refusing video codec %i (%s)",payload->pt,payload->a_rtpmap); |
|---|
| 1282 |         return -1; |
|---|
| 1283 | Â Â Â Â } |
|---|
| 1284 | |
|---|
| 1285 |     if (!ca->remote_sdp_video_port) |
|---|
| 1286 | Â Â Â Â { |
|---|
| 1287 | Â Â Â Â Â Â Â Â ca->remote_sdp_video_port =Â payload->remoteport; |
|---|
| 1288 | Â Â Â Â Â Â Â Â ca->remote_sdp_video_rtcp_port =Â payload->remotertcpport; |
|---|
| 1289 |         osip_strncpy(ca->remote_sdp_video_ip, payload->c_addr, sizeof(ca->remote_sdp_video_ip)-1); |
|---|
| 1290 | Â Â Â Â } |
|---|
| 1291 | |
|---|
| 1292 | Â Â Â Â //maybe si->streamport is useless ? |
|---|
| 1293 | Â Â Â Â { |
|---|
| 1294 |         si = ph_find_stream(ca->streams, "video", 16); |
|---|
| 1295 |         if (!si->streamaddr && si->streamport == -1) |
|---|
| 1296 | Â Â Â Â Â Â Â Â { |
|---|
| 1297 | Â Â Â Â Â Â Â Â Â Â Â Â si->streamport =Â ca->loc_sdp_video_port; |
|---|
| 1298 | Â Â Â Â Â Â Â Â } |
|---|
| 1299 | Â Â Â Â } |
|---|
| 1300 | |
|---|
| 1301 | Â Â Â Â payload->localport =Â ca->pub_sdp_video_port; |
|---|
| 1302 | Â Â Â Â payload->localrtcpport =Â ca->pub_sdp_video_rtcp_port; |
|---|
| 1303 | |
|---|
| 1304 |     sdp_payload_clone(payload, (void**) &new_payload); |
|---|
| 1305 |     if (new_payload->a_rtpmap) |
|---|
| 1306 | Â Â Â Â Â Â Â Â new_payload->a_rtpmap =Â osip_strdup(ca_payload->a_rtpmap); |
|---|
| 1307 | |
|---|
| 1308 | Â Â Â Â //we replace external payload number by local number |
|---|
| 1309 | Â Â Â Â //new_payload->pt = ca_payload->pt; |
|---|
| 1310 | |
|---|
| 1311 | Â Â Â Â vl =Â ph_valid_vlid(ca->vlid); |
|---|
| 1312 |     if (vl->mobility & PH_NORTCP_ATTR) |
|---|
| 1313 | Â Â Â Â Â Â Â Â new_payload->localrtcpport =Â 0; |
|---|
| 1314 | |
|---|
| 1315 |     osip_list_add(&ca->result_video_payloads, new_payload, -1); |
|---|
| 1316 | |
|---|
| 1317 |     return 0; |
|---|
| 1318 | } |
|---|
| 1319 | |
|---|
| 1320 | int ph_set_audio_offer(sdp_context_t *ctx) |
|---|
| 1321 | { |
|---|
| 1322 | Â Â Â Â phcall_t *ca =(phcall_t*)sdp_context_get_user_pointer(ctx); |
|---|
| 1323 | |
|---|
| 1324 | Â Â Â Â RtpProfile *profile =Â &av_profile; |
|---|
| 1325 | Â Â Â Â sdp_payload_t *cur_payload; |
|---|
| 1326 | Â Â Â Â //sdp_payload_t payload; |
|---|
| 1327 |     struct vline* vl; |
|---|
| 1328 | |
|---|
| 1329 |     int pos = 0; |
|---|
| 1330 | |
|---|
| 1331 |     if (!_is_audio_enabled(ca->user_mflags)) |
|---|
| 1332 |         return 0; |
|---|
| 1333 | |
|---|
| 1334 | Â Â Â Â vl =Â ph_valid_vlid(ca->vlid); |
|---|
| 1335 |     while (!osip_list_eol(&ca->audio_payloads, pos)) |
|---|
| 1336 | Â Â Â Â { |
|---|
| 1337 |         cur_payload = (sdp_payload_t *) osip_list_get (&ca->audio_payloads, pos); |
|---|
| 1338 | Â Â Â Â Â Â Â Â cur_payload->localport =Â ca->pub_sdp_audio_port; |
|---|
| 1339 | Â Â Â Â Â Â Â Â cur_payload->localrtcpport =Â ca->pub_sdp_audio_rtcp_port; |
|---|
| 1340 | |
|---|
| 1341 |         if (strncasecmp(cur_payload->a_rtpmap, "iLBC",4)==0) |
|---|
| 1342 | Â Â Â Â Â Â Â Â { |
|---|
| 1343 | Â Â Â Â Â Â Â Â Â Â Â Â /* prefer the 30 ms mode */ |
|---|
| 1344 | Â Â Â Â Â Â Â Â Â Â Â Â cur_payload->a_fmtp=osip_strdup("ptime=30"); |
|---|
| 1345 | Â Â Â Â Â Â Â Â } |
|---|
| 1346 | |
|---|
| 1347 |         if (vl->mobility & PH_NORTCP_ATTR) |
|---|
| 1348 | Â Â Â Â Â Â Â Â Â Â Â Â cur_payload->localrtcpport =Â 0; |
|---|
| 1349 | |
|---|
| 1350 |         sdp_context_add_audio_payload(ctx, cur_payload, phcfg.ptime); |
|---|
| 1351 | Â Â Â Â Â Â Â Â pos++; |
|---|
| 1352 | Â Â Â Â } |
|---|
| 1353 | |
|---|
| 1354 | Â Â Â Â /* add telephone-event payload*/ |
|---|
| 1355 | Â Â Â Â /*Â Â Â sdp_payload_init(&payload); |
|---|
| 1356 | Â Â Â Â payload.pt=rtp_profile_get_payload_number_from_mime(profile,"telephone-event"); |
|---|
| 1357 | Â Â Â Â payload.a_rtpmap="telephone-event/8000"; |
|---|
| 1358 | Â Â Â Â payload.a_fmtp="0-11"; |
|---|
| 1359 | |
|---|
| 1360 | Â Â Â Â sdp_context_add_audio_payload(ctx, &payload, 0);*/ |
|---|
| 1361 | |
|---|
| 1362 |     return 0; |
|---|
| 1363 | } |
|---|
| 1364 | |
|---|
| 1365 | int ph_set_video_offer(sdp_context_t *ctx) |
|---|
| 1366 | { |
|---|
| 1367 | Â Â Â Â phcall_t *ca =(phcall_t*)sdp_context_get_user_pointer(ctx); |
|---|
| 1368 | Â Â Â Â sdp_payload_t *cur_payload; |
|---|
| 1369 |     int pos = 0; |
|---|
| 1370 |     struct vline* vl; |
|---|
| 1371 | |
|---|
| 1372 |     if (!_is_video_enabled(ca->user_mflags)) |
|---|
| 1373 |         return 0; |
|---|
| 1374 | |
|---|
| 1375 | Â Â Â Â vl =Â ph_valid_vlid(ca->vlid); |
|---|
| 1376 |     while (!osip_list_eol(&ca->video_payloads, pos)) |
|---|
| 1377 | Â Â Â Â { |
|---|
| 1378 |         cur_payload = (sdp_payload_t *) osip_list_get (&ca->video_payloads, pos); |
|---|
| 1379 | Â Â Â Â Â Â Â Â cur_payload->localport=ca->pub_sdp_video_port; |
|---|
| 1380 | Â Â Â Â Â Â Â Â cur_payload->localrtcpport =Â ca->pub_sdp_video_rtcp_port; |
|---|
| 1381 |         if (vl->mobility & PH_NORTCP_ATTR) |
|---|
| 1382 | Â Â Â Â Â Â Â Â Â Â Â Â cur_payload->localrtcpport =Â 0; |
|---|
| 1383 | |
|---|
| 1384 |         sdp_context_add_video_payload(ctx, cur_payload); |
|---|
| 1385 | Â Â Â Â Â Â Â Â pos++; |
|---|
| 1386 | Â Â Â Â } |
|---|
| 1387 | |
|---|
| 1388 |     return 0; |
|---|
| 1389 | } |
|---|
| 1390 | |
|---|
| 1391 | |
|---|
| 1392 | int ph_read_audio_answer(sdp_context_t *ctx, sdp_payload_t *payload) |
|---|
| 1393 | { |
|---|
| 1394 | Â Â Â Â phcall_t *ca =(phcall_t*)sdp_context_get_user_pointer(ctx); |
|---|
| 1395 |     sdp_payload_t *new_payload, *ca_payload; |
|---|
| 1396 | |
|---|
| 1397 |     if (!(ca_payload = ph_call_support_payload(&ca->audio_payloads, payload))) |
|---|
| 1398 | Â Â Â Â { |
|---|
| 1399 | Â Â Â Â Â Â Â Â DBG_CODEC_LOOKUP("Refusing audio codec answered %i (%s)",payload->pt,payload->a_rtpmap); |
|---|
| 1400 |         return -1; |
|---|
| 1401 | Â Â Â Â } |
|---|
| 1402 | |
|---|
| 1403 |     sdp_payload_clone(payload, (void**) &new_payload); |
|---|
| 1404 |     if (new_payload->a_rtpmap) |
|---|
| 1405 | Â Â Â Â Â Â Â Â new_payload->a_rtpmap =Â osip_strdup(ca_payload->a_rtpmap); |
|---|
| 1406 | |
|---|
| 1407 | Â Â Â Â //we replace external payload number by local number |
|---|
| 1408 | Â Â Â Â new_payload->pt =Â ca_payload->pt; |
|---|
| 1409 |     osip_list_add(&ca->result_audio_payloads, new_payload, -1); |
|---|
| 1410 | |
|---|
| 1411 |     if (!ca->remote_sdp_audio_port) { |
|---|
| 1412 |         osip_strncpy(ca->remote_sdp_audio_ip, payload->c_addr, sizeof(ca->remote_sdp_audio_ip)-1); |
|---|
| 1413 | Â Â Â Â Â Â Â Â ca->remote_sdp_audio_port =Â payload->remoteport; |
|---|
| 1414 | Â Â Â Â Â Â Â Â ca->remote_sdp_audio_rtcp_port =Â payload->remotertcpport; |
|---|
| 1415 | Â Â Â Â } |
|---|
| 1416 |     return 0; |
|---|
| 1417 | } |
|---|
| 1418 | |
|---|
| 1419 | int ph_read_video_answer(sdp_context_t *ctx, sdp_payload_t *payload) |
|---|
| 1420 | { |
|---|
| 1421 | Â Â Â Â phcall_t *ca =(phcall_t*)sdp_context_get_user_pointer(ctx); |
|---|
| 1422 |     sdp_payload_t *new_payload, *ca_payload; |
|---|
| 1423 | |
|---|
| 1424 |     if (!(ca_payload = ph_call_support_payload(&ca->video_payloads, payload))) |
|---|
| 1425 | Â Â Â Â { |
|---|
| 1426 | Â Â Â Â Â Â Â Â DBG_CODEC_LOOKUP("Refusing video codec answered %i (%s)",payload->pt,payload->a_rtpmap); |
|---|
| 1427 |         return -1; |
|---|
| 1428 | Â Â Â Â } |
|---|
| 1429 | |
|---|
| 1430 |     sdp_payload_clone(payload, (void**) &new_payload); |
|---|
| 1431 |     if (new_payload->a_rtpmap) |
|---|
| 1432 | Â Â Â Â Â Â Â Â new_payload->a_rtpmap =Â osip_strdup(ca_payload->a_rtpmap); |
|---|
| 1433 | |
|---|
| 1434 | Â Â Â Â //we replace external payload number by local number |
|---|
| 1435 | Â Â Â Â new_payload->pt =Â ca_payload->pt; |
|---|
| 1436 | |
|---|
| 1437 |     osip_list_add(&ca->result_video_payloads, new_payload, -1); |
|---|
| 1438 | |
|---|
| 1439 |     if (!ca->remote_sdp_video_port) { |
|---|
| 1440 |         osip_strncpy(ca->remote_sdp_video_ip, payload->c_addr, sizeof(ca->remote_sdp_video_ip)-1); |
|---|
| 1441 | Â Â Â Â Â Â Â Â ca->remote_sdp_video_port =Â payload->remoteport; |
|---|
| 1442 | Â Â Â Â Â Â Â Â ca->remote_sdp_audio_rtcp_port =Â payload->remotertcpport; |
|---|
| 1443 | Â Â Â Â } |
|---|
| 1444 |     return 0; |
|---|
| 1445 | } |
|---|
| 1446 | |
|---|
| 1447 | |
|---|
| 1448 | sdp_handler_t ph_sdp_handler={ |
|---|
| 1449 |         ph_accept_audio_offer,  /*from remote sdp */ |
|---|
| 1450 |         ph_accept_video_offer,  /*from remote sdp */ |
|---|
| 1451 |         ph_set_audio_offer,   /*to local sdp */ |
|---|
| 1452 |         ph_set_video_offer,   /*to local sdp */ |
|---|
| 1453 |         ph_read_audio_answer,  /*from incoming answer */ |
|---|
| 1454 |         ph_read_video_answer  /*from incoming answer */ |
|---|
| 1455 | }; |
|---|
| 1456 | |
|---|
| 1457 | int |
|---|
| 1458 | phGetVersion() |
|---|
| 1459 | { |
|---|
| 1460 |     static char version[] = PHAPI_VERSION_STRING; |
|---|
| 1461 |     char *subv = strstr(version, "."); |
|---|
| 1462 |     int v,s,r; |
|---|
| 1463 | |
|---|
| 1464 | Â Â Â Â v =Â atoi(version); |
|---|
| 1465 | Â Â Â Â s =Â atoi(subv+1); |
|---|
| 1466 |     r = atoi(strstr(subv+1, ".")+1); |
|---|
| 1467 | |
|---|
| 1468 |     return (v << 16) | (s << 8) | r; |
|---|
| 1469 | } |
|---|
| 1470 | #undef stringize |
|---|
| 1471 | |
|---|
| 1472 | const char * |
|---|
| 1473 | phGetRevision() |
|---|
| 1474 | { |
|---|
| 1475 | #ifdef PHAPI_REVISION |
|---|
| 1476 |     return PHAPI_REVISION; |
|---|
| 1477 | #else /*!PHAPI_REVISION */ |
|---|
| 1478 |     return ""; |
|---|
| 1479 | #endif /*!PHAPI_REVISION */ |
|---|
| 1480 | } |
|---|
| 1481 | |
|---|
| 1482 | |
|---|
| 1483 | |
|---|
| 1484 | /* |
|---|
| 1485 | |
|---|
| 1486 | PHAPI_EXPORT int |
|---|
| 1487 | phGetAudioVersion() |
|---|
| 1488 | { |
|---|
| 1489 | Â int fd, ret=-1; |
|---|
| 1490 | #if !defined(WIN32) && !defined(__APPLE__) && !defined(__FreeBSD__) |
|---|
| 1491 | #ifndef EMBED |
|---|
| 1492 | Â fd = open("/dev/dsp", O_RDWR, O_NONBLOCK); |
|---|
| 1493 | #else |
|---|
| 1494 | Â fd = open("/dev/sound/mixer0", O_RDWR, O_NONBLOCK); |
|---|
| 1495 | #endif |
|---|
| 1496 | Â if (fd>=0) |
|---|
| 1497 | |
|---|
| 1498 | Â Â { |
|---|
| 1499 | #if defined(EMBED) |
|---|
| 1500 | Â Â if(0>ioctl(fd, SOUND_MIXER_PRIVATE5, &ret)) |
|---|
| 1501 | #else |
|---|
| 1502 | Â Â Â if(0>ioctl(fd, OSS_GETVERSION, &ret)) |
|---|
| 1503 | #endif |
|---|
| 1504 | Â Â Â Â ret = -1; |
|---|
| 1505 | Â Â close(fd); |
|---|
| 1506 | Â Â } |
|---|
| 1507 | Â return ret; |
|---|
| 1508 | #else |
|---|
| 1509 | Â return 0; |
|---|
| 1510 | #endif |
|---|
| 1511 | } */ |
|---|
| 1512 | |
|---|
| 1513 | PHAPI_EXPORT int |
|---|
| 1514 | phGetNatInfo(char *ntstr, int ntlen, char *fwip, int fwiplen) |
|---|
| 1515 | { |
|---|
| 1516 | Â Â Â Â assert(ntstr!=NULL); |
|---|
| 1517 | Â Â Â Â assert(fwip!=NULL); |
|---|
| 1518 | |
|---|
| 1519 | Â Â Â Â //osip_strncpy(ntstr, ph_get_nat_type(), ntlen-1); |
|---|
| 1520 |     osip_strncpy(fwip, ph_nat_router_addr, fwiplen-1); |
|---|
| 1521 |     return 0; |
|---|
| 1522 | } |
|---|
| 1523 | |
|---|
| 1524 | |
|---|
| 1525 | |
|---|
| 1526 | |
|---|
| 1527 | PHAPI_EXPORT int |
|---|
| 1528 | phSetUaString(const char *uastr) |
|---|
| 1529 | { |
|---|
| 1530 | Â Â Â Â eXosip_set_user_agent(uastr); |
|---|
| 1531 |     return 0; |
|---|
| 1532 | } |
|---|
| 1533 | |
|---|
| 1534 | #define FROM_DISPLAYNAME 1 |
|---|
| 1535 | #define FROM_PORT 2 |
|---|
| 1536 | #define FROM_FORCEPORT 4 |
|---|
| 1537 | #define FROM_NRUSERNAME 8 |
|---|
| 1538 | |
|---|
| 1539 | static void |
|---|
| 1540 | ph_build_from2(char *buf, int n, struct vline *vl, int flags) |
|---|
| 1541 | { |
|---|
| 1542 |     char *un, *s; |
|---|
| 1543 |     char port[32]={0}; |
|---|
| 1544 |     const char *uphone = ""; |
|---|
| 1545 | |
|---|
| 1546 | Â Â Â Â assert(buf !=Â NULL); |
|---|
| 1547 | Â Â Â Â assert(vl !=Â NULL); |
|---|
| 1548 | |
|---|
| 1549 |     if (checkmobility(vl->mobility,PH_LINE_MOBILITY_PHONE)) |
|---|
| 1550 | Â Â Â Â Â Â Â Â uphone=";user=phone"; |
|---|
| 1551 | |
|---|
| 1552 | |
|---|
| 1553 |     if (flags & FROM_NRUSERNAME) |
|---|
| 1554 |         un = nonempty(vl->nrusername) ? vl->nrusername : "unknown"; |
|---|
| 1555 | Â Â Â Â else |
|---|
| 1556 |         un = nonempty(vl->rusername) ? vl->rusername : "unknown"; |
|---|
| 1557 | |
|---|
| 1558 |     s = nonempty(vl->server) ? vl->server : "localhost"; |
|---|
| 1559 |     if ((vl->port >= 0 && vl->port != 5060 && (flags & FROM_PORT)) || (vl->port == 5060 && (flags & FROM_FORCEPORT))) |
|---|
| 1560 |         snprintf(port, sizeof(port), ":%d", vl->port); |
|---|
| 1561 | |
|---|
| 1562 | |
|---|
| 1563 |     if ((flags & FROM_DISPLAYNAME) && nonempty(vl->displayname)) |
|---|
| 1564 | Â Â Â Â { |
|---|
| 1565 |         if (!strchr(vl->displayname, ' ')) |
|---|
| 1566 | Â Â Â Â Â Â Â Â { |
|---|
| 1567 |             snprintf(buf, n, "%s <sip:%s@%s%s%s>", vl->displayname, un, s, port, uphone); |
|---|
| 1568 | Â Â Â Â Â Â Â Â } |
|---|
| 1569 | Â Â Â Â Â Â Â Â else |
|---|
| 1570 | Â Â Â Â Â Â Â Â { |
|---|
| 1571 |             snprintf(buf, n, "\"%s\" <sip:%s@%s%s%s>", vl->displayname, un, s, port, uphone); |
|---|
| 1572 | Â Â Â Â Â Â Â Â } |
|---|
| 1573 | |
|---|
| 1574 | Â Â Â Â } |
|---|
| 1575 | Â Â Â Â else |
|---|
| 1576 | Â Â Â Â { |
|---|
| 1577 |         snprintf(buf, n, "<sip:%s@%s%s%s>", un, s, port, uphone); |
|---|
| 1578 | Â Â Â Â } |
|---|
| 1579 | } |
|---|
| 1580 | |
|---|
| 1581 | |
|---|
| 1582 | static void |
|---|
| 1583 | ph_build_from(char *buf, int n, struct vline *vl) |
|---|
| 1584 | { |
|---|
| 1585 |     ph_build_from2(buf, n, vl, FROM_DISPLAYNAME|FROM_NRUSERNAME); |
|---|
| 1586 | } |
|---|
| 1587 | |
|---|
| 1588 | |
|---|
| 1589 | static void |
|---|
| 1590 | ph_build_contact(char *buf, int n, struct vline *vl) |
|---|
| 1591 | { |
|---|
| 1592 |     char fbuf[512]; |
|---|
| 1593 |     char *ctct; |
|---|
| 1594 | |
|---|
| 1595 |     ph_build_from2(fbuf, 512, vl, 0); |
|---|
| 1596 |     if (!eXosip_build_contact_str(fbuf, 0, &ctct)) |
|---|
| 1597 | Â Â Â Â { |
|---|
| 1598 |         strncpy(buf, ctct, n); |
|---|
| 1599 | Â Â Â Â Â Â Â Â osip_free(ctct); |
|---|
| 1600 | Â Â Â Â Â Â Â Â return; |
|---|
| 1601 | Â Â Â Â } |
|---|
| 1602 |     strncpy(buf, fbuf, n); |
|---|
| 1603 | |
|---|
| 1604 | |
|---|
| 1605 | } |
|---|
| 1606 | |
|---|
| 1607 | |
|---|
| 1608 | static int |
|---|
| 1609 | ph_build_cname(char *buf, int n, struct vline *vl) |
|---|
| 1610 | { |
|---|
| 1611 |     char *un, *s; |
|---|
| 1612 |     int res; |
|---|
| 1613 | Â Â Â Â assert(buf!=NULL); |
|---|
| 1614 | Â Â Â Â assert(vl!=NULL); |
|---|
| 1615 | |
|---|
| 1616 |     un = nonempty(vl->nrusername) ? vl->nrusername : "unknown"; |
|---|
| 1617 |     s = nonempty(vl->server) ? vl->server : "localhost"; |
|---|
| 1618 | |
|---|
| 1619 |     res = snprintf(buf, n, "%s@%s", un, s); |
|---|
| 1620 |     return res < 0 ? 1 : res >= n; |
|---|
| 1621 | } |
|---|
| 1622 | |
|---|
| 1623 | // |
|---|
| 1624 | |
|---|
| 1625 | static int |
|---|
| 1626 | ph_retrieve_from(int did, char **from) |
|---|
| 1627 | { |
|---|
| 1628 | Â Â Â Â osip_dialog_t *dlg =Â eXosip_call_get_osip_dialog(did); |
|---|
| 1629 | |
|---|
| 1630 |     if (did) |
|---|
| 1631 |         return -1; |
|---|
| 1632 | |
|---|
| 1633 |     return osip_from_to_str(dlg->remote_uri, from); |
|---|
| 1634 | |
|---|
| 1635 | } |
|---|
| 1636 | |
|---|
| 1637 | #define optional(x) (x[0] ? x : 0) |
|---|
| 1638 | |
|---|
| 1639 | static void |
|---|
| 1640 | ph_replace_contact(osip_message_t *msg, const char *ctct) |
|---|
| 1641 | { |
|---|
| 1642 |     osip_list_special_free(&msg->contacts, (void (*)(void *)) &osip_contact_free); |
|---|
| 1643 |     osip_message_set_contact(msg, ctct); |
|---|
| 1644 | } |
|---|
| 1645 | |
|---|
| 1646 | int |
|---|
| 1647 | phLinePlaceCall_withCa(int vlid, const char *uri, void *userdata, int rcid, int streams, phcall_t *ca0, const char *adev, const char *audio_addr, const char *video_addr) |
|---|
| 1648 | { |
|---|
| 1649 |     int i; |
|---|
| 1650 | Â Â Â Â osip_message_t *invite; |
|---|
| 1651 | Â Â Â Â phcall_t *ca =Â 0; |
|---|
| 1652 |     char *proxy = 0; |
|---|
| 1653 |     struct vline *vl; |
|---|
| 1654 |     char from[512]; |
|---|
| 1655 |     char local_voice_port[16]; |
|---|
| 1656 |     char local_video_port[16]; |
|---|
| 1657 |     char local_ip[16]; |
|---|
| 1658 | |
|---|
| 1659 | Â Â Â Â DBG_SIP_NEGO("phLinePlaceCall_withCa: a new call has been placed\n"); |
|---|
| 1660 | |
|---|
| 1661 | Â Â Â Â local_video_port[0]Â =Â 0; |
|---|
| 1662 | Â Â Â Â local_voice_port[0]Â =Â 0; |
|---|
| 1663 | |
|---|
| 1664 |     if (!phIsInitialized) |
|---|
| 1665 |         return -PH_NOTINIT; |
|---|
| 1666 | |
|---|
| 1667 |     if (!nonempty(uri)) |
|---|
| 1668 |         return -PH_BADARG; |
|---|
| 1669 | |
|---|
| 1670 | Â Â Â Â vl =Â ph_valid_vlid(vlid); |
|---|
| 1671 | |
|---|
| 1672 |     if (!vl) |
|---|
| 1673 |         return -PH_BADVLID; |
|---|
| 1674 | |
|---|
| 1675 |     if (rcid) |
|---|
| 1676 | Â Â Â Â { |
|---|
| 1677 | Â Â Â Â Â Â Â Â ca =Â ph_locate_call_by_cid(rcid); |
|---|
| 1678 |         if (!ca) |
|---|
| 1679 |             return -PH_BADCID; |
|---|
| 1680 | Â Â Â Â } |
|---|
| 1681 | |
|---|
| 1682 | Â Â Â Â eXosip_lock(); |
|---|
| 1683 |     if (!ca0) |
|---|
| 1684 | Â Â Â Â Â Â Â Â ca0 =Â ph_allocate_call(-2); |
|---|
| 1685 | Â Â Â Â else |
|---|
| 1686 | Â Â Â Â Â Â Â Â ca0->cid =Â -2; |
|---|
| 1687 | Â Â Â Â eXosip_unlock(); |
|---|
| 1688 | |
|---|
| 1689 |     if (!ca0) |
|---|
| 1690 |         return -PH_NORESOURCES; |
|---|
| 1691 | |
|---|
| 1692 |     if (adev) |
|---|
| 1693 | Â Â Â Â Â Â Â Â ca0->audiodev_in =Â osip_strdup(adev); |
|---|
| 1694 |     else |
|---|
| 1695 | Â Â Â Â { |
|---|
| 1696 |         if (phcfg.audio_dev_in) { |
|---|
| 1697 | Â Â Â Â Â Â Â Â Â Â Â Â ca0->audiodev_in =Â osip_strdup(phcfg.audio_dev_in); |
|---|
| 1698 | Â Â Â Â Â Â Â Â } |
|---|
| 1699 |         if (phcfg.audio_dev_out) { |
|---|
| 1700 | Â Â Â Â Â Â Â Â Â Â Â Â ca0->audiodev_out =Â osip_strdup(phcfg.audio_dev_out); |
|---|
| 1701 | Â Â Â Â Â Â Â Â } |
|---|
| 1702 | Â Â Â Â } |
|---|
| 1703 | |
|---|
| 1704 | Â Â Â Â ca0->user_mflags =Â streams |Â (vl->mobility &Â PH_NOEARLY_MEDIA); |
|---|
| 1705 | Â Â Â Â ca0->nego_mflags =Â streams; |
|---|
| 1706 | |
|---|
| 1707 |     if (rcid) |
|---|
| 1708 | Â Â Â Â Â Â Â Â ca0->rcid =Â rcid; |
|---|
| 1709 | |
|---|
| 1710 |     if (audio_addr == NULL) |
|---|
| 1711 | Â Â Â Â { |
|---|
| 1712 |         if (phcfg.local_ip_addr[0] == 0) |
|---|
| 1713 | Â Â Â Â Â Â Â Â { |
|---|
| 1714 |             eXosip_guess_localip(AF_INET, local_ip, 16); |
|---|
| 1715 | Â Â Â Â Â Â Â Â } |
|---|
| 1716 | Â Â Â Â Â Â Â Â else |
|---|
| 1717 | Â Â Â Â Â Â Â Â { |
|---|
| 1718 |             osip_strncpy(local_ip, phcfg.local_ip_addr, sizeof(local_ip)-1); |
|---|
| 1719 | Â Â Â Â Â Â Â Â } |
|---|
| 1720 | Â Â Â Â } |
|---|
| 1721 | Â Â Â Â else |
|---|
| 1722 |         osip_strncpy(local_ip, audio_addr, sizeof(local_ip)-1); |
|---|
| 1723 | |
|---|
| 1724 | Â Â Â Â ca0->vlid =Â ph_vline2vlid(vl); |
|---|
| 1725 | Â Â Â Â ca0->state =Â PH_CALLER; |
|---|
| 1726 | |
|---|
| 1727 |     if (streams & PH_ANONYMOUS_CALL) |
|---|
| 1728 |         strcpy(from, "<sip:anonymous@anonymous.invalid>"); |
|---|
| 1729 | Â Â Â Â else |
|---|
| 1730 |         ph_build_from2(from, sizeof(from), vl, FROM_DISPLAYNAME | FROM_PORT | FROM_NRUSERNAME); |
|---|
| 1731 | |
|---|
| 1732 | Â Â Â Â proxy =Â vl->proxy; |
|---|
| 1733 | |
|---|
| 1734 | Â Â Â Â eXosip_lock(); |
|---|
| 1735 | Â Â Â Â i =Â eXosip_call_build_initial_invite(&invite, |
|---|
| 1736 | Â Â Â Â Â Â Â Â Â Â Â Â uri, |
|---|
| 1737 | Â Â Â Â Â Â Â Â Â Â Â Â from, |
|---|
| 1738 | Â Â Â Â Â Â Â Â Â Â Â Â proxy, |
|---|
| 1739 | Â Â Â Â Â Â Â Â Â Â Â Â "PHAPI CALL"); |
|---|
| 1740 | Â Â Â Â eXosip_unlock(); |
|---|
| 1741 |     if (i!=0) |
|---|
| 1742 |         return -1; |
|---|
| 1743 | |
|---|
| 1744 |     osip_message_set_allow(invite, "INVITE, ACK, BYE, CANCEL, REFER, NOTIFY, SUBSCRIBE, REGISTER"); |
|---|
| 1745 | |
|---|
| 1746 |     ph_apply_customizations(invite, NULL, NULL); |
|---|
| 1747 |     if (streams & PH_ANONYMOUS_CALL) { |
|---|
| 1748 |         osip_message_set_header(invite, "Privacy", "id"); |
|---|
| 1749 |         ph_replace_contact(invite, vl->contact); |
|---|
| 1750 | Â Â Â Â } |
|---|
| 1751 | |
|---|
| 1752 | |
|---|
| 1753 |     if (_is_audio_enabled(streams)) |
|---|
| 1754 | Â Â Â Â { |
|---|
| 1755 | Â Â Â Â Â Â Â Â _get_local_audio_sdp_port(local_voice_port); |
|---|
| 1756 | Â Â Â Â Â Â Â Â ca0->loc_sdp_audio_port =Â atoi(local_voice_port); |
|---|
| 1757 | Â Â Â Â Â Â Â Â ca0->loc_sdp_audio_rtcp_port =Â ca0->loc_sdp_audio_port +Â 1; |
|---|
| 1758 | Â Â Â Â } |
|---|
| 1759 | |
|---|
| 1760 |     if (_is_video_enabled(streams)) |
|---|
| 1761 | Â Â Â Â { |
|---|
| 1762 | Â Â Â Â Â Â Â Â _get_local_video_sdp_port(local_video_port); |
|---|
| 1763 | Â Â Â Â Â Â Â Â ca0->loc_sdp_video_port =Â atoi(local_video_port); |
|---|
| 1764 | Â Â Â Â Â Â Â Â ca0->loc_sdp_video_rtcp_port =Â ca0->loc_sdp_video_port +Â 1; |
|---|
| 1765 | Â Â Â Â } |
|---|
| 1766 | |
|---|
| 1767 | |
|---|
| 1768 |     if (streams == PH_STREAM_DATA) |
|---|
| 1769 | Â Â Â Â { |
|---|
| 1770 |         osip_message_set_header(invite, "Accept-Contact", "*;g.oma.sip-im"); |
|---|
| 1771 | Â Â Â Â Â Â Â Â eXosip_lock(); |
|---|
| 1772 |         i = eXosip_call_send_initial_invite(invite); // userdata, NULL, 0, 0, 0, 0, 0, 0); |
|---|
| 1773 | Â Â Â Â } |
|---|
| 1774 | Â Â Â Â else |
|---|
| 1775 | Â Â Â Â { |
|---|
| 1776 |         if (!ca0->sdpctx) { |
|---|
| 1777 | Â Â Â Â Â Â Â Â Â Â Â Â ph_prepare_stream_ports(ca0); |
|---|
| 1778 |             ca0->sdpctx = sdp_handler_create_context(&ph_sdp_handler, local_ip, vl->nrusername, 0); |
|---|
| 1779 | Â Â Â Â Â Â Â Â Â Â Â Â ca0->cfg =Â &phcfg; |
|---|
| 1780 |             sdp_context_set_user_pointer(ca0->sdpctx, ca0); |
|---|
| 1781 | Â Â Â Â Â Â Â Â } |
|---|
| 1782 | |
|---|
| 1783 | |
|---|
| 1784 | Â Â Â Â Â Â Â Â sdp_context_build_offer(ca0->sdpctx); |
|---|
| 1785 | Â Â Â Â Â Â Â Â ca0->local_sdp =Â ca0->sdpctx->offer; |
|---|
| 1786 | |
|---|
| 1787 |         ph_req_set_body(invite, ca0->sdpctx->offerstr, "application/sdp"); |
|---|
| 1788 | |
|---|
| 1789 | Â Â Â Â Â Â Â Â eXosip_lock(); |
|---|
| 1790 | Â Â Â Â Â Â Â Â i =Â eXosip_call_send_initial_invite(invite); |
|---|
| 1791 | Â Â Â Â } |
|---|
| 1792 | |
|---|
| 1793 |     eXosip_call_set_reference(i, userdata); |
|---|
| 1794 | Â Â Â Â ca0->cid =Â i; |
|---|
| 1795 | Â Â Â Â ca0->state =Â PH_CALLER; |
|---|
| 1796 | Â Â Â Â eXosip_unlock(); |
|---|
| 1797 |     return i; |
|---|
| 1798 | |
|---|
| 1799 | } |
|---|
| 1800 | |
|---|
| 1801 | PHAPI_EXPORT int |
|---|
| 1802 | phLinePlaceCall2(int vlid, const char *uri, void *userdata, int rcid, int streams) |
|---|
| 1803 | { |
|---|
| 1804 |     return phLinePlaceCall_withCa(vlid, uri, userdata, rcid, streams, 0, 0, 0, 0); |
|---|
| 1805 | } |
|---|
| 1806 | |
|---|
| 1807 | |
|---|
| 1808 | PHAPI_EXPORT int |
|---|
| 1809 | phLinePlaceCall3(int vlid, const char *uri, void *userdata, int rcid, int streams, const char *adev) |
|---|
| 1810 | { |
|---|
| 1811 |     return phLinePlaceCall_withCa(vlid, uri, userdata, rcid, streams, 0, adev, 0, 0); |
|---|
| 1812 | } |
|---|
| 1813 | |
|---|
| 1814 | PHAPI_EXPORT int |
|---|
| 1815 | phLinePlaceCall4(int vlid, const char *uri, void *userdata, int rcid, int streams, const char *adev, const char *audio_addr, const char *video_addr) |
|---|
| 1816 | { |
|---|
| 1817 |     return phLinePlaceCall_withCa(vlid, uri, userdata, rcid, streams, 0, adev, audio_addr, video_addr); |
|---|
| 1818 | } |
|---|
| 1819 | |
|---|
| 1820 | PHAPI_EXPORT int |
|---|
| 1821 | phLinePlaceMcCall(int vlid, const char *uri, void *userdata, int streams, const char *adev) |
|---|
| 1822 | { |
|---|
| 1823 |     if (!streams) |
|---|
| 1824 | Â Â Â Â Â Â Â Â streams =Â PH_STREAM_AUDIO; |
|---|
| 1825 | |
|---|
| 1826 |     return phLinePlaceCall_withCa(vlid, uri, userdata, 0, |
|---|
| 1827 |             streams|PH_STREAM_MCRECV, 0, adev, 0, 0); |
|---|
| 1828 | } |
|---|
| 1829 | |
|---|
| 1830 | PHAPI_EXPORT int |
|---|
| 1831 | phLinePlaceCall(int vlid, const char *uri, void *userdata, int rcid) |
|---|
| 1832 | { |
|---|
| 1833 |     return phLinePlaceCall_withCa(vlid, uri, userdata, rcid, PH_STREAM_AUDIO, 0, 0, 0, 0); |
|---|
| 1834 | } |
|---|
| 1835 | |
|---|
| 1836 | PHAPI_EXPORT int |
|---|
| 1837 | phLineSendMessage(int vlid, const char *uri, const char *buff, const char *mime) |
|---|
| 1838 | { |
|---|
| 1839 |     return phLineSendMessage2(vlid, uri, uri, buff, mime, 0); |
|---|
| 1840 | } |
|---|
| 1841 | |
|---|
| 1842 | |
|---|
| 1843 | PHAPI_EXPORT int |
|---|
| 1844 | phLineSendMessage2(int vlid, const char *target, const char *uri, |
|---|
| 1845 |         const char *buff, const char *mime, const char *sipcid) |
|---|
| 1846 | { |
|---|
| 1847 |     int i; |
|---|
| 1848 |     struct vline *vl; |
|---|
| 1849 |     char from[512]; |
|---|
| 1850 | Â Â Â Â osip_message_t *msg; |
|---|
| 1851 | |
|---|
| 1852 | |
|---|
| 1853 | |
|---|
| 1854 |     if (!phIsInitialized) |
|---|
| 1855 |         return -PH_NOTINIT; |
|---|
| 1856 | |
|---|
| 1857 | Â Â Â Â vl =Â ph_valid_vlid(vlid); |
|---|
| 1858 |     if (!vl) { |
|---|
| 1859 |         return -PH_BADVLID; |
|---|
| 1860 | Â Â Â Â } |
|---|
| 1861 | |
|---|
| 1862 |     if ( !nonempty(uri)) { |
|---|
| 1863 |         return -PH_BADARG; |
|---|
| 1864 | Â Â Â Â } |
|---|
| 1865 | |
|---|
| 1866 |     ph_build_from(from, sizeof(from), vl); |
|---|
| 1867 | |
|---|
| 1868 | Â Â Â Â eXosip_lock(); |
|---|
| 1869 |     i = eXosip_message_build_request(&msg, "MESSAGE", (char *)uri, |
|---|
| 1870 |             from, vl->proxy); |
|---|
| 1871 | |
|---|
| 1872 | |
|---|
| 1873 |     ph_req_set_body(msg, buff, mime); |
|---|
| 1874 |     osip_message_set_contact(msg, vl->contact); |
|---|
| 1875 | |
|---|
| 1876 |     if (sipcid) |
|---|
| 1877 |         osip_message_set_call_id(msg, sipcid); |
|---|
| 1878 | |
|---|
| 1879 |     ph_apply_customizations(msg, NULL, NULL); |
|---|
| 1880 | Â Â Â Â i =Â eXosip_message_send_request(msg); |
|---|
| 1881 | |
|---|
| 1882 | Â Â Â Â eXosip_unlock(); |
|---|
| 1883 |     return i > 0 ? i : -PH_BADARG; |
|---|
| 1884 | } |
|---|
| 1885 | |
|---|
| 1886 | PHAPI_EXPORT int |
|---|
| 1887 | phLineSendMessage3(int vlid, const char *target, const char *uri, |
|---|
| 1888 |         const char *buff, const char *mime, int hcount, const struct ph_hdr_val *hdrs) |
|---|
| 1889 | { |
|---|
| 1890 |     int i,j; |
|---|
| 1891 |     struct vline *vl; |
|---|
| 1892 |     char from[512]; |
|---|
| 1893 | Â Â Â Â osip_message_t *msg; |
|---|
| 1894 | |
|---|
| 1895 | |
|---|
| 1896 | |
|---|
| 1897 |     if (!phIsInitialized) |
|---|
| 1898 |         return -PH_NOTINIT; |
|---|
| 1899 | |
|---|
| 1900 | Â Â Â Â vl =Â ph_valid_vlid(vlid); |
|---|
| 1901 |     if (!vl) { |
|---|
| 1902 |         return -PH_BADVLID; |
|---|
| 1903 | Â Â Â Â } |
|---|
| 1904 | |
|---|
| 1905 |     if ( !nonempty(uri)) { |
|---|
| 1906 |         return -PH_BADARG; |
|---|
| 1907 | Â Â Â Â } |
|---|
| 1908 | |
|---|
| 1909 |     ph_build_from(from, sizeof(from), vl); |
|---|
| 1910 | |
|---|
| 1911 | Â Â Â Â eXosip_lock(); |
|---|
| 1912 |     i = eXosip_message_build_request(&msg, "MESSAGE", (char *)uri, |
|---|
| 1913 |             from, vl->proxy); |
|---|
| 1914 | |
|---|
| 1915 | |
|---|
| 1916 |     ph_req_set_body(msg, buff, mime); |
|---|
| 1917 |     osip_message_set_contact(msg, vl->contact); |
|---|
| 1918 | |
|---|
| 1919 |     for (j = 0; j < hcount; j++) |
|---|
| 1920 |         set_custom_header(msg, hdrs[j].hdr, hdrs[j].val); |
|---|
| 1921 | |
|---|
| 1922 |     ph_apply_customizations(msg, NULL, NULL); |
|---|
| 1923 | Â Â Â Â i =Â eXosip_message_send_request(msg); |
|---|
| 1924 | |
|---|
| 1925 | Â Â Â Â eXosip_unlock(); |
|---|
| 1926 |     return i > 0 ? i : -PH_BADARG; |
|---|
| 1927 | } |
|---|
| 1928 | |
|---|
| 1929 | |
|---|
| 1930 | PHAPI_EXPORT int |
|---|
| 1931 | phCallSendMessage(int cid, const char *buff, const char *mime) |
|---|
| 1932 | { |
|---|
| 1933 |     int i; |
|---|
| 1934 | Â Â Â Â phcall_t *ca; |
|---|
| 1935 | Â Â Â Â osip_message_t *msg; |
|---|
| 1936 | |
|---|
| 1937 |     if (!phIsInitialized) |
|---|
| 1938 |         return -PH_NOTINIT; |
|---|
| 1939 | |
|---|
| 1940 | Â Â Â Â ca =Â ph_locate_call_by_cid(cid); |
|---|
| 1941 | |
|---|
| 1942 |     if (!ca) |
|---|
| 1943 |         return -PH_BADCID; |
|---|
| 1944 | |
|---|
| 1945 | Â Â Â Â eXosip_lock(); |
|---|
| 1946 | |
|---|
| 1947 |     i = eXosip_call_build_request(ca->did, "MESSAGE", &msg); |
|---|
| 1948 |     if ( i < 0) { |
|---|
| 1949 | Â Â Â Â Â Â Â Â eXosip_unlock(); |
|---|
| 1950 |         return -PH_BADARG; |
|---|
| 1951 | Â Â Â Â } |
|---|
| 1952 |     ph_req_set_body(msg, buff, mime); |
|---|
| 1953 |     osip_message_set_contact(msg, ph_get_call_contact(ca)); |
|---|
| 1954 |     i = eXosip_call_send_request(ca->did, msg); |
|---|
| 1955 | |
|---|
| 1956 | Â Â Â Â eXosip_unlock(); |
|---|
| 1957 | |
|---|
| 1958 |     return i > 0 ? i : -PH_BADARG; |
|---|
| 1959 | } |
|---|
| 1960 | |
|---|
| 1961 | |
|---|
| 1962 | |
|---|
| 1963 | |
|---|
| 1964 | PHAPI_EXPORT int |
|---|
| 1965 | phSendMessage(const char *from, const char *uri, |
|---|
| 1966 |         const char *buff, const char *mime) |
|---|
| 1967 | { |
|---|
| 1968 |     int i; |
|---|
| 1969 | Â Â Â Â osip_message_t *msg; |
|---|
| 1970 | |
|---|
| 1971 |     if (!phIsInitialized) |
|---|
| 1972 |         return -PH_NOTINIT; |
|---|
| 1973 | |
|---|
| 1974 |     if (!nonempty(from) || !nonempty(uri)) |
|---|
| 1975 |         return -PH_BADARG; |
|---|
| 1976 | |
|---|
| 1977 | Â Â Â Â eXosip_lock(); |
|---|
| 1978 |     i = eXosip_message_build_request(&msg, "MESSAGE", uri, from, ph_get_proxy(from)); |
|---|
| 1979 |     ph_req_set_body(msg, buff, mime); |
|---|
| 1980 |     ph_apply_customizations(msg, NULL, NULL); |
|---|
| 1981 | Â Â Â Â i =Â eXosip_message_send_request(msg); |
|---|
| 1982 | Â Â Â Â eXosip_unlock(); |
|---|
| 1983 |     return i > 0 ? i : -PH_BADARG; |
|---|
| 1984 | } |
|---|
| 1985 | |
|---|
| 1986 | PHAPI_EXPORT int |
|---|
| 1987 | phLineSubscribe(int vlid, const char *uri, const int winfo) |
|---|
| 1988 | { |
|---|
| 1989 |     return phLineSubscribe2(vlid, uri, winfo, NULL, 1, 600); |
|---|
| 1990 | } |
|---|
| 1991 | |
|---|
| 1992 | PHAPI_EXPORT int |
|---|
| 1993 | phLineSubscribe2(int vlid, const char *uri, const int winfo, char *data, int use_proxy, int expire) |
|---|
| 1994 | { |
|---|
| 1995 |     int i; |
|---|
| 1996 |     struct vline *vl; |
|---|
| 1997 |     char from[512]; |
|---|
| 1998 | Â Â Â Â osip_message_t *msg; |
|---|
| 1999 | |
|---|
| 2000 |     if (!phIsInitialized) |
|---|
| 2001 |         return -PH_NOTINIT; |
|---|
| 2002 | |
|---|
| 2003 | Â Â Â Â vl =Â ph_valid_vlid(vlid); |
|---|
| 2004 | |
|---|
| 2005 |     if (!vl) |
|---|
| 2006 |         return -PH_BADVLID; |
|---|
| 2007 | |
|---|
| 2008 |     ph_build_from(from, sizeof(from), vl); |
|---|
| 2009 | |
|---|
| 2010 | |
|---|
| 2011 |     if ( !nonempty(uri)) |
|---|
| 2012 |         return -PH_BADARG; |
|---|
| 2013 | |
|---|
| 2014 | |
|---|
| 2015 | Â Â Â Â eXosip_lock(); |
|---|
| 2016 |     if (use_proxy) |
|---|
| 2017 |         i = eXosip_subscribe_build_initial_request(&msg, uri, from, vl->proxy, ph_get_event_type_str(winfo), expire); |
|---|
| 2018 | Â Â Â Â else |
|---|
| 2019 |         i = eXosip_subscribe_build_initial_request(&msg, uri, from, uri, ph_get_event_type_str(winfo), expire); |
|---|
| 2020 | |
|---|
| 2021 |     if (!i) |
|---|
| 2022 | Â Â Â Â { |
|---|
| 2023 |         if (data) |
|---|
| 2024 | Â Â Â Â Â Â Â Â {Â Â Â Â Â Â Â Â |
|---|
| 2025 | Â Â Â Â Â Â Â Â Â Â Â Â osip_header_t *data_header; |
|---|
| 2026 | |
|---|
| 2027 | Â Â Â Â Â Â Â Â Â Â Â Â osip_header_init(&data_header); |
|---|
| 2028 |             osip_header_set_name(data_header, osip_strdup("X-Addressbook")); |
|---|
| 2029 |             osip_header_set_value(data_header, osip_strdup(data)); |
|---|
| 2030 |             osip_list_add(&msg->headers, data_header, 0); |
|---|
| 2031 | Â Â Â Â Â Â Â Â } |
|---|
| 2032 |         ph_apply_customizations(msg, NULL, NULL); |
|---|
| 2033 | Â Â Â Â Â Â Â Â i =Â eXosip_subscribe_send_initial_request(msg); |
|---|
| 2034 | Â Â Â Â } |
|---|
| 2035 | Â Â Â Â eXosip_unlock(); |
|---|
| 2036 |     return i; |
|---|
| 2037 | } |
|---|
| 2038 | |
|---|
| 2039 | |
|---|
| 2040 | PHAPI_EXPORT int |
|---|
| 2041 | phLineUnsubscribe(int sid, int winfo) |
|---|
| 2042 | { |
|---|
| 2043 |     int i = 0; |
|---|
| 2044 | Â Â Â Â osip_message_t *sub; |
|---|
| 2045 | |
|---|
| 2046 |     if (!phIsInitialized) |
|---|
| 2047 |         return -PH_NOTINIT; |
|---|
| 2048 | |
|---|
| 2049 | Â Â Â Â eXosip_lock(); |
|---|
| 2050 |     if ((i = eXosip_subscribe_build_refresh_request(sid,&sub)) < 0) { |
|---|
| 2051 | Â Â Â Â Â Â Â Â eXosip_unlock(); |
|---|
| 2052 |         return i; |
|---|
| 2053 | Â Â Â Â } |
|---|
| 2054 |     osip_message_set_expires(sub, osip_strdup("0")); |
|---|
| 2055 |     osip_message_set_header(sub, "Event", ph_get_event_type_str(winfo)); |
|---|
| 2056 |     ph_apply_customizations(sub, NULL, NULL); |
|---|
| 2057 |     if ((i = eXosip_subscribe_send_refresh_request(sid,sub)) < 0) { |
|---|
| 2058 | Â Â Â Â Â Â Â Â eXosip_unlock(); |
|---|
| 2059 |         return i; |
|---|
| 2060 | Â Â Â Â } |
|---|
| 2061 | Â Â Â Â eXosip_unlock(); |
|---|
| 2062 |     return 0; |
|---|
| 2063 | } |
|---|
| 2064 | |
|---|
| 2065 | |
|---|
| 2066 | PHAPI_EXPORT int |
|---|
| 2067 | phSubscribe(const char *from, const char *to, const int winfo) |
|---|
| 2068 | { |
|---|
| 2069 |     int sid; |
|---|
| 2070 | Â Â Â Â osip_message_t *msg; |
|---|
| 2071 | |
|---|
| 2072 |     if (!phIsInitialized) |
|---|
| 2073 |         return -PH_NOTINIT; |
|---|
| 2074 | |
|---|
| 2075 |     if (!nonempty(to) || !nonempty(from)) |
|---|
| 2076 |         return -PH_BADARG; |
|---|
| 2077 | |
|---|
| 2078 | Â Â Â Â eXosip_lock(); |
|---|
| 2079 |     sid = eXosip_subscribe_build_initial_request(&msg, to, from, ph_get_proxy(from), ph_get_event_type_str(winfo), 600); |
|---|
| 2080 |     if (!sid) { |
|---|
| 2081 |         ph_apply_customizations(msg, NULL, NULL); |
|---|
| 2082 | Â Â Â Â Â Â Â Â sid =Â eXosip_subscribe_send_initial_request(msg); |
|---|
| 2083 | Â Â Â Â } |
|---|
| 2084 | Â Â Â Â eXosip_unlock(); |
|---|
| 2085 |     return sid; |
|---|
| 2086 | } |
|---|
| 2087 | |
|---|
| 2088 | |
|---|
| 2089 | |
|---|
| 2090 | PHAPI_EXPORT int |
|---|
| 2091 | phLinePublish(int vlid, const char *uri, int winfo, const char * content_type, const char * content) |
|---|
| 2092 | { |
|---|
| 2093 |     return phLinePublish2(vlid, uri, ph_get_event_type_str(winfo), content_type, content, 600); |
|---|
| 2094 | } |
|---|
| 2095 | |
|---|
| 2096 | |
|---|
| 2097 | |
|---|
| 2098 | PHAPI_EXPORT int |
|---|
| 2099 | phLinePublish2(int vlid, const char *uri, const char *evt, const char *ctt, const char *body, int expires) |
|---|
| 2100 | { |
|---|
| 2101 |     int i; |
|---|
| 2102 |     struct vline *vl; |
|---|
| 2103 |     char from[512]; |
|---|
| 2104 |     char expstr[16]; |
|---|
| 2105 | Â Â Â Â osip_message_t *publish; |
|---|
| 2106 | |
|---|
| 2107 |     if (!phIsInitialized) |
|---|
| 2108 |         return -PH_NOTINIT; |
|---|
| 2109 | |
|---|
| 2110 |     if ( !nonempty(uri)) |
|---|
| 2111 |         return -PH_BADARG; |
|---|
| 2112 | |
|---|
| 2113 | Â Â Â Â vl =Â ph_valid_vlid(vlid); |
|---|
| 2114 | |
|---|
| 2115 |     if (!vl) |
|---|
| 2116 |         return -PH_BADVLID; |
|---|
| 2117 | |
|---|
| 2118 |     ph_build_from(from, sizeof(from), vl); |
|---|
| 2119 | |
|---|
| 2120 |     snprintf(expstr, sizeof(expstr), "%d", expires); |
|---|
| 2121 | |
|---|
| 2122 | Â Â Â Â eXosip_lock(); |
|---|
| 2123 |     i = eXosip_build_publish(&publish, uri, from, vl->proxy, evt, expstr, ctt, body); |
|---|
| 2124 |     if (!i) { |
|---|
| 2125 |         ph_apply_customizations(publish, NULL, NULL); |
|---|
| 2126 |         i = eXosip_publish(publish, uri); |
|---|
| 2127 | Â Â Â Â } |
|---|
| 2128 | Â Â Â Â eXosip_unlock(); |
|---|
| 2129 | |
|---|
| 2130 | |
|---|
| 2131 |     if (i) |
|---|
| 2132 |         return -PH_ERROR; |
|---|
| 2133 | |
|---|
| 2134 |     return i; |
|---|
| 2135 | } |
|---|
| 2136 | |
|---|
| 2137 | |
|---|
| 2138 | |
|---|
| 2139 | |
|---|
| 2140 | static const char *ph_get_expires_str() |
|---|
| 2141 | { |
|---|
| 2142 | Â Â Â Â // FIXME: |
|---|
| 2143 |     return "1200"; |
|---|
| 2144 | }Â |
|---|
| 2145 | |
|---|
| 2146 | PHAPI_EXPORT int |
|---|
| 2147 | phPublish(const char *from, const char *to, const int winfo, const char * content_type, const char * content) |
|---|
| 2148 | { |
|---|
| 2149 |     int i; |
|---|
| 2150 | Â Â Â Â osip_message_t *msg; |
|---|
| 2151 | |
|---|
| 2152 |     if (!phIsInitialized) |
|---|
| 2153 |         return -PH_NOTINIT; |
|---|
| 2154 | |
|---|
| 2155 |     if (!nonempty(to) || !nonempty(from) || !nonempty(content_type) || !nonempty(content)) |
|---|
| 2156 |         return -PH_BADARG; |
|---|
| 2157 | |
|---|
| 2158 | |
|---|
| 2159 | Â Â Â Â eXosip_lock(); |
|---|
| 2160 |     i = eXosip_build_publish(&msg, to, from, ph_get_proxy(from), ph_get_event_type_str(winfo), ph_get_expires_str(), content_type, content); |
|---|
| 2161 |     if (!i) { |
|---|
| 2162 |         ph_apply_customizations(msg, NULL, NULL); |
|---|
| 2163 |         i = eXosip_publish(msg, to); |
|---|
| 2164 | Â Â Â Â } |
|---|
| 2165 | |
|---|
| 2166 | Â Â Â Â eXosip_unlock(); |
|---|
| 2167 |     return i; |
|---|
| 2168 | } |
|---|
| 2169 | |
|---|
| 2170 | extern void eXosip_update(); |
|---|
| 2171 | |
|---|
| 2172 | PHAPI_EXPORT void |
|---|
| 2173 | phRefresh() |
|---|
| 2174 | { |
|---|
| 2175 |     if (!phIsInitialized) |
|---|
| 2176 | Â Â Â Â Â Â Â Â return; |
|---|
| 2177 | Â Â Â Â eXosip_lock(); |
|---|
| 2178 | Â Â Â Â eXosip_update(); |
|---|
| 2179 | Â Â Â Â eXosip_unlock(); |
|---|
| 2180 | } |
|---|
| 2181 | |
|---|
| 2182 | |
|---|
| 2183 | PHAPI_EXPORT int |
|---|
| 2184 | phLineSendOptions(int vlid, const char *to) |
|---|
| 2185 | { |
|---|
| 2186 |     int i; |
|---|
| 2187 |     struct vline *vl; |
|---|
| 2188 |     char from[512]; |
|---|
| 2189 | Â Â Â Â osip_message_t *msg; |
|---|
| 2190 | |
|---|
| 2191 |     if (!phIsInitialized) |
|---|
| 2192 |         return -PH_NOTINIT; |
|---|
| 2193 | |
|---|
| 2194 | Â Â Â Â vl =Â ph_valid_vlid(vlid); |
|---|
| 2195 | |
|---|
| 2196 |     if (!vl) |
|---|
| 2197 |         return -PH_BADVLID; |
|---|
| 2198 | |
|---|
| 2199 |     ph_build_from(from, sizeof(from), vl); |
|---|
| 2200 | |
|---|
| 2201 | |
|---|
| 2202 |     if (!nonempty(to)) |
|---|
| 2203 |         return -PH_BADARG; |
|---|
| 2204 | |
|---|
| 2205 | |
|---|
| 2206 | Â Â Â Â eXosip_lock(); |
|---|
| 2207 |     i = eXosip_options_build_request(&msg, to, from, vl->proxy); |
|---|
| 2208 |     if (!i) { |
|---|
| 2209 |         ph_apply_customizations(msg, NULL, NULL); |
|---|
| 2210 | Â Â Â Â Â Â Â Â i =Â eXosip_options_send_request(msg); |
|---|
| 2211 | Â Â Â Â } |
|---|
| 2212 | |
|---|
| 2213 | Â Â Â Â eXosip_unlock(); |
|---|
| 2214 | |
|---|
| 2215 |     if (i && (msg!=0)) |
|---|
| 2216 | Â Â Â Â Â Â Â Â osip_message_free(msg); |
|---|
| 2217 | |
|---|
| 2218 |     return i ? PH_ERROR : i; |
|---|
| 2219 | |
|---|
| 2220 | } |
|---|
| 2221 | |
|---|
| 2222 | |
|---|
| 2223 | |
|---|
| 2224 | PHAPI_EXPORT int |
|---|
| 2225 | phSendOptions(const char *from, const char *uri) |
|---|
| 2226 | { |
|---|
| 2227 |     int i; |
|---|
| 2228 | Â Â Â Â osip_message_t *req =Â 0; |
|---|
| 2229 | |
|---|
| 2230 |     if (!phIsInitialized) |
|---|
| 2231 |         return -PH_NOTINIT; |
|---|
| 2232 | |
|---|
| 2233 |     if (!nonempty(from) || !nonempty(uri)) |
|---|
| 2234 |         return -PH_BADARG; |
|---|
| 2235 | |
|---|
| 2236 | Â Â Â Â eXosip_lock(); |
|---|
| 2237 |     i = eXosip_options_build_request(&req, (char *)uri, (char*) from, ph_get_proxy(from)); |
|---|
| 2238 |     if (!i) { |
|---|
| 2239 |         ph_apply_customizations(req, NULL, NULL); |
|---|
| 2240 | Â Â Â Â Â Â Â Â i =Â eXosip_options_send_request(req); |
|---|
| 2241 | Â Â Â Â } |
|---|
| 2242 | Â Â Â Â eXosip_unlock(); |
|---|
| 2243 | |
|---|
| 2244 |     if (i && (req!=0)) |
|---|
| 2245 | Â Â Â Â Â Â Â Â osip_message_free(req); |
|---|
| 2246 | |
|---|
| 2247 | |
|---|
| 2248 |     return i ? PH_ERROR : i; |
|---|
| 2249 | } |
|---|
| 2250 | |
|---|
| 2251 | |
|---|
| 2252 | PHAPI_EXPORT int |
|---|
| 2253 | phAcceptCall2(int cid, void *userData) |
|---|
| 2254 | { |
|---|
| 2255 |     return phAcceptCall3(cid, userData, PH_STREAM_AUDIO); |
|---|
| 2256 | } |
|---|
| 2257 | |
|---|
| 2258 | PHAPI_EXPORT int |
|---|
| 2259 | phAcceptCall3(int cid, void *userData, int streams) |
|---|
| 2260 | { |
|---|
| 2261 |     return phAcceptCall4(cid, userData, streams, 0, 0); |
|---|
| 2262 | } |
|---|
| 2263 | |
|---|
| 2264 | |
|---|
| 2265 | static int |
|---|
| 2266 | ph_answer_call(int cid, int tid, int status, const char *laport, const char *ctct, |
|---|
| 2267 |         const char *lvport, const char *paport, const char *pvport, |
|---|
| 2268 |         const char *audio_addr, const char *video_addr, const char *uri) |
|---|
| 2269 | { |
|---|
| 2270 |     int i; |
|---|
| 2271 | Â Â Â Â osip_message_t *msg =Â 0; |
|---|
| 2272 | |
|---|
| 2273 | Â Â Â Â phcall_t *ca =Â ph_locate_call_by_cid(cid); |
|---|
| 2274 | |
|---|
| 2275 |     if (!ca) |
|---|
| 2276 |         return -PH_BADCID; |
|---|
| 2277 | |
|---|
| 2278 |     i = eXosip_call_build_answer(tid, status, &msg); |
|---|
| 2279 |     if (!i) { |
|---|
| 2280 |         if (ctct) |
|---|
| 2281 |             osip_message_set_contact(msg, ctct); |
|---|
| 2282 | |
|---|
| 2283 |         i = eXosip_call_send_answer(tid, status, msg); |
|---|
| 2284 | Â Â Â Â } |
|---|
| 2285 | |
|---|
| 2286 |     return i; |
|---|
| 2287 | } |
|---|
| 2288 | |
|---|
| 2289 | |
|---|
| 2290 | PHAPI_EXPORT int |
|---|
| 2291 | phAcceptCall4(int cid, void *userData, int streams, const char *audio_addr, const char *video_addr) |
|---|
| 2292 | { |
|---|
| 2293 |     int i; |
|---|
| 2294 | Â Â Â Â phcall_t *ca; |
|---|
| 2295 |     char local_video_port[16] = "0"; |
|---|
| 2296 |     char local_voice_port[16] = "0"; |
|---|
| 2297 | |
|---|
| 2298 | Â Â Â Â phCallStateInfo_t info; |
|---|
| 2299 | Â Â Â Â osip_message_t *msg =Â 0; |
|---|
| 2300 |     struct vline *vl; |
|---|
| 2301 |     char local_ip[16]; |
|---|
| 2302 |     char *remoteUri = 0; |
|---|
| 2303 | |
|---|
| 2304 | Â Â Â Â DBG_SIP_NEGO("SIP NEGO: phAcceptCall4\n"); |
|---|
| 2305 | |
|---|
| 2306 |     if (!phIsInitialized) |
|---|
| 2307 |         return -PH_NOTINIT; |
|---|
| 2308 | |
|---|
| 2309 | Â Â Â Â ca =Â ph_locate_call_by_cid(cid); |
|---|
| 2310 | |
|---|
| 2311 |     if (!ca) |
|---|
| 2312 |         return -PH_BADCID; |
|---|
| 2313 | |
|---|
| 2314 | Â Â Â Â vl =Â ph_valid_vlid(ca->vlid); |
|---|
| 2315 | |
|---|
| 2316 |     if (!vl) |
|---|
| 2317 |         return -PH_BADVLID; |
|---|
| 2318 | |
|---|
| 2319 |     if (audio_addr == NULL) |
|---|
| 2320 | Â Â Â Â { |
|---|
| 2321 |         if (phcfg.local_ip_addr[0] == 0) |
|---|
| 2322 | Â Â Â Â Â Â Â Â { |
|---|
| 2323 |             eXosip_guess_localip(AF_INET, local_ip, 16); |
|---|
| 2324 | Â Â Â Â Â Â Â Â } |
|---|
| 2325 | Â Â Â Â Â Â Â Â else |
|---|
| 2326 | Â Â Â Â Â Â Â Â { |
|---|
| 2327 |             osip_strncpy(local_ip, phcfg.local_ip_addr, sizeof(local_ip)-1); |
|---|
| 2328 | Â Â Â Â Â Â Â Â } |
|---|
| 2329 | Â Â Â Â } |
|---|
| 2330 | Â Â Â Â else |
|---|
| 2331 |         osip_strncpy(local_ip, audio_addr, sizeof(local_ip)-1); |
|---|
| 2332 | |
|---|
| 2333 | Â Â Â Â ca->user_mflags =Â streams;Â // trace of what the user decided |
|---|
| 2334 | Â Â Â Â ca->nego_mflags =Â ca->user_mflags;Â // current negociated media flags |
|---|
| 2335 | Â Â Â Â ca->state =Â PH_CALLEE_ACCEPTED; |
|---|
| 2336 | |
|---|
| 2337 | Â Â Â Â //listening ports are already set by allocatePorts |
|---|
| 2338 |     if (_is_video_enabled(streams)) |
|---|
| 2339 | Â Â Â Â { |
|---|
| 2340 | Â Â Â Â Â Â Â Â _get_local_video_sdp_port(local_video_port); |
|---|
| 2341 | Â Â Â Â Â Â Â Â ca->loc_sdp_video_port =Â atoi(local_video_port); |
|---|
| 2342 | Â Â Â Â Â Â Â Â ca->loc_sdp_video_rtcp_port =Â ca->loc_sdp_video_port +Â 1; |
|---|
| 2343 | Â Â Â Â } |
|---|
| 2344 | |
|---|
| 2345 |     if (_is_audio_enabled(streams)) |
|---|
| 2346 | Â Â Â Â { |
|---|
| 2347 | Â Â Â Â Â Â Â Â _get_local_audio_sdp_port(local_voice_port); |
|---|
| 2348 | Â Â Â Â Â Â Â Â ca->loc_sdp_audio_port =Â atoi(local_voice_port); |
|---|
| 2349 | Â Â Â Â Â Â Â Â ca->loc_sdp_audio_rtcp_port =Â ca->loc_sdp_audio_port +Â 1; |
|---|
| 2350 | Â Â Â Â } |
|---|
| 2351 | |
|---|
| 2352 | |
|---|
| 2353 | Â Â Â Â eXosip_lock(); |
|---|
| 2354 |     ph_retrieve_from(ca->did, &remoteUri); |
|---|
| 2355 | Â Â Â Â eXosip_unlock(); |
|---|
| 2356 | |
|---|
| 2357 |     if (streams == PH_STREAM_DATA) |
|---|
| 2358 | Â Â Â Â { |
|---|
| 2359 | Â Â Â Â Â Â Â Â eXosip_lock(); |
|---|
| 2360 |         i = ph_answer_call(ca->cid, ca->tid, 200, 0, 0, 0, 0, 0, 0, 0, 0); |
|---|
| 2361 | Â Â Â Â } |
|---|
| 2362 | Â Â Â Â else |
|---|
| 2363 | Â Â Â Â { |
|---|
| 2364 | Â Â Â Â Â Â Â Â eXosip_lock(); |
|---|
| 2365 | |
|---|
| 2366 |         i = eXosip_call_build_answer(ca->tid, 200, &msg); |
|---|
| 2367 |         if (i < 0) |
|---|
| 2368 | Â Â Â Â Â Â Â Â { |
|---|
| 2369 | Â Â Â Â Â Â Â Â Â Â Â Â eXosip_unlock(); |
|---|
| 2370 |             return -1; |
|---|
| 2371 | Â Â Â Â Â Â Â Â } |
|---|
| 2372 | |
|---|
| 2373 |         if (!ca->sdpctx) { |
|---|
| 2374 | Â Â Â Â Â Â Â Â Â Â Â Â ph_prepare_stream_ports(ca); |
|---|
| 2375 |             ca->sdpctx = sdp_handler_create_context(&ph_sdp_handler, local_ip, vl->nrusername, 0); |
|---|
| 2376 | Â Â Â Â Â Â Â Â Â Â Â Â ca->cfg =Â &phcfg; |
|---|
| 2377 |             sdp_context_set_user_pointer(ca->sdpctx, ca); |
|---|
| 2378 | Â Â Â Â Â Â Â Â Â Â Â Â ca->sdpctx->offer =Â ca->remote_sdp; |
|---|
| 2379 | Â Â Â Â Â Â Â Â } |
|---|
| 2380 |         if (sdp_context_build_answer(ca->sdpctx, ca->remote_sdp, phcfg.ptime) == NULL) |
|---|
| 2381 | Â Â Â Â Â Â Â Â { |
|---|
| 2382 |             eXosip_call_send_answer(ca->tid, 606, NULL); //error, no matching payload |
|---|
| 2383 | Â Â Â Â Â Â Â Â Â Â Â Â eXosip_unlock(); |
|---|
| 2384 |             return -1; |
|---|
| 2385 | Â Â Â Â Â Â Â Â } |
|---|
| 2386 | |
|---|
| 2387 | Â Â Â Â Â Â Â Â ca->local_sdp =Â ca->sdpctx->answer; |
|---|
| 2388 |         ph_req_set_body(msg, ca->sdpctx->answerstr, "application/sdp"); |
|---|
| 2389 |         i = eXosip_call_send_answer(ca->tid, 200, msg); |
|---|
| 2390 | Â Â Â Â } |
|---|
| 2391 | |
|---|
| 2392 |     if (i == 0 && streams != PH_STREAM_DATA) |
|---|
| 2393 | Â Â Â Â { |
|---|
| 2394 |         i = ph_call_retrieve_payloads(ca, streams | PH_STREAM_CNG ); |
|---|
| 2395 | Â Â Â Â } |
|---|
| 2396 | |
|---|
| 2397 | Â Â Â Â eXosip_unlock(); |
|---|
| 2398 | |
|---|
| 2399 |     if (!i && streams != PH_STREAM_DATA) |
|---|
| 2400 |         i = ph_call_media_start(ca, NULL, streams, 0); |
|---|
| 2401 | |
|---|
| 2402 |     if (i) |
|---|
| 2403 |         return i; |
|---|
| 2404 | |
|---|
| 2405 | Â Â Â Â clear(info); |
|---|
| 2406 | |
|---|
| 2407 | Â Â Â Â info.remoteUri =Â remoteUri; |
|---|
| 2408 | Â Â Â Â info.event =Â phCALLOK; |
|---|
| 2409 |     phcb->callProgress(cid, &info); |
|---|
| 2410 | |
|---|
| 2411 |     if (remoteUri) |
|---|
| 2412 | Â Â Â Â Â Â Â Â osip_free(remoteUri); |
|---|
| 2413 | |
|---|
| 2414 |     return 0; |
|---|
| 2415 | } |
|---|
| 2416 | |
|---|
| 2417 | PHAPI_EXPORT int |
|---|
| 2418 | phAcceptMcCall(int cid, const char *adev_in, const char *adev_out, const char *audioaddr, int port) |
|---|
| 2419 | { |
|---|
| 2420 | Â Â Â Â phcall_t *ca; |
|---|
| 2421 |     char local_voice_port[16] = "0"; |
|---|
| 2422 |     int streams = PH_STREAM_AUDIO; |
|---|
| 2423 | Â Â Â Â phCallStateInfo_t info; |
|---|
| 2424 |     int i; |
|---|
| 2425 |     char *remoteUri; |
|---|
| 2426 | |
|---|
| 2427 |     if (!phIsInitialized) |
|---|
| 2428 |         return -PH_NOTINIT; |
|---|
| 2429 | |
|---|
| 2430 | Â Â Â Â ca =Â ph_locate_call_by_cid(cid); |
|---|
| 2431 | |
|---|
| 2432 |     if (!ca) |
|---|
| 2433 |         return -PH_BADCID; |
|---|
| 2434 | |
|---|
| 2435 |     snprintf(local_voice_port,16, "%d", port); |
|---|
| 2436 | Â Â Â Â eXosip_lock(); |
|---|
| 2437 | |
|---|
| 2438 |     i = ph_answer_call(ca->cid, ca->did, 200, local_voice_port, ph_get_call_contact(ca), |
|---|
| 2439 | Â Â Â Â Â Â Â Â Â Â Â Â NULL,NULL,NULL, |
|---|
| 2440 |             audioaddr, NULL, 0); |
|---|
| 2441 | |
|---|
| 2442 |     if (i == 0) |
|---|
| 2443 | Â Â Â Â { |
|---|
| 2444 |         char tmp[16]; |
|---|
| 2445 | |
|---|
| 2446 |         i = ph_call_retrieve_payloads(ca, streams); |
|---|
| 2447 | |
|---|
| 2448 | Â Â Â Â Â Â Â Â _get_local_audio_sdp_port(tmp); |
|---|
| 2449 | Â Â Â Â Â Â Â Â ca->loc_sdp_audio_port =Â atoi(tmp); |
|---|
| 2450 | Â Â Â Â Â Â Â Â ca->remote_sdp_audio_port =Â port; |
|---|
| 2451 |         osip_strncpy(ca->remote_sdp_audio_ip, audioaddr, sizeof(ca->remote_sdp_audio_ip)-1); |
|---|
| 2452 | |
|---|
| 2453 | Â Â Â Â } |
|---|
| 2454 | |
|---|
| 2455 | Â Â Â Â eXosip_unlock(); |
|---|
| 2456 | |
|---|
| 2457 |     if (adev_in) |
|---|
| 2458 | Â Â Â Â { |
|---|
| 2459 |         if (ca->audiodev_in) |
|---|
| 2460 | Â Â Â Â Â Â Â Â Â Â Â Â osip_free(ca->audiodev_in); |
|---|
| 2461 | Â Â Â Â Â Â Â Â ca->audiodev_in =Â osip_strdup(adev_in); |
|---|
| 2462 | Â Â Â Â } |
|---|
| 2463 | Â Â Â Â |
|---|
| 2464 |     if (adev_out) |
|---|
| 2465 | Â Â Â Â { |
|---|
| 2466 |         if (ca->audiodev_out) |
|---|
| 2467 | Â Â Â Â Â Â Â Â Â Â Â Â osip_free(ca->audiodev_out); |
|---|
| 2468 | Â Â Â Â Â Â Â Â ca->audiodev_out =Â osip_strdup(adev_out); |
|---|
| 2469 | Â Â Â Â } |
|---|
| 2470 | |
|---|
| 2471 |     ph_call_media_start(ca, NULL, streams|PH_STREAM_MCSEND, 0); |
|---|
| 2472 | |
|---|
| 2473 | Â Â Â Â eXosip_lock(); |
|---|
| 2474 |     ph_retrieve_from(ca->did, &remoteUri); |
|---|
| 2475 | Â Â Â Â eXosip_unlock(); |
|---|
| 2476 | |
|---|
| 2477 | Â Â Â Â clear(info); |
|---|
| 2478 | |
|---|
| 2479 | Â Â Â Â info.remoteUri =Â remoteUri; |
|---|
| 2480 | Â Â Â Â info.event =Â phCALLOK; |
|---|
| 2481 |     phcb->callProgress(cid, &info); |
|---|
| 2482 | |
|---|
| 2483 |     if (remoteUri) |
|---|
| 2484 | Â Â Â Â Â Â Â Â osip_free(remoteUri); |
|---|
| 2485 | |
|---|
| 2486 |     return 0; |
|---|
| 2487 | } |
|---|
| 2488 | |
|---|
| 2489 | PHAPI_EXPORT int |
|---|
| 2490 | phAcceptMcCall2(int cid, int mcid) |
|---|
| 2491 | { |
|---|
| 2492 | Â Â Â Â phcall_t *ca; |
|---|
| 2493 | Â Â Â Â phcall_t *mca; |
|---|
| 2494 |     char local_voice_port[16] = "0"; |
|---|
| 2495 |     int streams = PH_STREAM_AUDIO; |
|---|
| 2496 | Â Â Â Â phCallStateInfo_t info; |
|---|
| 2497 |     int i; |
|---|
| 2498 |     char *remoteUri; |
|---|
| 2499 | |
|---|
| 2500 |     if (!phIsInitialized) |
|---|
| 2501 |         return -PH_NOTINIT; |
|---|
| 2502 | |
|---|
| 2503 | Â Â Â Â ca =Â ph_locate_call_by_cid(cid); |
|---|
| 2504 | Â Â Â Â mca =Â ph_locate_call_by_cid(mcid); |
|---|
| 2505 | |
|---|
| 2506 |     if (!ca || !mca) |
|---|
| 2507 |         return -PH_BADCID; |
|---|
| 2508 | |
|---|
| 2509 |     i = ph_call_retrieve_payloads(ca, streams); |
|---|
| 2510 | |
|---|
| 2511 | Â Â Â Â ca->loc_sdp_audio_port =Â mca->loc_sdp_audio_port; |
|---|
| 2512 | Â Â Â Â ca->remote_sdp_audio_port =Â mca->remote_sdp_audio_port; |
|---|
| 2513 |     osip_strncpy(ca->remote_sdp_audio_ip, mca->remote_sdp_audio_ip, sizeof(ca->remote_sdp_audio_ip)-1); |
|---|
| 2514 |     if (mca->audiodev_in) |
|---|
| 2515 | Â Â Â Â Â Â Â Â ca->audiodev_in =Â osip_strdup(mca->audiodev_in); |
|---|
| 2516 |     if (mca->audiodev_out) |
|---|
| 2517 | Â Â Â Â Â Â Â Â ca->audiodev_out =Â osip_strdup(mca->audiodev_out); |
|---|
| 2518 | |
|---|
| 2519 | |
|---|
| 2520 | Â Â Â Â ph_msession_use(mca->mses); |
|---|
| 2521 | Â Â Â Â ca->mses =Â mca->mses; |
|---|
| 2522 | |
|---|
| 2523 | Â Â Â Â ca->user_mflags =Â mca->user_mflags; |
|---|
| 2524 | Â Â Â Â ca->nego_mflags =Â mca->nego_mflags; |
|---|
| 2525 | |
|---|
| 2526 |     snprintf(local_voice_port,16, "%d", ca->remote_sdp_audio_port); |
|---|
| 2527 | |
|---|
| 2528 | |
|---|
| 2529 | |
|---|
| 2530 | Â Â Â Â eXosip_lock(); |
|---|
| 2531 |     i = ph_answer_call(ca->cid, ca->did, 200, local_voice_port, ph_get_call_contact(ca), |
|---|
| 2532 | Â Â Â Â Â Â Â Â Â Â Â Â NULL,NULL,NULL, |
|---|
| 2533 |             ca->remote_sdp_audio_ip, NULL, NULL); |
|---|
| 2534 | |
|---|
| 2535 |     ph_retrieve_from(ca->did, &remoteUri); |
|---|
| 2536 | |
|---|
| 2537 | Â Â Â Â eXosip_unlock(); |
|---|
| 2538 | |
|---|
| 2539 | |
|---|
| 2540 | |
|---|
| 2541 | Â Â Â Â clear(info); |
|---|
| 2542 | |
|---|
| 2543 | Â Â Â Â info.remoteUri =Â remoteUri; |
|---|
| 2544 | Â Â Â Â info.event =Â phCALLOK; |
|---|
| 2545 |     phcb->callProgress(cid, &info); |
|---|
| 2546 | |
|---|
| 2547 |     if (remoteUri) |
|---|
| 2548 | Â Â Â Â Â Â Â Â osip_free(remoteUri); |
|---|
| 2549 | |
|---|
| 2550 |     return 0; |
|---|
| 2551 | } |
|---|
| 2552 | |
|---|
| 2553 | |
|---|
| 2554 | static void |
|---|
| 2555 | add_contact_param(struct vline *vl, const char *param, const char *value, int inside) |
|---|
| 2556 | { |
|---|
| 2557 | Â Â Â Â osip_contact_t *ctct; |
|---|
| 2558 | |
|---|
| 2559 | |
|---|
| 2560 |     if (!vl->contact) |
|---|
| 2561 | Â Â Â Â Â Â Â Â return; |
|---|
| 2562 | |
|---|
| 2563 | Â Â Â Â osip_contact_init(&ctct); |
|---|
| 2564 | |
|---|
| 2565 |     osip_contact_parse(ctct, vl->contact); |
|---|
| 2566 |     if (inside) |
|---|
| 2567 |         osip_uri_param_add(&ctct->url->url_params, osip_strdup(param), osip_strdup(value)); |
|---|
| 2568 | Â Â Â Â else |
|---|
| 2569 |         osip_contact_param_add(ctct, osip_strdup(param), osip_strdup(value)); |
|---|
| 2570 | |
|---|
| 2571 | Â Â Â Â osip_free(vl->contact); |
|---|
| 2572 |     osip_contact_to_str(ctct, &vl->contact); |
|---|
| 2573 | Â Â Â Â osip_contact_free(ctct); |
|---|
| 2574 | } |
|---|
| 2575 | |
|---|
| 2576 | |
|---|
| 2577 | PHAPI_EXPORT int |
|---|
| 2578 | phLineGetMobility(int vlid) |
|---|
| 2579 | { |
|---|
| 2580 |     struct vline *vl; |
|---|
| 2581 | |
|---|
| 2582 |     if (!phIsInitialized) |
|---|
| 2583 |         return -PH_NOTINIT; |
|---|
| 2584 | |
|---|
| 2585 | Â Â Â Â vl =Â ph_valid_vlid(vlid); |
|---|
| 2586 | |
|---|
| 2587 |     if (!vl) |
|---|
| 2588 |         return -PH_BADVLID; |
|---|
| 2589 | |
|---|
| 2590 |     return vl->mobility; |
|---|
| 2591 | |
|---|
| 2592 | } |
|---|
| 2593 | |
|---|
| 2594 | PHAPI_EXPORT int |
|---|
| 2595 | phLineSetUsername2(int vlid, const char* username) |
|---|
| 2596 | { |
|---|
| 2597 |     struct vline *vl; |
|---|
| 2598 | |
|---|
| 2599 |     if (!phIsInitialized) |
|---|
| 2600 |         return -PH_NOTINIT; |
|---|
| 2601 | |
|---|
| 2602 | Â Â Â Â vl =Â ph_valid_vlid(vlid); |
|---|
| 2603 | |
|---|
| 2604 |     if (!vl) |
|---|
| 2605 |         return -PH_BADVLID; |
|---|
| 2606 | |
|---|
| 2607 | Â Â Â Â osip_free(vl->nrusername); |
|---|
| 2608 | Â Â Â Â vl->nrusername =Â osip_strdup(username); |
|---|
| 2609 | |
|---|
| 2610 |     return 0; |
|---|
| 2611 | } |
|---|
| 2612 | |
|---|
| 2613 | |
|---|
| 2614 | |
|---|
| 2615 | /* |
|---|
| 2616 |  find and return a stream of the given type in the 'streams'. |
|---|
| 2617 |  if the stream is not found allocate a new one if there is space            int j; |
|---|
| 2618 | Â Â in the table |
|---|
| 2619 | Â maxtsr specifices the size of the table |
|---|
| 2620 | Â */ |
|---|
| 2621 | static struct ph_stream_params * |
|---|
| 2622 | ph_find_stream(struct ph_stream_params **streams, const char *strtype, int maxstrs) |
|---|
| 2623 | { |
|---|
| 2624 | |
|---|
| 2625 |     struct ph_stream_params *si, **strs = streams; |
|---|
| 2626 | |
|---|
| 2627 | Â Â Â Â while(si =Â *strs++) |
|---|
| 2628 | Â Â Â Â { |
|---|
| 2629 |         if (!strcmp(si->streamtype, strtype)) |
|---|
| 2630 |             return si; |
|---|
| 2631 | Â Â Â Â } |
|---|
| 2632 | |
|---|
| 2633 |     if (!maxstrs) |
|---|
| 2634 |         return 0; |
|---|
| 2635 | |
|---|
| 2636 |     if (strs - streams < (maxstrs - 1)) |
|---|
| 2637 | Â Â Â Â { |
|---|
| 2638 |         si = calloc(sizeof(*si), 1); |
|---|
| 2639 | Â Â Â Â Â Â Â Â si->streamtype =Â strdup(strtype); |
|---|
| 2640 | Â Â Â Â Â Â Â Â si->streamport =Â -1; |
|---|
| 2641 | Â Â Â Â Â Â Â Â strs[-1]Â =Â si; |
|---|
| 2642 | Â Â Â Â Â Â Â Â strs[0]Â =Â 0; |
|---|
| 2643 |         return si; |
|---|
| 2644 | Â Â Â Â } |
|---|
| 2645 | |
|---|
| 2646 |     return 0; |
|---|
| 2647 | } |
|---|
| 2648 | |
|---|
| 2649 | |
|---|
| 2650 | static void |
|---|
| 2651 | ph_copy_streams_from_args(struct ph_stream_params **streams, va_list args) |
|---|
| 2652 | { |
|---|
| 2653 |     struct ph_stream_params *psi; |
|---|
| 2654 |     int i = 0; |
|---|
| 2655 | |
|---|
| 2656 |     while(0 != (psi = va_arg(args, struct ph_stream_params *))) { |
|---|
| 2657 |         struct ph_stream_params *esi= calloc(sizeof(*psi), 1); |
|---|
| 2658 |         if (!esi) |
|---|
| 2659 | Â Â Â Â Â Â Â Â Â Â Â Â return; |
|---|
| 2660 | Â Â Â Â Â Â Â Â streams[i]Â =Â esi; |
|---|
| 2661 |         ph_copy_stream(esi, psi); |
|---|
| 2662 | Â Â Â Â } |
|---|
| 2663 | |
|---|
| 2664 |     if (i < PH_MAX_STREAMS) |
|---|
| 2665 | Â Â Â Â Â Â Â Â streams[i]Â =Â 0; |
|---|
| 2666 | |
|---|
| 2667 | } |
|---|
| 2668 | |
|---|
| 2669 | static int |
|---|
| 2670 | ph_answer_request(int cid, int tid, int reason, const char *ctct) |
|---|
| 2671 | { |
|---|
| 2672 |     int i; |
|---|
| 2673 | |
|---|
| 2674 | Â Â Â Â eXosip_lock(); |
|---|
| 2675 |     i = ph_answer_call(cid, tid, reason, 0, ctct, 0, 0, 0, 0, 0, 0); |
|---|
| 2676 | Â Â Â Â eXosip_unlock(); |
|---|
| 2677 | |
|---|
| 2678 |     return i; |
|---|
| 2679 | } |
|---|
| 2680 | |
|---|
| 2681 | |
|---|
| 2682 | PHAPI_EXPORT int |
|---|
| 2683 | phRejectCall(int cid, int reason) |
|---|
| 2684 | { |
|---|
| 2685 | Â Â Â Â phcall_t *ca; |
|---|
| 2686 | |
|---|
| 2687 |     if (!phIsInitialized) |
|---|
| 2688 |         return -PH_NOTINIT; |
|---|
| 2689 | |
|---|
| 2690 | Â Â Â Â ca =Â ph_locate_call_by_cid(cid); |
|---|
| 2691 | |
|---|
| 2692 |     if (!ca) |
|---|
| 2693 |         return -PH_BADCID; |
|---|
| 2694 | |
|---|
| 2695 |     return phRejectCall2(cid, ph_get_call_contact(ca), reason); |
|---|
| 2696 | |
|---|
| 2697 | } |
|---|
| 2698 | |
|---|
| 2699 | PHAPI_EXPORT int |
|---|
| 2700 | phRejectCall2(int cid, const char *uri,int reason) |
|---|
| 2701 | { |
|---|
| 2702 |     int i; |
|---|
| 2703 | Â Â Â Â phcall_t *ca; |
|---|
| 2704 | Â Â Â Â phCallStateInfo_t info; |
|---|
| 2705 | |
|---|
| 2706 |     if (!phIsInitialized) |
|---|
| 2707 |         return -PH_NOTINIT; |
|---|
| 2708 | |
|---|
| 2709 | Â Â Â Â ca =Â ph_locate_call_by_cid(cid); |
|---|
| 2710 | |
|---|
| 2711 |     if (!ca) |
|---|
| 2712 |         return -PH_BADCID; |
|---|
| 2713 | |
|---|
| 2714 | Â Â Â Â if(!reason) |
|---|
| 2715 | Â Â Â Â Â Â Â Â reason =Â 302; |
|---|
| 2716 | |
|---|
| 2717 |     i = ph_answer_request(ca->cid, ca->tid, reason, uri); |
|---|
| 2718 | |
|---|
| 2719 | Â Â Â Â ph_release_call(ca); |
|---|
| 2720 | |
|---|
| 2721 | Â Â Â Â clear(info); |
|---|
| 2722 | Â Â Â Â info.event =Â phCALLCLOSED; |
|---|
| 2723 |     phcb->callProgress(cid, &info); |
|---|
| 2724 | |
|---|
| 2725 | |
|---|
| 2726 |     return i; |
|---|
| 2727 | } |
|---|
| 2728 | |
|---|
| 2729 | |
|---|
| 2730 | PHAPI_EXPORT int |
|---|
| 2731 | phRingingCall(int cid) |
|---|
| 2732 | { |
|---|
| 2733 |     int i; |
|---|
| 2734 | Â Â Â Â osip_message_t *msg =Â 0; |
|---|
| 2735 | Â Â Â Â phcall_t *ca; |
|---|
| 2736 | |
|---|
| 2737 |     if (!phIsInitialized) |
|---|
| 2738 |         return -PH_NOTINIT; |
|---|
| 2739 | |
|---|
| 2740 | Â Â Â Â ca =Â ph_locate_call_by_cid(cid); |
|---|
| 2741 | |
|---|
| 2742 |     if (!ca) |
|---|
| 2743 |         return -PH_BADCID; |
|---|
| 2744 | |
|---|
| 2745 | Â Â Â Â eXosip_lock(); |
|---|
| 2746 |     i = eXosip_call_build_answer(ca->tid, 180, &msg); |
|---|
| 2747 |     if (i < 0) |
|---|
| 2748 | |
|---|
| 2749 | |
|---|
| 2750 | Â Â Â Â { |
|---|
| 2751 | Â Â Â Â Â Â Â Â eXosip_unlock(); |
|---|
| 2752 |         return -1; |
|---|
| 2753 | Â Â Â Â } |
|---|
| 2754 | |
|---|
| 2755 | |
|---|
| 2756 |     i = eXosip_call_send_answer(ca->tid, 180, msg); |
|---|
| 2757 | Â Â Â Â eXosip_unlock(); |
|---|
| 2758 |     return i; |
|---|
| 2759 | } |
|---|
| 2760 | |
|---|
| 2761 | |
|---|
| 2762 | |
|---|
| 2763 | PHAPI_EXPORT int |
|---|
| 2764 | phCloseCall(int cid) |
|---|
| 2765 | { |
|---|
| 2766 |     int i; |
|---|
| 2767 | Â Â Â Â phcall_t *ca; |
|---|
| 2768 | Â Â Â Â phCallStateInfo_t info; |
|---|
| 2769 |     int did; |
|---|
| 2770 | |
|---|
| 2771 |     DBG_SIP_NEGO("phCloseCall %d\n", cid); |
|---|
| 2772 | |
|---|
| 2773 |     if (!phIsInitialized) |
|---|
| 2774 |         return -PH_NOTINIT; |
|---|
| 2775 | |
|---|
| 2776 |     if (cid < 0) |
|---|
| 2777 |         return -PH_BADCID; |
|---|
| 2778 | |
|---|
| 2779 | Â Â Â Â eXosip_lock(); |
|---|
| 2780 | Â Â Â Â ca =Â ph_locate_call_by_cid(cid); |
|---|
| 2781 | |
|---|
| 2782 |     if (!ca) |
|---|
| 2783 | Â Â Â Â { |
|---|
| 2784 | Â Â Â Â Â Â Â Â eXosip_unlock(); |
|---|
| 2785 |         return -PH_BADCID; |
|---|
| 2786 | Â Â Â Â } |
|---|
| 2787 | |
|---|
| 2788 | Â Â Â Â clear(info); |
|---|
| 2789 | Â Â Â Â info.event =Â phCALLCLOSED; |
|---|
| 2790 | |
|---|
| 2791 |     if (ca->isringing) |
|---|
| 2792 | Â Â Â Â { |
|---|
| 2793 | Â Â Â Â Â Â Â Â info.event =Â phCALLCLOSEDandSTOPRING; |
|---|
| 2794 | Â Â Â Â Â Â Â Â ca->isringing =Â 0; |
|---|
| 2795 | Â Â Â Â } |
|---|
| 2796 | |
|---|
| 2797 | |
|---|
| 2798 | Â Â Â Â info.vlid =Â ca->vlid; |
|---|
| 2799 | Â Â Â Â did =Â ca->did; |
|---|
| 2800 | |
|---|
| 2801 | |
|---|
| 2802 |     i = eXosip_call_terminate(cid, did); |
|---|
| 2803 | |
|---|
| 2804 | |
|---|
| 2805 | Â Â Â Â ph_release_call(ca); |
|---|
| 2806 | |
|---|
| 2807 | Â Â Â Â eXosip_unlock(); |
|---|
| 2808 | |
|---|
| 2809 |     if (i) |
|---|
| 2810 |         return i; |
|---|
| 2811 | |
|---|
| 2812 | Â Â Â Â info.userData =Â 0; |
|---|
| 2813 | |
|---|
| 2814 | Â Â Â Â info.errorCode =Â 0; |
|---|
| 2815 |     phcb->callProgress(cid, &info); |
|---|
| 2816 | |
|---|
| 2817 |     return i; |
|---|
| 2818 | |
|---|
| 2819 | } |
|---|
| 2820 | |
|---|
| 2821 | |
|---|
| 2822 | PHAPI_EXPORT int phCallStartMedia(int cid, int streamFlags) |
|---|
| 2823 | { |
|---|
| 2824 | Â Â Â Â phcall_t *ca; |
|---|
| 2825 | |
|---|
| 2826 |     if (!phIsInitialized) |
|---|
| 2827 |         return -PH_NOTINIT; |
|---|
| 2828 | |
|---|
| 2829 | Â Â Â Â ca =Â ph_locate_call_by_cid(cid); |
|---|
| 2830 | |
|---|
| 2831 |     if (!ca) |
|---|
| 2832 |         return -PH_BADCID; |
|---|
| 2833 | |
|---|
| 2834 | |
|---|
| 2835 | Â Â Â Â ca->user_mflags &=Â ~(PH_NOMEDIA_STREAMS|PH_STREAM_AUDIO|PH_STREAM_VIDEO_TX|PH_STREAM_VIDEO_RX); |
|---|
| 2836 | Â Â Â Â ca->user_mflags |=Â streamFlags; |
|---|
| 2837 | Â Â Â Â ca->nego_mflags =Â ca->user_mflags; |
|---|
| 2838 | |
|---|
| 2839 |     return ph_call_media_start(ca, 0, 0, 0); |
|---|
| 2840 | |
|---|
| 2841 | } |
|---|
| 2842 | |
|---|
| 2843 | PHAPI_EXPORT int |
|---|
| 2844 | phTransferCall(int cid, int tcid) |
|---|
| 2845 | { |
|---|
| 2846 | Â Â Â Â phcall_t *ca; |
|---|
| 2847 | Â Â Â Â phcall_t *txca; |
|---|
| 2848 |     char uri[512]; |
|---|
| 2849 | Â Â Â Â osip_message_t *refer =Â 0; |
|---|
| 2850 |     int i; |
|---|
| 2851 | |
|---|
| 2852 |     if (!phIsInitialized) |
|---|
| 2853 |         return -PH_NOTINIT; |
|---|
| 2854 | |
|---|
| 2855 | Â Â Â Â ca =Â ph_locate_call_by_cid(cid); |
|---|
| 2856 | Â Â Â Â txca =Â ph_locate_call_by_cid(tcid); |
|---|
| 2857 | |
|---|
| 2858 |     if (!ca || !txca) |
|---|
| 2859 |         return -PH_BADCID; |
|---|
| 2860 | |
|---|
| 2861 | |
|---|
| 2862 | Â Â Â Â eXosip_lock(); |
|---|
| 2863 |     i = eXosip_call_get_referto(tcid, uri, sizeof(uri)); |
|---|
| 2864 |     if (i) goto err; |
|---|
| 2865 |     i = eXosip_call_build_refer(ca->did, uri, &refer); |
|---|
| 2866 |     if (i) goto err; |
|---|
| 2867 |     ph_apply_customizations(refer, NULL, NULL); |
|---|
| 2868 |     i = eXosip_call_send_request(ca->did, refer); |
|---|
| 2869 | Â Â Â Â refer =Â 0; |
|---|
| 2870 |     if (i) goto err; |
|---|
| 2871 | |
|---|
| 2872 | Â Â Â Â ca->localrefer =Â 1; |
|---|
| 2873 | Â Â Â Â ca->txcid =Â tcid; |
|---|
| 2874 | |
|---|
| 2875 | |
|---|
| 2876 | Â Â Â Â eXosip_unlock(); |
|---|
| 2877 | |
|---|
| 2878 | |
|---|
| 2879 |     return 0; |
|---|
| 2880 | |
|---|
| 2881 | Â Â Â Â err: |
|---|
| 2882 | Â Â Â Â eXosip_unlock(); |
|---|
| 2883 | |
|---|
| 2884 |     if (refer) |
|---|
| 2885 | Â Â Â Â Â Â Â Â osip_message_free(refer); |
|---|
| 2886 | |
|---|
| 2887 |     if (i == OSIP_NOMEM) |
|---|
| 2888 |         return -PH_NORESOURCES; |
|---|
| 2889 | |
|---|
| 2890 |     return -PH_ERROR; |
|---|
| 2891 | |
|---|
| 2892 | } |
|---|
| 2893 | |
|---|
| 2894 | |
|---|
| 2895 | PHAPI_EXPORTÂ int |
|---|
| 2896 | phSetContact(int vlid, const char *uri) |
|---|
| 2897 | { |
|---|
| 2898 |     return phSetContact2(vlid, uri, 1); |
|---|
| 2899 | } |
|---|
| 2900 | |
|---|
| 2901 | PHAPI_EXPORTÂ int |
|---|
| 2902 | phSetContact2(int vlid, const char *uri, int translate) |
|---|
| 2903 | { |
|---|
| 2904 |     struct vline *vl; |
|---|
| 2905 | |
|---|
| 2906 |     if (!phIsInitialized) |
|---|
| 2907 |         return -PH_NOTINIT; |
|---|
| 2908 | |
|---|
| 2909 |     if (!vlid) |
|---|
| 2910 | Â Â Â Â { |
|---|
| 2911 | Â Â Â Â Â Â Â Â /* set contact for all VL */ |
|---|
| 2912 |         osip_strncpy(vcontact, uri, sizeof(vcontact)-1); |
|---|
| 2913 |         return 0; |
|---|
| 2914 | Â Â Â Â } |
|---|
| 2915 | |
|---|
| 2916 | Â Â Â Â vl =Â ph_valid_vlid(vlid); |
|---|
| 2917 | |
|---|
| 2918 |     if (!vl) |
|---|
| 2919 |         return -PH_BADVLID; |
|---|
| 2920 | |
|---|
| 2921 |     if (vl->contact) |
|---|
| 2922 | Â Â Â Â Â Â Â Â osip_free(vl->contact); |
|---|
| 2923 | |
|---|
| 2924 | #if OLDOSIP |
|---|
| 2925 |     if (translate) |
|---|
| 2926 | Â Â Â Â { |
|---|
| 2927 |         char contact[256]; |
|---|
| 2928 |         eXosip_guess_contact_uri(uri, contact, sizeof(contact), 1); |
|---|
| 2929 | Â Â Â Â Â Â Â Â vl->contact =Â osip_strdup(contact); |
|---|
| 2930 | Â Â Â Â } |
|---|
| 2931 | Â Â Â Â else |
|---|
| 2932 | #endif |
|---|
| 2933 | Â Â Â Â Â Â Â Â vl->contact =Â osip_strdup(uri); |
|---|
| 2934 |     return 0; |
|---|
| 2935 | |
|---|
| 2936 | } |
|---|
| 2937 | |
|---|
| 2938 | |
|---|
| 2939 | |
|---|
| 2940 | PHAPI_EXPORT int |
|---|
| 2941 | phConf(int cid1, int cid2) |
|---|
| 2942 | { |
|---|
| 2943 | Â Â Â Â phcall_t *ca1; |
|---|
| 2944 | Â Â Â Â phcall_t *ca2; |
|---|
| 2945 | |
|---|
| 2946 |     if (!phIsInitialized) |
|---|
| 2947 |         return -PH_NOTINIT; |
|---|
| 2948 | |
|---|
| 2949 | Â Â Â Â ca1 =Â ph_locate_call_by_cid(cid1); |
|---|
| 2950 | Â Â Â Â ca2 =Â ph_locate_call_by_cid(cid2); |
|---|
| 2951 | |
|---|
| 2952 | Â Â Â Â if(!ca1 ||Â !ca2) |
|---|
| 2953 |         return -PH_BADCFID; |
|---|
| 2954 | |
|---|
| 2955 |     if (0 > ph_msession_conf_start(ca1->mses, ca2->mses, ca1->audiodev_in, ca1->audiodev_out)) |
|---|
| 2956 |         return -PH_NORESOURCES; |
|---|
| 2957 | Â Â Â Â else |
|---|
| 2958 |         return 0; |
|---|
| 2959 | } |
|---|
| 2960 | |
|---|
| 2961 | PHAPI_EXPORT int |
|---|
| 2962 | phStopConf(int cid1, int cid2) |
|---|
| 2963 | { |
|---|
| 2964 | Â Â Â Â phcall_t *ca1; |
|---|
| 2965 | Â Â Â Â phcall_t *ca2; |
|---|
| 2966 | |
|---|
| 2967 |     if (!phIsInitialized) |
|---|
| 2968 |         return -PH_NOTINIT; |
|---|
| 2969 | |
|---|
| 2970 | Â Â Â Â ca1 =Â ph_locate_call_by_cid(cid1); |
|---|
| 2971 | Â Â Â Â ca2 =Â ph_locate_call_by_cid(cid2); |
|---|
| 2972 | |
|---|
| 2973 | Â Â Â Â if(!ca1 ||Â !ca2) |
|---|
| 2974 |         return -PH_BADCFID; |
|---|
| 2975 | |
|---|
| 2976 |     if( 0 > ph_msession_conf_stop(ca1->mses, ca2->mses)) |
|---|
| 2977 |         return -PH_NORESOURCES; |
|---|
| 2978 | Â Â Â Â else |
|---|
| 2979 |         return 0; |
|---|
| 2980 | } |
|---|
| 2981 | |
|---|
| 2982 | #define CONF_MODE 1 |
|---|
| 2983 | |
|---|
| 2984 | PHAPI_EXPORT int |
|---|
| 2985 | phSetFollowMe(const char *uri) |
|---|
| 2986 | { |
|---|
| 2987 |     if (!phIsInitialized) |
|---|
| 2988 |         return -PH_NOTINIT; |
|---|
| 2989 | |
|---|
| 2990 |     if (!uri) |
|---|
| 2991 | Â Â Â Â Â Â Â Â ph_follow_me_addr[0]Â =Â 0; |
|---|
| 2992 | |
|---|
| 2993 |     if (ph_find_matching_vline(uri, PHM_IGNORE_PORT)) |
|---|
| 2994 |         return -PH_REDIRLOOP; |
|---|
| 2995 | |
|---|
| 2996 |     osip_strncpy(ph_follow_me_addr, uri, sizeof(ph_follow_me_addr)-1); |
|---|
| 2997 |     return 0; |
|---|
| 2998 | |
|---|
| 2999 | |
|---|
| 3000 | } |
|---|
| 3001 | |
|---|
| 3002 | |
|---|
| 3003 | PHAPI_EXPORT int |
|---|
| 3004 | phSetBusy(int busyFlag) |
|---|
| 3005 | { |
|---|
| 3006 | Â Â Â Â ph_busyFlag =Â busyFlag; |
|---|
| 3007 |     return 0; |
|---|
| 3008 | } |
|---|
| 3009 | |
|---|
| 3010 | |
|---|
| 3011 | PHAPI_EXPORT int |
|---|
| 3012 | phLineSetFollowMe(int vlid, const char *uri) |
|---|
| 3013 | { |
|---|
| 3014 |     struct vline *vl; |
|---|
| 3015 | |
|---|
| 3016 |     if (!phIsInitialized) |
|---|
| 3017 |         return -PH_NOTINIT; |
|---|
| 3018 | |
|---|
| 3019 | Â Â Â Â vl =Â ph_valid_vlid(vlid); |
|---|
| 3020 | |
|---|
| 3021 |     if (!vl) |
|---|
| 3022 |         return -PH_BADVLID; |
|---|
| 3023 | |
|---|
| 3024 |     if (ph_find_matching_vline(uri, PHM_IGNORE_PORT)) |
|---|
| 3025 |         return -PH_REDIRLOOP; |
|---|
| 3026 | |
|---|
| 3027 |     if (vl->followme) |
|---|
| 3028 | Â Â Â Â Â Â Â Â osip_free(vl->followme); |
|---|
| 3029 | |
|---|
| 3030 | Â Â Â Â vl->followme =Â osip_strdup(uri); |
|---|
| 3031 | |
|---|
| 3032 |     return 0; |
|---|
| 3033 | |
|---|
| 3034 | } |
|---|
| 3035 | |
|---|
| 3036 | |
|---|
| 3037 | PHAPI_EXPORT int |
|---|
| 3038 | phBlindTransferCall(int cid, const char *uri) |
|---|
| 3039 | { |
|---|
| 3040 |     int i; |
|---|
| 3041 | Â Â Â Â phcall_t *ca; |
|---|
| 3042 | Â Â Â Â osip_message_t*Â refer; |
|---|
| 3043 | |
|---|
| 3044 |     if (!phIsInitialized) |
|---|
| 3045 |         return -PH_NOTINIT; |
|---|
| 3046 | |
|---|
| 3047 | Â Â Â Â ca =Â ph_locate_call_by_cid(cid); |
|---|
| 3048 | |
|---|
| 3049 |     if (!ca) |
|---|
| 3050 |         return -PH_BADCID; |
|---|
| 3051 | |
|---|
| 3052 |     if (!nonempty(uri)) |
|---|
| 3053 |         return -PH_BADARG; |
|---|
| 3054 | |
|---|
| 3055 |     if (ph_find_matching_vline(uri, PHM_IGNORE_PORT)) |
|---|
| 3056 |         return -PH_REDIRLOOP; |
|---|
| 3057 | |
|---|
| 3058 | |
|---|
| 3059 | Â Â Â Â ca->localrefer =Â 1; |
|---|
| 3060 | Â Â Â Â phHoldCall(cid); |
|---|
| 3061 | |
|---|
| 3062 | Â Â Â Â eXosip_lock(); |
|---|
| 3063 |     i = eXosip_call_build_refer(ca->did, (char *)uri, &refer); |
|---|
| 3064 |     if (!i) |
|---|
| 3065 |         i = eXosip_call_send_request(ca->did, refer); |
|---|
| 3066 | Â Â Â Â eXosip_unlock(); |
|---|
| 3067 | |
|---|
| 3068 |     return i; |
|---|
| 3069 | |
|---|
| 3070 | } |
|---|
| 3071 | |
|---|
| 3072 | |
|---|
| 3073 | static char *ph_call_fix_media_dir(phcall_t *ca, const char *dir) |
|---|
| 3074 | { |
|---|
| 3075 |     if (!ca->sdpctx) |
|---|
| 3076 |         return 0; |
|---|
| 3077 | |
|---|
| 3078 |     if (ca->sdpctx->offer) { |
|---|
| 3079 |         sdp_context_update_media_direction(ca->sdpctx, dir, 1); |
|---|
| 3080 |         return ca->sdpctx->offerstr; |
|---|
| 3081 | Â Â Â Â } |
|---|
| 3082 | |
|---|
| 3083 |     if (ca->sdpctx->answer) { |
|---|
| 3084 |         sdp_context_update_media_direction(ca->sdpctx, dir, 0); |
|---|
| 3085 |         return ca->sdpctx->answerstr; |
|---|
| 3086 | Â Â Â Â } |
|---|
| 3087 | |
|---|
| 3088 |     return 0; |
|---|
| 3089 | |
|---|
| 3090 | } |
|---|
| 3091 | |
|---|
| 3092 | int _ph_send_reinvite(int cid) |
|---|
| 3093 | { |
|---|
| 3094 |     int i; |
|---|
| 3095 | Â Â Â Â osip_message_t *reinvite; |
|---|
| 3096 | Â Â Â Â phcall_t *ca; |
|---|
| 3097 | Â Â Â Â Â Â Â Â |
|---|
| 3098 |     if (!phIsInitialized) |
|---|
| 3099 |         return -PH_NOTINIT; |
|---|
| 3100 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 3101 | Â Â Â Â ca =Â ph_locate_call_by_cid(cid); |
|---|
| 3102 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 3103 |     if (!ca) |
|---|
| 3104 |         return -PH_BADCID; |
|---|
| 3105 | Â Â Â Â |
|---|
| 3106 | Â Â Â Â eXosip_lock(); |
|---|
| 3107 |     if (eXosip_call_build_request(ca->did, "INVITE", &reinvite)) { |
|---|
| 3108 | Â Â Â Â Â Â Â Â eXosip_unlock(); |
|---|
| 3109 |         return -1; |
|---|
| 3110 | Â Â Â Â } |
|---|
| 3111 | Â Â Â Â eXosip_unlock(); |
|---|
| 3112 | |
|---|
| 3113 |     osip_message_set_subject(reinvite, "Call reinvite"); |
|---|
| 3114 |     osip_message_set_allow(reinvite, "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO"); |
|---|
| 3115 | Â Â Â Â Â Â Â Â |
|---|
| 3116 | Â Â Â Â sdp_context_build_offer(ca->sdpctx); |
|---|
| 3117 | |
|---|
| 3118 |     ph_set_media_direction(ca->sdpctx->offer, "audio", ph_get_local_media_direction(ca, "audio")); |
|---|
| 3119 |     ph_set_media_direction(ca->sdpctx->offer, "video", ph_get_local_media_direction(ca, "video")); |
|---|
| 3120 | |
|---|
| 3121 |     sdp_message_to_str(ca->sdpctx->offer, &ca->sdpctx->offerstr); |
|---|
| 3122 | |
|---|
| 3123 | Â Â Â Â ca->local_sdp =Â ca->sdpctx->offer; |
|---|
| 3124 | Â Â Â Â ca->remote_sdp =Â 0;Â // force ph_call_media_start on ph_call_answered |
|---|
| 3125 |     ph_req_set_body(reinvite, ca->sdpctx->offerstr, "application/sdp"); |
|---|
| 3126 | |
|---|
| 3127 | Â Â Â Â eXosip_lock(); |
|---|
| 3128 |     i = eXosip_call_send_request(ca->did, reinvite); |
|---|
| 3129 | Â Â Â Â eXosip_unlock(); |
|---|
| 3130 | |
|---|
| 3131 | Â Â Â Â osip_mutex_lock(ph_media_stop_mutex); |
|---|
| 3132 | Â Â Â Â ph_call_media_stop(ca); |
|---|
| 3133 | Â Â Â Â osip_mutex_unlock(ph_media_stop_mutex); |
|---|
| 3134 | |
|---|
| 3135 |     return i; |
|---|
| 3136 | }Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 3137 | |
|---|
| 3138 | PHAPI_EXPORT int |
|---|
| 3139 | phResumeCall(int cid) |
|---|
| 3140 | { |
|---|
| 3141 | Â Â Â Â phcall_t *ca; |
|---|
| 3142 | |
|---|
| 3143 |     if (!phIsInitialized) |
|---|
| 3144 |         return -PH_NOTINIT; |
|---|
| 3145 | |
|---|
| 3146 | Â Â Â Â ca =Â ph_locate_call_by_cid(cid); |
|---|
| 3147 | |
|---|
| 3148 |     if (!ca) |
|---|
| 3149 |         return -PH_BADCID; |
|---|
| 3150 | |
|---|
| 3151 | Â Â Â Â ca->nego_mflags |=Â PH_STREAM_AUDIO_RX; |
|---|
| 3152 | Â Â Â Â ca->nego_mflags |=Â PH_STREAM_VIDEO_RX; |
|---|
| 3153 | Â Â Â Â |
|---|
| 3154 | Â Â Â Â ca->localhold =Â 0;Â Â Â |
|---|
| 3155 | Â Â Â Â ca->localresume =Â 1; |
|---|
| 3156 | Â Â Â Â Â Â Â Â |
|---|
| 3157 |     return _ph_send_reinvite(cid); |
|---|
| 3158 | } |
|---|
| 3159 | |
|---|
| 3160 | PHAPI_EXPORT int |
|---|
| 3161 | phHoldCall(int cid) |
|---|
| 3162 | { |
|---|
| 3163 | Â Â Â Â phcall_t *ca; |
|---|
| 3164 | |
|---|
| 3165 |     if (!phIsInitialized) |
|---|
| 3166 |         return -PH_NOTINIT; |
|---|
| 3167 | |
|---|
| 3168 | Â Â Â Â ca =Â ph_locate_call_by_cid(cid); |
|---|
| 3169 | |
|---|
| 3170 |     if (!ca) |
|---|
| 3171 |         return -PH_BADCID; |
|---|
| 3172 | |
|---|
| 3173 | Â Â Â Â ca->nego_mflags &=Â ~PH_STREAM_AUDIO_RX; |
|---|
| 3174 | Â Â Â Â ca->nego_mflags &=Â ~PH_STREAM_VIDEO_RX; |
|---|
| 3175 | Â Â Â Â |
|---|
| 3176 | Â Â Â Â ca->localresume =Â 0; |
|---|
| 3177 | Â Â Â Â ca->localhold =Â 1; |
|---|
| 3178 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 3179 |     return _ph_send_reinvite(cid); |
|---|
| 3180 | } |
|---|
| 3181 | |
|---|
| 3182 | |
|---|
| 3183 | PHAPI_EXPORT int |
|---|
| 3184 | phLineSetBusy(int vlid, int busyFlag) |
|---|
| 3185 | { |
|---|
| 3186 |     struct vline *vl; |
|---|
| 3187 | |
|---|
| 3188 |     if (!phIsInitialized) |
|---|
| 3189 |         return -PH_NOTINIT; |
|---|
| 3190 | |
|---|
| 3191 | Â Â Â Â vl =Â ph_valid_vlid(vlid); |
|---|
| 3192 | |
|---|
| 3193 |     if (!vl) |
|---|
| 3194 |         return -PH_BADVLID; |
|---|
| 3195 | |
|---|
| 3196 | Â Â Â Â vl->busy =Â busyFlag; |
|---|
| 3197 |     return 0; |
|---|
| 3198 | } |
|---|
| 3199 | |
|---|
| 3200 | PHAPI_EXPORT int |
|---|
| 3201 | phAddAuthInfo(const char *username, const char *userid, |
|---|
| 3202 |         const char *passwd, const char *ha1, |
|---|
| 3203 |         const char *realm) |
|---|
| 3204 | { |
|---|
| 3205 |     int ret; |
|---|
| 3206 | |
|---|
| 3207 | Â Â Â Â DBG_SIP_EVENT("Add auth info username %s userid %s passwd %s realm %s ha1 %s\n", |
|---|
| 3208 |         username, userid, passwd, realm, ha1); |
|---|
| 3209 | |
|---|
| 3210 |     if (!phIsInitialized) |
|---|
| 3211 |         return -PH_NOTINIT; |
|---|
| 3212 | |
|---|
| 3213 |     if (!username) |
|---|
| 3214 |         return -PH_BADARG; |
|---|
| 3215 | |
|---|
| 3216 |     if (!userid) |
|---|
| 3217 |         return -PH_BADARG; |
|---|
| 3218 | |
|---|
| 3219 |     if (!passwd) |
|---|
| 3220 |         return -PH_BADARG; |
|---|
| 3221 | |
|---|
| 3222 | Â Â Â Â eXosip_lock(); |
|---|
| 3223 | |
|---|
| 3224 |     ret = eXosip_add_authentication_info(username, userid, passwd, ha1, realm); |
|---|
| 3225 | |
|---|
| 3226 | Â Â Â Â eXosip_unlock(); |
|---|
| 3227 | |
|---|
| 3228 |     return ret; |
|---|
| 3229 | } |
|---|
| 3230 | |
|---|
| 3231 | static void ph_fix_reg_contact(struct vline* vl, char **rcontact) |
|---|
| 3232 | { |
|---|
| 3233 | Â Â Â Â osip_contact_t*Â ctct =Â 0; |
|---|
| 3234 |     char regid[16]; |
|---|
| 3235 |     int fixit = (PH_USE_RFC5626 == (vl->mobility & PH_USE_RFC5626)); |
|---|
| 3236 | |
|---|
| 3237 | Â Â Â Â *rcontact =Â vl->contact; |
|---|
| 3238 | |
|---|
| 3239 |     if (!fixit) |
|---|
| 3240 | Â Â Â Â Â Â Â Â return; |
|---|
| 3241 | |
|---|
| 3242 | |
|---|
| 3243 | |
|---|
| 3244 |     if (osip_contact_init(&ctct)) |
|---|
| 3245 | Â Â Â Â Â Â Â Â return; |
|---|
| 3246 | |
|---|
| 3247 |     if (osip_contact_parse(ctct, vl->contact)) |
|---|
| 3248 |         goto err; |
|---|
| 3249 | |
|---|
| 3250 |     snprintf(regid, 16, "%d", ph_vline2vlid(vl) ); |
|---|
| 3251 |     if (osip_contact_param_add(ctct, osip_strdup("reg-id"), osip_strdup(regid))) |
|---|
| 3252 |         goto err; |
|---|
| 3253 | |
|---|
| 3254 |     if (osip_contact_param_add(ctct, osip_strdup("+sip.instance"), osip_strdup(phcfg.sip_id))) |
|---|
| 3255 |         goto err; |
|---|
| 3256 | |
|---|
| 3257 |     osip_contact_to_str(ctct, rcontact); |
|---|
| 3258 | |
|---|
| 3259 | err: |
|---|
| 3260 | Â Â Â Â osip_contact_free(ctct); |
|---|
| 3261 | } |
|---|
| 3262 | |
|---|
| 3263 | PHAPI_EXPORT int |
|---|
| 3264 | phvlRegister(int vlid) |
|---|
| 3265 | { |
|---|
| 3266 |     struct vline *vl; |
|---|
| 3267 |     int ret = -1; |
|---|
| 3268 |     char utmp[256]; |
|---|
| 3269 |     char stmp[256]; |
|---|
| 3270 |     char *server; |
|---|
| 3271 | Â Â Â Â osip_message_t *msg=0; |
|---|
| 3272 | |
|---|
| 3273 |     if (!phIsInitialized) |
|---|
| 3274 |         return -PH_NOTINIT; |
|---|
| 3275 | |
|---|
| 3276 | Â Â Â Â vl =Â ph_vlid2vline(vlid); |
|---|
| 3277 | |
|---|
| 3278 | Â Â Â Â assert(vl!=NULL); |
|---|
| 3279 | Â Â Â Â assert(vl->rusername!=NULL); |
|---|
| 3280 | Â Â Â Â assert(vl->server!=NULL); |
|---|
| 3281 | |
|---|
| 3282 |     if (vl->displayname) |
|---|
| 3283 |         snprintf(utmp, sizeof(utmp), "\"%s\" <sip:%s@%s>", vl->displayname, vl->rusername, vl->server); |
|---|
| 3284 | Â Â Â Â else |
|---|
| 3285 |         snprintf(utmp, sizeof(utmp), "sip:%s@%s", vl->rusername, vl->server); |
|---|
| 3286 | |
|---|
| 3287 | Â Â Â Â server =Â stmp; |
|---|
| 3288 |     if (vl->port && vl->port != 5060) |
|---|
| 3289 | Â Â Â Â { |
|---|
| 3290 | Â Â Â Â Â Â Â Â /*Â Â Â snprintf(stmp, sizeof(stmp), "sip:%s@%s:%d", vl->rusername, vl->server, vl->port); */ |
|---|
| 3291 |         snprintf(stmp, sizeof(stmp), "sip:%s:%d", vl->server, vl->port); |
|---|
| 3292 | Â Â Â Â } |
|---|
| 3293 | Â Â Â Â else |
|---|
| 3294 | Â Â Â Â { |
|---|
| 3295 | Â Â Â Â Â Â Â Â /*Â Â Â snprintf(stmp, sizeof(stmp), "sip:%s@%s:%d", vl->rusername, vl->server, vl->port); */ |
|---|
| 3296 |         snprintf(stmp, sizeof(stmp), "sip:%s", vl->server); |
|---|
| 3297 | Â Â Â Â } |
|---|
| 3298 | |
|---|
| 3299 | Â Â Â Â eXosip_lock(); |
|---|
| 3300 | |
|---|
| 3301 |     if (vl->rid > 0) { |
|---|
| 3302 |         ret = eXosip_register_build_register(vl->rid, vl->regTimeout, &msg); |
|---|
| 3303 |         if (ret) |
|---|
| 3304 | Â Â Â Â Â Â Â Â Â Â Â Â vl->rid =Â -2; |
|---|
| 3305 |     } else { |
|---|
| 3306 | #if 1 |
|---|
| 3307 |         char *rcontact; |
|---|
| 3308 | |
|---|
| 3309 |         ph_fix_reg_contact(vl, &rcontact); |
|---|
| 3310 | |
|---|
| 3311 |         vl->rid = eXosip_register_build_initial_register(utmp, server, rcontact, vl->regTimeout, &msg); |
|---|
| 3312 |         if (vl->proxy) |
|---|
| 3313 |             osip_message_set_route(msg, vl->proxy); |
|---|
| 3314 |         if (rcontact != vl->contact) |
|---|
| 3315 | Â Â Â Â Â Â Â Â Â Â Â Â osip_free(rcontact); |
|---|
| 3316 | Â Â Â Â } |
|---|
| 3317 | #else |
|---|
| 3318 |         if (vl->proxy && vl->proxy[0] == '<') { |
|---|
| 3319 |             int size = strlen(vl->proxy); |
|---|
| 3320 |             char *proxy = alloca(size-1); |
|---|
| 3321 |             strncpy(proxy, vl->proxy + 1, size - 2); |
|---|
| 3322 | Â Â Â Â Â Â Â Â Â Â Â Â proxy[size-2]Â =Â '\0'; |
|---|
| 3323 |             vl->rid = eXosip_register_build_initial_register(utmp, proxy, vl->contact, vl->regTimeout, &msg); |
|---|
| 3324 | Â Â Â Â Â Â Â Â } |
|---|
| 3325 | Â Â Â Â Â Â Â Â else |
|---|
| 3326 | Â Â Â Â Â Â Â Â { |
|---|
| 3327 |             if (vl->proxy) |
|---|
| 3328 |                 vl->rid = eXosip_register_build_initial_register(utmp, vl->proxy, vl->contact, vl->regTimeout, &msg); |
|---|
| 3329 | Â Â Â Â Â Â Â Â Â Â Â Â else |
|---|
| 3330 |                 vl->rid = eXosip_register_build_initial_register(utmp, server, vl->contact, vl->regTimeout, &msg); |
|---|
| 3331 | |
|---|
| 3332 | Â Â Â Â Â Â Â Â } |
|---|
| 3333 | Â Â Â Â } |
|---|
| 3334 | #endif |
|---|
| 3335 | |
|---|
| 3336 |     if (vl->rid >= 0) |
|---|
| 3337 | Â Â Â Â { |
|---|
| 3338 |         osip_message_set_allow(msg, "INVITE, ACK, BYE, CANCEL, OPTIONS, REFER, NOTIFY, SUBSCRIBE, REGISTER, MESSAGE"); |
|---|
| 3339 |         ph_apply_customizations(msg, NULL, NULL); |
|---|
| 3340 |         ret = eXosip_register_send_register(vl->rid, msg); |
|---|
| 3341 | Â Â Â Â Â Â Â Â msg =Â 0; |
|---|
| 3342 |         if (ret == 0) |
|---|
| 3343 | Â Â Â Â Â Â Â Â { |
|---|
| 3344 | Â Â Â Â Â Â Â Â Â Â Â Â ret =Â vl->rid; |
|---|
| 3345 | Â Â Â Â Â Â Â Â Â Â Â Â vl->lastRegTime =Â time(0); |
|---|
| 3346 | Â Â Â Â Â Â Â Â } |
|---|
| 3347 | Â Â Â Â } |
|---|
| 3348 | |
|---|
| 3349 | Â Â Â Â eXosip_unlock(); |
|---|
| 3350 |     if (msg) |
|---|
| 3351 | Â Â Â Â Â Â osip_message_free(msg); |
|---|
| 3352 |     return ret; |
|---|
| 3353 | |
|---|
| 3354 | } |
|---|
| 3355 | |
|---|
| 3356 | PHAPI_EXPORT int phvlSetRegisterTimeOut(int vlid,int regTimeout) |
|---|
| 3357 | { |
|---|
| 3358 |     struct vline *vl; |
|---|
| 3359 | |
|---|
| 3360 |     if (!phIsInitialized) |
|---|
| 3361 |         return -PH_NOTINIT; |
|---|
| 3362 | |
|---|
| 3363 | Â Â Â Â vl =Â ph_vlid2vline(vlid); |
|---|
| 3364 | |
|---|
| 3365 |     if (vl) { |
|---|
| 3366 | Â Â Â Â Â Â Â Â vl->regTimeout =Â regTimeout; |
|---|
| 3367 |         eXosip_register_update_timeout(vl->rid, regTimeout); |
|---|
| 3368 |         return 0; |
|---|
| 3369 | Â Â Â Â } |
|---|
| 3370 |     return -1; |
|---|
| 3371 | } |
|---|
| 3372 | |
|---|
| 3373 | PHAPI_EXPORT int |
|---|
| 3374 | phSendDtmf(int cid, int dtmfEvent, int mode) |
|---|
| 3375 | { |
|---|
| 3376 | Â Â Â Â phcall_t *ca; |
|---|
| 3377 |     char buf[64]; |
|---|
| 3378 |     char *ctt; |
|---|
| 3379 |     int i = -1; |
|---|
| 3380 | Â Â Â Â osip_message_t *msg; |
|---|
| 3381 | |
|---|
| 3382 |     if (!phIsInitialized) |
|---|
| 3383 |         return -PH_NOTINIT; |
|---|
| 3384 | |
|---|
| 3385 | Â Â Â Â ca =Â ph_locate_call_by_cid(cid); |
|---|
| 3386 | |
|---|
| 3387 |     if (!ca) |
|---|
| 3388 |         return -PH_BADCID; |
|---|
| 3389 | |
|---|
| 3390 |     if (mode & (PH_DTMF_MODE_SIP|PH_DTMF_MODE_SIPRELAY)) |
|---|
| 3391 | Â Â Â Â { |
|---|
| 3392 |         if (mode & PH_DTMF_MODE_SIP) |
|---|
| 3393 | Â Â Â Â Â Â Â Â { |
|---|
| 3394 | Â Â Â Â Â Â Â Â Â Â Â Â ctt =Â "application/dtmf"; |
|---|
| 3395 |             snprintf(buf, sizeof(buf), "%c", dtmfEvent); |
|---|
| 3396 | Â Â Â Â Â Â Â Â } |
|---|
| 3397 | Â Â Â Â Â Â Â Â else |
|---|
| 3398 | Â Â Â Â Â Â Â Â { |
|---|
| 3399 |             char sipEvent[3] = { 0, 0, 0 }; |
|---|
| 3400 | Â Â Â Â Â Â Â Â Â Â Â Â ctt =Â "application/dtmf-relay"; |
|---|
| 3401 |             if (dtmfEvent == '!') |
|---|
| 3402 | Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 3403 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â sipEvent[0]Â =Â '1'; |
|---|
| 3404 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â sipEvent[1]Â =Â '6'; |
|---|
| 3405 | Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 3406 | Â Â Â Â Â Â Â Â Â Â Â Â else |
|---|
| 3407 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â sipEvent[0]Â =Â dtmfEvent; |
|---|
| 3408 | |
|---|
| 3409 |             snprintf(buf, sizeof(buf), "Signal=%s\r\nDuration=250\r\n", sipEvent); |
|---|
| 3410 | Â Â Â Â Â Â Â Â } |
|---|
| 3411 | |
|---|
| 3412 | Â Â Â Â Â Â Â Â eXosip_lock(); |
|---|
| 3413 | |
|---|
| 3414 |         i = eXosip_call_build_info(ca->did, &msg), |
|---|
| 3415 |                 ph_req_set_body(msg, buf, ctt); |
|---|
| 3416 |         osip_message_set_contact(msg, ph_get_call_contact(ca)); |
|---|
| 3417 |         ph_apply_customizations(msg, NULL, NULL); |
|---|
| 3418 |         i = eXosip_call_send_request(ca->did, msg); |
|---|
| 3419 | |
|---|
| 3420 | Â Â Â Â Â Â Â Â eXosip_unlock(); |
|---|
| 3421 | |
|---|
| 3422 |         if (!(mode & PH_DTMF_MODE_ALLRTP)) /* do we need to send DTMF in RTP stream? */ |
|---|
| 3423 |             return i; |
|---|
| 3424 | |
|---|
| 3425 | Â Â Â Â } |
|---|
| 3426 | |
|---|
| 3427 |     if (!ph_call_hasaudio(ca)) |
|---|
| 3428 | Â Â Â Â { |
|---|
| 3429 |         if (!i) |
|---|
| 3430 |             return 0;  /* we've managed to send using SIP INFO request */ |
|---|
| 3431 | |
|---|
| 3432 |         return -PH_NOMEDIA; |
|---|
| 3433 | Â Â Â Â } |
|---|
| 3434 | |
|---|
| 3435 |     return ph_msession_send_dtmf(ca->mses, dtmfEvent, mode); |
|---|
| 3436 | |
|---|
| 3437 | } |
|---|
| 3438 | |
|---|
| 3439 | |
|---|
| 3440 | PHAPI_EXPORT phStream * |
|---|
| 3441 | phPlaySoundFile(const char *fileName , int loop, const char * deviceid) |
|---|
| 3442 | { |
|---|
| 3443 |     if (!phIsInitialized) |
|---|
| 3444 |         return NULL; |
|---|
| 3445 | |
|---|
| 3446 |     return phms_audio_play_sound_file(fileName,loop,deviceid,phcb->soundFileStopped); |
|---|
| 3447 | } |
|---|
| 3448 | |
|---|
| 3449 | PHAPI_EXPORT int |
|---|
| 3450 | phSetSoundFileGain( phStream * stream, float gain) |
|---|
| 3451 | { |
|---|
| 3452 |     if (!phIsInitialized) |
|---|
| 3453 |         return -PH_NOTINIT; |
|---|
| 3454 | |
|---|
| 3455 |     return phms_audio_set_sound_file_gain(stream,gain); |
|---|
| 3456 | } |
|---|
| 3457 | |
|---|
| 3458 | PHAPI_EXPORT int |
|---|
| 3459 | phSendSoundFile(int cid, const char *fileName) |
|---|
| 3460 | { |
|---|
| 3461 | Â Â Â Â phcall_t *ca; |
|---|
| 3462 | |
|---|
| 3463 |     if (!phIsInitialized) |
|---|
| 3464 |         return -PH_NOTINIT; |
|---|
| 3465 | |
|---|
| 3466 | Â Â Â Â ca =Â ph_locate_call_by_cid(cid); |
|---|
| 3467 | |
|---|
| 3468 |     if (!ca) |
|---|
| 3469 |         return -PH_BADCID; |
|---|
| 3470 | |
|---|
| 3471 |     if (!ph_call_hasaudio(ca)) |
|---|
| 3472 |         return -PH_NOMEDIA; |
|---|
| 3473 | |
|---|
| 3474 |     return ph_msession_send_sound_file(ca->mses, fileName); |
|---|
| 3475 | } |
|---|
| 3476 | |
|---|
| 3477 | PHAPI_EXPORT int |
|---|
| 3478 | phStopSoundFile(Â phStream *Â stream) |
|---|
| 3479 | { |
|---|
| 3480 |     if (!phIsInitialized) |
|---|
| 3481 |         return -PH_NOTINIT; |
|---|
| 3482 | |
|---|
| 3483 |     return phms_audio_stop_sound_file(stream); |
|---|
| 3484 | } |
|---|
| 3485 | |
|---|
| 3486 | PHAPI_EXPORT int |
|---|
| 3487 | phSetSpeakerVolume(int cid, int volume) |
|---|
| 3488 | { |
|---|
| 3489 | #if 0 |
|---|
| 3490 | Â Â Â Â phcall_t *ca = ph_locate_call_by_cid(cid); |
|---|
| 3491 | |
|---|
| 3492 | Â Â Â Â if (!ca) |
|---|
| 3493 | Â Â Â Â Â Â Â Â return -PH_BADCID; |
|---|
| 3494 | |
|---|
| 3495 | Â Â Â Â return(ph_media_set_spkvol(ca, volume)); |
|---|
| 3496 | #else |
|---|
| 3497 |     return 0; |
|---|
| 3498 | #endif |
|---|
| 3499 | } |
|---|
| 3500 | |
|---|
| 3501 | |
|---|
| 3502 | PHAPI_EXPORT int |
|---|
| 3503 | phSetRecLevel(int cid, int level) |
|---|
| 3504 | { |
|---|
| 3505 | #if 0 |
|---|
| 3506 | Â Â Â Â phcall_t *ca = ph_locate_call_by_cid(cid); |
|---|
| 3507 | |
|---|
| 3508 | Â Â Â Â if (!ca) |
|---|
| 3509 | Â Â Â Â Â Â Â Â return -PH_BADCID; |
|---|
| 3510 | |
|---|
| 3511 | Â Â Â Â return(ph_media_set_recvol(ca, level)); |
|---|
| 3512 | #else |
|---|
| 3513 |     return 0; |
|---|
| 3514 | #endif |
|---|
| 3515 | } |
|---|
| 3516 | |
|---|
| 3517 | |
|---|
| 3518 | |
|---|
| 3519 | |
|---|
| 3520 | PHAPI_EXPORT int |
|---|
| 3521 | phAddVline(const char* username, const char *server, const char* proxy, int regTimeout) |
|---|
| 3522 | { |
|---|
| 3523 |     return phAddVline2(NULL, username, server, proxy, regTimeout); |
|---|
| 3524 | } |
|---|
| 3525 | |
|---|
| 3526 | /* |
|---|
| 3527 | Â scrap the :port part from the host uri |
|---|
| 3528 | Â */ |
|---|
| 3529 | static const char * |
|---|
| 3530 | ph_scrap_port(char *buf, int bufsize, const char *host, int *port) |
|---|
| 3531 | { |
|---|
| 3532 | |
|---|
| 3533 | Â Â Â Â assert(buf !=Â 0); |
|---|
| 3534 | Â Â Â Â assert(port !=Â 0); |
|---|
| 3535 | |
|---|
| 3536 | Â Â Â Â *port =Â 0; |
|---|
| 3537 | |
|---|
| 3538 |     if (!host) |
|---|
| 3539 |         return 0; |
|---|
| 3540 | |
|---|
| 3541 |     if (!strchr(host, ':')) |
|---|
| 3542 |         return host; |
|---|
| 3543 | |
|---|
| 3544 |     osip_strncpy(buf, host, bufsize-1); |
|---|
| 3545 |     host = strchr(buf, ':'); |
|---|
| 3546 |     if (host) |
|---|
| 3547 | Â Â Â Â { |
|---|
| 3548 |         *( char *) host = 0; |
|---|
| 3549 | Â Â Â Â Â Â Â Â *port =Â atoi(host+1); |
|---|
| 3550 | Â Â Â Â } |
|---|
| 3551 | |
|---|
| 3552 |     return buf; |
|---|
| 3553 | |
|---|
| 3554 | } |
|---|
| 3555 | |
|---|
| 3556 | static const char emptystr[] = { 0 }; |
|---|
| 3557 | #define nonull(x) ((x) ? (x) : emptystr) |
|---|
| 3558 | |
|---|
| 3559 | PHAPI_EXPORT int |
|---|
| 3560 | phAddVline2(const char *displayname, const char* username, const char *server, const char* proxy, int regTimeout) |
|---|
| 3561 | { |
|---|
| 3562 |     return phAddVline3(displayname, username, server, proxy, regTimeout, 0); |
|---|
| 3563 | } |
|---|
| 3564 | PHAPI_EXPORT int |
|---|
| 3565 | phAddVline3(const char *displayname, const char* username, const char *server, const char* proxy, int regTimeout, int mobility) |
|---|
| 3566 | |
|---|
| 3567 | { |
|---|
| 3568 |     struct vline *vl; |
|---|
| 3569 |     int oldTimeout = 0; |
|---|
| 3570 |     char srvbuf[256]; |
|---|
| 3571 |     const char *srv2; |
|---|
| 3572 |     int port; |
|---|
| 3573 | |
|---|
| 3574 |     DBG_SIP_NEGO("AddVline3(dn = %s, un=%s, srv=%s pxy=%s regT=%d)\n", nonull(displayname), nonull(username), nonull(server), |
|---|
| 3575 |             nonull(proxy), regTimeout); |
|---|
| 3576 | |
|---|
| 3577 |     if (!phIsInitialized) |
|---|
| 3578 |         return -PH_NOTINIT; |
|---|
| 3579 | |
|---|
| 3580 |     srv2 = ph_scrap_port(srvbuf, sizeof(srvbuf), server, &port); |
|---|
| 3581 | |
|---|
| 3582 |     if (!port) |
|---|
| 3583 | Â Â Â Â Â Â Â Â port =Â 5060; |
|---|
| 3584 | |
|---|
| 3585 |     if (!username) |
|---|
| 3586 | Â Â Â Â Â Â Â Â username =Â ""; |
|---|
| 3587 | |
|---|
| 3588 | |
|---|
| 3589 |     vl = ph_find_matching_vline3(username, srv2, port, 0); |
|---|
| 3590 | |
|---|
| 3591 |     if (0 < regTimeout && regTimeout < 100) |
|---|
| 3592 | Â Â Â Â Â Â Â Â regTimeout =Â 100; |
|---|
| 3593 | |
|---|
| 3594 |     if (!vl) |
|---|
| 3595 | Â Â Â Â { |
|---|
| 3596 | Â Â Â Â Â Â Â Â vl =Â vline_alloc(); |
|---|
| 3597 |         if (!vl) |
|---|
| 3598 |             return -PH_NORESOURCES; |
|---|
| 3599 | |
|---|
| 3600 | Â Â Â Â Â Â Â Â vl->rusername =Â osip_strdup(username); |
|---|
| 3601 | Â Â Â Â Â Â Â Â vl->nrusername =Â osip_strdup(username); |
|---|
| 3602 | Â Â Â Â } |
|---|
| 3603 | Â Â Â Â else |
|---|
| 3604 | Â Â Â Â { |
|---|
| 3605 |         if (vl->proxy) |
|---|
| 3606 | Â Â Â Â Â Â Â Â { |
|---|
| 3607 | Â Â Â Â Â Â Â Â Â Â Â Â osip_free(vl->proxy); |
|---|
| 3608 | Â Â Â Â Â Â Â Â Â Â Â Â vl->proxy =Â 0; |
|---|
| 3609 | Â Â Â Â Â Â Â Â } |
|---|
| 3610 | |
|---|
| 3611 |         if (vl->displayname) |
|---|
| 3612 | Â Â Â Â Â Â Â Â { |
|---|
| 3613 | Â Â Â Â Â Â Â Â Â Â Â Â osip_free(vl->displayname); |
|---|
| 3614 | Â Â Â Â Â Â Â Â Â Â Â Â vl->displayname =Â 0; |
|---|
| 3615 | Â Â Â Â Â Â Â Â } |
|---|
| 3616 | |
|---|
| 3617 |         if (vl->contact) |
|---|
| 3618 | Â Â Â Â Â Â Â Â { |
|---|
| 3619 | Â Â Â Â Â Â Â Â Â Â Â Â osip_free(vl->contact); |
|---|
| 3620 | Â Â Â Â Â Â Â Â Â Â Â Â vl->contact =Â 0; |
|---|
| 3621 | Â Â Â Â Â Â Â Â } |
|---|
| 3622 | Â Â Â Â Â Â Â Â oldTimeout =Â vl->regTimeout; |
|---|
| 3623 | |
|---|
| 3624 | Â Â Â Â } |
|---|
| 3625 | |
|---|
| 3626 | Â Â Â Â vl->port =Â port; |
|---|
| 3627 | |
|---|
| 3628 |     if (nonempty(proxy)) |
|---|
| 3629 | Â Â Â Â { |
|---|
| 3630 |         if (0 == strstr(proxy, "sip:")) |
|---|
| 3631 | Â Â Â Â Â Â Â Â { |
|---|
| 3632 |             int l = 15 + strlen(proxy); |
|---|
| 3633 | Â Â Â Â Â Â Â Â Â Â Â Â vl->proxy =Â osip_malloc(l); |
|---|
| 3634 |             snprintf(vl->proxy, l, "sip:%s", proxy); |
|---|
| 3635 | Â Â Â Â Â Â Â Â } |
|---|
| 3636 | Â Â Â Â Â Â Â Â else |
|---|
| 3637 | Â Â Â Â Â Â Â Â Â Â Â Â vl->proxy =Â osip_strdup(proxy); |
|---|
| 3638 | Â Â Â Â } |
|---|
| 3639 | |
|---|
| 3640 | |
|---|
| 3641 | |
|---|
| 3642 |     if (nonempty(srv2) && !vl->server) |
|---|
| 3643 | Â Â Â Â Â Â Â Â vl->server =Â osip_strdup(srv2); |
|---|
| 3644 | |
|---|
| 3645 |     if (nonempty(displayname)) |
|---|
| 3646 | Â Â Â Â Â Â Â Â vl->displayname =Â osip_strdup(displayname); |
|---|
| 3647 | |
|---|
| 3648 | Â Â Â Â vl->regTimeout =Â regTimeout; |
|---|
| 3649 | |
|---|
| 3650 | Â Â Â Â if(vcontact[0]) |
|---|
| 3651 | Â Â Â Â Â Â Â Â vl->contact =Â osip_strdup(vcontact); |
|---|
| 3652 | Â Â Â Â else |
|---|
| 3653 | Â Â Â Â { |
|---|
| 3654 |         char ctct[512]; |
|---|
| 3655 | |
|---|
| 3656 |         ph_build_contact(ctct, sizeof(ctct), vl); |
|---|
| 3657 | Â Â Â Â Â Â Â Â vl->contact =Â osip_strdup(ctct); |
|---|
| 3658 | |
|---|
| 3659 | Â Â Â Â } |
|---|
| 3660 | |
|---|
| 3661 |     if (checkmobility(mobility,PH_LINE_MOBILITY_FIXED)) |
|---|
| 3662 |         add_contact_param(vl, "mobility", "fixed", FALSE); |
|---|
| 3663 |     else if (checkmobility(mobility, PH_LINE_MOBILITY_MOBILE)) |
|---|
| 3664 |         add_contact_param(vl, "mobility", "mobile", FALSE); |
|---|
| 3665 |     else if (checkmobility(mobility,PH_LINE_MOBILITY_PHONE)) |
|---|
| 3666 |         add_contact_param(vl, "user", "phone", TRUE); |
|---|
| 3667 | |
|---|
| 3668 |     if ((mobility & PH_USE_RFC5626) == PH_USE_RFC5626) { |
|---|
| 3669 | Â Â Â Â Â Â Â Â eXosip_set_keepalive_hook(ph_generate_rfc5626_probe); |
|---|
| 3670 | Â Â Â Â Â Â Â Â // add_contact_param(vl, "ob", 0, TRUE); |
|---|
| 3671 | Â Â Â Â } |
|---|
| 3672 | |
|---|
| 3673 | Â Â Â Â vl->mobility =Â mobility; |
|---|
| 3674 | |
|---|
| 3675 |     if (nonempty(srv2) && (oldTimeout > 0 || regTimeout > 0)) |
|---|
| 3676 | Â Â Â Â Â Â Â Â phvlRegister(ph_vline2vlid(vl)); |
|---|
| 3677 | |
|---|
| 3678 |     return ph_vline2vlid(vl); |
|---|
| 3679 | } |
|---|
| 3680 | |
|---|
| 3681 | |
|---|
| 3682 | PHAPI_EXPORT int |
|---|
| 3683 | phDelVline(int vlid) |
|---|
| 3684 | { |
|---|
| 3685 |     struct vline *vl; |
|---|
| 3686 | Â Â Â Â phcall_t *ca; |
|---|
| 3687 | |
|---|
| 3688 |     if (!phIsInitialized) |
|---|
| 3689 |         return -PH_NOTINIT; |
|---|
| 3690 | |
|---|
| 3691 |     if (!(vl = ph_valid_vlid(vlid))) |
|---|
| 3692 |         return -PH_BADVLID; |
|---|
| 3693 | |
|---|
| 3694 | Â Â Â Â /* forbid deletion of the lines which have pending calls */ |
|---|
| 3695 | Â Â Â Â for(ca =Â ph_calls;Â ca <Â &ph_calls[PH_MAX_CALLS];Â ca++) |
|---|
| 3696 | Â Â Â Â { |
|---|
| 3697 |         if (ca->vlid == vlid && ca->cid > 0) |
|---|
| 3698 |             return -PH_VLBUSY; |
|---|
| 3699 | Â Â Â Â } |
|---|
| 3700 | |
|---|
| 3701 | |
|---|
| 3702 |     if (vl->pub.timeout) |
|---|
| 3703 |         phLinePublish2(vlid, vl->pub.uri, 0, 0, 0, 0); |
|---|
| 3704 | |
|---|
| 3705 | Â Â Â Â /* |
|---|
| 3706 | Â Â Â if the line has an associatied timeout, |
|---|
| 3707 | Â Â Â it means it is regsitered on some server, |
|---|
| 3708 | Â Â Â so we need to unregister |
|---|
| 3709 | Â Â Â Â Â */ |
|---|
| 3710 |     if (vl->regTimeout) |
|---|
| 3711 | Â Â Â Â { |
|---|
| 3712 | Â Â Â Â Â Â Â Â osip_message_t *msg; |
|---|
| 3713 | |
|---|
| 3714 | Â Â Â Â Â Â Â Â eXosip_lock(); |
|---|
| 3715 |         eXosip_register_build_register(vl->rid, 0, &msg); |
|---|
| 3716 |         eXosip_register_send_register(vl->rid, msg); |
|---|
| 3717 | Â Â Â Â Â Â Â Â vl->regTimeout =Â 0; |
|---|
| 3718 | Â Â Â Â Â Â Â Â vl->used =Â VL_DELETING; |
|---|
| 3719 | Â Â Â Â Â Â Â Â eXosip_unlock(); |
|---|
| 3720 | |
|---|
| 3721 | Â Â Â Â } |
|---|
| 3722 | |
|---|
| 3723 |     if (vl->used != VL_DELETING) |
|---|
| 3724 |         return 0; |
|---|
| 3725 | |
|---|
| 3726 |     return 0; |
|---|
| 3727 | } |
|---|
| 3728 | |
|---|
| 3729 | |
|---|
| 3730 | |
|---|
| 3731 | PHAPI_EXPORT int phChangeAudioDeviceIn(const char *devstr) |
|---|
| 3732 | { |
|---|
| 3733 |     if (devstr) |
|---|
| 3734 |         osip_strncpy(phcfg.audio_dev_in, devstr, sizeof(phcfg.audio_dev_in)-1); |
|---|
| 3735 | |
|---|
| 3736 |     return 0; |
|---|
| 3737 | } |
|---|
| 3738 | |
|---|
| 3739 | PHAPI_EXPORT int phChangeAudioDeviceOut(const char *devstr) |
|---|
| 3740 | { |
|---|
| 3741 |     if (devstr) |
|---|
| 3742 |         osip_strncpy(phcfg.audio_dev_out, devstr, sizeof(phcfg.audio_dev_out)-1); |
|---|
| 3743 | Â Â Â Â |
|---|
| 3744 |     return 0; |
|---|
| 3745 | } |
|---|
| 3746 | |
|---|
| 3747 | PHAPI_EXPORT int phChangeVideoDevices(const char *devstr) |
|---|
| 3748 | { |
|---|
| 3749 |     if (devstr) |
|---|
| 3750 |         osip_strncpy(phcfg.video_config.video_device, devstr, sizeof(phcfg.video_config.video_device)-1); |
|---|
| 3751 | Â Â Â Â |
|---|
| 3752 |     return 0; |
|---|
| 3753 | } |
|---|
| 3754 | |
|---|
| 3755 | static struct vline * |
|---|
| 3756 | vline_alloc() |
|---|
| 3757 | { |
|---|
| 3758 |     int i; |
|---|
| 3759 | |
|---|
| 3760 | Â Â Â Â for(i =Â 0;Â i <Â PH_MAX_VLINES;Â i++) |
|---|
| 3761 | Â Â Â Â { |
|---|
| 3762 |         struct vline *vl = ph_vlines + i; |
|---|
| 3763 | |
|---|
| 3764 |         if (!vl->used) |
|---|
| 3765 | Â Â Â Â Â Â Â Â { |
|---|
| 3766 |             memset(vl, 0, sizeof(*vl)); |
|---|
| 3767 | Â Â Â Â Â Â Â Â Â Â Â Â vl->used =Â 1; |
|---|
| 3768 | Â Â Â Â Â Â Â Â Â Â Â Â vl->port =Â 0; |
|---|
| 3769 |             return vl; |
|---|
| 3770 | Â Â Â Â Â Â Â Â } |
|---|
| 3771 | |
|---|
| 3772 | Â Â Â Â } |
|---|
| 3773 |     return 0; |
|---|
| 3774 | } |
|---|
| 3775 | |
|---|
| 3776 | static void |
|---|
| 3777 | vline_free(struct vline *vl) |
|---|
| 3778 | { |
|---|
| 3779 |     if (vl->used) |
|---|
| 3780 | Â Â Â Â { |
|---|
| 3781 | Â Â Â Â Â Â Â Â osip_free(vl->rusername); |
|---|
| 3782 | Â Â Â Â Â Â Â Â osip_free(vl->nrusername); |
|---|
| 3783 |         if (vl->server) |
|---|
| 3784 | Â Â Â Â Â Â Â Â Â Â Â Â osip_free(vl->server); |
|---|
| 3785 |         if (vl->proxy) |
|---|
| 3786 | Â Â Â Â Â Â Â Â Â Â Â Â osip_free(vl->proxy); |
|---|
| 3787 |         if (vl->displayname) |
|---|
| 3788 | Â Â Â Â Â Â Â Â Â Â Â Â osip_free(vl->displayname); |
|---|
| 3789 |         if (vl->followme) |
|---|
| 3790 | Â Â Â Â Â Â Â Â Â Â Â Â osip_free(vl->followme); |
|---|
| 3791 |         if (vl->contact) |
|---|
| 3792 | Â Â Â Â Â Â Â Â Â Â Â Â osip_free(vl->contact); |
|---|
| 3793 |         if (vl->pub.etag) |
|---|
| 3794 | Â Â Â Â Â Â Â Â Â Â Â Â osip_free(vl->pub.etag); |
|---|
| 3795 |         if (vl->pub.uri) |
|---|
| 3796 | Â Â Â Â Â Â Â Â Â Â Â Â osip_free(vl->pub.uri); |
|---|
| 3797 |         if (vl->pub.evt) |
|---|
| 3798 | Â Â Â Â Â Â Â Â Â Â Â Â osip_free(vl->pub.evt); |
|---|
| 3799 |         if (vl->pub.ctt) |
|---|
| 3800 | Â Â Â Â Â Â Â Â Â Â Â Â osip_free(vl->pub.ctt); |
|---|
| 3801 |         if (vl->pub.body) |
|---|
| 3802 | Â Â Â Â Â Â Â Â Â Â Â Â osip_free(vl->pub.body); |
|---|
| 3803 | |
|---|
| 3804 | |
|---|
| 3805 | Â Â Â Â Â Â Â Â vl->used =Â 0; |
|---|
| 3806 | Â Â Â Â } |
|---|
| 3807 | } |
|---|
| 3808 | |
|---|
| 3809 | static struct vline * |
|---|
| 3810 | ph_find_vline_by_rid(int rid) |
|---|
| 3811 | { |
|---|
| 3812 |     int i; |
|---|
| 3813 | |
|---|
| 3814 | Â Â Â Â for(i =Â 0;Â i <Â PH_MAX_VLINES;Â i++) |
|---|
| 3815 | Â Â Â Â { |
|---|
| 3816 |         struct vline *vl = ph_vlines + i; |
|---|
| 3817 | |
|---|
| 3818 |         if (vl->used && rid == vl->rid) |
|---|
| 3819 |             return vl; |
|---|
| 3820 | Â Â Â Â } |
|---|
| 3821 |     return 0; |
|---|
| 3822 | } |
|---|
| 3823 | |
|---|
| 3824 | |
|---|
| 3825 | static osip_from_t * |
|---|
| 3826 | ph_parse_from(const char *userid) |
|---|
| 3827 | { |
|---|
| 3828 | Â Â Â Â osip_from_t *from; |
|---|
| 3829 | |
|---|
| 3830 | Â Â Â Â osip_from_init(&from); |
|---|
| 3831 |     if (!from) |
|---|
| 3832 |         return 0; |
|---|
| 3833 | |
|---|
| 3834 |     osip_from_parse(from, userid); |
|---|
| 3835 |     if (from->url && from->url->port && !strcmp(from->url->port, "5060")) |
|---|
| 3836 | Â Â Â Â { |
|---|
| 3837 | Â Â Â Â Â Â Â Â osip_free(from->url->port); |
|---|
| 3838 | Â Â Â Â Â Â Â Â from->url->port =Â NULL; |
|---|
| 3839 | Â Â Â Â } |
|---|
| 3840 | |
|---|
| 3841 |     return from; |
|---|
| 3842 | |
|---|
| 3843 | } |
|---|
| 3844 | |
|---|
| 3845 | static struct vline * |
|---|
| 3846 | ph_find_matching_vline(const char *userid, int ignore) |
|---|
| 3847 | { |
|---|
| 3848 | Â Â Â Â osip_from_t *from; |
|---|
| 3849 |     struct vline *vl; |
|---|
| 3850 |     char *host; |
|---|
| 3851 |     char hostport[256]; |
|---|
| 3852 |     char *uname; |
|---|
| 3853 | |
|---|
| 3854 | Â Â Â Â hostport[0]Â =Â 0; |
|---|
| 3855 | Â Â Â Â from =Â ph_parse_from(userid); |
|---|
| 3856 | |
|---|
| 3857 |     if (!from) |
|---|
| 3858 |         return 0; |
|---|
| 3859 | |
|---|
| 3860 |     if (from->url) |
|---|
| 3861 | Â Â Â Â Â Â Â Â uname =Â from->url->username; |
|---|
| 3862 | Â Â Â Â else |
|---|
| 3863 | Â Â Â Â Â Â Â Â uname =Â hostport; |
|---|
| 3864 | |
|---|
| 3865 | |
|---|
| 3866 |     if (!(ignore & PHM_IGNORE_PORT) && from->url && from->url->port) |
|---|
| 3867 | Â Â Â Â { |
|---|
| 3868 |         snprintf(hostport, sizeof(hostport), "%s:%s", from->url->host, from->url->port); |
|---|
| 3869 | Â Â Â Â Â Â Â Â host =Â hostport; |
|---|
| 3870 | Â Â Â Â } |
|---|
| 3871 |     else if (ignore & PHM_IGNORE_HOST) |
|---|
| 3872 | Â Â Â Â Â Â Â Â host =Â 0; |
|---|
| 3873 |     else if (from->url) |
|---|
| 3874 | Â Â Â Â { |
|---|
| 3875 | Â Â Â Â Â Â Â Â host =Â from->url->host; |
|---|
| 3876 | Â Â Â Â } |
|---|
| 3877 | Â Â Â Â else |
|---|
| 3878 | Â Â Â Â Â Â Â Â host =Â hostport; |
|---|
| 3879 | |
|---|
| 3880 |     vl = ph_find_matching_vline2(uname, host, ignore); |
|---|
| 3881 | |
|---|
| 3882 | Â Â Â Â osip_from_free(from); |
|---|
| 3883 | |
|---|
| 3884 |     return vl; |
|---|
| 3885 | |
|---|
| 3886 | } |
|---|
| 3887 | |
|---|
| 3888 | static size_t |
|---|
| 3889 | ph_generate_rfc5626_probe(int rid, const void *addr, int addrlen, char* buf, size_t bsize) |
|---|
| 3890 | { |
|---|
| 3891 |     struct vline* vl = ph_find_vline_by_rid(rid); |
|---|
| 3892 | Â Â Â Â StunMessage req; |
|---|
| 3893 |     int len; |
|---|
| 3894 | |
|---|
| 3895 |     if (!vl || !(vl->mobility & PH_USE_RFC5626)) |
|---|
| 3896 |         return 0; |
|---|
| 3897 | |
|---|
| 3898 |     memset(&req, 0, sizeof(StunMessage)); |
|---|
| 3899 |     stunBuildReqSimple( &req, 0, 0,0, 1); |
|---|
| 3900 |   len = stunEncodeMessage( &req, buf, bsize, 0 ); |
|---|
| 3901 | |
|---|
| 3902 |     return len; |
|---|
| 3903 | |
|---|
| 3904 | } |
|---|
| 3905 | |
|---|
| 3906 | |
|---|
| 3907 | static struct vline * |
|---|
| 3908 | ph_find_matching_vline2(const char *username, const char* host, int ignore) |
|---|
| 3909 | { |
|---|
| 3910 |     return ph_find_matching_vline3(username, host, 0, ignore); |
|---|
| 3911 | } |
|---|
| 3912 | |
|---|
| 3913 | static struct vline * |
|---|
| 3914 | ph_find_matching_vline3(const char *username, const char* host, int port, int ignore) |
|---|
| 3915 | { |
|---|
| 3916 |     int i; |
|---|
| 3917 |     int  hostlen; |
|---|
| 3918 |     int  unamelen; |
|---|
| 3919 |     struct vline *vl, *defaultvl = 0; |
|---|
| 3920 | |
|---|
| 3921 |     if (!username) |
|---|
| 3922 | Â Â Â Â Â Â Â Â username =Â ""; |
|---|
| 3923 | |
|---|
| 3924 |     hostlen = host ? strlen(host) : 0; |
|---|
| 3925 | Â Â Â Â unamelen =Â strlen(username); |
|---|
| 3926 | |
|---|
| 3927 |     if (port == 0) |
|---|
| 3928 | Â Â Â Â Â Â Â Â port =Â 5060; |
|---|
| 3929 | |
|---|
| 3930 | Â Â Â Â for(Â i =Â 0;Â i <Â PH_MAX_VLINES;Â i++) |
|---|
| 3931 | Â Â Â Â { |
|---|
| 3932 |         int len; |
|---|
| 3933 | Â Â Â Â Â Â Â Â vl =Â ph_vlines +Â i; |
|---|
| 3934 | |
|---|
| 3935 |         if (!vl->used) |
|---|
| 3936 | Â Â Â Â Â Â Â Â Â Â Â Â continue; |
|---|
| 3937 | |
|---|
| 3938 |         if (!vl->server) |
|---|
| 3939 | Â Â Â Â Â Â Â Â { |
|---|
| 3940 | Â Â Â Â Â Â Â Â Â Â Â Â defaultvl =Â vl; |
|---|
| 3941 | Â Â Â Â Â Â Â Â Â Â Â Â continue; |
|---|
| 3942 | Â Â Â Â Â Â Â Â } |
|---|
| 3943 | |
|---|
| 3944 | Â Â Â Â Â Â Â Â len =Â strlen(vl->server); |
|---|
| 3945 | |
|---|
| 3946 |         if ((ignore & PHM_IGNORE_HOST) || ((len == hostlen) && !strcasecmp(host, vl->server))) |
|---|
| 3947 | Â Â Â Â Â Â Â Â { |
|---|
| 3948 |             int nrlen = strlen(vl->nrusername); |
|---|
| 3949 | |
|---|
| 3950 | Â Â Â Â Â Â Â Â Â Â Â Â len =Â strlen(vl->rusername); |
|---|
| 3951 | |
|---|
| 3952 |             if ((len == unamelen) && !strcasecmp(username, vl->rusername) || |
|---|
| 3953 |               (nrlen == unamelen) && !strcasecmp(username, vl->nrusername)) |
|---|
| 3954 | Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 3955 |                 if (ignore & PHM_IGNORE_PORT) |
|---|
| 3956 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 3957 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â defaultvl =Â vl; |
|---|
| 3958 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â break; |
|---|
| 3959 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 3960 |                 if (port == vl->port) |
|---|
| 3961 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 3962 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â defaultvl =Â vl; |
|---|
| 3963 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â break; |
|---|
| 3964 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 3965 | Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 3966 | Â Â Â Â Â Â Â Â } |
|---|
| 3967 | Â Â Â Â } |
|---|
| 3968 | |
|---|
| 3969 |     return defaultvl; |
|---|
| 3970 | } |
|---|
| 3971 | |
|---|
| 3972 | static void |
|---|
| 3973 | ph_nat_refresh(struct vline *vl) |
|---|
| 3974 | { |
|---|
| 3975 |     char buf[128]; |
|---|
| 3976 |     char to[128]; |
|---|
| 3977 | Â Â Â Â assert(vl!=NULL); |
|---|
| 3978 | |
|---|
| 3979 |     if (!(vl->mobility & PH_USE_RFC5626)) { |
|---|
| 3980 |         ph_build_from(buf, sizeof(buf), vl); |
|---|
| 3981 |         snprintf(to, sizeof(to), "sip:ping@%s", vl->server); |
|---|
| 3982 |         phSendOptions(buf, to); |
|---|
| 3983 | Â Â Â Â } |
|---|
| 3984 | |
|---|
| 3985 | #if 0 |
|---|
| 3986 | Â Â Â Â int port; |
|---|
| 3987 | |
|---|
| 3988 | |
|---|
| 3989 | Â Â Â Â osip_uri_init(&uri); |
|---|
| 3990 |     osip_uri_parse(uri, (vl->proxy && vl->proxy[0]) ? vl->proxy : vl->server); |
|---|
| 3991 | |
|---|
| 3992 | Â Â Â Â port = atoi((uri->port && uri->port[0]) ? uri->port : "5060"); |
|---|
| 3993 | Â Â Â Â phPing(uri->host, port, 30); |
|---|
| 3994 | |
|---|
| 3995 | Â Â Â Â osip_uri_free(uri); |
|---|
| 3996 | #endif |
|---|
| 3997 | |
|---|
| 3998 | } |
|---|
| 3999 | |
|---|
| 4000 | static time_t last_vline_refresh, last_nat_refresh; |
|---|
| 4001 | static void |
|---|
| 4002 | ph_refresh_vlines() |
|---|
| 4003 | { |
|---|
| 4004 |     int nat_refresh_time = ( phcfg.transport == IPPROTO_UDP ) ? phcfg.nat_refresh_udp_time : phcfg.nat_refresh_tcp_time; |
|---|
| 4005 |     time_t now = time(NULL); |
|---|
| 4006 | |
|---|
| 4007 |     if (now - last_vline_refresh > 5) |
|---|
| 4008 | Â Â Â Â { |
|---|
| 4009 |         int i; |
|---|
| 4010 |         struct vline *vl; |
|---|
| 4011 | |
|---|
| 4012 | Â Â Â Â Â Â Â Â for(Â i =Â 0;Â i <Â PH_MAX_VLINES;Â i++) |
|---|
| 4013 | Â Â Â Â Â Â Â Â { |
|---|
| 4014 | Â Â Â Â Â Â Â Â Â Â Â Â vl =Â ph_vlines +Â i; |
|---|
| 4015 |             if (!vl->used) |
|---|
| 4016 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â continue; |
|---|
| 4017 | |
|---|
| 4018 | Â Â Â Â Â Â Â Â Â Â Â Â //it's now handled by eXosip_automatic_action() so no more need to do ti manually |
|---|
| 4019 | Â Â Â Â Â Â Â Â Â Â Â Â /*if (vl->server && vl->server[0] && vl->regTimeout > 0) |
|---|
| 4020 | Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 4021 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if ((now - vl->lastRegTime) > (vl->regTimeout - 10)) |
|---|
| 4022 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â phvlRegister(ph_vline2vlid(vl)); |
|---|
| 4023 | Â Â Â Â Â Â Â Â Â Â Â Â }*/ |
|---|
| 4024 |             if (vl->pub.timeout && (now - vl->pub.last) > (vl->pub.timeout - ph_resend_offset)) |
|---|
| 4025 | Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 4026 |                 phLinePublish2(ph_vline2vlid(vl), vl->pub.uri, 0, 0, 0, vl->pub.timeout); |
|---|
| 4027 | Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 4028 | Â Â Â Â Â Â Â Â } |
|---|
| 4029 | Â Â Â Â Â Â Â Â last_vline_refresh =Â time(0); |
|---|
| 4030 | Â Â Â Â } |
|---|
| 4031 | |
|---|
| 4032 | Â Â Â Â nat_refresh_time /=Â 1000;Â //nat_refresh_time is in ms ! |
|---|
| 4033 | Â Â Â Â //if (!phcfg.use_tunnel && phcfg.nat_refresh_time > 0) |
|---|
| 4034 |     if (nat_refresh_time > 0) |
|---|
| 4035 | Â Â Â Â { |
|---|
| 4036 |         int i; |
|---|
| 4037 |         struct vline *vl; |
|---|
| 4038 | |
|---|
| 4039 |         if (now - last_nat_refresh > nat_refresh_time) |
|---|
| 4040 | Â Â Â Â Â Â Â Â { |
|---|
| 4041 | Â Â Â Â Â Â Â Â Â Â Â Â for(Â i =Â 0;Â i <Â PH_MAX_VLINES;Â i++) |
|---|
| 4042 | Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 4043 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â vl =Â ph_vlines +Â i; |
|---|
| 4044 |                 if (!vl->used) |
|---|
| 4045 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â continue; |
|---|
| 4046 | |
|---|
| 4047 |                 if (vl->server && vl->server[0] && vl->regTimeout > ph_resend_offset) |
|---|
| 4048 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 4049 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ph_nat_refresh(vl); |
|---|
| 4050 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 4051 | Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 4052 | |
|---|
| 4053 | Â Â Â Â Â Â Â Â Â Â Â Â last_nat_refresh =Â time(0); |
|---|
| 4054 | Â Â Â Â Â Â Â Â } |
|---|
| 4055 | Â Â Â Â } |
|---|
| 4056 | |
|---|
| 4057 | |
|---|
| 4058 | } |
|---|
| 4059 | |
|---|
| 4060 | |
|---|
| 4061 | /* |
|---|
| 4062 | Â scan call marked for close and close them while delivering phCALLCLOSED to phApi client |
|---|
| 4063 | Â */ |
|---|
| 4064 | static void |
|---|
| 4065 | ph_scan_calls() |
|---|
| 4066 | { |
|---|
| 4067 |     int i; |
|---|
| 4068 | Â Â Â Â phcall_t *ca; |
|---|
| 4069 | |
|---|
| 4070 | Â Â Â Â ca =Â ph_calls; |
|---|
| 4071 |     for(i = PH_MAX_CALLS; i; i--, ca++) |
|---|
| 4072 | Â Â Â Â { |
|---|
| 4073 |         if (ca->cid > 0 && |
|---|
| 4074 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (ca->closereq || |
|---|
| 4075 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ((ph_call_hasaudio(ca)Â ||Â ph_call_hasvideo(ca))Â &&Â !ph_call_stream_alive(ca)))) |
|---|
| 4076 | Â Â Â Â Â Â Â Â { |
|---|
| 4077 | Â Â Â Â Â Â Â Â Â Â Â Â phCallStateInfo_t info; |
|---|
| 4078 |             int cid = ca->cid; |
|---|
| 4079 | |
|---|
| 4080 | Â Â Â Â Â Â Â Â Â Â Â Â clear(info); |
|---|
| 4081 | Â Â Â Â Â Â Â Â Â Â Â Â info.vlid =Â ca->vlid; |
|---|
| 4082 | Â Â Â Â Â Â Â Â Â Â Â Â info.event =Â phCALLCLOSED; |
|---|
| 4083 | |
|---|
| 4084 | Â Â Â Â Â Â Â Â Â Â Â Â ph_release_call(ca); |
|---|
| 4085 | |
|---|
| 4086 |             phcb->callProgress(cid, &info); |
|---|
| 4087 | Â Â Â Â Â Â Â Â } |
|---|
| 4088 | Â Â Â Â } |
|---|
| 4089 | |
|---|
| 4090 | } |
|---|
| 4091 | |
|---|
| 4092 | static char * |
|---|
| 4093 | ph_get_proxy(const char *userid) |
|---|
| 4094 | { |
|---|
| 4095 |     struct vline *vl = ph_find_matching_vline(userid, PHM_IGNORE_PORT); |
|---|
| 4096 | |
|---|
| 4097 |     if (!vl) |
|---|
| 4098 |         return ""; |
|---|
| 4099 | |
|---|
| 4100 |     return vl->proxy ? vl->proxy : ""; |
|---|
| 4101 | } |
|---|
| 4102 | |
|---|
| 4103 | |
|---|
| 4104 | static char * |
|---|
| 4105 | ph_get_call_contact(phcall_t *ca) |
|---|
| 4106 | { |
|---|
| 4107 |     struct vline *vl; |
|---|
| 4108 | Â Â Â Â assert(ca!=NULL); |
|---|
| 4109 | |
|---|
| 4110 | Â Â Â Â vl =Â ph_vlid2vline(ca->vlid); |
|---|
| 4111 |     if (!vl) |
|---|
| 4112 |         return 0; |
|---|
| 4113 | |
|---|
| 4114 |     return vl->contact; |
|---|
| 4115 | } |
|---|
| 4116 | |
|---|
| 4117 | |
|---|
| 4118 | static int |
|---|
| 4119 | ph_get_vline_id(const char *userid, const char *altid) |
|---|
| 4120 | { |
|---|
| 4121 | |
|---|
| 4122 |     struct vline *vl = ph_find_matching_vline(userid, PHM_IGNORE_PORT); |
|---|
| 4123 | |
|---|
| 4124 |     if (vl) |
|---|
| 4125 |         return ph_vline2vlid(vl); |
|---|
| 4126 | |
|---|
| 4127 |     if (nonempty(altid)) |
|---|
| 4128 | Â Â Â Â { |
|---|
| 4129 |         vl = ph_find_matching_vline(altid, PHM_IGNORE_PORT); |
|---|
| 4130 |         if (vl) |
|---|
| 4131 |             return ph_vline2vlid(vl); |
|---|
| 4132 | Â Â Â Â } |
|---|
| 4133 | |
|---|
| 4134 |     vl = ph_find_matching_vline(userid, PHM_IGNORE_HOST|PHM_IGNORE_PORT); |
|---|
| 4135 |     if (vl) |
|---|
| 4136 |         return ph_vline2vlid(vl); |
|---|
| 4137 | |
|---|
| 4138 | |
|---|
| 4139 |     if (nonempty(altid)) |
|---|
| 4140 | Â Â Â Â { |
|---|
| 4141 |         vl = ph_find_matching_vline(altid, PHM_IGNORE_HOST|PHM_IGNORE_PORT); |
|---|
| 4142 |         if (vl) |
|---|
| 4143 |             return ph_vline2vlid(vl); |
|---|
| 4144 | Â Â Â Â } |
|---|
| 4145 | |
|---|
| 4146 |     return 0; |
|---|
| 4147 | |
|---|
| 4148 | } |
|---|
| 4149 | |
|---|
| 4150 | static void ph_setup_payload(const char *ptstring) |
|---|
| 4151 | { |
|---|
| 4152 | Â Â Â Â PayloadType *rtppt; |
|---|
| 4153 | |
|---|
| 4154 | Â Â Â Â //DBG_CODEC_LOOKUP("trying to setup audio codec in eXosip: %s\n", ptstring, 0, 0); |
|---|
| 4155 | |
|---|
| 4156 |     if (ph_media_supported_payload(&rtppt, ptstring)) |
|---|
| 4157 | Â Â Â Â { |
|---|
| 4158 | Â Â Â Â Â Â Â Â char*Â fmtp =Â 0; |
|---|
| 4159 |         if (!strncasecmp(ptstring,"telephone-event", 15)) |
|---|
| 4160 | Â Â Â Â Â Â Â Â Â Â Â Â fmtp =Â osip_strdup("0-11"); |
|---|
| 4161 | |
|---|
| 4162 | |
|---|
| 4163 |         sdp_payload_list_add(&ph_audio_payloads, rtp_profile_get_payload_number_from_rtpmap(&av_profile, ptstring), payload_type_get_rtpmap(rtppt), fmtp, 0); |
|---|
| 4164 | Â Â Â Â Â Â Â Â DBG_CODEC_LOOKUP("added audio codec: %s\n",ptstring); |
|---|
| 4165 | Â Â Â Â }Â |
|---|
| 4166 | Â Â Â Â else |
|---|
| 4167 |         DBG_CODEC_LOOKUP("unsupported audio codec : %s not found in ortp profile or not supported by mediastreamer\n", ptstring); |
|---|
| 4168 | } |
|---|
| 4169 | |
|---|
| 4170 | #ifdef PHAPI_VIDEO_SUPPORT |
|---|
| 4171 | static void ph_setup_video_payload(const char *ptstring) |
|---|
| 4172 | { |
|---|
| 4173 | Â Â Â Â PayloadType *rtppt; |
|---|
| 4174 | Â Â Â Â |
|---|
| 4175 | Â Â Â Â //DBG_CODEC_LOOKUP("trying to setup video codec in eXosip: %s\n", ptstring, 0, 0); |
|---|
| 4176 | |
|---|
| 4177 |     if (ph_media_supported_payload(&rtppt, ptstring)) |
|---|
| 4178 | Â Â Â Â { |
|---|
| 4179 |         sdp_payload_list_add(&ph_video_payloads, rtp_profile_get_payload_number_from_rtpmap(&av_profile, ptstring), payload_type_get_rtpmap(rtppt), NULL, 1); |
|---|
| 4180 | Â Â Â Â Â Â Â Â DBG_CODEC_LOOKUP("added video codec: %s\n",ptstring); |
|---|
| 4181 | Â Â Â Â } |
|---|
| 4182 | Â Â Â Â else |
|---|
| 4183 | Â Â Â Â Â Â Â Â DBG_CODEC_LOOKUP("unsupported video codec :Â %s not found in ortp profile or not supported by mediastreamer\n",ptstring); |
|---|
| 4184 | } |
|---|
| 4185 | #endif |
|---|
| 4186 | |
|---|
| 4187 | |
|---|
| 4188 | /** |
|---|
| 4189 | Â * Initialize the phoneapi module |
|---|
| 4190 | Â */ |
|---|
| 4191 | |
|---|
| 4192 | #ifdef OS_WIN32 |
|---|
| 4193 | |
|---|
| 4194 | static int |
|---|
| 4195 | wsock_init() |
|---|
| 4196 | { |
|---|
| 4197 | Â Â Â Â WORD wVersionRequested; |
|---|
| 4198 | Â Â Â Â WSADATA wsaData; |
|---|
| 4199 |     int i; |
|---|
| 4200 | |
|---|
| 4201 | Â Â Â Â wVersionRequested =Â MAKEWORD(2,0); |
|---|
| 4202 |     if(i = WSAStartup(wVersionRequested, &wsaData)) |
|---|
| 4203 | Â Â Â Â { |
|---|
| 4204 |         return -1; |
|---|
| 4205 | Â Â Â Â } |
|---|
| 4206 |     return 0; |
|---|
| 4207 | } |
|---|
| 4208 | #else |
|---|
| 4209 | #define wsock_init() 0 |
|---|
| 4210 | #endif |
|---|
| 4211 | |
|---|
| 4212 | #ifdef ANDROID |
|---|
| 4213 | void and_osip_print_dbg(char *li, int fi, osip_trace_level_t level, char *chfr, va_list ap) |
|---|
| 4214 | { |
|---|
| 4215 |     int prio; |
|---|
| 4216 | Â Â Â Â switch(level){ |
|---|
| 4217 |     case OSIP_INFO3: |
|---|
| 4218 |     case OSIP_INFO4: |
|---|
| 4219 | Â Â Â Â Â Â Â Â prio =Â ANDROID_LOG_DEBUG; |
|---|
| 4220 | Â Â Â Â Â Â Â Â break;Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 4221 |     case OSIP_INFO1: |
|---|
| 4222 |     case OSIP_INFO2: |
|---|
| 4223 | Â Â Â Â Â Â Â Â prio =Â ANDROID_LOG_INFO; |
|---|
| 4224 | Â Â Â Â Â Â Â Â break;Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 4225 |     case OSIP_WARNING: |
|---|
| 4226 | Â Â Â Â Â Â Â Â prio =Â ANDROID_LOG_WARN; |
|---|
| 4227 | Â Â Â Â Â Â Â Â break;Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 4228 |     case OSIP_ERROR: |
|---|
| 4229 | Â Â Â Â Â Â Â Â prio =Â ANDROID_LOG_ERROR; |
|---|
| 4230 | Â Â Â Â Â Â Â Â break;Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 4231 |     case OSIP_FATAL: |
|---|
| 4232 | Â Â Â Â Â Â Â Â prio =Â ANDROID_LOG_FATAL; |
|---|
| 4233 | Â Â Â Â Â Â Â Â break;Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 4234 | Â Â Â Â default: |
|---|
| 4235 | Â Â Â Â Â Â Â Â prio =Â ANDROID_LOG_VERBOSE; |
|---|
| 4236 | Â Â Â Â Â Â Â Â break;Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 4237 | Â Â Â Â } |
|---|
| 4238 | |
|---|
| 4239 |     __android_log_vprint(prio, "phapi", chfr, ap); |
|---|
| 4240 | } |
|---|
| 4241 | #endif |
|---|
| 4242 | |
|---|
| 4243 | |
|---|
| 4244 | static int |
|---|
| 4245 | ph_debug_init() |
|---|
| 4246 | { |
|---|
| 4247 |     const char *dbgstr; |
|---|
| 4248 | |
|---|
| 4249 | Â Â Â Â dbgstr =Â getenv("PH_DEBUG_LEVEL"); |
|---|
| 4250 |     if (dbgstr) |
|---|
| 4251 | Â Â Â Â Â Â Â Â phDebugLevel =Â atoi(dbgstr); |
|---|
| 4252 | |
|---|
| 4253 |     if (phDebugLevel > 0) |
|---|
| 4254 | Â Â Â Â { |
|---|
| 4255 |         if (!phLogFileName) |
|---|
| 4256 | Â Â Â Â Â Â Â Â Â Â Â Â phLogFileName =Â getenv("PH_LOG_FILENAME"); |
|---|
| 4257 | |
|---|
| 4258 | |
|---|
| 4259 |         ph_log_file = phLogFileName ? fopen (phLogFileName, "w+") : stdout; |
|---|
| 4260 | |
|---|
| 4261 | |
|---|
| 4262 |         if (!ph_log_file) |
|---|
| 4263 | Â Â Â Â Â Â Â Â { |
|---|
| 4264 | Â Â Â Â Â Â Â Â Â Â Â Â perror ("phapi: log file"); |
|---|
| 4265 |             return -1; |
|---|
| 4266 | Â Â Â Â Â Â Â Â } |
|---|
| 4267 | #ifdef ANDROID |
|---|
| 4268 |     osip_trace_initialize_func(phDebugLevel, and_osip_print_dbg); |
|---|
| 4269 | #else |
|---|
| 4270 |     osip_trace_initialize (phDebugLevel, ph_log_file); |
|---|
| 4271 | #endif |
|---|
| 4272 | Â Â Â Â } |
|---|
| 4273 | |
|---|
| 4274 |     return 0; |
|---|
| 4275 | |
|---|
| 4276 | } |
|---|
| 4277 | |
|---|
| 4278 | |
|---|
| 4279 | static void |
|---|
| 4280 | ph_avcodec_init() |
|---|
| 4281 | { |
|---|
| 4282 | #ifdef PHAPI_VIDEO_SUPPORT |
|---|
| 4283 | Â Â Â Â avcodec_init(); |
|---|
| 4284 | Â Â Â Â avcodec_register_all(); |
|---|
| 4285 | Â Â Â Â phcfg.video_config.video_line_configuration =Â PHAPI_VIDEO_LINE_128KBPS; |
|---|
| 4286 | #endif |
|---|
| 4287 | |
|---|
| 4288 | } |
|---|
| 4289 | |
|---|
| 4290 | |
|---|
| 4291 | static void |
|---|
| 4292 | ph_calls_init() |
|---|
| 4293 | { |
|---|
| 4294 |     int i; |
|---|
| 4295 | |
|---|
| 4296 | Â Â Â Â for(Â i =Â 0;Â i <Â PH_MAX_CALLS;Â i++) |
|---|
| 4297 | Â Â Â Â Â Â Â Â ph_calls[i].cid =Â -1; |
|---|
| 4298 | |
|---|
| 4299 | } |
|---|
| 4300 | |
|---|
| 4301 | static int |
|---|
| 4302 | ph_tunnel_init() |
|---|
| 4303 | { |
|---|
| 4304 | #if ENABLE_SOCKS |
|---|
| 4305 |     if (phcfg.use_tunnel & PH_TUNNEL_USE) { |
|---|
| 4306 |         sip_tunnel_count = ph_parse_tunnel_list(sip_tunnel_set, phcfg.sip_tunnel_uris, TUNNEL_MAX); |
|---|
| 4307 | Â Â Â Â } |
|---|
| 4308 |     if (phcfg.use_tunnel & PH_RTP_TUNNEL_USE) { |
|---|
| 4309 |         rtp_tunnel_count = ph_parse_tunnel_list(rtp_tunnel_set, phcfg.rtp_tunnel_uris[0] ? |
|---|
| 4310 |                  phcfg.rtp_tunnel_uris : phcfg.sip_tunnel_uris, TUNNEL_MAX); |
|---|
| 4311 | Â Â Â Â } |
|---|
| 4312 | |
|---|
| 4313 |     return 0; |
|---|
| 4314 | #endif |
|---|
| 4315 | |
|---|
| 4316 | #ifdef USE_HTTP_TUNNEL |
|---|
| 4317 | Â Â Â Â eXosip_tunnel_t *tunnel =Â NULL; |
|---|
| 4318 |     int port; |
|---|
| 4319 |     char *c; |
|---|
| 4320 |     char buf[256]; |
|---|
| 4321 |     int tunerr; |
|---|
| 4322 | |
|---|
| 4323 |     if (!(phcfg.use_tunnel & PH_TUNNEL_USE)) |
|---|
| 4324 |         return 0; |
|---|
| 4325 | |
|---|
| 4326 |     http_tunnel_init_host(phcfg.httpt_server, phcfg.httpt_server_port, phcfg.use_tunnel & PH_TUNNEL_SSL); |
|---|
| 4327 | Â Â Â Â http_tunnel_init_proxy(phcfg.http_proxy,phcfg.http_proxy_port, |
|---|
| 4328 |             phcfg.http_proxy_user, phcfg.http_proxy_passwd); |
|---|
| 4329 | |
|---|
| 4330 | Â Â Â Â tunnel =Â malloc(sizeof(eXosip_tunnel_t)); |
|---|
| 4331 |     if (tunnel) |
|---|
| 4332 | Â Â Â Â { |
|---|
| 4333 |         osip_strncpy(buf, phcfg.proxy, sizeof(buf)-1); |
|---|
| 4334 |         c = strstr(buf, ":"); |
|---|
| 4335 | |
|---|
| 4336 | Â Â Â Â Â Â Â Â port =Â 5060; |
|---|
| 4337 |         if (c) |
|---|
| 4338 | Â Â Â Â Â Â Â Â { |
|---|
| 4339 | Â Â Â Â Â Â Â Â Â Â Â Â *c++Â =Â 0; |
|---|
| 4340 | Â Â Â Â Â Â Â Â Â Â Â Â port =Â atoi(c); |
|---|
| 4341 | Â Â Â Â Â Â Â Â } |
|---|
| 4342 |         tunnel->h_tunnel = http_tunnel_open(buf, port, HTTP_TUNNEL_VAR_MODE, &tunerr, -1); |
|---|
| 4343 |         if (!tunnel->h_tunnel) |
|---|
| 4344 | Â Â Â Â Â Â Â Â { |
|---|
| 4345 |             if (!tunnel->h_tunnel) |
|---|
| 4346 | Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 4347 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â free(tunnel); |
|---|
| 4348 |                 return -PH_NOTUNNEL; |
|---|
| 4349 | Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 4350 | Â Â Â Â Â Â Â Â } |
|---|
| 4351 | |
|---|
| 4352 | Â Â Â Â Â Â Â Â tunnel->tunnel_recv =Â http_tunnel_recv; |
|---|
| 4353 | Â Â Â Â Â Â Â Â tunnel->tunnel_send =Â http_tunnel_send; |
|---|
| 4354 | Â Â Â Â Â Â Â Â tunnel->get_tunnel_socket =Â http_tunnel_get_socket; |
|---|
| 4355 | Â Â Â Â Â Â Â Â phTunnel =Â tunnel; |
|---|
| 4356 | Â Â Â Â Â Â Â Â ph_nat_type =Â TUNNEL; |
|---|
| 4357 |         return 0; |
|---|
| 4358 | Â Â Â Â } |
|---|
| 4359 | |
|---|
| 4360 | |
|---|
| 4361 | |
|---|
| 4362 | |
|---|
| 4363 |     return -PH_NORESOURCES; |
|---|
| 4364 | #else |
|---|
| 4365 |     return -1; |
|---|
| 4366 | #endif |
|---|
| 4367 | } |
|---|
| 4368 | |
|---|
| 4369 | #ifdef USE_UPNP |
|---|
| 4370 | |
|---|
| 4371 | static int |
|---|
| 4372 | ph_upnp_add_redirection(const char * addr, char * local_port, char * extern_port, char * proto) |
|---|
| 4373 | { |
|---|
| 4374 |     if( UPNP_AddPortMapping(ph_upnp_urls.controlURL, ph_upnp_data.first.servicetype, extern_port,local_port, addr, 0,proto, 0) == UPNPCOMMAND_SUCCESS) |
|---|
| 4375 | Â Â Â Â { |
|---|
| 4376 |         return 0; |
|---|
| 4377 | Â Â Â Â } |
|---|
| 4378 | Â Â Â Â |
|---|
| 4379 |     return -1; |
|---|
| 4380 | } |
|---|
| 4381 | |
|---|
| 4382 | static int |
|---|
| 4383 | ph_upnp_remove_redirection(char * sport, char * proto) |
|---|
| 4384 | { |
|---|
| 4385 |     if( UPNP_DeletePortMapping(ph_upnp_urls.controlURL, ph_upnp_data.first.servicetype, sport, proto,0) == UPNPCOMMAND_SUCCESS) |
|---|
| 4386 | Â Â Â Â { |
|---|
| 4387 |         return 0; |
|---|
| 4388 | Â Â Â Â } |
|---|
| 4389 | Â Â Â Â |
|---|
| 4390 |     return -1; |
|---|
| 4391 | } |
|---|
| 4392 | |
|---|
| 4393 | static int |
|---|
| 4394 | ph_upnp_redirect_port(const char* addr, int lport, int* pport, const char *proto) |
|---|
| 4395 | { |
|---|
| 4396 |     char lpstr[16], ppstr[16]; |
|---|
| 4397 | |
|---|
| 4398 |     sinprintf(lpstr, 16, "%d", lport); |
|---|
| 4399 | |
|---|
| 4400 |     if (!ph_upnp_add_redirection(addr, lpstr, pppstr, proto)) { |
|---|
| 4401 | Â Â Â Â Â Â Â Â *pport =Â atoi(ppstr); |
|---|
| 4402 |         return 0; |
|---|
| 4403 | Â Â Â Â } |
|---|
| 4404 | |
|---|
| 4405 |     return -1; |
|---|
| 4406 | |
|---|
| 4407 | } |
|---|
| 4408 | |
|---|
| 4409 | static int |
|---|
| 4410 | ph_upnp_release_port(int lport, const char *proto) |
|---|
| 4411 | { |
|---|
| 4412 |     char lpstr[16], ppstr[16]; |
|---|
| 4413 | |
|---|
| 4414 |     sinprintf(lpstr, 16, "%d", lport); |
|---|
| 4415 | |
|---|
| 4416 |     if (!ph_upnp_remove_redirection(lpstr, proto)) { |
|---|
| 4417 |         return 0; |
|---|
| 4418 | Â Â Â Â } |
|---|
| 4419 | |
|---|
| 4420 |     return -1; |
|---|
| 4421 | |
|---|
| 4422 | } |
|---|
| 4423 | |
|---|
| 4424 | |
|---|
| 4425 | static int |
|---|
| 4426 | ph_upnp_init() |
|---|
| 4427 | { |
|---|
| 4428 |     int result = -1; |
|---|
| 4429 | Â Â Â Â |
|---|
| 4430 |     char lanaddr[16]; |
|---|
| 4431 |     struct UPNPDev * devlist = upnpDiscover(500, 0, 0, 0); |
|---|
| 4432 |     if( UPNP_GetValidIGD(devlist, &ph_upnp_urls, &ph_upnp_data, lanaddr, sizeof(lanaddr)) == 1 ) |
|---|
| 4433 | Â Â Â Â { |
|---|
| 4434 | Â Â Â Â Â Â Â Â if(phcfg.local_ip_addr[0]Â ==Â 0) |
|---|
| 4435 |             snprintf(phcfg.local_ip_addr, sizeof(phcfg.local_ip_addr),"%s",lanaddr); |
|---|
| 4436 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 4437 | Â Â Â Â Â Â Â Â if(Â UPNP_GetExternalIPAddress(ph_upnp_urls.controlURL,ph_upnp_data.first.servicetype,ph_nat_router_addr)Â ==Â UPNPCOMMAND_SUCCESS) |
|---|
| 4438 | Â Â Â Â Â Â Â Â { |
|---|
| 4439 |             snprintf(ph_nat_sip_port_str, sizeof(ph_nat_sip_port_str), "%s", _get_local_sip_port()); |
|---|
| 4440 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 4441 |             result = ph_upnp_add_redirection(phcfg.local_ip_addr,_get_local_sip_port(),ph_nat_sip_port_str, phcfg.transport == IPPROTO_UDP ? "UDP" : "TCP"); |
|---|
| 4442 | Â Â Â Â Â Â Â Â Â Â Â Â if(!result) |
|---|
| 4443 | Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 4444 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â eXosip_masquerade_contact(ph_nat_router_addr,atoi(ph_nat_sip_port_str)); |
|---|
| 4445 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ph_nat_type =Â UPNP; |
|---|
| 4446 | Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 4447 | Â Â Â Â Â Â Â Â } |
|---|
| 4448 | Â Â Â Â } |
|---|
| 4449 | Â Â Â Â ph_upnp_devlist =Â devlist; |
|---|
| 4450 | Â Â Â Â |
|---|
| 4451 |     return result; |
|---|
| 4452 | } |
|---|
| 4453 | |
|---|
| 4454 | #endif |
|---|
| 4455 | |
|---|
| 4456 | static int |
|---|
| 4457 | ph_stun_init() |
|---|
| 4458 | { |
|---|
| 4459 |     bool_t resPort = 0, hairpin = 0; |
|---|
| 4460 | Â Â Â Â StunAddress4 stunServerAddr; |
|---|
| 4461 |     stunParseServerName(phcfg.stunserver, &stunServerAddr); |
|---|
| 4462 | Â Â Â Â |
|---|
| 4463 |     ph_stun_nat_type = stunNatType( &stunServerAddr, &resPort, &hairpin,0, 0); |
|---|
| 4464 | Â Â Â Â |
|---|
| 4465 | Â Â Â Â if(Â ph_stun_nat_type ==Â StunTypeConeNat ||Â ph_stun_nat_type ==Â StunTypeRestrictedNat ||Â ph_stun_nat_type ==Â StunTypePortRestrictedNat) |
|---|
| 4466 | Â Â Â Â { |
|---|
| 4467 | Â Â Â Â Â Â Â Â StunAddress4 mappedAddr; |
|---|
| 4468 |         Socket sock = stunOpenSocket(&stunServerAddr, &mappedAddr, atoi(_get_local_sip_port()), 0); |
|---|
| 4469 | Â Â Â Â Â Â Â Â |
|---|
| 4470 |         if ( sock != -1 ) |
|---|
| 4471 | Â Â Â Â Â Â Â Â { |
|---|
| 4472 |             ph_ipv4tostr(ph_nat_router_addr, sizeof(ph_nat_router_addr), mappedAddr); |
|---|
| 4473 |             snprintf(ph_nat_sip_port_str, sizeof(ph_nat_sip_port_str), "%d", mappedAddr.port); |
|---|
| 4474 | Â Â Â Â Â Â Â Â Â Â Â Â closesocket(sock); |
|---|
| 4475 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 4476 | Â Â Â Â Â Â Â Â Â Â Â Â eXosip_masquerade_contact(ph_nat_router_addr,atoi(ph_nat_sip_port_str)); |
|---|
| 4477 | Â Â Â Â Â Â Â Â Â Â Â Â ph_nat_type =Â STUN; |
|---|
| 4478 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 4479 |             return 0; |
|---|
| 4480 | Â Â Â Â Â Â Â Â } |
|---|
| 4481 | Â Â Â Â } |
|---|
| 4482 | Â Â Â Â |
|---|
| 4483 |     return -1; |
|---|
| 4484 | } |
|---|
| 4485 | |
|---|
| 4486 | static void |
|---|
| 4487 | ph_nat_init() |
|---|
| 4488 | { |
|---|
| 4489 | Â Â Â Â ph_nat_router_addr[0]Â =Â 0; |
|---|
| 4490 | Â Â Â Â ph_nat_port_str[0]Â =Â 0; |
|---|
| 4491 | |
|---|
| 4492 | #if 0 |
|---|
| 4493 | Â Â Â Â if (!phcfg.nat_refresh_udp_time) |
|---|
| 4494 | Â Â Â Â Â Â Â Â phcfg.nat_refresh_udp_time = 15; |
|---|
| 4495 | Â Â Â Â |
|---|
| 4496 | Â Â Â Â if (!phcfg.nat_refresh_tcp_time) |
|---|
| 4497 | Â Â Â Â Â Â Â Â phcfg.nat_refresh_tcp_time = 15; |
|---|
| 4498 | #endif |
|---|
| 4499 | |
|---|
| 4500 | #ifdef USE_UPNP |
|---|
| 4501 | Â Â Â Â if(phcfg.use_upnp) |
|---|
| 4502 | Â Â Â Â { |
|---|
| 4503 | Â Â Â Â Â Â Â Â if(!ph_upnp_init()) |
|---|
| 4504 | Â Â Â Â Â Â Â Â Â Â Â Â return; |
|---|
| 4505 | Â Â Â Â } |
|---|
| 4506 | #endif |
|---|
| 4507 | Â Â Â Â |
|---|
| 4508 | Â Â Â Â if(phcfg.use_stun) |
|---|
| 4509 | Â Â Â Â { |
|---|
| 4510 | Â Â Â Â Â Â Â Â if(!ph_stun_init()) |
|---|
| 4511 | Â Â Â Â Â Â Â Â Â Â Â Â return; |
|---|
| 4512 | Â Â Â Â } |
|---|
| 4513 | Â Â Â Â |
|---|
| 4514 | Â Â Â Â if(phcfg.use_tunnel) |
|---|
| 4515 | Â Â Â Â { |
|---|
| 4516 | Â Â Â Â Â Â Â Â if(!ph_tunnel_init()) |
|---|
| 4517 | Â Â Â Â Â Â Â Â Â Â Â Â return; |
|---|
| 4518 | Â Â Â Â } |
|---|
| 4519 | |
|---|
| 4520 | Â Â Â Â //nat should be open |
|---|
| 4521 | Â Â Â Â ph_nat_type =Â OPEN; |
|---|
| 4522 | //Â Â Â phcfg.nat_refresh_udp_time = 0; |
|---|
| 4523 | //Â Â Â phcfg.nat_refresh_tcp_time = 0; |
|---|
| 4524 | Â Â Â Â |
|---|
| 4525 |     if (phcfg.local_ip_addr[0] != 0) |
|---|
| 4526 |         eXosip_masquerade_contact(phcfg.local_ip_addr, atoi(_get_local_sip_port())); |
|---|
| 4527 | } |
|---|
| 4528 | |
|---|
| 4529 | /** |
|---|
| 4530 | Â * @brief initialize the payload/codecs that are allowed to be handled by the SIP stack |
|---|
| 4531 | Â */ |
|---|
| 4532 | PHAPI_EXPORT void |
|---|
| 4533 | ph_payloads_init() |
|---|
| 4534 | { |
|---|
| 4535 |     char audio_codecs[128]; |
|---|
| 4536 | Â Â Â Â |
|---|
| 4537 | #ifdef PHAPI_VIDEO_SUPPORT |
|---|
| 4538 |     char video_codecs[128]; |
|---|
| 4539 | Â Â Â Â osip_strncpy(video_codecs,phcfg.video_codecs,sizeof(phcfg.video_codecs)-1); |
|---|
| 4540 | Â Â Â Â osip_list_init(&ph_video_payloads); |
|---|
| 4541 |     if (!video_codecs[0]) { |
|---|
| 4542 | Â Â Â Â Â Â Â Â ph_setup_video_payload("H263/90000"); |
|---|
| 4543 |     } else { |
|---|
| 4544 |         char tmp[32]; |
|---|
| 4545 |         char *tok = strtok(video_codecs, ","); |
|---|
| 4546 | |
|---|
| 4547 | Â Â Â Â Â Â Â Â while(tok)Â { |
|---|
| 4548 |             snprintf(tmp, sizeof(tmp), "%s/90000", tok); |
|---|
| 4549 | Â Â Â Â Â Â Â Â Â Â Â Â ph_setup_video_payload(tmp); |
|---|
| 4550 |             tok = strtok(0, ","); |
|---|
| 4551 | Â Â Â Â Â Â Â Â } |
|---|
| 4552 | Â Â Â Â } |
|---|
| 4553 | #endif |
|---|
| 4554 | Â Â Â Â |
|---|
| 4555 | Â Â Â Â // init payload/codecs for AUDIO |
|---|
| 4556 | Â Â Â Â osip_list_init(&ph_audio_payloads); |
|---|
| 4557 | Â Â Â Â osip_strncpy(audio_codecs,phcfg.audio_codecs,sizeof(phcfg.audio_codecs)-1); |
|---|
| 4558 | Â Â Â Â |
|---|
| 4559 | Â Â Â Â // add codecs out of an ENV var |
|---|
| 4560 | Â Â Â Â { |
|---|
| 4561 |         char *aclist = getenv("PH_AUDIO_CODECS"); |
|---|
| 4562 |         if (aclist) { |
|---|
| 4563 |             osip_strncpy(audio_codecs, aclist, sizeof(audio_codecs)-1); |
|---|
| 4564 | Â Â Â Â Â Â Â Â } |
|---|
| 4565 | |
|---|
| 4566 | Â Â Â Â } |
|---|
| 4567 | |
|---|
| 4568 | |
|---|
| 4569 | Â Â Â Â // limit codecs to G711 codecs according to compile time DEFINE |
|---|
| 4570 | #ifdef G711_ONLY |
|---|
| 4571 |     strcpy(audio_codecs, "PCMU/8000,PCMA/8000"); |
|---|
| 4572 | #endif |
|---|
| 4573 | |
|---|
| 4574 | Â Â Â Â // if at this stage, no codecs are required, fix a default list |
|---|
| 4575 |     if (!audio_codecs[0]) |
|---|
| 4576 | Â Â Â Â { |
|---|
| 4577 | Â Â Â Â Â Â Â Â ph_setup_payload("PCMU/8000"); |
|---|
| 4578 | Â Â Â Â Â Â Â Â ph_setup_payload("PCMA/8000"); |
|---|
| 4579 | Â Â Â Â Â Â Â Â ph_setup_payload("GSM/8000"); |
|---|
| 4580 | Â Â Â Â Â Â Â Â ph_setup_payload("ILBC/8000"); |
|---|
| 4581 | Â Â Â Â Â Â Â Â ph_setup_payload("SPEEX/16000"); |
|---|
| 4582 | Â Â Â Â Â Â Â Â ph_setup_payload("SPEEX/8000"); |
|---|
| 4583 | Â Â Â Â Â Â Â Â ph_setup_payload("AMR/8000"); |
|---|
| 4584 | Â Â Â Â Â Â Â Â ph_setup_payload("AMR-WB/16000"); |
|---|
| 4585 | Â Â Â Â Â Â Â Â ph_setup_payload("G722/8000"); |
|---|
| 4586 | Â Â Â Â Â Â Â Â ph_setup_payload("G726-32/8000"); |
|---|
| 4587 | |
|---|
| 4588 | Â Â Â Â } |
|---|
| 4589 | Â Â Â Â // phapi.h client has required a specific list of codecs |
|---|
| 4590 | Â Â Â Â else |
|---|
| 4591 | Â Â Â Â { |
|---|
| 4592 | |
|---|
| 4593 | Â Â Â Â Â Â Â Â /* |
|---|
| 4594 | Â Â Â Â The list is "," separated |
|---|
| 4595 | Â Â Â Â some hacks are present to allow for : |
|---|
| 4596 | Â Â Â Â - payload usurpation |
|---|
| 4597 | Â Â Â Â - default /8000 clockrate when not specified |
|---|
| 4598 | Â Â Â Â - ... look at the code |
|---|
| 4599 | Â Â Â Â Â Â Â Â Â */ |
|---|
| 4600 | |
|---|
| 4601 | |
|---|
| 4602 |         char tmp[32]; |
|---|
| 4603 |         char *tok = strtok(audio_codecs, ","); |
|---|
| 4604 | |
|---|
| 4605 | Â Â Â Â Â Â Â Â while(tok) |
|---|
| 4606 | Â Â Â Â Â Â Â Â { |
|---|
| 4607 |             if(!strcmp(tok, "AMR-WB")) |
|---|
| 4608 | Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 4609 | #ifdef AMR_OVER_G729_HACK |
|---|
| 4610 |                 snprintf(tmp, sizeof(tmp), "G729/8000"); |
|---|
| 4611 | #else |
|---|
| 4612 |                 snprintf(tmp, sizeof(tmp), "%s/16000", tok); |
|---|
| 4613 | #endif |
|---|
| 4614 | Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 4615 | #ifdef SPEEX_OVER_G729_HACK |
|---|
| 4616 |             else if(!strcmp(tok, "SPEEX/16000")) |
|---|
| 4617 | Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 4618 |                 snprintf(tmp, sizeof(tmp), "G729/8000"); |
|---|
| 4619 | Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 4620 | #endif |
|---|
| 4621 |             else if (strchr(tok, '/')) |
|---|
| 4622 |                 osip_strncpy(tmp, tok, sizeof(tmp)-1); |
|---|
| 4623 | Â Â Â Â Â Â Â Â Â Â Â Â else |
|---|
| 4624 |                 snprintf(tmp, sizeof(tmp), "%s/8000", tok); |
|---|
| 4625 | |
|---|
| 4626 | Â Â Â Â Â Â Â Â Â Â Â Â ph_setup_payload(tmp); |
|---|
| 4627 | |
|---|
| 4628 |             tok = strtok(0, ","); |
|---|
| 4629 | Â Â Â Â Â Â Â Â } |
|---|
| 4630 | Â Â Â Â } |
|---|
| 4631 | |
|---|
| 4632 | Â Â Â Â // set codec in sip stack for CNG (confort noise generator= |
|---|
| 4633 | Â Â Â Â if(phcfg.cng) |
|---|
| 4634 | Â Â Â Â Â Â Â Â ph_setup_payload("CN/8000"); |
|---|
| 4635 | |
|---|
| 4636 | Â Â Â Â // set codec in sip stack for DTMF |
|---|
| 4637 | Â Â Â Â ph_setup_payload("telephone-event/8000"); |
|---|
| 4638 | } |
|---|
| 4639 | |
|---|
| 4640 | static int |
|---|
| 4641 | ph_get_call_id(int did, char **cid) |
|---|
| 4642 | { |
|---|
| 4643 |     char referto[512]; |
|---|
| 4644 |     char *cp, *semi; |
|---|
| 4645 |     int i; |
|---|
| 4646 | |
|---|
| 4647 |     i = eXosip_call_get_referto(did, referto, sizeof(referto)); |
|---|
| 4648 |     if (i) |
|---|
| 4649 |         return -PH_ERROR; |
|---|
| 4650 |     cp = strstr(referto, "Replaces"); |
|---|
| 4651 |     if (!cp) |
|---|
| 4652 |         return -PH_ERROR; |
|---|
| 4653 | Â Â Â Â cp +=Â 9; |
|---|
| 4654 |     semi = strchr(cp, ';'); |
|---|
| 4655 |     if (semi) |
|---|
| 4656 | Â Â Â Â Â Â Â Â *semi =Â 0; |
|---|
| 4657 | |
|---|
| 4658 | Â Â Â Â *cid =Â osip_strdup(cp); |
|---|
| 4659 | |
|---|
| 4660 |     return *cid ? 0 : -PH_NORESOURCES; |
|---|
| 4661 | } |
|---|
| 4662 | |
|---|
| 4663 | |
|---|
| 4664 | PHAPI_EXPORT int |
|---|
| 4665 | phCallGetSipCallID(int cid, char* buf, int bufsize) |
|---|
| 4666 | { |
|---|
| 4667 | Â Â Â Â phcall_t *ca; |
|---|
| 4668 |     char *callid; |
|---|
| 4669 |     int i; |
|---|
| 4670 | |
|---|
| 4671 |     if (!phIsInitialized) |
|---|
| 4672 |         return -PH_NOTINIT; |
|---|
| 4673 | |
|---|
| 4674 | Â Â Â Â ca =Â ph_locate_call_by_cid(cid); |
|---|
| 4675 | |
|---|
| 4676 |     if (!ca) |
|---|
| 4677 |         return -PH_BADCID; |
|---|
| 4678 | |
|---|
| 4679 |     if( bufsize <= 0 || !buf) |
|---|
| 4680 |         return -PH_BADARG; |
|---|
| 4681 | |
|---|
| 4682 | |
|---|
| 4683 | Â Â Â Â eXosip_lock(); |
|---|
| 4684 |     i = ph_get_call_id(ca->did, &callid); |
|---|
| 4685 | Â Â Â Â eXosip_unlock(); |
|---|
| 4686 | |
|---|
| 4687 | Â Â Â Â if(!i) |
|---|
| 4688 | Â Â Â Â { |
|---|
| 4689 |         osip_strncpy(buf, callid, bufsize-1); |
|---|
| 4690 | Â Â Â Â Â Â Â Â osip_free(callid); |
|---|
| 4691 |         return 0; |
|---|
| 4692 | Â Â Â Â } |
|---|
| 4693 | |
|---|
| 4694 |     return -PH_ERROR; |
|---|
| 4695 | } |
|---|
| 4696 | |
|---|
| 4697 | PHAPI_EXPORT int |
|---|
| 4698 | phListenAddr(int local_sip_port) |
|---|
| 4699 | { |
|---|
| 4700 |     int i, cpt = 0; |
|---|
| 4701 |     int secure = 0; |
|---|
| 4702 |     int proto = phcfg.transport; |
|---|
| 4703 | |
|---|
| 4704 |     for (cpt = 0; cpt < 5; cpt++) |
|---|
| 4705 | Â Â Â Â { |
|---|
| 4706 |         if (phcfg.local_ip_addr[0] == 0) |
|---|
| 4707 |             i = eXosip_listen_addr(proto, NULL,local_sip_port + cpt, AF_INET, secure); |
|---|
| 4708 | Â Â Â Â Â Â Â Â else |
|---|
| 4709 |             i = eXosip_listen_addr(proto, phcfg.local_ip_addr,local_sip_port + cpt, AF_INET, secure); |
|---|
| 4710 | |
|---|
| 4711 | Â Â Â Â Â Â Â Â if(!i) |
|---|
| 4712 | Â Â Â Â Â Â Â Â Â Â Â Â break; |
|---|
| 4713 | Â Â Â Â } |
|---|
| 4714 | |
|---|
| 4715 |     return i; |
|---|
| 4716 | } |
|---|
| 4717 | |
|---|
| 4718 | PHAPI_EXPORT int |
|---|
| 4719 | phInit(phCallbacks_t *cbk, char * server, int asyncmode) |
|---|
| 4720 | { |
|---|
| 4721 |     int i; |
|---|
| 4722 |     const char *tmp; |
|---|
| 4723 |     int nat_refresh_time = 0; |
|---|
| 4724 | |
|---|
| 4725 |     if (phIsInitialized) |
|---|
| 4726 |         return 0; |
|---|
| 4727 | |
|---|
| 4728 |     memset(vcontact, 0, sizeof(vcontact)); |
|---|
| 4729 | |
|---|
| 4730 | Â Â Â Â i =Â ph_debug_init(); |
|---|
| 4731 | |
|---|
| 4732 |     if (i) |
|---|
| 4733 |         return i; |
|---|
| 4734 | |
|---|
| 4735 | Â Â Â Â tmp =Â getenv("EXOSIP_RESEND_OFFSET"); |
|---|
| 4736 |     if (tmp && strlen(tmp)) |
|---|
| 4737 | Â Â Â Â Â Â Â Â ph_resend_offset =Â atoi(tmp); |
|---|
| 4738 | |
|---|
| 4739 | Â Â Â Â ph_avcodec_init(); |
|---|
| 4740 | Â Â Â Â ph_calls_init(); |
|---|
| 4741 | |
|---|
| 4742 |     if (phcfg.use_tunnel) |
|---|
| 4743 | Â Â Â Â { |
|---|
| 4744 | Â Â Â Â Â Â Â Â i =Â ph_tunnel_init(); |
|---|
| 4745 |         if (i) |
|---|
| 4746 |             return i; |
|---|
| 4747 | Â Â Â Â } |
|---|
| 4748 | |
|---|
| 4749 | #ifdef FORCE_VAD |
|---|
| 4750 | Â Â Â Â /* HACK for test */ |
|---|
| 4751 | #ifdef EMBED |
|---|
| 4752 | Â Â Â Â phcfg.vad =Â VAD_VALID_MASK |Â (500Â &Â VAD_THRESHOLD_MASK); |
|---|
| 4753 | #else |
|---|
| 4754 | Â Â Â Â phcfg.vad =Â VAD_VALID_MASK |Â (1000Â &Â VAD_THRESHOLD_MASK); |
|---|
| 4755 | #endif |
|---|
| 4756 | #endif |
|---|
| 4757 | |
|---|
| 4758 | #ifdef FORCE_CNG |
|---|
| 4759 | Â Â Â Â /* HACK for test */ |
|---|
| 4760 | Â Â Â Â phcfg.cng =Â 1; |
|---|
| 4761 | #endif |
|---|
| 4762 | |
|---|
| 4763 | |
|---|
| 4764 | Â Â Â Â ph_media_init(phcfg.plugin_path);Â //init ortp/ms2 payloads list, init ms2 and ortp |
|---|
| 4765 | |
|---|
| 4766 | Â Â Â Â i =Â eXosip_init(); |
|---|
| 4767 |     if (i) |
|---|
| 4768 |         return -1; |
|---|
| 4769 | Â Â Â Â Â Â Â Â |
|---|
| 4770 | #if ENABLE_SOCKS |
|---|
| 4771 |     if (phcfg.use_tunnel & PH_TUNNEL_USE) { |
|---|
| 4772 |         struct tunnel_info *tun;    |
|---|
| 4773 |         tun = ph_select_tunnel(sip_tunnel_set, sip_tunnel_count); |
|---|
| 4774 |         if (tun) |
|---|
| 4775 |             eXosip_set_tunnel(tun->tunnel_proto, tun->tunnel_server, tun->tunnel_port); |
|---|
| 4776 | Â Â Â Â } |
|---|
| 4777 | #endif |
|---|
| 4778 | Â Â Â Â |
|---|
| 4779 | Â Â Â Â ph_nat_init(); |
|---|
| 4780 | Â Â Â Â |
|---|
| 4781 |     DBG_SIP_NEGO("NAT type: %s fw=%s \n", ph_get_nat_type(), ph_nat_router_addr); |
|---|
| 4782 | |
|---|
| 4783 |     if (phcfg.public_ip_addr[0]) |
|---|
| 4784 | Â Â Â Â { |
|---|
| 4785 |         int port = atoi(phcfg.public_sipport); |
|---|
| 4786 |         eXosip_masquerade_contact(phcfg.public_ip_addr, port ? port : atoi(phcfg.sipport)); |
|---|
| 4787 | Â Â Â Â } |
|---|
| 4788 | |
|---|
| 4789 |     if (!(phcfg.use_tunnel & PH_TUNNEL_USE)) { |
|---|
| 4790 | Â Â Â Â Â Â Â Â i =Â phListenAddr(atoi(phcfg.sipport)); |
|---|
| 4791 | Â Â Â Â Â Â Â Â if(i) |
|---|
| 4792 |             return -1; |
|---|
| 4793 | Â Â Â Â } |
|---|
| 4794 | |
|---|
| 4795 | Â Â Â Â { |
|---|
| 4796 |         const char * ua = "phapi/eXosip-" PHAPI_VERSION_STRING; |
|---|
| 4797 | Â Â Â Â Â Â Â Â eXosip_set_user_agent(ua); |
|---|
| 4798 | Â Â Â Â } |
|---|
| 4799 | |
|---|
| 4800 |     nat_refresh_time = (phcfg.transport == IPPROTO_UDP) ? phcfg.nat_refresh_udp_time : phcfg.nat_refresh_tcp_time; |
|---|
| 4801 |     eXosip_set_option(EXOSIP_OPT_UDP_KEEP_ALIVE, &nat_refresh_time); |
|---|
| 4802 |     eXosip_set_option(EXOSIP_OPT_UDP_KEEP_ALIVE_ADJUST, &phcfg.nat_refresh_time_adjust); |
|---|
| 4803 | |
|---|
| 4804 | Â Â Â Â eXosip_set_cbconnection_close(ph_connection_lost); |
|---|
| 4805 | Â Â Â Â ph_is_connection_lost =Â 0; |
|---|
| 4806 | Â Â Â Â |
|---|
| 4807 |     memset(ph_vlines, 0, sizeof(ph_vlines)); |
|---|
| 4808 | |
|---|
| 4809 | Â Â Â Â ph_payloads_init();Â //init phapi codecs lists |
|---|
| 4810 | |
|---|
| 4811 | Â Â Â Â /* register callbacks? */ |
|---|
| 4812 | Â Â Â Â phcb =Â cbk; |
|---|
| 4813 | Â Â Â Â phcfg.asyncmode =Â asyncmode; |
|---|
| 4814 |     if (!asyncmode) |
|---|
| 4815 | Â Â Â Â Â Â Â Â timeout =Â 0; |
|---|
| 4816 | Â Â Â Â else |
|---|
| 4817 | Â Â Â Â Â Â Â Â timeout =Â 10; |
|---|
| 4818 | |
|---|
| 4819 | Â Â Â Â ph_media_start_mutex =Â osip_mutex_init(); |
|---|
| 4820 | Â Â Â Â ph_media_stop_mutex =Â osip_mutex_init(); |
|---|
| 4821 | Â Â Â Â ph_custom_mutex =Â osip_mutex_init(); |
|---|
| 4822 | Â Â Â Â osip_list_init(&ph_custom_headers); |
|---|
| 4823 | |
|---|
| 4824 | Â Â Â Â ph_hdrmon_mutex =Â osip_mutex_init(); |
|---|
| 4825 | Â Â Â Â osip_list_init(&ph_hdrmon_list); |
|---|
| 4826 | |
|---|
| 4827 | |
|---|
| 4828 | |
|---|
| 4829 |     if (asyncmode) |
|---|
| 4830 |         phapithread = osip_thread_create(20000, ph_api_thread, (void*)0); |
|---|
| 4831 | |
|---|
| 4832 | Â Â Â Â phIsInitialized =Â 1; |
|---|
| 4833 | |
|---|
| 4834 |     return 0; |
|---|
| 4835 | } |
|---|
| 4836 | |
|---|
| 4837 | PHAPI_EXPORT int |
|---|
| 4838 | phAudioCaptureCardList(ph_audio_card_desc_t**Â device_tab) |
|---|
| 4839 | { |
|---|
| 4840 |     if (!phIsInitialized) |
|---|
| 4841 |         return -PH_NOTINIT; |
|---|
| 4842 | |
|---|
| 4843 |     return phms_audio_get_capture_sndcard_list(device_tab); |
|---|
| 4844 | } |
|---|
| 4845 | |
|---|
| 4846 | PHAPI_EXPORT int |
|---|
| 4847 | phAudioPlaybackCardList(ph_audio_card_desc_t**Â device_tab) |
|---|
| 4848 | { |
|---|
| 4849 |     if (!phIsInitialized) |
|---|
| 4850 |         return -PH_NOTINIT; |
|---|
| 4851 | |
|---|
| 4852 |     return phms_audio_get_playback_sndcard_list(device_tab); |
|---|
| 4853 | } |
|---|
| 4854 | |
|---|
| 4855 | PHAPI_EXPORT int |
|---|
| 4856 | phVideoWebcamList(ph_video_web_cam_desc_t**Â device_tab) |
|---|
| 4857 | { |
|---|
| 4858 |     if (!phIsInitialized) |
|---|
| 4859 |         return -PH_NOTINIT; |
|---|
| 4860 | #ifdef PHAPI_VIDEO_SUPPORTÂ Â Â |
|---|
| 4861 |     return phms_video_get_web_cam_list(device_tab); |
|---|
| 4862 | #else |
|---|
| 4863 |     return 0; |
|---|
| 4864 | #endif |
|---|
| 4865 | } |
|---|
| 4866 | |
|---|
| 4867 | #if 0 |
|---|
| 4868 | int phTunnelConfig(const char* http_proxy, const int http_proxy_port, |
|---|
| 4869 | Â Â Â Â Â Â Â Â const char* httpt_server, const int httpt_server_port, |
|---|
| 4870 | Â Â Â Â Â Â Â Â const char *proxy_user, const char* proxy_passwd, |
|---|
| 4871 | Â Â Â Â Â Â Â Â int use_ssl, int autoconf) |
|---|
| 4872 | { |
|---|
| 4873 | Â Â Â Â if (!phIsInitialized) |
|---|
| 4874 | Â Â Â Â Â Â Â Â return -PH_NOTINIT; |
|---|
| 4875 | |
|---|
| 4876 | Â Â Â Â phcfg.httpt_server[0] = 0; |
|---|
| 4877 | Â Â Â Â phcfg.http_proxy[0] = 0; |
|---|
| 4878 | Â Â Â Â phcfg.use_tunnel = 0; |
|---|
| 4879 | |
|---|
| 4880 | Â Â Â Â if (!httpt_server) { |
|---|
| 4881 | Â Â Â Â Â Â Â Â return -1; |
|---|
| 4882 | Â Â Â Â } |
|---|
| 4883 | |
|---|
| 4884 | Â Â Â Â phcfg.http_proxy_port = http_proxy_port; |
|---|
| 4885 | Â Â Â Â if (!httpt_server_port) |
|---|
| 4886 | Â Â Â Â Â Â Â Â if (!http_proxy) { |
|---|
| 4887 | Â Â Â Â Â Â Â Â Â Â Â Â phcfg.httpt_server_port = 80; |
|---|
| 4888 | Â Â Â Â Â Â Â Â } |
|---|
| 4889 | Â Â Â Â Â Â Â Â else { |
|---|
| 4890 | Â Â Â Â Â Â Â Â Â Â Â Â phcfg.httpt_server_port = 443; |
|---|
| 4891 | Â Â Â Â Â Â Â Â } |
|---|
| 4892 | Â Â Â Â else |
|---|
| 4893 | Â Â Â Â Â Â Â Â phcfg.httpt_server_port = httpt_server_port; |
|---|
| 4894 | |
|---|
| 4895 | Â Â Â Â if (httpt_server) |
|---|
| 4896 | Â Â Â Â Â Â Â Â osip_strncpy(phcfg.httpt_server, httpt_server, sizeof(phcfg.httpt_server)-1); |
|---|
| 4897 | Â Â Â Â if (http_proxy) |
|---|
| 4898 | Â Â Â Â Â Â Â Â osip_strncpy(phcfg.http_proxy, http_proxy, sizeof(phcfg.http_proxy)-1); |
|---|
| 4899 | |
|---|
| 4900 | Â Â Â Â if (proxy_user) |
|---|
| 4901 | Â Â Â Â Â Â Â Â osip_strncpy(phcfg.http_proxy_user, proxy_user, sizeof(phcfg.http_proxy_user)-1); |
|---|
| 4902 | Â Â Â Â if (proxy_passwd) |
|---|
| 4903 | Â Â Â Â Â Â Â Â osip_strncpy(phcfg.http_proxy_passwd, proxy_passwd, sizeof(phcfg.http_proxy_passwd)-1); |
|---|
| 4904 | |
|---|
| 4905 | Â Â Â Â phcfg.use_tunnel = PH_TUNNEL_USE; |
|---|
| 4906 | Â Â Â Â if (use_ssl) |
|---|
| 4907 | Â Â Â Â Â Â Â Â phcfg.use_tunnel |= PH_TUNNEL_SSL; |
|---|
| 4908 | |
|---|
| 4909 | Â Â Â Â if (autoconf) |
|---|
| 4910 | Â Â Â Â Â Â Â Â phcfg.use_tunnel |= PH_TUNNEL_AUTOCONF; |
|---|
| 4911 | Â Â Â Â return 0; |
|---|
| 4912 | } |
|---|
| 4913 | #endif |
|---|
| 4914 | |
|---|
| 4915 | int phTunnelConfig2(const char* sip_tunnel_uris, const char *rtp_tunnel_uris, const char *http_proxy, |
|---|
| 4916 |                                 const char *proxy_user, const char* proxy_passwd) |
|---|
| 4917 | { |
|---|
| 4918 |     if (sip_tunnel_uris) |
|---|
| 4919 |         osip_strncpy(phcfg.sip_tunnel_uris, sip_tunnel_uris, sizeof(phcfg.sip_tunnel_uris)-1 ); |
|---|
| 4920 | |
|---|
| 4921 | |
|---|
| 4922 |     if (rtp_tunnel_uris) |
|---|
| 4923 |         osip_strncpy(phcfg.rtp_tunnel_uris, rtp_tunnel_uris, sizeof(phcfg.rtp_tunnel_uris)-1 ); |
|---|
| 4924 | |
|---|
| 4925 | |
|---|
| 4926 |     if (http_proxy) |
|---|
| 4927 |         osip_strncpy(phcfg.http_proxy, http_proxy, sizeof(phcfg.http_proxy)-1); |
|---|
| 4928 | |
|---|
| 4929 |     if (proxy_user) |
|---|
| 4930 |         osip_strncpy(phcfg.http_proxy_user, proxy_user, sizeof(phcfg.http_proxy_user)-1); |
|---|
| 4931 | |
|---|
| 4932 |     if (proxy_passwd) |
|---|
| 4933 |         osip_strncpy(phcfg.http_proxy_passwd, proxy_passwd, sizeof(phcfg.http_proxy_passwd)-1); |
|---|
| 4934 | |
|---|
| 4935 | Â Â Â Â phcfg.use_tunnel =Â PH_TUNNEL_USE; |
|---|
| 4936 | |
|---|
| 4937 | } |
|---|
| 4938 | |
|---|
| 4939 | |
|---|
| 4940 | static void ph_payload_cleanup() |
|---|
| 4941 | { |
|---|
| 4942 |     if (osip_list_size(&ph_audio_payloads) > 0) |
|---|
| 4943 |         osip_list_special_free(&ph_audio_payloads, sdp_payload_free); |
|---|
| 4944 |     if (osip_list_size(&ph_video_payloads) > 0) |
|---|
| 4945 |         osip_list_special_free(&ph_video_payloads, sdp_payload_free); |
|---|
| 4946 | } |
|---|
| 4947 | |
|---|
| 4948 | /** |
|---|
| 4949 | Â * terminate ph api |
|---|
| 4950 | Â */ |
|---|
| 4951 | PHAPI_EXPORT void |
|---|
| 4952 | phTerminate() |
|---|
| 4953 | { |
|---|
| 4954 |     int i; |
|---|
| 4955 | |
|---|
| 4956 | Â Â Â Â DBG_SIP_EVENT("SIP NEGO: phTerminate\n"); |
|---|
| 4957 |     if (!phIsInitialized) |
|---|
| 4958 | Â Â Â Â Â Â Â Â return; |
|---|
| 4959 | |
|---|
| 4960 | Â Â Â Â for(i =Â 0;Â i <Â PH_MAX_CALLS;Â i++) |
|---|
| 4961 |         if (ph_calls[i].cid != -1) |
|---|
| 4962 | Â Â Â Â Â Â Â Â Â Â Â Â ph_release_call(&ph_calls[i]); |
|---|
| 4963 | |
|---|
| 4964 | Â Â Â Â for(i =Â 0;Â i <Â PH_MAX_VLINES;Â i++) |
|---|
| 4965 | Â Â Â Â { |
|---|
| 4966 | Â Â Â Â Â Â Â Â phDelVline(i+1); |
|---|
| 4967 | Â Â Â Â } |
|---|
| 4968 | |
|---|
| 4969 | Â Â Â Â usleep(200000); |
|---|
| 4970 | |
|---|
| 4971 | Â Â Â Â phPoll(); |
|---|
| 4972 | |
|---|
| 4973 | Â Â Â Â phIsInitialized =Â 0; |
|---|
| 4974 | |
|---|
| 4975 |     if (phapithread != NULL) { |
|---|
| 4976 | Â Â Â Â Â Â Â Â __eXosip_wakeup_event(); |
|---|
| 4977 |         i = osip_thread_join((struct osip_thread *) phapithread); |
|---|
| 4978 |         if (i != 0) { |
|---|
| 4979 | Â Â Â Â Â Â Â Â Â Â Â Â OSIP_TRACE(osip_trace |
|---|
| 4980 |                     (__FILE__, __LINE__, OSIP_ERROR, NULL, |
|---|
| 4981 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "phapithread: can't terminate thread!\n")); |
|---|
| 4982 | Â Â Â Â Â Â Â Â } |
|---|
| 4983 | Â Â Â Â Â Â Â Â osip_free(phapithread); |
|---|
| 4984 | Â Â Â Â Â Â Â Â phapithread =Â 0; |
|---|
| 4985 | Â Â Â Â } |
|---|
| 4986 | Â Â Â Â eXosip_quit(); |
|---|
| 4987 | |
|---|
| 4988 | |
|---|
| 4989 | Â Â Â Â for(i =Â 0;Â i <Â PH_MAX_VLINES;Â i++) |
|---|
| 4990 | Â Â Â Â { |
|---|
| 4991 |         struct vline *vl = ph_vlid2vline(i+1); |
|---|
| 4992 |         if (vl) |
|---|
| 4993 | Â Â Â Â Â Â Â Â Â Â Â Â vline_free(vl); |
|---|
| 4994 | Â Â Â Â } |
|---|
| 4995 | |
|---|
| 4996 | |
|---|
| 4997 | #ifdef USE_HTTP_TUNNEL |
|---|
| 4998 |     if (phTunnel) |
|---|
| 4999 | Â Â Â Â { |
|---|
| 5000 | Â Â Â Â Â Â Â Â http_tunnel_close(phTunnel->h_tunnel); |
|---|
| 5001 | Â Â Â Â Â Â Â Â http_tunnel_clean_up(); |
|---|
| 5002 | Â Â Â Â Â Â Â Â free(phTunnel); |
|---|
| 5003 | Â Â Â Â Â Â Â Â phTunnel =Â 0; |
|---|
| 5004 | Â Â Â Â } |
|---|
| 5005 | #endif |
|---|
| 5006 | |
|---|
| 5007 | Â Â Â Â ph_media_cleanup(); |
|---|
| 5008 | Â Â Â Â ph_payload_cleanup(); |
|---|
| 5009 | |
|---|
| 5010 | Â Â Â Â osip_mutex_destroy(ph_media_start_mutex); |
|---|
| 5011 | Â Â Â Â osip_mutex_destroy(ph_custom_mutex); |
|---|
| 5012 | |
|---|
| 5013 | |
|---|
| 5014 |     if (phLogFileName && phDebugLevel > 0) |
|---|
| 5015 | Â Â Â Â Â Â Â Â fclose(ph_log_file); |
|---|
| 5016 |     if (phDebugLevel > 0) |
|---|
| 5017 |         for (i = 0; i <= phDebugLevel && i < END_TRACE_LEVEL; ++i) |
|---|
| 5018 | Â Â Â Â Â Â Â Â Â Â Â Â TRACE_DISABLE_LEVEL(i); |
|---|
| 5019 | |
|---|
| 5020 |     if (phLogFileName) |
|---|
| 5021 | Â Â Â Â Â Â Â Â free(phLogFileName); |
|---|
| 5022 | |
|---|
| 5023 | Â Â Â Â phLogFileName =Â 0; |
|---|
| 5024 | |
|---|
| 5025 | } |
|---|
| 5026 | |
|---|
| 5027 | |
|---|
| 5028 | |
|---|
| 5029 | /** |
|---|
| 5030 | Â * poll for phApi events.c |
|---|
| 5031 | Â */ |
|---|
| 5032 | PHAPI_EXPORT int |
|---|
| 5033 | phPoll() |
|---|
| 5034 | { |
|---|
| 5035 | |
|---|
| 5036 |     if (!phIsInitialized) |
|---|
| 5037 |         return -PH_NOTINIT; |
|---|
| 5038 | |
|---|
| 5039 |     if (!phcfg.asyncmode) |
|---|
| 5040 | Â Â Â Â { |
|---|
| 5041 |         if (ph_event_get() == -2) |
|---|
| 5042 |             return -2; |
|---|
| 5043 | |
|---|
| 5044 | Â Â Â Â Â Â Â Â ph_keep_refreshing(); |
|---|
| 5045 | Â Â Â Â } |
|---|
| 5046 |     return 0; |
|---|
| 5047 | } |
|---|
| 5048 | |
|---|
| 5049 | |
|---|
| 5050 | |
|---|
| 5051 | void ph_refer_notify(int did, int status, const char* msg, int final) |
|---|
| 5052 | { |
|---|
| 5053 |     char statusmsg[128]; |
|---|
| 5054 | Â Â Â Â osip_message_t *notify =Â 0; |
|---|
| 5055 |     int i; |
|---|
| 5056 | |
|---|
| 5057 |     snprintf(statusmsg, sizeof(statusmsg), "SIP/2.0 %d %s", status, msg); |
|---|
| 5058 | |
|---|
| 5059 | Â Â Â Â eXosip_lock(); |
|---|
| 5060 | |
|---|
| 5061 |     i = eXosip_call_build_notify(did, final ? EXOSIP_SUBCRSTATE_TERMINATED : EXOSIP_SUBCRSTATE_ACTIVE, ¬ify); |
|---|
| 5062 |     if (i) |
|---|
| 5063 |         goto err; |
|---|
| 5064 | |
|---|
| 5065 |     osip_message_set_body(notify, statusmsg, strlen(statusmsg)); |
|---|
| 5066 |     osip_message_set_content_type(notify, "message/sipfrag"); |
|---|
| 5067 | |
|---|
| 5068 |     i = eXosip_call_send_request(did, notify); |
|---|
| 5069 | |
|---|
| 5070 | Â Â Â Â err: |
|---|
| 5071 | Â Â Â Â eXosip_unlock(); |
|---|
| 5072 |     if (i && (notify != 0)) |
|---|
| 5073 | Â Â Â Â Â Â Â Â osip_message_free(notify); |
|---|
| 5074 | |
|---|
| 5075 | |
|---|
| 5076 | } |
|---|
| 5077 | char * ph_get_fixed_payload_name(int idx) |
|---|
| 5078 | { |
|---|
| 5079 | Â Â Â Â if(Â idx ==Â 0Â ) |
|---|
| 5080 |         return "PCMU"; |
|---|
| 5081 |     else if( idx == 8 ) |
|---|
| 5082 |         return "PCMA"; |
|---|
| 5083 |     else if( idx == 9 ) |
|---|
| 5084 |         return "G722"; |
|---|
| 5085 |     else if( idx == 18 ) |
|---|
| 5086 |         return "G729"; |
|---|
| 5087 |     else if( idx == 34 ) |
|---|
| 5088 |         return "H263"; |
|---|
| 5089 | |
|---|
| 5090 |     return NULL; |
|---|
| 5091 | } |
|---|
| 5092 | |
|---|
| 5093 | static int |
|---|
| 5094 | ph_call_retrieve_payloads(phcall_t *ca, int flags) |
|---|
| 5095 | { |
|---|
| 5096 |     int i = 0; |
|---|
| 5097 | |
|---|
| 5098 | Â Â Â Â DBG_SIP_NEGO("looking for payloads...\n"); |
|---|
| 5099 | Â Â Â Â DBG_SIP_NEGO("audio...\n"); |
|---|
| 5100 |     if (_is_audio_enabled(flags)) |
|---|
| 5101 | Â Â Â Â { |
|---|
| 5102 |         const sdp_payload_t *cur_payload; |
|---|
| 5103 | |
|---|
| 5104 |         if (osip_list_size(&ca->result_audio_payloads) > 0) |
|---|
| 5105 | Â Â Â Â Â Â Â Â { |
|---|
| 5106 |             cur_payload = (sdp_payload_t *) osip_list_get (&ca->result_audio_payloads, 0); |
|---|
| 5107 | Â Â Â Â Â Â Â Â Â Â Â Â ca->audio_payload =Â cur_payload->pt; |
|---|
| 5108 | |
|---|
| 5109 |             if (cur_payload->a_rtpmap) |
|---|
| 5110 |                 osip_strncpy(ca->audio_payload_name, cur_payload->a_rtpmap, sizeof(ca->audio_payload_name)-1); |
|---|
| 5111 | Â Â Â Â Â Â Â Â Â Â Â Â else |
|---|
| 5112 | Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 5113 |                 char * payload_name = ph_get_fixed_payload_name(ca->audio_payload); |
|---|
| 5114 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if(payload_name) |
|---|
| 5115 |                     osip_strncpy(ca->audio_payload_name, payload_name, sizeof(ca->audio_payload_name)-1); |
|---|
| 5116 | Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 5117 | |
|---|
| 5118 | Â Â Â Â Â Â Â Â Â Â Â Â ca->remote_ptime =Â cur_payload->a_ptime; |
|---|
| 5119 | Â Â Â Â Â Â Â Â } |
|---|
| 5120 | Â Â Â Â } |
|---|
| 5121 | |
|---|
| 5122 | Â Â Â Â DBG_SIP_NEGO("video...\n"); |
|---|
| 5123 | |
|---|
| 5124 |     if ((_is_video_enabled(flags))) |
|---|
| 5125 | Â Â Â Â { |
|---|
| 5126 |         const sdp_payload_t *cur_payload; |
|---|
| 5127 | |
|---|
| 5128 | Â Â Â Â Â Â Â Â ca->video_payload =Â 0; |
|---|
| 5129 |         if (osip_list_size(&ca->result_video_payloads) > 0) |
|---|
| 5130 | Â Â Â Â Â Â Â Â { |
|---|
| 5131 |             cur_payload = (sdp_payload_t *) osip_list_get (&ca->result_video_payloads, 0); |
|---|
| 5132 | Â Â Â Â Â Â Â Â Â Â Â Â ca->video_payload =Â cur_payload->pt; |
|---|
| 5133 |             if (cur_payload->a_rtpmap) |
|---|
| 5134 |                 osip_strncpy(ca->video_payload_name, cur_payload->a_rtpmap, sizeof(ca->video_payload_name)-1); |
|---|
| 5135 | Â Â Â Â Â Â Â Â Â Â Â Â else |
|---|
| 5136 | Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 5137 |                 char * payload_name = ph_get_fixed_payload_name(ca->audio_payload); |
|---|
| 5138 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if(payload_name) |
|---|
| 5139 |                     osip_strncpy(ca->video_payload_name, payload_name, sizeof(ca->video_payload_name)-1); |
|---|
| 5140 | Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 5141 | |
|---|
| 5142 | Â Â Â Â Â Â Â Â Â Â Â Â ca->remote_ptime =Â cur_payload->a_ptime; |
|---|
| 5143 | Â Â Â Â Â Â Â Â } |
|---|
| 5144 | Â Â Â Â } |
|---|
| 5145 | |
|---|
| 5146 | Â Â Â Â DBG_SIP_NEGO("cng...\n"); |
|---|
| 5147 | Â Â Â Â if(!i &&Â phcfg.cng &&Â (flags &Â PH_STREAM_CNG))Â { |
|---|
| 5148 | Â Â Â Â Â Â Â Â // ca->cng = !eXosip_retrieve_negotiated_specific_payload(ca->did, PH_MEDIA_CN_PT_STR, strlen(PH_MEDIA_CN_PT_STR)); |
|---|
| 5149 | Â Â Â Â Â Â Â Â // DBG_SIP_NEGO("cng: %d", ca->cng); |
|---|
| 5150 | Â Â Â Â } |
|---|
| 5151 |     return i; |
|---|
| 5152 | } |
|---|
| 5153 | |
|---|
| 5154 | |
|---|
| 5155 | PHAPI_EXPORT int phCallGetCodecs(int cid, char *audioCodecBuf, int aBufLen, char *videoCodecBuf, int vBufLen) |
|---|
| 5156 | { |
|---|
| 5157 | Â Â Â Â phcall_t *ca; |
|---|
| 5158 | |
|---|
| 5159 |     if (!phIsInitialized) |
|---|
| 5160 |         return -PH_NOTINIT; |
|---|
| 5161 | |
|---|
| 5162 | Â Â Â Â ca =Â ph_locate_call_by_cid(cid); |
|---|
| 5163 | |
|---|
| 5164 |     if (!ca) |
|---|
| 5165 |         return -PH_BADCID; |
|---|
| 5166 | |
|---|
| 5167 |     if (audioCodecBuf) |
|---|
| 5168 |         osip_strncpy(audioCodecBuf, ca->audio_payload_name, aBufLen-1); |
|---|
| 5169 | |
|---|
| 5170 |     if (videoCodecBuf) |
|---|
| 5171 |         osip_strncpy(videoCodecBuf, ca->video_payload_name, vBufLen-1); |
|---|
| 5172 | |
|---|
| 5173 |     return 0; |
|---|
| 5174 | |
|---|
| 5175 | |
|---|
| 5176 | } |
|---|
| 5177 | |
|---|
| 5178 | PHAPI_EXPORT int |
|---|
| 5179 | phCallGetMediaInfo(int cid, struct ph_confirmed_media_info *mi) |
|---|
| 5180 | { |
|---|
| 5181 | Â Â Â Â phcall_t *ca; |
|---|
| 5182 | |
|---|
| 5183 |     if (!phIsInitialized) |
|---|
| 5184 |         return -PH_NOTINIT; |
|---|
| 5185 | |
|---|
| 5186 | Â Â Â Â ca =Â ph_locate_call_by_cid(cid); |
|---|
| 5187 | |
|---|
| 5188 |     if (!ca) |
|---|
| 5189 |         return -PH_BADCID; |
|---|
| 5190 | |
|---|
| 5191 | Â Â Â Â mi->audio.localport =Â ca->loc_sdp_audio_port; |
|---|
| 5192 | Â Â Â Â mi->audio.remoteport =Â ca->remote_sdp_audio_port; |
|---|
| 5193 |     osip_strncpy(mi->audio.remoteip, ca->remote_sdp_audio_ip, sizeof(mi->audio.remoteip-1)); |
|---|
| 5194 | Â Â Â Â mi->video.localport =Â ca->loc_sdp_video_port; |
|---|
| 5195 | Â Â Â Â mi->video.remoteport =Â ca->remote_sdp_video_port; |
|---|
| 5196 |     osip_strncpy(mi->video.remoteip, ca->remote_sdp_video_ip, sizeof(mi->video.remoteip)-1); |
|---|
| 5197 | |
|---|
| 5198 |     return 0; |
|---|
| 5199 | |
|---|
| 5200 | } |
|---|
| 5201 | |
|---|
| 5202 | static void |
|---|
| 5203 | ph_parse_payload_mime(struct ph_media_payload_s *pt, const char *mime, int rate, int chans) |
|---|
| 5204 | { |
|---|
| 5205 |     const char *rp = 0; |
|---|
| 5206 |     const char *cp = 0; |
|---|
| 5207 | |
|---|
| 5208 |     if (mime) { |
|---|
| 5209 |       rp = strchr(mime, '/'); |
|---|
| 5210 |       strncpy(pt->string, mime, sizeof(pt->string)); |
|---|
| 5211 | Â Â Â Â } |
|---|
| 5212 | Â Â Â Â pt->rate =Â rate; |
|---|
| 5213 | Â Â Â Â pt->chans =Â chans; |
|---|
| 5214 | |
|---|
| 5215 | |
|---|
| 5216 |     if (!rp) |
|---|
| 5217 | Â Â Â Â Â Â Â Â return; |
|---|
| 5218 | |
|---|
| 5219 | Â Â Â Â rp++; |
|---|
| 5220 |     if (!*rp) |
|---|
| 5221 | Â Â Â Â Â Â Â Â return; |
|---|
| 5222 | |
|---|
| 5223 | Â Â Â Â pt->rate =Â atol(rp); |
|---|
| 5224 | |
|---|
| 5225 |     cp = strchr(rp, '/'); |
|---|
| 5226 |     if (!cp) |
|---|
| 5227 | Â Â Â Â Â Â Â Â return; |
|---|
| 5228 | |
|---|
| 5229 | Â Â Â Â cp++; |
|---|
| 5230 |     if (!*cp) |
|---|
| 5231 | Â Â Â Â Â Â Â Â return; |
|---|
| 5232 | |
|---|
| 5233 | Â Â Â Â pt->chans =Â atol(cp); |
|---|
| 5234 | } |
|---|
| 5235 | |
|---|
| 5236 | |
|---|
| 5237 | |
|---|
| 5238 | static int |
|---|
| 5239 | ph_call_media_stop(phcall_t *ca) |
|---|
| 5240 | { |
|---|
| 5241 | Â Â Â Â DBG_SIP_NEGO("SIP_NEGO: ph_call_media_stop\n"); |
|---|
| 5242 | |
|---|
| 5243 |     if (ca->mses) |
|---|
| 5244 | Â Â Â Â { |
|---|
| 5245 |         if (ca->mses->refcnt == 1) |
|---|
| 5246 | Â Â Â Â Â Â Â Â { |
|---|
| 5247 |             if (!ca->audiodev_in) |
|---|
| 5248 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ca->audiodev_in =Â osip_strdup(phcfg.audio_dev_in); |
|---|
| 5249 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 5250 |             if (!ca->audiodev_out) |
|---|
| 5251 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ca->audiodev_out =Â osip_strdup(phcfg.audio_dev_out); |
|---|
| 5252 | |
|---|
| 5253 |             if (!ph_msession_stopped(ca->mses)) |
|---|
| 5254 | Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 5255 |                 ph_msession_stop(ca->mses, ca->audiodev_in, ca->audiodev_out,0); |
|---|
| 5256 | Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 5257 | Â Â Â Â Â Â Â Â } |
|---|
| 5258 | Â Â Â Â Â Â Â Â ph_msession_free(ca->mses); |
|---|
| 5259 | Â Â Â Â Â Â Â Â ca->mses =Â 0; |
|---|
| 5260 | Â Â Â Â } |
|---|
| 5261 | |
|---|
| 5262 |     return 0; |
|---|
| 5263 | |
|---|
| 5264 | } |
|---|
| 5265 | |
|---|
| 5266 | static int |
|---|
| 5267 | ph_call_media_suspend(phcall_t *ca, int localhold) |
|---|
| 5268 | { |
|---|
| 5269 |     if (ca->mses) |
|---|
| 5270 | Â Â Â Â { |
|---|
| 5271 |         if (!ca->audiodev_in) |
|---|
| 5272 | Â Â Â Â Â Â Â Â Â Â Â Â ca->audiodev_in =Â osip_strdup(phcfg.audio_dev_in); |
|---|
| 5273 | |
|---|
| 5274 |         ph_msession_suspend(ca->mses, PH_MSTREAM_TRAFFIC_IO, ca->audiodev_in, ca->audiodev_out); |
|---|
| 5275 | Â Â Â Â } |
|---|
| 5276 | |
|---|
| 5277 |     return 0; |
|---|
| 5278 | } |
|---|
| 5279 | |
|---|
| 5280 | |
|---|
| 5281 | static int |
|---|
| 5282 | ph_call_media_resume(phcall_t *ca, int localhold) |
|---|
| 5283 | { |
|---|
| 5284 |     if (ca->mses) |
|---|
| 5285 | Â Â Â Â { |
|---|
| 5286 |         if (!ca->audiodev_in) |
|---|
| 5287 | Â Â Â Â Â Â Â Â Â Â Â Â ca->audiodev_in =Â osip_strdup(phcfg.audio_dev_in); |
|---|
| 5288 | Â Â Â Â Â Â Â Â |
|---|
| 5289 |         if (!ca->audiodev_out) |
|---|
| 5290 | Â Â Â Â Â Â Â Â Â Â Â Â ca->audiodev_out =Â osip_strdup(phcfg.audio_dev_out); |
|---|
| 5291 | Â Â Â Â Â Â Â Â |
|---|
| 5292 |         ph_msession_resume(ca->mses, PH_MSTREAM_TRAFFIC_IO, ca->audiodev_in, ca->audiodev_out, 0); |
|---|
| 5293 | Â Â Â Â } |
|---|
| 5294 | |
|---|
| 5295 |     return 0; |
|---|
| 5296 | } |
|---|
| 5297 | |
|---|
| 5298 | |
|---|
| 5299 | |
|---|
| 5300 | static |
|---|
| 5301 | struct ph_msession_s *ph_msession_new() |
|---|
| 5302 | { |
|---|
| 5303 |     struct ph_msession_s *s = (struct ph_msession_s *)calloc(sizeof(struct ph_msession_s), 1); |
|---|
| 5304 | Â Â Â Â s->critsec_mstream_init =Â osip_mutex_init(); |
|---|
| 5305 | Â Â Â Â s->refcnt =Â 1; |
|---|
| 5306 |     return s; |
|---|
| 5307 | } |
|---|
| 5308 | |
|---|
| 5309 | |
|---|
| 5310 | static |
|---|
| 5311 | void ph_msession_use(struct ph_msession_s *s) |
|---|
| 5312 | { |
|---|
| 5313 |     if (s) |
|---|
| 5314 | Â Â Â Â { |
|---|
| 5315 | Â Â Â Â Â Â Â Â osip_mutex_lock(s->critsec_mstream_init); |
|---|
| 5316 | Â Â Â Â Â Â Â Â s->refcnt++; |
|---|
| 5317 | Â Â Â Â Â Â Â Â osip_mutex_unlock(s->critsec_mstream_init); |
|---|
| 5318 | Â Â Â Â } |
|---|
| 5319 | } |
|---|
| 5320 | |
|---|
| 5321 | static |
|---|
| 5322 | void ph_msession_free(struct ph_msession_s *s) |
|---|
| 5323 | { |
|---|
| 5324 |     if (s) |
|---|
| 5325 | Â Â Â Â { |
|---|
| 5326 | Â Â Â Â Â Â Â Â osip_mutex_lock(s->critsec_mstream_init); |
|---|
| 5327 |         if (s->refcnt-- == 1) |
|---|
| 5328 | Â Â Â Â Â Â Â Â { |
|---|
| 5329 | Â Â Â Â Â Â Â Â Â Â Â Â osip_mutex_unlock(s->critsec_mstream_init); |
|---|
| 5330 | Â Â Â Â Â Â Â Â Â Â Â Â osip_mutex_destroy(s->critsec_mstream_init); |
|---|
| 5331 | Â Â Â Â Â Â Â Â Â Â Â Â free(s); |
|---|
| 5332 | Â Â Â Â Â Â Â Â Â Â Â Â return; |
|---|
| 5333 | Â Â Â Â Â Â Â Â } |
|---|
| 5334 | Â Â Â Â Â Â Â Â osip_mutex_unlock(s->critsec_mstream_init); |
|---|
| 5335 | Â Â Â Â } |
|---|
| 5336 | } |
|---|
| 5337 | |
|---|
| 5338 | static int |
|---|
| 5339 | ph_call_media_start(phcall_t *ca, eXosip_event_t *je, int flags, int resumeflag) |
|---|
| 5340 | { |
|---|
| 5341 |     int use_socket; |
|---|
| 5342 |     int result = 0; |
|---|
| 5343 |     struct ph_msession_s *s = NULL; |
|---|
| 5344 |     const char* ptime = getenv("EXOSIP_FORCE_PTIME"); |
|---|
| 5345 |     if (!ptime || !*ptime) |
|---|
| 5346 | Â Â Â Â Â Â Â Â ptime =Â "20"; |
|---|
| 5347 | |
|---|
| 5348 |     if (!ca) |
|---|
| 5349 |         return -PH_BADARG; |
|---|
| 5350 | |
|---|
| 5351 | Â Â Â Â // cases when the invocation is ignored |
|---|
| 5352 |     if (phcfg.nomedia || ca->remotehold) |
|---|
| 5353 | Â Â Â Â { |
|---|
| 5354 |         return 0; |
|---|
| 5355 | Â Â Â Â } |
|---|
| 5356 | |
|---|
| 5357 | Â Â Â Â // we will work on the media sessions of the given phcall_t |
|---|
| 5358 | Â Â Â Â s =Â ca->mses; |
|---|
| 5359 | |
|---|
| 5360 | Â Â Â Â osip_mutex_lock(ph_media_start_mutex); |
|---|
| 5361 | |
|---|
| 5362 | Â Â Â Â // init the ph_msession_s for the call if the call doesn't have one yet |
|---|
| 5363 |     if (!s) |
|---|
| 5364 | Â Â Â Â { |
|---|
| 5365 | Â Â Â Â Â Â Â Â s =Â ca->mses =Â ph_msession_new(); |
|---|
| 5366 |         if (!s) |
|---|
| 5367 | Â Â Â Â Â Â Â Â { |
|---|
| 5368 | Â Â Â Â Â Â Â Â Â Â Â Â osip_mutex_unlock(ph_media_start_mutex); |
|---|
| 5369 |             return -PH_NORESOURCES; |
|---|
| 5370 | Â Â Â Â Â Â Â Â } |
|---|
| 5371 | Â Â Â Â Â Â Â Â s->confflags =Â 0; |
|---|
| 5372 | Â Â Â Â Â Â Â Â s->confsession =Â NULL; |
|---|
| 5373 | Â Â Â Â Â Â Â Â s->audio_conf =Â NULL; |
|---|
| 5374 | Â Â Â Â Â Â Â Â s->activestreams =Â 0; |
|---|
| 5375 | Â Â Â Â Â Â Â Â s->dtmfCallback =Â ph_wegot_dtmf; |
|---|
| 5376 | Â Â Â Â Â Â Â Â s->endCallback =Â ph_stream_ended; |
|---|
| 5377 | Â Â Â Â Â Â Â Â s->qosInfoCbk =Â ph_qos_info_cbk; |
|---|
| 5378 | Â Â Â Â Â Â Â Â s->frameDisplayCbk =Â ph_frame_display_cbk; |
|---|
| 5379 | Â Â Â Â } |
|---|
| 5380 | Â Â Â Â else |
|---|
| 5381 | Â Â Â Â { |
|---|
| 5382 | Â Â Â Â Â Â Â Â if(resumeflag ==Â 0) |
|---|
| 5383 | Â Â Â Â Â Â Â Â { |
|---|
| 5384 | Â Â Â Â Â Â Â Â Â Â Â Â if(s->activestreams) |
|---|
| 5385 | Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 5386 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â osip_mutex_lock(ph_media_stop_mutex); |
|---|
| 5387 |                 ph_msession_stop(s, phcfg.audio_dev_in, phcfg.audio_dev_out, 0); |
|---|
| 5388 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â osip_mutex_unlock(ph_media_stop_mutex); |
|---|
| 5389 | Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 5390 | Â Â Â Â Â Â Â Â Â Â Â Â s->confflags =Â 0; |
|---|
| 5391 | Â Â Â Â Â Â Â Â Â Â Â Â s->confsession =Â NULL; |
|---|
| 5392 | Â Â Â Â Â Â Â Â Â Â Â Â s->audio_conf =Â NULL; |
|---|
| 5393 | Â Â Â Â Â Â Â Â Â Â Â Â s->activestreams =Â 0; |
|---|
| 5394 | Â Â Â Â Â Â Â Â } |
|---|
| 5395 | Â Â Â Â } |
|---|
| 5396 | Â Â Â Â s->cbkInfo =Â ca; |
|---|
| 5397 | |
|---|
| 5398 | Â Â Â Â // we need to understand what is required from the function call |
|---|
| 5399 | Â Â Â Â // by default, nothing to do |
|---|
| 5400 | Â Â Â Â s->newstreams =Â 0; |
|---|
| 5401 | |
|---|
| 5402 |     if ( _is_video_enabled(ca->nego_mflags) && ca->video_payload && ca->remote_sdp_video_ip[0] && osip_strcasecmp(ca->remote_sdp_video_ip, "0")) |
|---|
| 5403 | Â Â Â Â { |
|---|
| 5404 |         struct ph_mstream_params_s *msp = &s->streams[PH_MSTREAM_VIDEO1]; |
|---|
| 5405 |         int ttype; |
|---|
| 5406 | |
|---|
| 5407 | Â Â Â Â Â Â Â Â // program activation of VIDEO1 |
|---|
| 5408 | Â Â Â Â Â Â Â Â s->newstreams |=Â (1Â <<Â PH_MSTREAM_VIDEO1); |
|---|
| 5409 | |
|---|
| 5410 | Â Â Â Â Â Â Â Â // define the traffic type of the stream |
|---|
| 5411 | Â Â Â Â Â Â Â Â ttype =Â _is_video_enabled(ca->nego_mflags); |
|---|
| 5412 |         if (ttype == (PH_STREAM_VIDEO_RX | PH_STREAM_VIDEO_TX)) |
|---|
| 5413 | Â Â Â Â Â Â Â Â { |
|---|
| 5414 | Â Â Â Â Â Â Â Â Â Â Â Â msp->traffictype =Â PH_MSTREAM_TRAFFIC_IO; |
|---|
| 5415 | Â Â Â Â Â Â Â Â } |
|---|
| 5416 |         else if (ttype == PH_STREAM_VIDEO_RX) |
|---|
| 5417 | Â Â Â Â Â Â Â Â { |
|---|
| 5418 | Â Â Â Â Â Â Â Â Â Â Â Â msp->traffictype =Â PH_MSTREAM_TRAFFIC_IN; |
|---|
| 5419 | Â Â Â Â Â Â Â Â } |
|---|
| 5420 |         else if (ttype == PH_STREAM_VIDEO_TX) |
|---|
| 5421 | Â Â Â Â Â Â Â Â { |
|---|
| 5422 | Â Â Â Â Â Â Â Â Â Â Â Â msp->traffictype =Â PH_MSTREAM_TRAFFIC_OUT; |
|---|
| 5423 | Â Â Â Â Â Â Â Â } |
|---|
| 5424 | |
|---|
| 5425 | Â Â Â Â Â Â Â Â msp->localport =Â ca->loc_sdp_video_port; |
|---|
| 5426 | Â Â Â Â Â Â Â Â msp->remoteport =Â ca->remote_sdp_video_port; |
|---|
| 5427 | Â Â Â Â Â Â Â Â msp->remotertcpport =Â ca->remote_sdp_video_rtcp_port; |
|---|
| 5428 | Â Â Â Â Â Â Â Â osip_strncpy(msp->remoteaddr, |
|---|
| 5429 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ca->remote_sdp_video_ip, |
|---|
| 5430 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â sizeof(msp->remoteaddr)-1); |
|---|
| 5431 | Â Â Â Â Â Â Â Â |
|---|
| 5432 | Â Â Â Â Â Â Â Â { |
|---|
| 5433 |             const sdp_payload_t *cur_payload; |
|---|
| 5434 |             int pos = osip_list_size(&ca->result_video_payloads); |
|---|
| 5435 |             int i = 0; |
|---|
| 5436 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 5437 |             for (; i < pos ; i++) |
|---|
| 5438 | Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 5439 |                 cur_payload = (sdp_payload_t *) osip_list_get (&ca->result_video_payloads, i); |
|---|
| 5440 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 5441 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â msp->ipayloads[i].number =Â cur_payload->pt; |
|---|
| 5442 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if(cur_payload->a_rtpmap) |
|---|
| 5443 |                     ph_parse_payload_mime(&msp->ipayloads[0], cur_payload->a_rtpmap, 90000, 1); |
|---|
| 5444 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â else |
|---|
| 5445 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 5446 |                     char * payload_name = ph_get_fixed_payload_name(msp->ipayloads[i].number); |
|---|
| 5447 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if(payload_name) |
|---|
| 5448 |                         ph_parse_payload_mime(&msp->ipayloads[i], payload_name, 90000, 1); |
|---|
| 5449 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 5450 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â msp->opayloads[i]Â =Â msp->ipayloads[i]; |
|---|
| 5451 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â msp->opayloads[i].ptime =Â cur_payload->a_ptime; |
|---|
| 5452 | Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 5453 | Â Â Â Â Â Â Â Â } |
|---|
| 5454 | |
|---|
| 5455 | Â Â Â Â Â Â Â Â // define the video callback |
|---|
| 5456 | Â Â Â Â Â Â Â Â |
|---|
| 5457 | |
|---|
| 5458 | Â Â Â Â Â Â Â Â // additional configuration for video |
|---|
| 5459 | |
|---|
| 5460 |         /* if(sdp_message_bandwidth_get(ca->remote_sdp, ) && !phcfg.video_config.force_high_speed) |
|---|
| 5461 | Â Â Â { |
|---|
| 5462 | Â Â Â msp->video_quality = ph_get_quality_from_bitrate(ca->max_bandwidth); |
|---|
| 5463 | Â Â Â } |
|---|
| 5464 | Â Â else |
|---|
| 5465 | Â Â msp->video_quality = phcfg.video_config.video_line_configuration;*/ |
|---|
| 5466 | Â Â Â Â } |
|---|
| 5467 | |
|---|
| 5468 |     if (_is_audio_enabled(ca->nego_mflags) && ca->remote_sdp_audio_ip[0] && osip_strcasecmp(ca->remote_sdp_audio_ip, "0")) |
|---|
| 5469 | Â Â Â Â { |
|---|
| 5470 |         struct ph_mstream_params_s *msp = &s->streams[PH_MSTREAM_AUDIO1]; |
|---|
| 5471 |         int ttype = 0; |
|---|
| 5472 | |
|---|
| 5473 | Â Â Â Â Â Â Â Â //TODO uncomment it after the work un payloads |
|---|
| 5474 | Â Â Â Â Â Â Â Â /*if(!strncmp(ca->audio_payload_name, "GSM", 3)) |
|---|
| 5475 | Â Â Â Â Â Â Â Â { |
|---|
| 5476 | Â Â Â Â Â Â Â Â Â Â Â Â if(30 == atoi(ptime)) |
|---|
| 5477 | Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 5478 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // for GSM reset ptime to 20ms |
|---|
| 5479 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ptime = "20"; |
|---|
| 5480 | Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 5481 | Â Â Â Â Â Â Â Â }*/ |
|---|
| 5482 | Â Â Â Â Â Â Â Â // Set to this stream the correct ptime negociated in the SDP |
|---|
| 5483 | Â Â Â Â Â Â Â Â // If there is no ptime negociated, use the default value (20 ms) |
|---|
| 5484 | Â Â Â Â Â Â Â Â //msp->ptime = (ca && ca->ptime > 0 ? ca->ptime : atoi(ptime)); |
|---|
| 5485 | Â Â Â Â Â Â Â Â msp->ptime =Â atoi(ptime); |
|---|
| 5486 | |
|---|
| 5487 | Â Â Â Â Â Â Â Â // program activation of AUDIO1 |
|---|
| 5488 | Â Â Â Â Â Â Â Â s->newstreams |=Â (1Â <<Â PH_MSTREAM_AUDIO1); |
|---|
| 5489 | |
|---|
| 5490 |         if (phcfg.vad & 0x80000000) |
|---|
| 5491 | Â Â Â Â Â Â Â Â { |
|---|
| 5492 | Â Â Â Â Â Â Â Â Â Â Â Â msp->flags |=Â PH_MSTREAM_FLAG_VAD; |
|---|
| 5493 | Â Â Â Â Â Â Â Â Â Â Â Â msp->vadthreshold =Â phcfg.vad &Â 0x7fff; |
|---|
| 5494 | Â Â Â Â Â Â Â Â } |
|---|
| 5495 | |
|---|
| 5496 |         if (phcfg.cng) |
|---|
| 5497 | Â Â Â Â Â Â Â Â { |
|---|
| 5498 | Â Â Â Â Â Â Â Â Â Â Â Â msp->flags |=Â PH_MSTREAM_FLAG_CNG; |
|---|
| 5499 | Â Â Â Â Â Â Â Â } |
|---|
| 5500 | |
|---|
| 5501 | Â Â Â Â Â Â Â Â msp->jitter =Â phcfg.jitterdepth; |
|---|
| 5502 | |
|---|
| 5503 |         if (!phcfg.noaec) |
|---|
| 5504 | Â Â Â Â Â Â Â Â { |
|---|
| 5505 | Â Â Â Â Â Â Â Â Â Â Â Â msp->flags |=Â PH_MSTREAM_FLAG_AEC; |
|---|
| 5506 | Â Â Â Â Â Â Â Â } |
|---|
| 5507 | |
|---|
| 5508 | Â Â Â Â Â Â Â Â ttype =Â _is_audio_enabled(ca->nego_mflags); |
|---|
| 5509 |         if (ttype == (PH_STREAM_AUDIO_RX | PH_STREAM_AUDIO_TX)) |
|---|
| 5510 | Â Â Â Â Â Â Â Â { |
|---|
| 5511 | Â Â Â Â Â Â Â Â Â Â Â Â msp->traffictype =Â PH_MSTREAM_TRAFFIC_IO; |
|---|
| 5512 | Â Â Â Â Â Â Â Â } |
|---|
| 5513 |         else if (ttype == PH_STREAM_AUDIO_RX) |
|---|
| 5514 | Â Â Â Â Â Â Â Â { |
|---|
| 5515 | Â Â Â Â Â Â Â Â Â Â Â Â msp->traffictype =Â PH_MSTREAM_TRAFFIC_IN; |
|---|
| 5516 | Â Â Â Â Â Â Â Â } |
|---|
| 5517 |         else if (ttype == PH_STREAM_AUDIO_TX) |
|---|
| 5518 | Â Â Â Â Â Â Â Â { |
|---|
| 5519 | Â Â Â Â Â Â Â Â Â Â Â Â msp->traffictype =Â PH_MSTREAM_TRAFFIC_OUT; |
|---|
| 5520 | Â Â Â Â Â Â Â Â } |
|---|
| 5521 | Â Â Â Â Â Â Â Â |
|---|
| 5522 | Â Â Â Â Â Â Â Â msp->localport =Â ca->loc_sdp_audio_port; |
|---|
| 5523 | |
|---|
| 5524 | Â Â Â Â Â Â Â Â msp->remoteport =Â ca->remote_sdp_audio_port; |
|---|
| 5525 | Â Â Â Â Â Â Â Â msp->remotertcpport =Â ca->remote_sdp_audio_rtcp_port; |
|---|
| 5526 | Â Â Â Â Â Â Â Â use_socket =Â 0; |
|---|
| 5527 | Â Â Â Â Â Â Â Â msp->rtcptr =Â ca->audio_rtcptr; |
|---|
| 5528 | Â Â Â Â Â Â Â Â msp->rtptr =Â ca->audio_rtptr; |
|---|
| 5529 | |
|---|
| 5530 | Â Â Â Â Â Â Â Â osip_strncpy(msp->remoteaddr, |
|---|
| 5531 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ca->remote_sdp_audio_ip, |
|---|
| 5532 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â sizeof(msp->remoteaddr)-1); |
|---|
| 5533 | |
|---|
| 5534 | Â Â Â Â Â Â Â Â // SPIKE_HDX |
|---|
| 5535 |         if (phcfg.hdxmode == PH_HDX_MODE_MIC) |
|---|
| 5536 | Â Â Â Â Â Â Â Â { |
|---|
| 5537 | Â Â Â Â Â Â Â Â Â Â Â Â msp->flags |=Â PH_MSTREAM_FLAG_MICHDX; |
|---|
| 5538 | Â Â Â Â Â Â Â Â Â Â Â Â msp->vadthreshold =Â phcfg.vad &Â 0x7fff; |
|---|
| 5539 | Â Â Â Â Â Â Â Â } |
|---|
| 5540 | |
|---|
| 5541 |         if (phcfg.hdxmode == PH_HDX_MODE_SPK) |
|---|
| 5542 | Â Â Â Â Â Â Â Â { |
|---|
| 5543 | Â Â Â Â Â Â Â Â Â Â Â Â msp->flags |=Â PH_MSTREAM_FLAG_SPKHDX; |
|---|
| 5544 | Â Â Â Â Â Â Â Â Â Â Â Â msp->vadthreshold =Â phcfg.vad &Â 0x7fff; |
|---|
| 5545 | Â Â Â Â Â Â Â Â } |
|---|
| 5546 | |
|---|
| 5547 | Â Â Â Â Â Â Â Â { |
|---|
| 5548 |             const sdp_payload_t *cur_payload; |
|---|
| 5549 |             int pos = osip_list_size(&ca->result_audio_payloads); |
|---|
| 5550 |             int i = 0; |
|---|
| 5551 | |
|---|
| 5552 |             for (; i < pos ; i++) |
|---|
| 5553 | Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 5554 |                 cur_payload = (sdp_payload_t *) osip_list_get (&ca->result_audio_payloads, i); |
|---|
| 5555 | |
|---|
| 5556 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â msp->ipayloads[i].number =Â cur_payload->pt; |
|---|
| 5557 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if(cur_payload->a_rtpmap) |
|---|
| 5558 |                     ph_parse_payload_mime(&msp->ipayloads[i], cur_payload->a_rtpmap, 8000, 1); |
|---|
| 5559 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â else |
|---|
| 5560 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 5561 |                     char * payload_name = ph_get_fixed_payload_name(msp->ipayloads[i].number); |
|---|
| 5562 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if(payload_name) |
|---|
| 5563 |                         ph_parse_payload_mime(&msp->ipayloads[i], payload_name, 8000, 1); |
|---|
| 5564 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 5565 |                 if (!strcasecmp(msp->ipayloads[i].string, "g722")) |
|---|
| 5566 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â msp->ipayloads[i].rate =Â 16000; |
|---|
| 5567 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â msp->opayloads[i]Â =Â msp->ipayloads[i]; |
|---|
| 5568 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â msp->opayloads[i].ptime =Â cur_payload->a_ptime; |
|---|
| 5569 | Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 5570 | Â Â Â Â Â Â Â Â } |
|---|
| 5571 | |
|---|
| 5572 |     } // end    if ( // audio is enabled |
|---|
| 5573 | |
|---|
| 5574 | Â Â Â Â // take action depending on the streaming configuration |
|---|
| 5575 |     if (s->newstreams || s->activestreams) |
|---|
| 5576 | Â Â Â Â { |
|---|
| 5577 |         if (ph_msession_start(s, ca->audiodev_in, ca->audiodev_out, use_socket)) |
|---|
| 5578 | Â Â Â Â Â Â Â Â { |
|---|
| 5579 | Â Â Â Â Â Â Â Â Â Â Â Â DBG_SIP_NEGO("SIP_NEGO:ph_call_media_start: just called ph_msession_start\n"); |
|---|
| 5580 | Â Â Â Â Â Â Â Â Â Â Â Â result =Â -PH_NOMEDIA; |
|---|
| 5581 | Â Â Â Â Â Â Â Â } |
|---|
| 5582 | Â Â Â Â } |
|---|
| 5583 | Â Â Â Â else |
|---|
| 5584 | Â Â Â Â { |
|---|
| 5585 | Â Â Â Â Â Â Â Â DBG_SIP_NEGO("SIP_NEGO:ph_call_media_start: nothing to start\n"); |
|---|
| 5586 | Â Â Â Â Â Â Â Â result =Â -PH_NOMEDIA; |
|---|
| 5587 | Â Â Â Â } |
|---|
| 5588 | |
|---|
| 5589 | Â Â Â Â osip_mutex_unlock(ph_media_start_mutex); |
|---|
| 5590 | |
|---|
| 5591 |     return result; |
|---|
| 5592 | } |
|---|
| 5593 | |
|---|
| 5594 | static char * |
|---|
| 5595 | ph_req_get_from(osip_message_t *msg); |
|---|
| 5596 | |
|---|
| 5597 | |
|---|
| 5598 | |
|---|
| 5599 | |
|---|
| 5600 | void |
|---|
| 5601 | ph_call_new(eXosip_event_t *je) |
|---|
| 5602 | { |
|---|
| 5603 | Â Â Â Â phCallStateInfo_t info; |
|---|
| 5604 | Â Â Â Â phcall_t *ca; |
|---|
| 5605 |     struct vline *vl; |
|---|
| 5606 |     char *localUri = NULL, *remoteUri= NULL, *sdp = NULL; |
|---|
| 5607 |     int i; |
|---|
| 5608 | |
|---|
| 5609 | Â Â Â Â clear(info); |
|---|
| 5610 |     if (ph_busyFlag) |
|---|
| 5611 | Â Â Â Â { |
|---|
| 5612 |         ph_answer_request(je->cid, je->tid, 486, 0); |
|---|
| 5613 |         goto done; |
|---|
| 5614 | Â Â Â Â } |
|---|
| 5615 | |
|---|
| 5616 |     if (ph_follow_me_addr[0]) |
|---|
| 5617 | Â Â Â Â { |
|---|
| 5618 |         ph_answer_request(je->cid, je->tid, 302, ph_follow_me_addr); |
|---|
| 5619 |         goto done; |
|---|
| 5620 | Â Â Â Â } |
|---|
| 5621 |     osip_uri_to_str(je->request->req_uri, &localUri); |
|---|
| 5622 |     osip_uri_to_str(osip_from_get_url(je->request->from), &remoteUri); |
|---|
| 5623 |     info.vlid = ph_get_vline_id(localUri, NULL); |
|---|
| 5624 | |
|---|
| 5625 |     if (!info.vlid) |
|---|
| 5626 | Â Â Â Â { |
|---|
| 5627 |         ph_answer_request(je->cid, je->tid, 404, 0); |
|---|
| 5628 |         goto done; |
|---|
| 5629 | Â Â Â Â } |
|---|
| 5630 | |
|---|
| 5631 | Â Â Â Â vl =Â ph_vlid2vline(info.vlid); |
|---|
| 5632 | |
|---|
| 5633 | Â Â Â Â assert(vl!=NULL); |
|---|
| 5634 | |
|---|
| 5635 |     ca = ph_locate_call(je, 1); |
|---|
| 5636 |     if (ca) |
|---|
| 5637 | Â Â Â Â { |
|---|
| 5638 |         if (vl->busy) |
|---|
| 5639 | Â Â Â Â Â Â Â Â { |
|---|
| 5640 |             ph_answer_request(je->cid, je->tid, 486, vl->contact); |
|---|
| 5641 |             goto done; |
|---|
| 5642 | Â Â Â Â Â Â Â Â } |
|---|
| 5643 | |
|---|
| 5644 |         if (vl->followme && vl->followme[0]) |
|---|
| 5645 | Â Â Â Â Â Â Â Â { |
|---|
| 5646 |             ph_answer_request(je->cid, je->tid, 302, vl->followme); |
|---|
| 5647 |             goto done; |
|---|
| 5648 | Â Â Â Â Â Â Â Â } |
|---|
| 5649 | |
|---|
| 5650 | Â Â Â Â Â Â Â Â ca->vlid =Â info.vlid; |
|---|
| 5651 | Â Â Â Â Â Â Â Â ca->state =Â PH_CALLEE_RECEIVED; |
|---|
| 5652 | |
|---|
| 5653 |         i = ph_build_cname(ca->cname, sizeof(ca->cname), vl); |
|---|
| 5654 | |
|---|
| 5655 |         if (i) |
|---|
| 5656 | Â Â Â Â Â Â Â Â { |
|---|
| 5657 |             ph_answer_request(je->cid, je->tid, 400, vl->contact); |
|---|
| 5658 |             goto done; |
|---|
| 5659 | Â Â Â Â Â Â Â Â } |
|---|
| 5660 | |
|---|
| 5661 |         if (phcfg.audio_dev_in) { |
|---|
| 5662 | Â Â Â Â Â Â Â Â Â Â Â Â ca->audiodev_in =Â osip_strdup(phcfg.audio_dev_in); |
|---|
| 5663 | Â Â Â Â Â Â Â Â } |
|---|
| 5664 | Â Â Â Â Â Â Â Â |
|---|
| 5665 |         if (phcfg.audio_dev_out) { |
|---|
| 5666 | Â Â Â Â Â Â Â Â Â Â Â Â ca->audiodev_out =Â osip_strdup(phcfg.audio_dev_out); |
|---|
| 5667 | Â Â Â Â Â Â Â Â } |
|---|
| 5668 | |
|---|
| 5669 | Â Â Â Â Â Â Â Â info.userData =Â je->external_reference; |
|---|
| 5670 | Â Â Â Â Â Â Â Â info.event =Â phINCALL; |
|---|
| 5671 | Â Â Â Â Â Â Â Â info.remoteUri =Â remoteUri; |
|---|
| 5672 | Â Â Â Â Â Â Â Â info.localUri =Â localUri; |
|---|
| 5673 | Â Â Â Â Â Â Â Â info.streams =Â ca->nego_mflags; |
|---|
| 5674 | Â Â Â Â Â Â Â Â info.callinfo =Â 0;Â //je->call_info; |
|---|
| 5675 | |
|---|
| 5676 | Â Â Â Â Â Â Â Â info.remoteSdp =Â sdp =Â ph_req_get_body(je->response); |
|---|
| 5677 | |
|---|
| 5678 |         ph_apply_header_monitor(je->request, &info.hlist); |
|---|
| 5679 | |
|---|
| 5680 |         phcb->callProgress(ca->cid, &info); |
|---|
| 5681 | done: |
|---|
| 5682 |         if (remoteUri) |
|---|
| 5683 | Â Â Â Â Â Â Â Â Â Â Â Â osip_free(remoteUri); |
|---|
| 5684 | |
|---|
| 5685 |         if (localUri) |
|---|
| 5686 | Â Â Â Â Â Â Â Â Â Â Â Â osip_free(localUri); |
|---|
| 5687 | |
|---|
| 5688 |         if (sdp) |
|---|
| 5689 | Â Â Â Â Â Â Â Â Â Â Â Â osip_free(sdp); |
|---|
| 5690 | |
|---|
| 5691 |         if (info.hlist.elems) |
|---|
| 5692 | Â Â Â Â Â Â Â Â Â Â Â Â osip_free(info.hlist.elems); |
|---|
| 5693 | |
|---|
| 5694 | Â Â Â Â } |
|---|
| 5695 | } |
|---|
| 5696 | |
|---|
| 5697 | #define ph_req_get_status(x) osip_message_get_status_code(x) |
|---|
| 5698 | |
|---|
| 5699 | |
|---|
| 5700 | static char * |
|---|
| 5701 | ph_req_get_to(osip_message_t *msg) |
|---|
| 5702 | { |
|---|
| 5703 |     char *str = 0; |
|---|
| 5704 | |
|---|
| 5705 |     osip_to_to_str(msg->to, &str); |
|---|
| 5706 |     return str; |
|---|
| 5707 | } |
|---|
| 5708 | |
|---|
| 5709 | static char * |
|---|
| 5710 | ph_req_get_from(osip_message_t *msg) |
|---|
| 5711 | { |
|---|
| 5712 |     char *str = 0; |
|---|
| 5713 | |
|---|
| 5714 |     osip_from_to_str(msg->from, &str); |
|---|
| 5715 |     return str; |
|---|
| 5716 | } |
|---|
| 5717 | |
|---|
| 5718 | static char * |
|---|
| 5719 | ph_req_get_body(osip_message_t *msg) |
|---|
| 5720 | { |
|---|
| 5721 |     char *str = 0; |
|---|
| 5722 | Â Â Â Â osip_body_t *body; |
|---|
| 5723 |     size_t len; |
|---|
| 5724 | |
|---|
| 5725 | |
|---|
| 5726 |     body = osip_list_get(&msg->bodies, 0); |
|---|
| 5727 |     if (!body) |
|---|
| 5728 |         return 0; |
|---|
| 5729 | |
|---|
| 5730 |     osip_body_to_str(body, &str, &len); |
|---|
| 5731 | Â Â Â Â str[len]Â =Â 0; |
|---|
| 5732 |     return str; |
|---|
| 5733 | } |
|---|
| 5734 | |
|---|
| 5735 | static osip_header_t * |
|---|
| 5736 | ph_req_find_header(osip_message_t *msg, const char *hname) |
|---|
| 5737 | { |
|---|
| 5738 | Â Â Â Â osip_header_t *hdr =Â 0; |
|---|
| 5739 | |
|---|
| 5740 |     osip_message_header_get_byname(msg, hname, 0, &hdr); |
|---|
| 5741 |     return hdr; |
|---|
| 5742 | |
|---|
| 5743 | } |
|---|
| 5744 | |
|---|
| 5745 | static char * |
|---|
| 5746 | ph_req_get_event(osip_message_t *msg) |
|---|
| 5747 | { |
|---|
| 5748 | Â Â Â Â osip_header_t *hdr =Â 0; |
|---|
| 5749 | |
|---|
| 5750 |     osip_message_header_get_byname(msg, "Event", 0, &hdr); |
|---|
| 5751 | |
|---|
| 5752 |     if (hdr) |
|---|
| 5753 |         return osip_strdup(hdr->hvalue); |
|---|
| 5754 | |
|---|
| 5755 |     return 0; |
|---|
| 5756 | } |
|---|
| 5757 | |
|---|
| 5758 | static int |
|---|
| 5759 | sdp_cmp(struct sdp_message* m1, struct sdp_message* m2) |
|---|
| 5760 | { |
|---|
| 5761 |     char *s1, *s2; |
|---|
| 5762 |     int ret = -1; |
|---|
| 5763 | |
|---|
| 5764 |     sdp_message_to_str(m1, &s1); |
|---|
| 5765 |     sdp_message_to_str(m2, &s2); |
|---|
| 5766 | |
|---|
| 5767 |     if (s1 && s2) |
|---|
| 5768 |         ret = strcmp(s1, s2); |
|---|
| 5769 | |
|---|
| 5770 | Â Â Â Â osip_free(s2); |
|---|
| 5771 | Â Â Â Â osip_free(s1); |
|---|
| 5772 | |
|---|
| 5773 |     return ret; |
|---|
| 5774 | |
|---|
| 5775 | } |
|---|
| 5776 | |
|---|
| 5777 | |
|---|
| 5778 | void |
|---|
| 5779 | ph_call_answered(eXosip_event_t *je) |
|---|
| 5780 | { |
|---|
| 5781 | Â Â Â Â phCallStateInfo_t info; |
|---|
| 5782 |     phcall_t *ca, *rca=0; |
|---|
| 5783 |     int rdid; |
|---|
| 5784 |     char *from = 0, *to=0, *sdp = 0; |
|---|
| 5785 | Â Â Â Â osip_message_t *ack; |
|---|
| 5786 | |
|---|
| 5787 | Â Â Â Â DBG_SIP_NEGO("SIP NEGO: ph_call_answered\n"); |
|---|
| 5788 | Â Â Â Â clear(info); |
|---|
| 5789 | |
|---|
| 5790 |     ca = ph_locate_call(je, 0); |
|---|
| 5791 | |
|---|
| 5792 |     if (!ca) |
|---|
| 5793 | Â Â Â Â Â Â Â Â return; |
|---|
| 5794 | |
|---|
| 5795 | Â Â Â Â rca =Â ph_locate_call_by_cid(ca->rcid); |
|---|
| 5796 | |
|---|
| 5797 | Â Â Â Â info.remoteSdp =Â sdp =Â ph_req_get_body(je->response); |
|---|
| 5798 | |
|---|
| 5799 | Â Â Â Â //if (!ca->localhold) |
|---|
| 5800 | Â Â Â Â { |
|---|
| 5801 |         const int mflags = -1 & ~(PH_STREAM_MCSEND|PH_STREAM_MCRECV); |
|---|
| 5802 | |
|---|
| 5803 |         if (sdp) |
|---|
| 5804 | Â Â Â Â Â Â Â Â {Â Â Â Â |
|---|
| 5805 |             struct sdp_message* new_sdp; |
|---|
| 5806 | |
|---|
| 5807 | Â Â Â Â Â Â Â Â Â Â Â Â sdp_message_init(&new_sdp); |
|---|
| 5808 |             sdp_message_parse(new_sdp, sdp); |
|---|
| 5809 | |
|---|
| 5810 |             if (ca->remote_sdp) { |
|---|
| 5811 |                 if (!sdp_cmp(new_sdp, ca->remote_sdp)) { |
|---|
| 5812 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â sdp_message_free(new_sdp); |
|---|
| 5813 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â DBG_SIP_NEGO("ph_call_answered: same sdp\n") |
|---|
| 5814 |                     goto same_sdp; |
|---|
| 5815 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 5816 |                 else { |
|---|
| 5817 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â DBG_SIP_NEGO("ph_call_answered: different sdp restarting streams\n"); |
|---|
| 5818 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 5819 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â sdp_message_free(ca->remote_sdp); |
|---|
| 5820 | Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 5821 | Â Â Â Â Â Â Â Â Â Â Â Â ph_call_media_stop(ca); |
|---|
| 5822 | Â Â Â Â Â Â Â Â Â Â Â Â ca->remote_sdp =Â new_sdp; |
|---|
| 5823 | Â Â Â Â Â Â Â Â Â Â Â Â ca->sdpctx->answer =Â ca->remote_sdp; |
|---|
| 5824 |             osip_list_special_free(&ca->result_audio_payloads, sdp_payload_free); |
|---|
| 5825 |             osip_list_special_free(&ca->result_video_payloads, sdp_payload_free); |
|---|
| 5826 |             sdp_context_process_answer(ca->sdpctx, ca->remote_sdp); |
|---|
| 5827 |             ph_call_retrieve_payloads(ca, -1); |
|---|
| 5828 | Â Â Â Â |
|---|
| 5829 | Â Â Â Â Â Â Â Â Â Â Â Â ph_update_nego_mflags(ca,ph_get_media_direction(new_sdp,"audio"),ph_get_media_direction(new_sdp,"video")); |
|---|
| 5830 | Â Â Â Â |
|---|
| 5831 |             if (ph_call_media_start(ca, je, mflags, ca->localresume)) |
|---|
| 5832 | Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 5833 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â DBG_SIP_NEGO("SIP NEGO: ph_call_answered but without stream\n"); |
|---|
| 5834 | Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 5835 | Â Â Â Â Â Â Â Â } |
|---|
| 5836 | Â Â Â Â } |
|---|
| 5837 | same_sdp: |
|---|
| 5838 | Â Â Â Â info.localUri =Â from =Â ph_req_get_from(je->response); |
|---|
| 5839 | Â Â Â Â info.userData =Â je->external_reference; |
|---|
| 5840 |     if (ca->localhold) |
|---|
| 5841 | Â Â Â Â { |
|---|
| 5842 | Â Â Â Â Â Â Â Â info.event =Â phHOLDOK; |
|---|
| 5843 | Â Â Â Â } |
|---|
| 5844 |     else if (ca->localresume) |
|---|
| 5845 | Â Â Â Â { |
|---|
| 5846 | Â Â Â Â Â Â Â Â info.event =Â phRESUMEOK; |
|---|
| 5847 | Â Â Â Â Â Â Â Â ca->localresume =Â 0; |
|---|
| 5848 | Â Â Â Â } |
|---|
| 5849 |     else { |
|---|
| 5850 | Â Â Â Â Â Â Â Â info.event =Â phCALLOK; |
|---|
| 5851 | Â Â Â Â } |
|---|
| 5852 | |
|---|
| 5853 | Â Â Â Â eXosip_lock(); |
|---|
| 5854 |     eXosip_call_build_ack(ca->did, &ack); |
|---|
| 5855 |     eXosip_call_send_ack(ca->did, ack); |
|---|
| 5856 | Â Â Â Â eXosip_unlock(); |
|---|
| 5857 | |
|---|
| 5858 | Â Â Â Â info.remoteUri =Â to =Â ph_req_get_to(je->response); |
|---|
| 5859 | Â Â Â Â info.vlid =Â ca->vlid; |
|---|
| 5860 |     if (rca) |
|---|
| 5861 | Â Â Â Â { |
|---|
| 5862 | Â Â Â Â Â Â Â Â info.oldcid =Â rca->cid; |
|---|
| 5863 | Â Â Â Â Â Â Â Â rdid =Â rca->rdid; |
|---|
| 5864 | Â Â Â Â } |
|---|
| 5865 | |
|---|
| 5866 | Â Â Â Â info.streams =Â PH_STREAM_AUDIO; |
|---|
| 5867 |     if (ca->video_payload) |
|---|
| 5868 | Â Â Â Â { |
|---|
| 5869 | Â Â Â Â Â Â Â Â info.streams |=Â PH_STREAM_VIDEO_RX; |
|---|
| 5870 | Â Â Â Â } |
|---|
| 5871 | |
|---|
| 5872 |     if (!ca->localrefer) |
|---|
| 5873 | Â Â Â Â { |
|---|
| 5874 | Â Â Â Â Â Â Â Â /* |
|---|
| 5875 |          * the call back can call phCloseCall(odlcid)... but we have rdid in |
|---|
| 5876 | Â Â Â Â Â Â Â Â Â * the local var |
|---|
| 5877 | Â Â Â Â Â Â Â Â Â */ |
|---|
| 5878 |         ph_apply_header_monitor(je->response, &info.hlist); |
|---|
| 5879 |         phcb->callProgress(ca->cid, &info); |
|---|
| 5880 | Â Â Â Â } |
|---|
| 5881 | |
|---|
| 5882 |     if (rca) |
|---|
| 5883 | Â Â Â Â { |
|---|
| 5884 |         ph_refer_notify(rdid, ph_req_get_status(je->response), "OK", 1); |
|---|
| 5885 | Â Â Â Â } |
|---|
| 5886 | |
|---|
| 5887 |     if (sdp) |
|---|
| 5888 | Â Â Â Â Â Â Â Â osip_free(sdp); |
|---|
| 5889 | |
|---|
| 5890 |     if (to) |
|---|
| 5891 | Â Â Â Â Â Â Â Â osip_free(to); |
|---|
| 5892 | |
|---|
| 5893 |     if (from) |
|---|
| 5894 | Â Â Â Â Â Â Â Â osip_free(from); |
|---|
| 5895 | |
|---|
| 5896 |     if (info.hlist.elems) |
|---|
| 5897 | Â Â Â Â Â Â Â Â osip_free(info.hlist.elems); |
|---|
| 5898 | |
|---|
| 5899 | } |
|---|
| 5900 | |
|---|
| 5901 | |
|---|
| 5902 | void |
|---|
| 5903 | ph_call_proceeding(eXosip_event_t *je) |
|---|
| 5904 | { |
|---|
| 5905 | Â Â Â Â phCallStateInfo_t info; |
|---|
| 5906 |     phcall_t *ca, *rca=0; |
|---|
| 5907 |     char *to = 0; |
|---|
| 5908 |     int s = 0; |
|---|
| 5909 | |
|---|
| 5910 | Â Â Â Â DBG_SIP_NEGO("SIP NEGO: ph_call_proceeding\n"); |
|---|
| 5911 | Â Â Â Â clear(info); |
|---|
| 5912 | |
|---|
| 5913 | |
|---|
| 5914 |     ca = ph_locate_call(je, 1); |
|---|
| 5915 |     if (!ca) |
|---|
| 5916 | Â Â Â Â Â Â Â Â return; |
|---|
| 5917 | |
|---|
| 5918 | Â Â Â Â rca =Â ph_locate_call_by_cid(ca->rcid); |
|---|
| 5919 | |
|---|
| 5920 |     if (ca && !ca->localrefer && !ca->localhold && !ca->localresume) |
|---|
| 5921 | Â Â Â Â { |
|---|
| 5922 |         ph_call_retrieve_payloads(ca, PH_STREAM_CNG); |
|---|
| 5923 |         ph_call_media_start(ca, je, -1, 0); |
|---|
| 5924 | |
|---|
| 5925 | Â Â Â Â Â Â Â Â info.userData =Â je->external_reference; |
|---|
| 5926 | Â Â Â Â Â Â Â Â info.event =Â phDIALING; |
|---|
| 5927 | Â Â Â Â Â Â Â Â info.remoteUri =Â to =Â ph_req_get_to(je->response); |
|---|
| 5928 | Â Â Â Â Â Â Â Â info.vlid =Â ca->vlid; |
|---|
| 5929 | |
|---|
| 5930 | Â Â Â Â Â Â Â Â info.streams =Â ca->nego_mflags; |
|---|
| 5931 | |
|---|
| 5932 |         ph_apply_header_monitor(je->response, &info.hlist); |
|---|
| 5933 |         phcb->callProgress(ca->cid, &info); |
|---|
| 5934 | Â Â Â Â } |
|---|
| 5935 | |
|---|
| 5936 |     if (rca) |
|---|
| 5937 | Â Â Â Â { |
|---|
| 5938 |         ph_refer_notify(rca->rdid, s, "Proceeding", 0); |
|---|
| 5939 | Â Â Â Â } |
|---|
| 5940 | |
|---|
| 5941 |     if (to) |
|---|
| 5942 | Â Â Â Â Â Â Â Â free(to); |
|---|
| 5943 | |
|---|
| 5944 |     if (info.hlist.elems) |
|---|
| 5945 | Â Â Â Â Â Â Â Â osip_free(info.hlist.elems); |
|---|
| 5946 | |
|---|
| 5947 | |
|---|
| 5948 | } |
|---|
| 5949 | |
|---|
| 5950 | void ph_callStopRinging(eXosip_event_t *je) |
|---|
| 5951 | { |
|---|
| 5952 | Â Â Â Â phCallStateInfo_t info; |
|---|
| 5953 | Â Â Â Â phcall_t *ca; |
|---|
| 5954 |     char *from = 0, *to = 0; |
|---|
| 5955 | |
|---|
| 5956 | Â Â Â Â clear(info); |
|---|
| 5957 | |
|---|
| 5958 |     ca = ph_locate_call(je, 1); |
|---|
| 5959 |     if (ca && ca->isringing) |
|---|
| 5960 | Â Â Â Â { |
|---|
| 5961 | Â Â Â Â Â Â Â Â ca->isringing =Â 0; |
|---|
| 5962 | Â Â Â Â Â Â Â Â info.event =Â phRINGandSTOP; |
|---|
| 5963 | |
|---|
| 5964 | Â Â Â Â Â Â Â Â info.localUri =Â from =Â ph_req_get_from(je->request); |
|---|
| 5965 | Â Â Â Â Â Â Â Â info.userData =Â je->external_reference; |
|---|
| 5966 | |
|---|
| 5967 | Â Â Â Â Â Â Â Â info.remoteUri =Â to =Â ph_req_get_to(je->request); |
|---|
| 5968 | Â Â Â Â Â Â Â Â info.vlid =Â ca->vlid; |
|---|
| 5969 | |
|---|
| 5970 |         phcb->callProgress(je->cid, &info); |
|---|
| 5971 | Â Â Â Â } |
|---|
| 5972 | |
|---|
| 5973 |     if (to) |
|---|
| 5974 | Â Â Â Â Â Â Â Â osip_free(to); |
|---|
| 5975 |     if (from) |
|---|
| 5976 | Â Â Â Â Â Â Â Â osip_free(from); |
|---|
| 5977 | |
|---|
| 5978 | |
|---|
| 5979 | } |
|---|
| 5980 | |
|---|
| 5981 | |
|---|
| 5982 | //from osip_uri.c, Don't add the port number into the string |
|---|
| 5983 | static int ph_uri_to_str(const osip_uri_t * url, char **dest) |
|---|
| 5984 | { |
|---|
| 5985 |     char *buf; |
|---|
| 5986 |     size_t len; |
|---|
| 5987 |     char *tmp; |
|---|
| 5988 |     const char *scheme; |
|---|
| 5989 | |
|---|
| 5990 | Â Â Â Â *dest =Â NULL; |
|---|
| 5991 |     if (url == NULL) |
|---|
| 5992 |         return OSIP_BADPARAMETER; |
|---|
| 5993 |     if (url->host == NULL && url->string == NULL) |
|---|
| 5994 |         return OSIP_BADPARAMETER; |
|---|
| 5995 |     if (url->scheme == NULL && url->string != NULL) |
|---|
| 5996 |         return OSIP_BADPARAMETER; |
|---|
| 5997 |     if (url->string == NULL && url->scheme == NULL) |
|---|
| 5998 | Â Â Â Â Â Â Â Â scheme =Â "sip";Â Â Â Â Â Â Â Â Â /* default is sipurl */ |
|---|
| 5999 | Â Â Â Â else |
|---|
| 6000 | Â Â Â Â Â Â Â Â scheme =Â url->scheme; |
|---|
| 6001 | |
|---|
| 6002 |     if (url->string != NULL) { |
|---|
| 6003 |         buf = (char *) osip_malloc(strlen(scheme) + strlen(url->string) + 3); |
|---|
| 6004 |         if (buf == NULL) |
|---|
| 6005 |             return OSIP_NOMEM; |
|---|
| 6006 | Â Â Â Â Â Â Â Â *dest =Â buf; |
|---|
| 6007 |         sprintf(buf, "%s:", scheme); |
|---|
| 6008 | Â Â Â Â Â Â Â Â buf =Â buf +Â strlen(scheme)Â +Â 1; |
|---|
| 6009 |         sprintf(buf, "%s", url->string); |
|---|
| 6010 | Â Â Â Â Â Â Â Â buf =Â buf +Â strlen(url->string); |
|---|
| 6011 |         return OSIP_SUCCESS; |
|---|
| 6012 | Â Â Â Â } |
|---|
| 6013 | |
|---|
| 6014 | Â Â Â Â len =Â strlen(scheme)Â +Â 1Â +Â strlen(url->host)Â +Â 5; |
|---|
| 6015 |     if (url->username != NULL) |
|---|
| 6016 | Â Â Â Â Â Â Â Â len =Â len +Â (strlen(url->username)Â *Â 3)Â +Â 1;Â Â /* count escaped char */ |
|---|
| 6017 |     if (url->password != NULL) |
|---|
| 6018 | Â Â Â Â Â Â Â Â len =Â len +Â (strlen(url->password)Â *Â 3)Â +Â 1; |
|---|
| 6019 |     if (url->port != NULL) |
|---|
| 6020 | Â Â Â Â Â Â Â Â len =Â len +Â strlen(url->port)Â +Â 3; |
|---|
| 6021 | |
|---|
| 6022 |     buf = (char *) osip_malloc(len); |
|---|
| 6023 |     if (buf == NULL) |
|---|
| 6024 |         return OSIP_NOMEM; |
|---|
| 6025 | Â Â Â Â tmp =Â buf; |
|---|
| 6026 | |
|---|
| 6027 |     sprintf(tmp, "%s:", scheme); |
|---|
| 6028 | Â Â Â Â tmp =Â tmp +Â strlen(tmp); |
|---|
| 6029 | |
|---|
| 6030 |     if (url->username != NULL) { |
|---|
| 6031 |         char *tmp2 = __osip_uri_escape_userinfo(url->username); |
|---|
| 6032 | |
|---|
| 6033 |         sprintf(tmp, "%s", tmp2); |
|---|
| 6034 | Â Â Â Â Â Â Â Â osip_free(tmp2); |
|---|
| 6035 | Â Â Â Â Â Â Â Â tmp =Â tmp +Â strlen(tmp); |
|---|
| 6036 | Â Â Â Â } |
|---|
| 6037 |     if (url->username != NULL) {  /* we add a '@' only when username is present... */ |
|---|
| 6038 |         sprintf(tmp, "@"); |
|---|
| 6039 | Â Â Â Â Â Â Â Â tmp++; |
|---|
| 6040 | Â Â Â Â } |
|---|
| 6041 |     if (strchr(url->host, ':') != NULL) { |
|---|
| 6042 |         sprintf(tmp, "[%s]", url->host); |
|---|
| 6043 | Â Â Â Â Â Â Â Â tmp =Â tmp +Â strlen(tmp); |
|---|
| 6044 |     } else { |
|---|
| 6045 |         sprintf(tmp, "%s", url->host); |
|---|
| 6046 | Â Â Â Â Â Â Â Â tmp =Â tmp +Â strlen(tmp); |
|---|
| 6047 | Â Â Â Â } |
|---|
| 6048 | |
|---|
| 6049 | Â Â Â Â *dest =Â buf; |
|---|
| 6050 |     return OSIP_SUCCESS; |
|---|
| 6051 | } |
|---|
| 6052 | |
|---|
| 6053 | |
|---|
| 6054 | |
|---|
| 6055 | void |
|---|
| 6056 | ph_call_ringing(eXosip_event_t *je) |
|---|
| 6057 | { |
|---|
| 6058 |     int ret = 0; |
|---|
| 6059 | Â Â Â Â phCallStateInfo_t info; |
|---|
| 6060 |     phcall_t *ca, *rca=0; |
|---|
| 6061 |     char *from = 0, *to = 0; |
|---|
| 6062 |     const int mflags = -1 & ~(PH_STREAM_MCSEND|PH_STREAM_MCRECV); |
|---|
| 6063 |     char *sdp = 0; |
|---|
| 6064 | |
|---|
| 6065 | Â Â Â Â DBG_SIP_NEGO("SIP NEGO: ph_call_ringing\n"); |
|---|
| 6066 | |
|---|
| 6067 | Â Â Â Â clear(info); |
|---|
| 6068 | |
|---|
| 6069 |     ca = ph_locate_call(je, 1); |
|---|
| 6070 |     if (!ca) |
|---|
| 6071 | Â Â Â Â Â Â Â Â return; |
|---|
| 6072 | |
|---|
| 6073 | Â Â Â Â rca =Â ph_locate_call_by_cid(ca->rcid); |
|---|
| 6074 | |
|---|
| 6075 | Â Â Â Â info.remoteSdp =Â sdp =Â ph_req_get_body(je->response); |
|---|
| 6076 | |
|---|
| 6077 |     if (!(ca->user_mflags & PH_NOEARLY_MEDIA) && 0 != sdp) |
|---|
| 6078 | Â Â Â Â { |
|---|
| 6079 |         if (ca->remote_sdp) { |
|---|
| 6080 | Â Â Â Â Â Â Â Â Â Â Â Â sdp_message_free(ca->remote_sdp); |
|---|
| 6081 | Â Â Â Â Â Â Â Â } |
|---|
| 6082 | Â Â Â Â Â Â Â Â sdp_message_init(&ca->remote_sdp); |
|---|
| 6083 |         sdp_message_parse(ca->remote_sdp, sdp); |
|---|
| 6084 | Â Â Â Â Â Â Â Â ca->sdpctx->answer =Â ca->remote_sdp; |
|---|
| 6085 |         sdp_context_process_answer(ca->sdpctx, ca->remote_sdp); |
|---|
| 6086 | Â Â Â Â } |
|---|
| 6087 | |
|---|
| 6088 | |
|---|
| 6089 |     ph_call_retrieve_payloads(ca, -1); |
|---|
| 6090 | |
|---|
| 6091 |     ret = ph_call_media_start(ca, je, mflags, 0); |
|---|
| 6092 | |
|---|
| 6093 | //Â Â Â ph_call_retrieve_payloads(ca, PH_STREAM_CNG); |
|---|
| 6094 | |
|---|
| 6095 | //Â Â Â ret = ph_call_media_start(ca, je, -1, 0); |
|---|
| 6096 | |
|---|
| 6097 | Â Â Â Â info.event =Â phRINGING; |
|---|
| 6098 |     if (ret == -PH_NOMEDIA && !ph_call_hasaudio(ca) && !ca->isringing) /* no audio and softPhone is now not ringing and has no sound */ |
|---|
| 6099 | Â Â Â Â { |
|---|
| 6100 | Â Â Â Â Â Â Â Â ca->isringing =Â 1; |
|---|
| 6101 | Â Â Â Â Â Â Â Â info.event =Â phRINGandSTART; |
|---|
| 6102 | Â Â Â Â } |
|---|
| 6103 |     else if (ca->isringing ) |
|---|
| 6104 | Â Â Â Â { |
|---|
| 6105 | Â Â Â Â Â Â Â Â ca->isringing =Â 0; |
|---|
| 6106 | Â Â Â Â Â Â Â Â info.event =Â phRINGandSTOP; |
|---|
| 6107 | Â Â Â Â } |
|---|
| 6108 | |
|---|
| 6109 | Â Â Â Â info.localUri =Â from =Â ph_req_get_from(je->response); |
|---|
| 6110 | Â Â Â Â info.userData =Â je->external_reference; |
|---|
| 6111 | |
|---|
| 6112 | Â Â Â Â info.remoteUri =Â to =Â ph_req_get_to(je->response); |
|---|
| 6113 | Â Â Â Â info.vlid =Â ca->vlid; |
|---|
| 6114 | |
|---|
| 6115 | Â Â Â Â info.streams =Â ca->nego_mflags; |
|---|
| 6116 | |
|---|
| 6117 |     ph_apply_header_monitor(je->response, &info.hlist); |
|---|
| 6118 | |
|---|
| 6119 |     phcb->callProgress(je->cid, &info); |
|---|
| 6120 | |
|---|
| 6121 |     if (rca) |
|---|
| 6122 | Â Â Â Â { |
|---|
| 6123 |         ph_refer_notify(rca->rdid, 180, "Ringing", 0); |
|---|
| 6124 | Â Â Â Â } |
|---|
| 6125 | |
|---|
| 6126 |     if (sdp) |
|---|
| 6127 | Â Â Â Â Â Â Â Â osip_free(sdp); |
|---|
| 6128 | |
|---|
| 6129 |     if (to) |
|---|
| 6130 | Â Â Â Â Â Â Â Â osip_free(to); |
|---|
| 6131 |     if (from) |
|---|
| 6132 | Â Â Â Â Â Â Â Â osip_free(from); |
|---|
| 6133 | |
|---|
| 6134 |     if (info.hlist.elems) |
|---|
| 6135 | Â Â Â Â Â Â Â Â osip_free(info.hlist.elems); |
|---|
| 6136 | } |
|---|
| 6137 | |
|---|
| 6138 | |
|---|
| 6139 | static void |
|---|
| 6140 | ph_call_requestfailure(eXosip_event_t *je) |
|---|
| 6141 | { |
|---|
| 6142 | Â Â Â Â phCallStateInfo_t info; |
|---|
| 6143 |     phcall_t *ca, *rca=0; |
|---|
| 6144 |     int s = 0; |
|---|
| 6145 |     char *from = 0, *to = 0; |
|---|
| 6146 | |
|---|
| 6147 | Â Â Â Â DBG_SIP_NEGO("call invite failure\n"); |
|---|
| 6148 | |
|---|
| 6149 | Â Â Â Â clear(info); |
|---|
| 6150 | |
|---|
| 6151 |     ca = ph_locate_call(je, 0); |
|---|
| 6152 |     if (!ca) |
|---|
| 6153 | Â Â Â Â Â Â Â Â return; |
|---|
| 6154 | |
|---|
| 6155 | Â Â Â Â rca =Â ph_locate_call_by_cid(ca->rcid); |
|---|
| 6156 | Â Â Â Â info.vlid =Â ca->vlid; |
|---|
| 6157 | |
|---|
| 6158 |     if (je->response) { |
|---|
| 6159 | Â Â Â Â Â Â Â Â s =Â ph_req_get_status(je->response); |
|---|
| 6160 |         if (s == 407 || s == 401) |
|---|
| 6161 | Â Â Â Â Â Â Â Â Â Â Â Â return; |
|---|
| 6162 | Â Â Â Â } |
|---|
| 6163 | |
|---|
| 6164 | Â Â Â Â ph_release_call(ca); |
|---|
| 6165 | |
|---|
| 6166 |     if (je->response) { |
|---|
| 6167 | Â Â Â Â Â Â Â Â info.localUri =Â from =Â ph_req_get_from(je->response); |
|---|
| 6168 | Â Â Â Â } |
|---|
| 6169 | |
|---|
| 6170 | Â Â Â Â info.userData =Â je->external_reference; |
|---|
| 6171 |     if (s == 486) |
|---|
| 6172 | Â Â Â Â { |
|---|
| 6173 | Â Â Â Â Â Â Â Â info.event =Â phCALLBUSY; |
|---|
| 6174 | Â Â Â Â Â Â Â Â info.remoteUri =Â to =Â ph_req_get_to(je->response); |
|---|
| 6175 | Â Â Â Â } |
|---|
| 6176 | Â Â Â Â else |
|---|
| 6177 | Â Â Â Â { |
|---|
| 6178 | Â Â Â Â Â Â Â Â info.event =Â phCALLERROR; |
|---|
| 6179 | Â Â Â Â Â Â Â Â info.errorCode =Â s; |
|---|
| 6180 | Â Â Â Â } |
|---|
| 6181 | |
|---|
| 6182 |     ph_apply_header_monitor(je->response, &info.hlist); |
|---|
| 6183 | |
|---|
| 6184 |     phcb->callProgress(je->cid, &info); |
|---|
| 6185 |     if (rca) |
|---|
| 6186 | Â Â Â Â { |
|---|
| 6187 |         ph_refer_notify(rca->rdid, s, s == 486 ? "Busy" : "Request failure", 1); |
|---|
| 6188 | Â Â Â Â } |
|---|
| 6189 | |
|---|
| 6190 |     if (to) |
|---|
| 6191 | Â Â Â Â Â Â Â Â osip_free(to); |
|---|
| 6192 |     if (from) |
|---|
| 6193 | Â Â Â Â Â Â Â Â osip_free(from); |
|---|
| 6194 | |
|---|
| 6195 |     if (info.hlist.elems) |
|---|
| 6196 | Â Â Â Â Â Â Â Â osip_free(info.hlist.elems); |
|---|
| 6197 | } |
|---|
| 6198 | |
|---|
| 6199 | |
|---|
| 6200 | void |
|---|
| 6201 | ph_call_serverfailure(eXosip_event_t *je) |
|---|
| 6202 | { |
|---|
| 6203 | Â Â Â Â phCallStateInfo_t info; |
|---|
| 6204 |     phcall_t *ca, *rca=0; |
|---|
| 6205 |     char *from = 0, *to = 0; |
|---|
| 6206 |     int s = 0; |
|---|
| 6207 | |
|---|
| 6208 | Â Â Â Â clear(info); |
|---|
| 6209 | |
|---|
| 6210 |     ca = ph_locate_call(je, 0); |
|---|
| 6211 |     if (ca) |
|---|
| 6212 | Â Â Â Â { |
|---|
| 6213 | Â Â Â Â Â Â Â Â rca =Â ph_locate_call_by_cid(ca->rcid); |
|---|
| 6214 | Â Â Â Â Â Â Â Â info.vlid =Â ca->vlid; |
|---|
| 6215 | Â Â Â Â Â Â Â Â ph_release_call(ca); |
|---|
| 6216 | Â Â Â Â } |
|---|
| 6217 | |
|---|
| 6218 |     if (je->response) { |
|---|
| 6219 | Â Â Â Â Â Â Â Â s =Â ph_req_get_status(je->response); |
|---|
| 6220 | Â Â Â Â Â Â Â Â info.localUri =Â from =Â ph_req_get_from(je->response); |
|---|
| 6221 | Â Â Â Â } |
|---|
| 6222 | |
|---|
| 6223 | Â Â Â Â info.userData =Â je->external_reference; |
|---|
| 6224 | Â Â Â Â info.event =Â phCALLERROR; |
|---|
| 6225 | Â Â Â Â info.errorCode =Â s; |
|---|
| 6226 | |
|---|
| 6227 |     ph_apply_header_monitor(je->response, &info.hlist); |
|---|
| 6228 | |
|---|
| 6229 |     phcb->callProgress(je->cid, &info); |
|---|
| 6230 | |
|---|
| 6231 |     if (rca) |
|---|
| 6232 | Â Â Â Â { |
|---|
| 6233 |         ph_refer_notify(rca->rdid, s, "Server failure", 1); |
|---|
| 6234 | Â Â Â Â } |
|---|
| 6235 | |
|---|
| 6236 |     if (to) |
|---|
| 6237 | Â Â Â Â Â Â Â Â osip_free(to); |
|---|
| 6238 |     if (from) |
|---|
| 6239 | Â Â Â Â Â Â Â Â osip_free(from); |
|---|
| 6240 | |
|---|
| 6241 |     if (info.hlist.elems) |
|---|
| 6242 | Â Â Â Â Â Â Â Â osip_free(info.hlist.elems); |
|---|
| 6243 | } |
|---|
| 6244 | |
|---|
| 6245 | void |
|---|
| 6246 | ph_call_globalfailure(eXosip_event_t *je) |
|---|
| 6247 | { |
|---|
| 6248 | Â Â Â Â phCallStateInfo_t info; |
|---|
| 6249 |     phcall_t *ca, *rca=0; |
|---|
| 6250 |     char *from = 0, *to = 0; |
|---|
| 6251 |     int s = 0; |
|---|
| 6252 | |
|---|
| 6253 | Â Â Â Â clear(info); |
|---|
| 6254 | |
|---|
| 6255 |     ca = ph_locate_call(je, 0); |
|---|
| 6256 |     if (ca) |
|---|
| 6257 | Â Â Â Â { |
|---|
| 6258 | Â Â Â Â Â Â Â Â rca =Â ph_locate_call_by_cid(ca->rcid); |
|---|
| 6259 | Â Â Â Â Â Â Â Â info.vlid =Â ca->vlid; |
|---|
| 6260 | Â Â Â Â Â Â Â Â ph_release_call(ca); |
|---|
| 6261 | Â Â Â Â } |
|---|
| 6262 | |
|---|
| 6263 | Â Â Â Â s =Â ph_req_get_status(je->response); |
|---|
| 6264 | Â Â Â Â info.userData =Â je->external_reference; |
|---|
| 6265 | Â Â Â Â info.localUri =Â from =Â ph_req_get_from(je->response); |
|---|
| 6266 | |
|---|
| 6267 |     if (s == 600) |
|---|
| 6268 | Â Â Â Â { |
|---|
| 6269 | Â Â Â Â Â Â Â Â info.event =Â phCALLBUSY; |
|---|
| 6270 | Â Â Â Â Â Â Â Â info.remoteUri =Â to =Â ph_req_get_to(je->response); |
|---|
| 6271 | Â Â Â Â } |
|---|
| 6272 | Â Â Â Â else |
|---|
| 6273 | Â Â Â Â { |
|---|
| 6274 | Â Â Â Â Â Â Â Â info.event =Â phCALLERROR; |
|---|
| 6275 | Â Â Â Â Â Â Â Â info.errorCode =Â s; |
|---|
| 6276 | Â Â Â Â } |
|---|
| 6277 | |
|---|
| 6278 |     ph_apply_header_monitor(je->request, &info.hlist); |
|---|
| 6279 | |
|---|
| 6280 |     phcb->callProgress(je->cid, &info); |
|---|
| 6281 | |
|---|
| 6282 |     if (rca) |
|---|
| 6283 | Â Â Â Â { |
|---|
| 6284 |         ph_refer_notify(rca->rdid, s, "Global failure", 1); |
|---|
| 6285 | Â Â Â Â } |
|---|
| 6286 | |
|---|
| 6287 |     if (to) |
|---|
| 6288 | Â Â Â Â Â Â Â Â osip_free(to); |
|---|
| 6289 |     if (from) |
|---|
| 6290 | Â Â Â Â Â Â Â Â osip_free(from); |
|---|
| 6291 | |
|---|
| 6292 |     if (info.hlist.elems) |
|---|
| 6293 | Â Â Â Â Â Â Â Â osip_free(info.hlist.elems); |
|---|
| 6294 | } |
|---|
| 6295 | |
|---|
| 6296 | void |
|---|
| 6297 | ph_call_noanswer(eXosip_event_t *je, int alloc) |
|---|
| 6298 | { |
|---|
| 6299 | Â Â Â Â phCallStateInfo_t info; |
|---|
| 6300 |     phcall_t *ca, *rca=0; |
|---|
| 6301 |     char *from = 0, *to = 0; |
|---|
| 6302 | |
|---|
| 6303 | |
|---|
| 6304 | Â Â Â Â clear(info); |
|---|
| 6305 | |
|---|
| 6306 |     ca = ph_locate_call(je, alloc); |
|---|
| 6307 |     if (ca) |
|---|
| 6308 | Â Â Â Â { |
|---|
| 6309 | Â Â Â Â Â Â Â Â rca =Â ph_locate_call_by_cid(ca->rcid); |
|---|
| 6310 | Â Â Â Â Â Â Â Â info.vlid =Â ca->vlid; |
|---|
| 6311 | Â Â Â Â Â Â Â Â ph_release_call(ca); |
|---|
| 6312 | Â Â Â Â } |
|---|
| 6313 | |
|---|
| 6314 |     if (!ca && !alloc) |
|---|
| 6315 | Â Â Â Â Â Â Â Â return; |
|---|
| 6316 | |
|---|
| 6317 | Â Â Â Â info.userData =Â je->external_reference; |
|---|
| 6318 | Â Â Â Â info.event =Â phNOANSWER; |
|---|
| 6319 | Â Â Â Â //Â Â Â info.remoteUri = to = ph_req_get_to(je->response); |
|---|
| 6320 | Â Â Â Â //Â Â Â info.localUri = from = ph_req_get_to(je->response); |
|---|
| 6321 | |
|---|
| 6322 |     ph_apply_header_monitor(je->request, &info.hlist); |
|---|
| 6323 | |
|---|
| 6324 |     phcb->callProgress(je->cid, &info); |
|---|
| 6325 | |
|---|
| 6326 |     if (rca) |
|---|
| 6327 | Â Â Â Â { |
|---|
| 6328 |         ph_refer_notify(rca->rdid, ph_req_get_status(je->response), "No answer", 1); |
|---|
| 6329 | Â Â Â Â } |
|---|
| 6330 | |
|---|
| 6331 |     if (to) |
|---|
| 6332 | Â Â Â Â Â Â Â Â osip_free(to); |
|---|
| 6333 |     if (from) |
|---|
| 6334 | Â Â Â Â Â Â Â Â osip_free(from); |
|---|
| 6335 | |
|---|
| 6336 |     if (info.hlist.elems) |
|---|
| 6337 | Â Â Â Â Â Â Â Â osip_free(info.hlist.elems); |
|---|
| 6338 | } |
|---|
| 6339 | |
|---|
| 6340 | void |
|---|
| 6341 | ph_call_message_new(eXosip_event_t *je) |
|---|
| 6342 | { |
|---|
| 6343 |     int i; |
|---|
| 6344 | Â Â Â Â osip_message_t *msg; |
|---|
| 6345 |     int status = 405; |
|---|
| 6346 | |
|---|
| 6347 | |
|---|
| 6348 |     if (MSG_IS_OPTIONS(je->request)) |
|---|
| 6349 | Â Â Â Â Â Â Â Â status =Â 200; |
|---|
| 6350 | |
|---|
| 6351 | Â Â Â Â eXosip_lock(); |
|---|
| 6352 |     i = eXosip_call_build_answer(je->tid, status, &msg); |
|---|
| 6353 | |
|---|
| 6354 |     if (!i) |
|---|
| 6355 |         i = eXosip_call_send_answer(je->tid, status, msg); |
|---|
| 6356 | Â Â Â Â eXosip_unlock(); |
|---|
| 6357 | |
|---|
| 6358 | } |
|---|
| 6359 | |
|---|
| 6360 | void |
|---|
| 6361 | ph_call_closed(eXosip_event_t *je) |
|---|
| 6362 | { |
|---|
| 6363 | Â Â Â Â phCallStateInfo_t info; |
|---|
| 6364 |     phcall_t *ca, *rca=0; |
|---|
| 6365 | |
|---|
| 6366 | Â Â Â Â clear(info); |
|---|
| 6367 | |
|---|
| 6368 |     ca = ph_locate_call(je, 0); |
|---|
| 6369 |     if (ca) |
|---|
| 6370 | Â Â Â Â { |
|---|
| 6371 | Â Â Â Â Â Â Â Â rca =Â ph_locate_call_by_cid(ca->rcid); |
|---|
| 6372 | Â Â Â Â Â Â Â Â info.vlid =Â ca->vlid; |
|---|
| 6373 | |
|---|
| 6374 | |
|---|
| 6375 | Â Â Â Â Â Â Â Â ph_release_call(ca); |
|---|
| 6376 | |
|---|
| 6377 | Â Â Â Â Â Â Â Â info.userData =Â je->external_reference; |
|---|
| 6378 | Â Â Â Â Â Â Â Â info.event =Â phCALLCLOSED; |
|---|
| 6379 | Â Â Â Â Â Â Â Â info.errorCode =Â 0; |
|---|
| 6380 | |
|---|
| 6381 |         ph_apply_header_monitor(je->request, &info.hlist); |
|---|
| 6382 |         phcb->callProgress(je->cid, &info); |
|---|
| 6383 | Â Â Â Â } |
|---|
| 6384 | |
|---|
| 6385 |     if (rca) |
|---|
| 6386 | Â Â Â Â { |
|---|
| 6387 |         ph_refer_notify(rca->rdid, ph_req_get_status(je->response), "Closed", 1); |
|---|
| 6388 | Â Â Â Â } |
|---|
| 6389 | |
|---|
| 6390 |     if (info.hlist.elems) |
|---|
| 6391 | Â Â Â Â Â Â Â Â osip_free(info.hlist.elems); |
|---|
| 6392 | } |
|---|
| 6393 | |
|---|
| 6394 | |
|---|
| 6395 | void |
|---|
| 6396 | ph_call_onhold(eXosip_event_t *je) |
|---|
| 6397 | { |
|---|
| 6398 | Â Â Â Â phCallStateInfo_t info; |
|---|
| 6399 | Â Â Â Â phcall_t *ca; |
|---|
| 6400 | |
|---|
| 6401 | Â Â Â Â DBG_SIP_NEGO("SIP_NEGO: ph_call_onhold\n"); |
|---|
| 6402 | |
|---|
| 6403 | Â Â Â Â clear(info); |
|---|
| 6404 | |
|---|
| 6405 |     ca = ph_locate_call(je, 0); |
|---|
| 6406 | |
|---|
| 6407 |     if (!ca) |
|---|
| 6408 | Â Â Â Â Â Â Â Â return; |
|---|
| 6409 | |
|---|
| 6410 | Â Â Â Â info.vlid =Â ca->vlid; |
|---|
| 6411 | Â Â Â Â /*if (ph_call_hasaudio(ca) || ph_call_hasvideo(ca)) |
|---|
| 6412 | Â Â Â Â { |
|---|
| 6413 | #ifndef MEDIA_SUSPEND |
|---|
| 6414 | Â Â Â Â Â Â Â Â ph_call_media_stop(ca); |
|---|
| 6415 | #else |
|---|
| 6416 | Â Â Â Â Â Â Â Â ph_call_media_suspend(ca, 0); |
|---|
| 6417 | #endif |
|---|
| 6418 | Â Â Â Â }*/ |
|---|
| 6419 | |
|---|
| 6420 | Â Â Â Â ca->remotehold =Â 1; |
|---|
| 6421 | Â Â Â Â info.userData =Â je->external_reference; |
|---|
| 6422 | Â Â Â Â info.event =Â phCALLHELD; |
|---|
| 6423 |     phcb->callProgress(je->cid, &info); |
|---|
| 6424 | } |
|---|
| 6425 | |
|---|
| 6426 | void |
|---|
| 6427 | ph_call_offhold(eXosip_event_t *je) |
|---|
| 6428 | { |
|---|
| 6429 | Â Â Â Â phCallStateInfo_t info; |
|---|
| 6430 | Â Â Â Â phcall_t *ca; |
|---|
| 6431 |     int remotehold; |
|---|
| 6432 | |
|---|
| 6433 | Â Â Â Â DBG_SIP_NEGO("SIP NEGO: ph_call_offhold\n"); |
|---|
| 6434 | |
|---|
| 6435 |     ca = ph_locate_call(je, 0); |
|---|
| 6436 |     if (!ca) |
|---|
| 6437 | Â Â Â Â Â Â Â Â return; |
|---|
| 6438 | |
|---|
| 6439 | Â Â Â Â clear(info); |
|---|
| 6440 | |
|---|
| 6441 | Â Â Â Â info.vlid =Â ca->vlid; |
|---|
| 6442 | |
|---|
| 6443 | Â Â Â Â remotehold =Â ca->remotehold; |
|---|
| 6444 | Â Â Â Â ca->remotehold =Â 0; |
|---|
| 6445 | |
|---|
| 6446 | Â Â Â Â /*if (ph_call_hasaudio(ca) || ph_call_hasvideo(ca)) { |
|---|
| 6447 | Â Â Â Â Â Â Â Â ph_call_retrieve_payloads(ca, -1); |
|---|
| 6448 | Â Â Â Â Â Â Â Â ph_call_media_resume(ca, !remotehold); |
|---|
| 6449 | Â Â Â Â }*/ |
|---|
| 6450 | |
|---|
| 6451 |     if (remotehold) { |
|---|
| 6452 | Â Â Â Â Â Â Â Â info.userData =Â je->external_reference; |
|---|
| 6453 | Â Â Â Â Â Â Â Â info.event =Â phCALLRESUMED; |
|---|
| 6454 | Â Â Â Â Â Â Â Â info.streams =Â ca->nego_mflags; |
|---|
| 6455 | |
|---|
| 6456 |         if (phcb->callProgress) { |
|---|
| 6457 |             phcb->callProgress(ca->cid, &info); |
|---|
| 6458 | Â Â Â Â Â Â Â Â } |
|---|
| 6459 | Â Â Â Â } |
|---|
| 6460 | } |
|---|
| 6461 | |
|---|
| 6462 | #define keywordcmp(key,str)Â strncmp(key,str,strlen(key)) |
|---|
| 6463 | |
|---|
| 6464 | int ph_set_media_direction( sdp_message_t * sdp, const char *media_type, enum ph_direction direction) |
|---|
| 6465 | { |
|---|
| 6466 |     int mline =0; |
|---|
| 6467 | Â Â Â Â |
|---|
| 6468 |     for (mline=0; !sdp_message_endof_media (sdp, mline); mline++) |
|---|
| 6469 | Â Â Â Â { |
|---|
| 6470 |         const char * mtype = sdp_message_m_media_get(sdp, mline); |
|---|
| 6471 |         if(!osip_strcasecmp(media_type, mtype)) |
|---|
| 6472 | Â Â Â Â Â Â Â Â { |
|---|
| 6473 |             const char * sdir = ph_get_str_direction(direction); |
|---|
| 6474 |             sdp_message_a_attribute_del(sdp, mline, "inactive"); |
|---|
| 6475 |             sdp_message_a_attribute_del(sdp, mline, "sendonly"); |
|---|
| 6476 |             sdp_message_a_attribute_del(sdp, mline, "sendrecv"); |
|---|
| 6477 |             sdp_message_a_attribute_add(sdp, mline, osip_strdup(sdir), 0); |
|---|
| 6478 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 6479 |             return 0; |
|---|
| 6480 | Â Â Â Â Â Â Â Â } |
|---|
| 6481 | Â Â Â Â } |
|---|
| 6482 |     return -1; |
|---|
| 6483 | } |
|---|
| 6484 | |
|---|
| 6485 | enum ph_direction ph_get_local_media_direction( phcall_t *ca, const char * media_type) |
|---|
| 6486 | { |
|---|
| 6487 |     if(!osip_strcasecmp(media_type, "audio")) |
|---|
| 6488 | Â Â Â Â { |
|---|
| 6489 | Â Â Â Â Â Â Â Â if(ca->nego_mflags &Â PH_STREAM_AUDIO_TX &&Â ca->nego_mflags &Â PH_STREAM_AUDIO_RX) |
|---|
| 6490 |             return sendrecv; |
|---|
| 6491 | Â Â Â Â Â Â Â Â if(ca->nego_mflags &Â PH_STREAM_AUDIO_TX) |
|---|
| 6492 |             return sendonly; |
|---|
| 6493 | Â Â Â Â Â Â Â Â if(ca->nego_mflags &Â PH_STREAM_AUDIO_RX) |
|---|
| 6494 |             return recvonly; |
|---|
| 6495 | Â Â Â Â } |
|---|
| 6496 |     else if(!osip_strcasecmp(media_type, "video")) |
|---|
| 6497 | Â Â Â Â { |
|---|
| 6498 | Â Â Â Â Â Â Â Â if(ca->nego_mflags &Â PH_STREAM_VIDEO_TX &&Â ca->nego_mflags &Â PH_STREAM_VIDEO_RX) |
|---|
| 6499 |             return sendrecv; |
|---|
| 6500 | Â Â Â Â Â Â Â Â if(ca->nego_mflags &Â PH_STREAM_VIDEO_TX) |
|---|
| 6501 |             return sendonly; |
|---|
| 6502 | Â Â Â Â Â Â Â Â if(ca->nego_mflags &Â PH_STREAM_VIDEO_RX) |
|---|
| 6503 |             return recvonly; |
|---|
| 6504 | Â Â Â Â } |
|---|
| 6505 | Â Â Â Â |
|---|
| 6506 |     return inactive; |
|---|
| 6507 | } |
|---|
| 6508 | |
|---|
| 6509 | enum ph_direction ph_get_media_direction( sdp_message_t * sdp, const char * media_type) |
|---|
| 6510 | { |
|---|
| 6511 |     int mline = 0; |
|---|
| 6512 |     for (mline=0; !sdp_message_endof_media (sdp, mline); mline++) |
|---|
| 6513 | Â Â Â Â { |
|---|
| 6514 |         int i =0; |
|---|
| 6515 | Â Â Â Â Â Â Â Â sdp_attribute_t *attr; |
|---|
| 6516 |         const char * mtype = sdp_message_m_media_get(sdp, mline); |
|---|
| 6517 |         if(!osip_strcasecmp(media_type, mtype)) |
|---|
| 6518 | Â Â Â Â Â Â Â Â { |
|---|
| 6519 |             for (i=0;(attr=sdp_message_attribute_get(sdp,mline,i))!=NULL;i++) |
|---|
| 6520 | Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 6521 |                 if ( keywordcmp("sendrecv",attr->a_att_field) == 0 ) |
|---|
| 6522 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 6523 |                     return sendrecv; |
|---|
| 6524 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 6525 |                 else if( keywordcmp("sendonly",attr->a_att_field) == 0 ) |
|---|
| 6526 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 6527 |                     return sendonly; |
|---|
| 6528 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 6529 |                 else if( keywordcmp("recvonly",attr->a_att_field) == 0 ) |
|---|
| 6530 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 6531 |                     return recvonly; |
|---|
| 6532 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 6533 |                 else if( keywordcmp("inactive",attr->a_att_field) == 0 ) |
|---|
| 6534 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â { |
|---|
| 6535 |                     return inactive; |
|---|
| 6536 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 6537 | Â Â Â Â Â Â Â Â Â Â Â Â } |
|---|
| 6538 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 6539 |             return sendrecv; |
|---|
| 6540 | Â Â Â Â Â Â Â Â } |
|---|
| 6541 | Â Â Â Â } |
|---|
| 6542 |     return inactive; |
|---|
| 6543 | } |
|---|
| 6544 | |
|---|
| 6545 | int ph_update_nego_mflags( phcall_t *ca, enum ph_direction remote_audio_direction, enum ph_direction remote_video_direction) |
|---|
| 6546 | { |
|---|
| 6547 | Â Â Â Â switch(remote_audio_direction) |
|---|
| 6548 | Â Â Â Â { |
|---|
| 6549 |         case sendrecv: |
|---|
| 6550 | Â Â Â Â Â Â Â Â Â Â Â Â ca->nego_mflags |=Â PH_STREAM_AUDIO; |
|---|
| 6551 | Â Â Â Â Â Â Â Â break; |
|---|
| 6552 | Â Â Â Â Â Â Â Â |
|---|
| 6553 |         case sendonly: |
|---|
| 6554 | Â Â Â Â Â Â Â Â Â Â Â Â ca->nego_mflags &=Â ~PH_STREAM_AUDIO_TX; |
|---|
| 6555 | Â Â Â Â Â Â Â Â Â Â Â Â //ca->nego_mflags |= PH_STREAM_AUDIO_RX; |
|---|
| 6556 | Â Â Â Â Â Â Â Â break; |
|---|
| 6557 | Â Â Â Â Â Â Â Â |
|---|
| 6558 |         case recvonly: |
|---|
| 6559 | Â Â Â Â Â Â Â Â Â Â Â Â ca->nego_mflags &=Â ~PH_STREAM_AUDIO_RX; |
|---|
| 6560 | Â Â Â Â Â Â Â Â Â Â Â Â ca->nego_mflags |=Â PH_STREAM_AUDIO_TX; |
|---|
| 6561 | Â Â Â Â Â Â Â Â break; |
|---|
| 6562 | Â Â Â Â Â Â Â Â |
|---|
| 6563 |         case inactive: |
|---|
| 6564 | Â Â Â Â Â Â Â Â Â Â Â Â ca->nego_mflags &=Â ~PH_STREAM_AUDIO; |
|---|
| 6565 | Â Â Â Â Â Â Â Â break; |
|---|
| 6566 | Â Â Â Â } |
|---|
| 6567 | Â Â Â Â |
|---|
| 6568 | Â Â Â Â switch(remote_video_direction) |
|---|
| 6569 | Â Â Â Â { |
|---|
| 6570 |         case sendrecv: |
|---|
| 6571 | Â Â Â Â Â Â Â Â Â Â Â Â ca->nego_mflags |=Â PH_STREAM_VIDEO; |
|---|
| 6572 | Â Â Â Â Â Â Â Â break; |
|---|
| 6573 | Â Â Â Â Â Â Â Â |
|---|
| 6574 |         case sendonly: |
|---|
| 6575 | Â Â Â Â Â Â Â Â Â Â Â Â ca->nego_mflags &=Â ~PH_STREAM_VIDEO_TX; |
|---|
| 6576 | Â Â Â Â Â Â Â Â Â Â Â Â //ca->nego_mflags |= PH_STREAM_VIDEO_RX; |
|---|
| 6577 | Â Â Â Â Â Â Â Â break; |
|---|
| 6578 | Â Â Â Â Â Â Â Â |
|---|
| 6579 |         case recvonly: |
|---|
| 6580 | Â Â Â Â Â Â Â Â Â Â Â Â ca->nego_mflags &=Â ~PH_STREAM_VIDEO_RX; |
|---|
| 6581 | Â Â Â Â Â Â Â Â Â Â Â Â ca->nego_mflags |=Â |
|---|