char * generating_sdp_answer(osip_message_t *request, osip_negotiation_ctx_t *context) { sdp_message_t *remote_sdp; sdp_message_t *local_sdp = NULL; int i; char *local_body; if (context==NULL) return NULL; local_body = NULL; if (MSG_IS_INVITE(request)||MSG_IS_OPTIONS(request)||MSG_IS_RESPONSE_FOR(request, "INVITE")) { osip_body_t *body; body = (osip_body_t *)osip_list_get(&request->bodies,0); if(body == NULL) return NULL; /* remote_sdp = (sdp_message_t *) osip_malloc(sizeof(sdp_message_t)); */ i = sdp_message_init(&remote_sdp); if (i!=0) return NULL; /* WE ASSUME IT IS A SDP BODY AND THAT */ /* IT IS THE ONLY ONE, OF COURSE, THIS IS */ /* NOT TRUE */ i = sdp_message_parse(remote_sdp,body->body); if (i!=0) return NULL; i = osip_negotiation_ctx_set_remote_sdp(context, remote_sdp); i = osip_negotiation_ctx_execute_negotiation(eXosip.osip_negotiation, context); if (i==200) { local_sdp = osip_negotiation_ctx_get_local_sdp(context); i = sdp_message_to_str(local_sdp, &local_body); remote_sdp = osip_negotiation_ctx_get_remote_sdp(context); sdp_message_free(remote_sdp); osip_negotiation_ctx_set_remote_sdp(context, NULL); if (i!=0) { OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_ERROR,NULL,"ERROR: Could not parse local SDP answer %i\n",i)); return NULL; } return local_body; } else if (i==415) { OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO1,NULL,"WARNING: Unsupported media %i\n",i)); } else { OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_ERROR,NULL,"ERROR: while building answer to SDP (%i)\n",i)); } remote_sdp = osip_negotiation_ctx_get_remote_sdp(context); sdp_message_free(remote_sdp); osip_negotiation_ctx_set_remote_sdp(context, NULL); } return NULL; }
int test_sdp_message (char *msg, int verbose) { sdp_message_t *sdp; { char *result; sdp_message_init (&sdp); if (sdp_message_parse (sdp, msg) != 0) { fprintf (stdout, "ERROR: failed while parsing!\n"); sdp_message_free (sdp); /* try to free msg, even if it failed! */ /* this seems dangerous..... */ return -1; } else { int i; i = sdp_message_to_str (sdp, &result); test_accessor_get_api (sdp); if (i == -1) { fprintf (stdout, "ERROR: failed while printing message!\n"); sdp_message_free (sdp); return -1; } else { if (verbose) fprintf (stdout, "%s", result); if (strlen (result) != strlen (msg)) fprintf (stdout, "length differ from original message!\n"); if (0 == strncmp (result, msg, strlen (result))) fprintf (stdout, "result equals msg!!\n"); osip_free (result); { osip_negotiation_ctx_t *context; sdp_message_t *dest; i = osip_negotiation_ctx_init (&context); i = osip_negotiation_ctx_set_mycontext (context, (void *) ua_context); { sdp_message_t *sdp; osip_negotiation_sdp_build_offer (osip_negotiation, context, &sdp, ua_context->m_audio_port, ua_context->m_video_port); sdp_message_to_str (sdp, &result); fprintf (stdout, "Here is the offer:\n%s\n", result); osip_free (result); osip_negotiation_sdp_message_put_on_hold (sdp); sdp_message_to_str (sdp, &result); fprintf (stdout, "Here is the offer on hold:\n%s\n", result); osip_free (result); sdp_message_free (sdp); } i = osip_negotiation_ctx_set_remote_sdp (context, sdp); if (i != 0) { fprintf (stdout, "Initialisation of context failed. Could not negociate\n"); } else { fprintf (stdout, "Trying to execute a SIP negotiation:\n"); i = osip_negotiation_ctx_execute_negotiation (osip_negotiation, context); fprintf (stdout, "return code: %i\n", i); if (i == 200) { dest = osip_negotiation_ctx_get_local_sdp (context); fprintf (stdout, "SDP answer:\n"); i = sdp_message_to_str (dest, &result); if (i != 0) fprintf (stdout, "Error found in SDP answer while printing\n"); else fprintf (stdout, "%s\n", result); osip_free (result); } osip_negotiation_ctx_free (context); return 0; } } } sdp_message_free (sdp); } } return 0; }