Software Version: libosip2-3.3.0.tar.gzlibeXosip2-3.3.0.tar.gz.configure -- prefixoptsiptarget -- disable-staticmakemakeinstall test code: code source: blog. csdn. netbat603archive200611151386277. aspx1, UAS ******************** U
Software Version: libosip2-3.3.0.tar.gz libeXosip2-3.3.0.tar.gz. /configure -- prefix =/opt/sip/target -- disable-static make install test code: code source: http://blog.csdn.net/bat603/archive/2006/11/15/1386277.aspx 1, UAS // ********************* U
Software Version:
Libosip2-3.3.0.tar.gz
LibeXosip2-3.3.0.tar.gz
./Configure -- prefix =/opt/sip/target -- disable-static
Make
Make install
Test code:
Code Source: http://blog.csdn.net/bat603/archive/2006/11/15/1386277.aspx
1. UAS
// ******************** UAS ****************** ****************************** // # include <eXosip2/eXosip. h> # include <osip2/osip_mt.h> # include <stdio. h> # include <stdlib. h> # include <netinet/in. h> # include <sys/socket. h> # include <sys/types. h> intmain (int argc, char * argv []) {eXosip_event_t * je = NULL; osip_message_t * ack = NULL; osip_message_t * invite = NULL; osip_message_t * answer = NULL; sdp_message_t * r Emote_sdp = NULL; int call_id, dialog_id; int I, j; int id; char * sour_call = "sip: 133@192.168.0.133"; char * dest_call = "sip: 140@192.168.0.140: 5060 "; char command; char tmp [4096]; char localip [128]; int pos = 0; // initialize sip I = eXosip_init (); if (I! = 0) {printf ("Can't initialize eXosip! /N "); return-1;} else {printf (" eXosip_init successfully! /N ");} I = eXosip_listen_addr (IPPROTO_UDP, NULL, 5060, AF_INET, 0); if (I! = 0) {eXosip_quit (); fprintf (stderr, "eXosip_listen_addr error! /NCouldn't initialize transport layer! /N ") ;}for (;) {// listen for message arrival je = eXosip_event_wait (); // The protocol stack carries this statement, unknown eXosip_lock (); eXosip_default_action (je); eXosip_automatic_refresh (); eXosip_unlock (); if (je = NULL) // No message continue is received; // printf ("the cid is % s, did is % s/n", je-> did, je-> cid); switch (je-> type) {case EXOSIP_MESSAGE_NEW: // new message arrival printf ("EXOSIP_MESSAGE_NEW! /N "); if (MSG_IS_MESSAGE (je-> request) // if the received MESSAGE type is MESSAGE {osip_body_t * body; osip_message_get_body (je-> request, 0, & body); printf ("I get the msg is: % s/n", body-> body); // printf ("the cid is % s, did is % s/n ", je-> did, je-> cid);} // according to the rule, the 200 OK message eXosip_message_build_answer (je-> tid, 200, & answer); eXosip_message_send_answer (je-> tid, 200, answer);} break; case EXOSIP_CALL_INVITE: // get received Message Details printf ("Received a INVITE msg from % s: % s, UserName is % s, password is % s/n ", je-> request-> req_uri-> host, je-> request-> req_uri-> port, je-> request-> req_uri-> username, je-> request-> req_uri-> password); // obtain the message body. The message is in SDP format. remote_sdp = require (je-> did); call_id = je-> cid; dialog_id = je-> did; eXosip_lock (); eXosip_call_send_answer (je-> tid, 180, NULL ); I = eXosip_call_build_an Swer (je-& gt; tid, 200, & answer); if (I! = 0) {printf ("This request msg is invalid! Cann' t response! /N "); eXosip_call_send_answer (je-> tid, 400, NULL);} else {snprintf (tmp, 4096, "v = 0/r/n" "o = anonymous 0 0 IN IP4 0.0.0.0/r/n" "t = 1 10/r/n" "a = username: rainfish/r/n "" a = password: 123/r/n "); // set the SDP message body for the reply. The next step is to analyze the message body. // the message body is not analyzed, directly reply to the original message, which is not doing well. Osip_message_set_body (answer, tmp, strlen (tmp); Evaluate (answer, "application/sdp"); eXosip_call_send_answer (je-> tid, 200, answer ); printf ("send 200 over! /N ") ;}exosip_unlock (); // display the attribute content in the sdp message body, which is scheduled to store our information printf (" the INFO is:/n "); while (! Callback (remote_sdp-> a_attributes, pos) {sdp_attribute_t * at; at = (sdp_attribute_t *) osip_list_get (remote_sdp-> a_attributes, pos); printf ("% s: % s/n ", at-> a_att_field, at-> a_att_value ); // The reason why attribute a in the SDP message body must be stored in two columns: pos ++;} break; case EXOSIP_CALL_ACK: printf ("ACK recieved! /N "); // printf (" the cid is % s, did is % s/n ", je-> did, je-> cid); break; case EXOSIP_CALL_CLOSED: printf ("the remote hold the session! /N "); // eXosip_call_build_ack (dialog_id, & ack); // eXosip_call_send_ack (dialog_id, ack); I = encrypt (je-> tid, 200, & answer ); if (I! = 0) {printf ("This request msg is invalid! Cann' t response! /N "); eXosip_call_send_answer (je-> tid, 400, NULL);} else {eXosip_call_send_answer (je-> tid, 200, answer); printf (" bye send 200 over! /N ");} break; case EXOSIP_CALL_MESSAGE_NEW: // As for the difference between this type and EXOSIP_MESSAGE_NEW, The Source Code explains this/* request related events within CILS (Response t INVITE) */EXOSIP_CALL_MESSAGE_NEW,/** <announce new incoming request. * // * response received ed for request outside call*/EXOSIP_MESSAGE_NEW,/** <announce new incoming request. */I don't quite understand either. The understanding is: EXOSIP_CALL_MESSAGE_NEW is the arrival of a new message in a call, such as ring trying. Therefore, you must determine the message type after receiving the message, EXOSIP_MESSAGE_NEW indicates that messages in the call are not received. This explanation is for reference only. */Printf ("EXOSIP_CALL_MESSAGE_NEW/n"); if (MSG_IS_INFO (je-> request) // if the information method is transmitted {eXosip_lock (); I = eXosip_call_build_answer (je-> tid, 200, & answer); if (I = 0) {equals (je-> tid, 200, answer);} eXosip_unlock (); {osip_body_t * body; osip_message_get_body (je-> request, 0, & body); printf ("the body is % s/n", body-> body) ;}} break; default: printf ("cocould not parse the msg! /N ");}}}
> Gcc uastest. c-o uastest-L/opt/sip/target/lib/-I/opt/sip/target/include/-leXosip2
Problems and Solutions:
Compilation problems:
Uastest. c: In function 'main ':
Uastest. c: 118: incompatible type for argument 1 of 'osip _ list_eol'
Uastest. c: 122: incompatible type for argument 1 of 'osip _ list_get'
Solution:
The osip_list _ * interface has been changed in latest versions
Osip and osip_list_t in structures are not pointer any more.
I think Updating is just a matter of adding "&" in front
Remote_sdp-> m_medias and to other list accessed.
Running problems:
[Root @ localhost linphonenew] #./uastest
./Uastest: error while loading shared libraries: libosipparser2.so. 4: cannot open shared object file: No such file or directory
Solution:
# Copy the libosipparser2 library files to the usr and lib directories.
Cp/opt/sip/target/lib/libosipp */usr/lib
2. uac
# Include <eXosip2/eXosip. h> # include <stdio. h> # include <stdlib. h> # include <netinet/in. h> # include <sys/socket. h> # include <sys/types. h> int main (int argc, char * argv []) {eXosip_event_t * je; osip_message_t * reg = NULL; osip_message_t * invite = NULL; osip_message_t * ack = NULL; osip_message_t * info = NULL; osip_message_t * message = NULL; int call_id, dialog_id; int I, flag; int flag1 = 1; int id; char * I Dentity = "sip: 140@192.168.0.140"; char * registerer = "sip: 192.168.0.20.: 5060"; char * source_call = "sip: 140@192.168.0.140"; char * dest_call = "sip: 133@192.168.0.133: 5060 "; char command; char tmp [4096]; char localip [128]; printf (" r register with the server/n "); printf ("c cancel registration/n"); printf ("I initiate a call request/n"); printf ("h /n "); printf ("q exit Program/n"); printf ("s execution method INFO/n "); printf ("m execution method MESSAGE/n"); // initialize I = e Xosip_init (); if (I! = 0) {printf ("Couldn't initialize eXosip! /N "); return-1;} else {printf (" eXosip_init successfully! /N ");} I = eXosip_listen_addr (IPPROTO_UDP, NULL, 5060, AF_INET, 0); if (I! = 0) {eXosip_quit (); fprintf (stderr, "Couldn't initialize transport layer! /N "); return-1;} flag = 1; while (flag) {printf (" please input the comand:/n "); scanf (" % c ", & command); getchar (); switch (command) {case 'r': printf ("This modal isn't commleted! /N "); break; case 'I':/* INVITE */I = eXosip_call_build_initial_invite (& invite, dest_call, source_call, NULL, "This si a call for a conversation"); if (I! = 0) {printf ("Intial INVITE failed! /N "); break;} // complies with the SDP format, where attribute a is a custom format, that is, you can store your own information, but only two columns are allowed, for example, the account information // but tested, the format: v o t is indispensable, and the cause is unknown. It is estimated that the protocol stack needs to check the snprintf (tmp, 4096, "v = 0/r/n" "o = anonymous 0 0 IN IP4 0.0.0.0/r/n" "t = 1 10/r/n" "a = username: rainfish/r/n "" a = password: 123/r/n "); osip_message_set_body (invite, tmp, strlen (tmp); osip_message_set_content_type (invite, "application/sdp"); eXosip_lock (); I = eXosip_call_send_initial_invite (I Nvite); eXosip_unlock (); flag1 = 1; while (flag1) {je = eXosip_event_wait (0,200); if (je = NULL) {printf ("No response or the time is over! /N "); break;} switch (je-> type) {case EXOSIP_CALL_INVITE: printf (" a new invite reveived! /N "); break; case EXOSIP_CALL_PROCEEDING: printf (" proceeding! /N "); break; case EXOSIP_CALL_RINGING: printf (" ringing! /N "); // call_id = je-> cid; // dialog_id = je-> did; printf (" call_id is % d, dialog_id is % d/n ", je-> cid, je-> did); break; case EXOSIP_CALL_ANSWERED: printf ("OK! Connected! /N "); call_id = je-> cid; dialog_id = je-> did; printf (" call_id is % d, dialog_id is % d/n ", je-> cid, je-> did); eXosip_call_build_ack (je-> did, & ack); eXosip_call_send_ack (je-> did, ack); flag1 = 0; break; case EXOSIP_CALL_CLOSED: printf ("the other sid closed! /N "); break; case EXOSIP_CALL_ACK: printf (" ACK received! /N "); break; default: printf (" other response! /N "); break;} eXosip_event_free (je);} break; case 'H': printf (" Holded! /N "); eXosip_lock (); eXosip_call_terminate (call_id, dialog_id); eXosip_unlock (); break; case 'C': printf (" This modal isn't commleted! /N "); break; case's ': // transfer the INFO method eXosip_call_build_info (dialog_id, & info); snprintf (tmp, 4096," hello, rainfish "); osip_message_set_body (info, tmp, strlen (tmp); // The format can be set arbitrarily. text/plain indicates text information watermark (info, "text/plain"); eXosip_call_send_request (dialog_id, info); break; case 'M': // MESSAGE transmission method, that is, instant MESSAGE. Compared with the INFO method, I think the main difference is that the MESSAGE does not need to be connected, directly transfer information, while INFO must be // transmitted Based on the INVITE. Printf ("the mothed: MESSAGE/n"); eXosip_message_build_request (& message, "MESSAGE", dest_call, source_call, NULL); snprintf (tmp, 4096, "hellor rainfish "); osip_message_set_body (message, tmp, strlen (tmp); // assume that the format is xml osip_message_set_content_type (message, "text/xml"); eXosip_message_send_request (message); break; case 'q': eXosip_quit (); printf ("Exit the setup! /N "); flag = 0; break;} return (0 );}
> Gcc uastest. c-o uastest-L/opt/sip/target/lib/-I/opt/sip/target/include/-leXosip2
3. standalone test Guide
Local ip Address: 192.168.3.168
Uac modification:
Line23-26 changed:
Char * identity = "sip: 140@192.168.3.168"; // UAC1, port 5060
Char * registar = "sip: 133@192.168.3.168: 5061"; // UAS, port is 5061
Char * source_call = "sip: 140@192.168.3.168 ";
Char * dest_call = "sip: 133@192.168.3.168: 5061 ";
Uas modification:
Changed line44 to: I = eXosip_listen_addr (IPPROTO_UDP, NULL, 5061, AF_INET, 0 );
Others:
Http://hi.baidu.com/yangkaiii/blog/item/e2946f44ecdeaa86b3b7dc5d.html
Http://hi.baidu.com/yangkaiii/blog/item/e46a59dde1ad5e305882dd5c.html
4/call color e
Local ip Address: 192.168.3.168
Color E: 192.168.3.167
Change line80 to 85:
Snprintf (tmp, 4096, "v = 0/r/n" "o =-6 2 IN IP4 192.168.3.46/r/n" "s = CounterPath X-Lite 3.0/r/n" "c = IN IP4 192.168.3.46/r/n "" t = 0 0/r/n "" m = audio 52386 RTP/AVP 107 0 8 101/r/n "" a = alt: 1 1: 0 + Y3WBhV SIknnQeS 192.168.3.46 52386/r/n "" a = fmtp: 101 0-15/r/n "a = rtpmap: 107 BV32/16000/r/n "" a = rtpmap: 101 telephone-event/8000/r/n "" a = sendrecv/r/n ");
Line26:
Char * dest_call = "sip: 111@192.168.3.167: 5060 ";
Note: The user name of 111 cannot be the account of the color e, and cannot be changed to other 121 or the like. Otherwise, the user will receive a response such as busy.