### Create and Start a Thread with libosip2 Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/doxygen/ht5-portability.dox Demonstrates how to create and start a new thread using libosip2's thread creation function. The thread executes a specified function until a stop condition is met. ```c void *_my_thread (void *arg) { struct sometype_t *excontext = (struct sometype_t *) arg; int i; while (stopthread == 0) { do_actions (excontext); } osip_thread_exit (); return NULL; } struct osip_thread *thread; thread = osip_thread_create (20000, _my_thread, argpointer); ``` -------------------------------- ### Via Header API Examples Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/doxygen/ht2-parser.dox Provides code examples for common operations related to the 'Via' SIP header, including getting a Via header from a message, adding a new Via header, and parsing a Via header string. ```APIDOC ## Via Header API ### Description This section provides examples for interacting with the 'Via' SIP header using the libosip2 library. It covers retrieving, adding, and parsing 'Via' headers. ### Method Various `osip_via_t` functions and `osip_message_get_via`, `osip_message_set_via`. ### Endpoint N/A (Library functions) ### Parameters Refer to individual function documentation within libosip2. ### Get Via from message #### Description Retrieves the first 'Via' header from a SIP message. #### Request Example ```c osip_via_t *dest; osip_message_get_via (msg, 0, &dest); ``` ### Add Via in message #### Description Constructs a 'Via' header string and adds it to a SIP message. #### Request Example ```c char tmp[200]; snprintf (tmp, 200, "SIP/2.0/UDP %s:%s;rport;branch=z9hG4bK%u", ip, port, osip_build_random_number ()); osip_message_set_via (msg, tmp); ``` ### Parse Via #### Description Initializes a `osip_via_t` structure, parses a 'Via' header string into it, and then frees the structure. #### Request Example ```c osip_via_t *header; char tmp[200]; snprintf (tmp, 200, "SIP/2.0/UDP %s:%s;rport;branch=z9hG4bK%u", ip, port, osip_build_random_number ()); osip_via_init (&header); osip_via_parse (header, tmp); osip_free(header); ``` ### Response - **dest** (*osip_via_t**) - Pointer to the retrieved 'Via' header structure. - The `osip_message_set_via` and `osip_via_parse` functions modify the message or the header structure in place. ``` -------------------------------- ### Initialize oSIP Library Source: https://context7.com/distrotech/libosip2/llms.txt Demonstrates the mandatory initialization steps for the oSIP parser and transaction management system. This setup must be performed before executing any other library functions. ```c #include #include int main(void) { osip_t *osip; int ret; /* Initialize the parser */ parser_init(); /* Initialize the oSIP transaction management */ ret = osip_init(&osip); if (ret != 0) { fprintf(stderr, "Failed to initialize osip\n"); return -1; } /* Set application context for callbacks */ osip_set_application_context(osip, my_app_data); /* ... use the library ... */ /* Clean up */ osip_release(osip); return 0; } ``` -------------------------------- ### Construct SIP Messages Source: https://context7.com/distrotech/libosip2/llms.txt Provides an example of building a SIP INVITE request programmatically. It covers setting the method, URI, mandatory headers, and serializing the object into a string. ```c #include #include int create_invite_request(void) { osip_message_t *invite; char *dest; size_t length; int ret; /* Initialize message */ osip_message_init(&invite); /* Set request method and version */ osip_message_set_method(invite, osip_strdup("INVITE")); osip_message_set_version(invite, osip_strdup("SIP/2.0")); /* Set Request-URI */ osip_uri_t *uri; osip_uri_init(&uri); osip_uri_set_scheme(uri, osip_strdup("sip")); osip_uri_set_username(uri, osip_strdup("bob")); osip_uri_set_host(uri, osip_strdup("example.com")); osip_message_set_uri(invite, uri); /* Set mandatory headers */ osip_message_set_to(invite, "Bob "); osip_message_set_from(invite, "Alice ;tag=12345"); osip_message_set_call_id(invite, "call-id-12345@192.168.1.1"); osip_message_set_cseq(invite, "1 INVITE"); osip_message_set_via(invite, "SIP/2.0/UDP 192.168.1.1:5060;branch=z9hG4bK776asdhds"); osip_message_set_max_forwards(invite, "70"); osip_message_set_contact(invite, ""); osip_message_set_content_length(invite, "0"); /* Convert to string */ ret = osip_message_to_str(invite, &dest, &length); if (ret == 0) { printf("Generated INVITE:\n%s\n", dest); osip_free(dest); } osip_message_free(invite); return 0; } ``` -------------------------------- ### Manage SIP Transactions in C Source: https://context7.com/distrotech/libosip2/llms.txt Illustrates the setup and management of SIP transactions using libosip2's state machine. It covers initializing transactions (ICT), registering callbacks for message sending and specific events (like 2xx responses), adding events, and executing the transaction loop for timer and event handling. Dependencies include osip2/osip.h. ```c #include /* Callback for outgoing messages */ int send_message_callback(osip_transaction_t *tr, osip_message_t *msg, char *host, int port, int out_socket) { char *dest; size_t length; osip_message_to_str(msg, &dest, &length); printf("Sending to %s:%d\n%s\n", host, port, dest); /* Actually send the message via socket */ /* send(out_socket, dest, length, 0); */ osip_free(dest); return 0; } /* Callback when INVITE receives 2xx response */ void cb_ict_2xx_received(int type, osip_transaction_t *tr, osip_message_t *msg) { printf("INVITE successful! Call established.\n"); } int setup_transaction(osip_t *osip, osip_message_t *request) { osip_transaction_t *tr; osip_event_t *evt; int ret; /* Register callbacks */ osip_set_cb_send_message(osip, send_message_callback); osip_set_message_callback(osip, OSIP_ICT_STATUS_2XX_RECEIVED, cb_ict_2xx_received); /* Create Invite Client Transaction (ICT) */ ret = osip_transaction_init(&tr, ICT, osip, request); if (ret != 0) { fprintf(stderr, "Failed to create transaction\n"); return -1; } /* Set custom application data */ osip_transaction_set_your_instance(tr, my_call_context); /* Create and add send event */ evt = osip_new_outgoing_sipmessage(request); osip_transaction_add_event(tr, evt); /* Execute transaction */ osip_ict_execute(osip); return 0; } /* Main event loop */ void transaction_event_loop(osip_t *osip) { struct timeval timeout; while (1) { /* Get minimum timeout for next timer event */ osip_timers_gettimeout(osip, &timeout); /* Wait for network data or timeout */ /* select() or poll() here */ /* Execute pending timer events */ osip_timers_ict_execute(osip); osip_timers_ist_execute(osip); osip_timers_nict_execute(osip); osip_timers_nist_execute(osip); /* Execute pending transaction events */ osip_ict_execute(osip); osip_ist_execute(osip); osip_nict_execute(osip); osip_nist_execute(osip); /* Handle retransmissions */ osip_retransmissions_execute(osip); } } ``` -------------------------------- ### SIP Header API (Example: To Header) Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html API functions for manipulating SIP headers, with 'To' header as an example. The same API structure applies to other headers by replacing 'osip_to_' with the respective header prefix. ```APIDOC ## osip_to_init ### Description Allocate and initialize the structure _to_. ### Method `int osip_to_init(osip_to_t **to);` ### Endpoint N/A (Library Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (0) Returns 0 on success. #### Response Example `0` ``` ```APIDOC ## osip_to_free ### Description Free resources contained in _to_. ### Method `void osip_to_free(osip_to_t **to);` ### Endpoint N/A (Library Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response None #### Response Example None ``` ```APIDOC ## osip_to_parse ### Description Parse _field_value_ and store results in _to_. ### Method `int osip_to_parse(osip_to_t *to, char *field_value);` ### Endpoint N/A (Library Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (0) Returns 0 on success. #### Response Example `0` ``` ```APIDOC ## osip_to_to_str ### Description Allocate a string in _field_value_ with the information stored in the _to_ parameter. ### Method `int osip_to_to_str(osip_to_t *to, char **field_value);` ### Endpoint N/A (Library Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (0) Returns 0 on success. #### Response Example `0` ``` -------------------------------- ### SIP INVITE Request Example Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html This snippet demonstrates the structure of a SIP INVITE request, used to initiate or modify sessions. It includes essential headers like Via, To, From, Call-ID, CSeq, and Contact, along with the SDP payload for media negotiation. ```sip INVITE sip:jacK@atosc.org SIP/2.0 Via: SIP/2.0/UDP home.sipworld.org;branch=z9hG4bK776asdhds Max-Forwards: 70 To: sip:jacK@atosc.org From: sip:cha@sipworld.org Call-ID: 35778645354@home.sipworld.org CSeq: 1 INVITE Contact: sip:cha@home.sipworld.org Content-type: application/sdp Content-length: 267 v=0 o=user1 53655765 2353687637 IN IP4 128.3.4.5 s=Mbone Audio i=Discussion of Mbone Engineering Issues e=mbone@somewhere.com c=IN IP4 128.3.4.5 t=0 0 m=audio 3456 RTP/AVP 0 a=rtpmap:0 PCMU/8000 ``` -------------------------------- ### Get SIP Message Header by Name (C) Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Finds the first header matching a given name, starting the search from a specified position. Returns the header as a pointer to a header_t structure. Returns 0 on success. ```c int osip_message_header_get_byname(char *hname, osip_message_t *sip, int pos, header_t **dest); ``` -------------------------------- ### Get and Compensate Time with libosip2 Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/doxygen/ht5-portability.dox Provides function signatures for getting the current time and compensating for time drift, particularly useful on systems like Android where the monotonic clock might not advance during deep sleep. ```c int osip_gettimeofday (struct timeval *tp, void *tz); void osip_compensatetime (); ``` -------------------------------- ### Manage SIP Message Headers Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/doxygen/ht2-parser.dox Provides examples for adding custom headers to a SIP message and retrieving specific headers by name. It includes logic for iterating through multiple headers with the same name. ```c /* Adding a header */ osip_message_set_header (msg, "Refer-to", refer_to_header); /* Finding the first header */ osip_message_header_get_byname (msg, "min-se", 0, &min_se_header); if (min_se_header != NULL && min_se_header->hvalue != NULL) { } /* Finding all headers with the same name */ int pos=0; while (1) { pos = osip_message_header_get_byname (msg, "x-header", pos, &min_se_new); if (min_se_new == NULL) { break; } } ``` -------------------------------- ### SIP INVITE Transaction Call Flow Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html This example illustrates a basic SIP INVITE transaction, showing the interaction between a User Agent Client (UAC) and a User Agent Server (UAS) during call initiation. It includes the initial INVITE, provisional responses (100 Trying, 180 Ringing), the final success response (200 OK), and the ACK message. ```sip UAC1 UAS2 jacks | INVITE | initiate a |----------------->| call | | | 100 Trying | |<-----------------| | 180 Ringing| |<-----------------| | | | | | 200 OK | |<-----------------| | ACK | |----------------->| ``` -------------------------------- ### Get osip_uri_param_t by Name from List (C) Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Finds and retrieves an osip_uri_param_t element from a list based on its name. It populates the provided double pointer with the found parameter. Returns 0 on success. ```c void osip_uri_param_get_byname(list_t *osip_uri_params, char *pname, osip_uri_param_t **osip_uri_param); ``` -------------------------------- ### Initialize and Free SIP Structures Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Demonstrates the mandatory allocation and deallocation pattern for libosip2 structures like osip_message_t and osip_uri_t using init and free methods. ```C osip_message_t *msg; osip_message_init(&msg); osip_message_free(msg); osip_uri_t *url; osip_uri_init(&url); osip_uri_free(url); ``` -------------------------------- ### Build SIP Request Line Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Shows how to construct a SIP request line by initializing a URI, setting its components, and assigning it to an INVITE message. ```C osip_uri_t *uri; osip_uri_init(&uri); osip_uri_set_scheme(url,osip_strdup("sip")); osip_uri_set_username(url,osip_strdup("jack")); osip_uri_set_host(url,osip_strdup("atosc.org")); osip_message_set_method(msg,osip_strdup("INVITE")); osip_message_set_uri(msg,uri); osip_message_set_version(msg,osip_strdup("2.0")); ``` -------------------------------- ### Initiating a SIP Session and Sending Messages Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Demonstrates how to initialize a SIP transaction and send a message. It involves creating a message object, initializing the transaction context, and dispatching the event to the transaction's FIFO queue. ```c int create_session(osip_t *osip) { osip_message_t *invite; osip_transaction_t *transaction; osip_message_init (&invite); your_own_method_to_setup_messages(invite); osip_transaction_init(&transaction, osip, invite->to, invite->from, invite->callid, invite->cseq); osip_sendmsg(transaction, invite); } int osip_sendmsg(osip_transaction_t *transaction, osip_message_t *msg) { osip_event_t *evt = osip_new_outgoing_sipmessage(msg); osip_fifo_add(transaction->transactionff, evt); osip_transaction_execute(transaction, evt); return 0; } ``` -------------------------------- ### To Header Manipulation API Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Functions for cloning, setting, and getting display names and URLs for the 'To' header. ```APIDOC ## osip_to_clone ### Description Duplicates the 'To' element into a new destination element. ### Method `int osip_to_clone(osip_to_t *to, osip_to_t **dest)` ### Parameters - **to** (osip_to_t *) - The source 'To' element to clone. - **dest** (osip_to_t **) - Pointer to the destination 'To' element. ### Response - **Success Response (0)**: Indicates successful cloning. ## osip_to_set_displayname ### Description Sets the display name in the 'To' element. ### Method `void osip_to_set_displayname(osip_to_t *to, char *value)` ### Parameters - **to** (osip_to_t *) - The 'To' element to modify. - **value** (char *) - The display name string to set. ## osip_to_get_displayname ### Description Retrieves the display name from the 'To' element. ### Method `char *osip_to_get_displayname(osip_to_t *to)` ### Parameters - **to** (osip_to_t *) - The 'To' element to query. ### Response - **Return Value** (char *): The display name string, or NULL if not set. ## osip_to_set_url ### Description Sets the URL in the 'To' element. ### Method `void osip_to_set_url(osip_to_t *to, osip_uri_t *url)` ### Parameters - **to** (osip_to_t *) - The 'To' element to modify. - **url** (osip_uri_t *) - Pointer to the URI structure to set. ## osip_to_get_url ### Description Retrieves the URL from the 'To' element. ### Method `osip_uri_t *osip_to_get_url(osip_to_t *to)` ### Parameters - **to** (osip_to_t *) - The 'To' element to query. ### Response - **Return Value** (osip_uri_t *): Pointer to the URI structure, or NULL if not set. ``` -------------------------------- ### To Header Generic Parameter API Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Functions for adding, getting, and managing generic parameters within the 'To' header. ```APIDOC ## osip_to_param_add ### Description Adds a generic parameter to the 'To' element. ### Method `int osip_to_param_add(osip_to_t *to, char *name, char *value)` ### Parameters - **to** (osip_to_t *) - The 'To' element to modify. - **name** (char *) - The name of the parameter. - **value** (char *) - The value of the parameter. ### Response - **Success Response (0)**: Indicates successful addition. ## osip_to_param_get ### Description Retrieves a generic parameter from the 'To' element by its position. ### Method `int osip_to_param_get(osip_to_t *to, int pos, generic_param_t **gp)` ### Parameters - **to** (osip_to_t *) - The 'To' element to query. - **pos** (int) - The index (position) of the parameter to retrieve. - **gp** (generic_param_t **) - Pointer to store the retrieved generic parameter. ### Response - **Success Response (0)**: Indicates successful retrieval. ## osip_to_get_tag ### Description Retrieves the value associated with the 'tag' parameter from the 'To' element. ### Method `void osip_to_get_tag(osip_to_t *to, generic_param_t **dest)` ### Parameters - **to** (osip_to_t *) - The 'To' element to query. - **dest** (generic_param_t **) - Pointer to store the 'tag' generic parameter. ## osip_to_set_tag ### Description Sets the 'tag' parameter in the 'To' element. ### Method `void osip_to_set_tag(osip_to_t *to, char *tag)` ### Parameters - **to** (osip_to_t *) - The 'To' element to modify. - **tag** (char *) - The value of the 'tag' parameter. ## osip_to_param_get_byname ### Description Retrieves a generic parameter from the 'To' element by its name. ### Method `int osip_to_param_get_byname(osip_to_t *to, char *pname, generic_param_t **dest)` ### Parameters - **to** (osip_to_t *) - The 'To' element to query. - **pname** (char *) - The name of the parameter to retrieve. - **dest** (generic_param_t **) - Pointer to store the retrieved generic parameter. ### Response - **Success Response (0)**: Indicates successful retrieval. ``` -------------------------------- ### Create Dialog as UAS Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/doxygen/ht4-dialog.dox Shows how to initialize a dialog as a User Agent Server upon receiving an INVITE request, requiring a valid response with a tag. ```c osip_dialog_t *dialog; osip_dialog_init_as_uas(&dialog, original_invite, response_that_you_build); ``` -------------------------------- ### Get SIP To (C) Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Retrieves the To attribute from the SIP message. Returns a pointer to the osip_to_t structure. Returns 0 on success. ```c osip_to_t *osip_message_get_to(osip_message_t *sip); ``` -------------------------------- ### Get SIP From (C) Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Retrieves the From attribute from the SIP message. Returns a pointer to the osip_from_t structure. Returns 0 on success. ```c osip_from_t *osip_message_get_from(osip_message_t *sip); ``` -------------------------------- ### Handle SIP Dialogs as UAC with libosip2 Source: https://context7.com/distrotech/libosip2/llms.txt Demonstrates how to initialize and manage a SIP dialog as a User Agent Client (UAC) using libosip2. This includes creating the dialog from a response, setting application-specific data, checking dialog states (early, confirmed), accessing dialog properties like Call-ID and tags, and matching incoming requests to the dialog. It also shows how to update the dialog state based on incoming messages. Requires the osip2/osip_dialog.h header. ```c #include int handle_dialog(osip_message_t *invite, osip_message_t *response) { osip_dialog_t *dialog; int ret; /* Create dialog as UAC (caller) from received response */ ret = osip_dialog_init_as_uac(&dialog, response); if (ret != 0) { fprintf(stderr, "Failed to create dialog\n"); return -1; } /* Store application-specific data */ osip_dialog_set_instance(dialog, my_call_data); /* Check dialog state */ if (dialog->state == DIALOG_EARLY) { printf("Dialog is in early state (provisional response)\n"); } else if (dialog->state == DIALOG_CONFIRMED) { printf("Dialog confirmed (2xx response)\n"); } /* Access dialog properties */ printf("Call-ID: %s\n", dialog->call_id); printf("Local tag: %s\n", dialog->local_tag); printf("Remote tag: %s\n", dialog->remote_tag); printf("Local CSeq: %d\n", dialog->local_cseq); /* Check if we are the caller or callee */ if (osip_dialog_is_originator(dialog)) { printf("We initiated this call\n"); } /* Match incoming request to dialog */ osip_message_t *incoming_request = /* received from network */; if (osip_dialog_match_as_uac(dialog, incoming_request) == 0) { printf("Request matches our dialog\n"); /* Update dialog state */ osip_dialog_update_osip_cseq_as_uas(dialog, incoming_request); } /* Clean up */ osip_dialog_free(dialog); return 0; } ``` -------------------------------- ### Get Name from Generic Parameter (C) Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Retrieves the name of a generic parameter. This function allows inspection of the parameter's name. ```c char *generic_param_get_name(generic_param_t *gen_param); ``` -------------------------------- ### Get SIP CSeq (C) Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Retrieves the CSeq attribute from the SIP message. Returns a pointer to the osip_cseq_t structure. Returns 0 on success. ```c osip_cseq_t *osip_message_get_cseq(osip_message_t *sip); ``` -------------------------------- ### Initialize libosip2 Parser Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/doxygen/ht0-initialize.dox Initializes the osip parser and state machine. This must be performed before any other libosip2 functions are called. ```c #include int i; osip_t *osip; i=osip_init(&osip); if (i!=0) return -1; ``` -------------------------------- ### Get SIP Call-ID (C) Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Retrieves the Call-ID attribute from the SIP message. Returns a pointer to the osip_call_id_t structure. Returns 0 on success. ```c osip_call_id_t *osip_message_get_call_id(osip_message_t *sip); ``` -------------------------------- ### INITIALIZE /osip_global_init Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Initializes the oSIP stack and the internal parser. This must be called exactly once before any other stack operations. ```APIDOC ## INITIALIZE /osip_global_init ### Description Initializes the oSIP stack and the internal parser. This method must be called once at runtime before using the stack. ### Method FUNCTION ### Endpoint osip_global_init() ### Parameters None ### Request Example osip_global_init(); ### Response #### Success Response (0) - **status** (int) - Returns 0 on success, non-zero on failure. ``` -------------------------------- ### Get Value from Generic Parameter (C) Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Retrieves the value of a generic parameter. This function allows inspection of the parameter's associated value. ```c char *generic_param_get_value(generic_param_t *gen_param); ``` -------------------------------- ### Initialize libosip2 Dialog Header Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/doxygen/ht4-dialog.dox Includes the necessary header file to access the dialog management API in libosip2. ```c #include ``` -------------------------------- ### Get Tag Parameter from To Header (C) Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Retrieves the value of the 'tag' parameter from the 'To' header element. The 'tag' is a common parameter in SIP. ```c void osip_to_get_tag(osip_to_t *to, generic_param_t **dest); ``` -------------------------------- ### Parse and Serialize SIP Messages Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/doxygen/ht2-parser.dox Demonstrates how to initialize a SIP message structure, parse raw buffer data into it, and convert the message back into a printable string. Note that the output string must be manually freed to prevent memory leaks. ```c osip_message_t *sip; int i; i=osip_message_init(&sip); if (i!=0) { fprintf(stderr, "cannot allocate\n"); return -1; } i=osip_message_parse(sip, buffer, length_of_buffer); if (i!=0) { fprintf(stderr, "cannot parse sip message\n"); } osip_message_free(sip); char *dest=NULL; int length=0; i = osip_message_to_str(sip, &dest, &length); if (i!=0) { fprintf(stderr, "cannot get printable message\n"); return -1; } fprintf(stdout, "message:\n%s\n", dest); osip_free(dest); ``` -------------------------------- ### Get Parameter from To Header by Index (C) Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Retrieves a generic parameter from the 'To' header element at a specific index. This allows iteration through all parameters. ```c int osip_to_param_get(osip_to_t *to, int pos, generic_param_t **gp); ``` -------------------------------- ### Get URL from To Header (C) Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Retrieves the SIP URI associated with the 'To' header element. This function provides access to the destination address details. ```c osip_uri_t *osip_to_get_url(osip_to_t *to); ``` -------------------------------- ### POST /osip/transaction/init Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/doxygen/ht3-fsm.dox Initializes a new SIP transaction context and adds an outgoing message event to the state machine. ```APIDOC ## POST /osip/transaction/init ### Description Initializes a new transaction context in the oSIP stack and triggers the state machine with an outgoing SIP message event. ### Method POST ### Endpoint /osip/transaction/init ### Parameters #### Request Body - **transaction_type** (enum) - Required - The type of transaction (ICT, NICT, IST, NIST). - **osip_context** (pointer) - Required - The global oSIP library context. - **sip_message** (object) - Required - The pre-built SIP message object. ### Request Example { "transaction_type": "NICT", "osip_context": "global_osip_ctx", "sip_message": "" } ### Response #### Success Response (200) - **transaction_id** (int) - The unique identifier for the created transaction. #### Response Example { "status": "success", "transaction_id": 1024 } ``` -------------------------------- ### Create SIP Transaction Events Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/doxygen/ht2-parser.dox Shows how to create an event object for transaction management from a received SIP message buffer. ```c osip_event_t *evt; int length = size_of_buffer; evt = osip_parse(buffer, i); ``` -------------------------------- ### Get Parameter from To Header by Name (C) Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Retrieves a generic parameter from the 'To' header element by its name. This provides a direct way to access a specific parameter. ```c int osip_to_param_get_byname(osip_to_t *to, char *pname, generic_param_t **dest); ``` -------------------------------- ### Library Initialization Source: https://context7.com/distrotech/libosip2/llms.txt Initializes the oSIP parser and transaction management system required for library operations. ```APIDOC ## Initialization ### Description Initializes the oSIP parser and the transaction management system. This must be called before any other library functions. ### Method N/A (C Function Call) ### Parameters - **osip** (osip_t**) - Required - Pointer to the oSIP structure to be initialized. ### Response - **int** - Returns 0 on success, non-zero on failure. ``` -------------------------------- ### Initialize Generic Parameter Structure (C) Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Allocates and initializes a generic parameter structure. This is the first step before setting name and value for a parameter. ```c int generic_param_init(generic_param_t * gen_param); ``` -------------------------------- ### Initialize and manage oSIP library Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Core API functions for initializing the oSIP element, executing event processing, and freeing allocated resources. ```c int osip_init(osip_t **osip); int osip_execute(osip_t *osip); void osip_free(osip_t *osip); ``` -------------------------------- ### Get Display Name from To Header (C) Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Retrieves the display name from a 'To' header element. This function allows access to the human-readable name part of the SIP address. ```c char *osip_to_get_displayname(osip_to_t *to); ``` -------------------------------- ### Get Via Header from SIP Message Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/doxygen/ht2-parser.dox Retrieves the first Via header from a SIP message object. This function is part of the Via header manipulation API in libosip2. ```c osip_via_t *dest; osip_message_get_via (msg, 0, &dest); ``` -------------------------------- ### Create Dialog as UAC Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/doxygen/ht4-dialog.dox Demonstrates how to create a dialog in a callback function when receiving a 1xx or 2xx response to an INVITE request. ```c void cb_rcv1xx(osip_transaction_t *tr,osip_message_t *sip) { osip_dialog_t *dialog; if (MSG_IS_RESPONSEFOR(sip, "INVITE")&&!MSG_TEST_CODE(sip, 100)) { dialog = my_application_search_existing_dialog(sip); if (dialog==NULL) //NO EXISTING DIALOG { i = osip_dialog_init_as_uac(&dialog, sip); my_application_add_existing_dialog(dialog); } } else { //no dialog establishment for other REQUEST } } ``` -------------------------------- ### Manage Mutexes with libosip2 Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/doxygen/ht5-portability.dox Illustrates the lifecycle of a mutex using libosip2 functions, including initialization, locking, unlocking, and destruction. This is essential for protecting shared resources. ```c struct osip_mutex *mutex; mutex = osip_mutex_init (); osip_mutex_lock (mutex); do_actions (); osip_mutex_unlock (mutex); osip_mutex_destroy (mutex); ``` -------------------------------- ### Initialize osip_to_t Structure (C) Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Allocates and initializes the osip_to_t structure, which represents a SIP 'To' header. This function is the first step in creating or manipulating a 'To' header. It returns 0 on success. ```c int osip_to_init(osip_to_t **to); ``` -------------------------------- ### Get SIP Contact by Index (C) Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Retrieves a specific Contact header from the SIP message at a given position. Returns the contact as a pointer to a contact_t structure. Returns 0 on success. ```c int osip_message_get_contact(osip_message_t *sip, int pos, contact_t **contact); ``` -------------------------------- ### Get SIP Message Header by Index (C) Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Retrieves a specific header from the SIP message at a given position. The header is returned as a pointer to a header_t structure. Returns 0 on success. ```c int osip_message_get_header(osip_message_t *sip, int pos, header_t **header); ``` -------------------------------- ### Initialize osip_uri_param_t Element (C) Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Allocates and initializes an osip_uri_param_t element. This structure is used to represent parameters within a SIP URI. It returns 0 on success. ```c int osip_uri_param_init(osip_uri_param_t **osip_uri_param); ``` -------------------------------- ### Create and Send SIP Transaction Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Demonstrates the process of creating a new SIP session, initializing a transaction, and sending an initial INVITE message. ```APIDOC ## Create and Send SIP Transaction ### Description This section outlines the steps to create a new SIP session, initialize a transaction, and send an initial INVITE request. ### Method create_session(osip_t *osip) ### Endpoint N/A (Function Call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c int create_session(osip_t *osip) { osip_message_t *invite; osip_transaction_t *transaction; // Initialize a new SIP message osip_message_init (&invite); your_own_method_to_setup_messages(invite); // Placeholder for message setup // Initialize a new transaction for the first invite osip_transaction_init(&transaction, osip, invite->to, invite->from, invite->callid, invite->cseq); // Send the INVITE message within the transaction osip_sendmsg(transaction, invite); return 0; } ``` ### Response None (This is a function call, not an API endpoint) #### Success Response (200) None #### Response Example None ``` ```APIDOC ## osip_sendmsg Function ### Description This function creates an outgoing SIP message event and adds it to the transaction's FIFO, then executes the transaction with the event. ### Method osip_sendmsg(osip_transaction_t *transaction, osip_message_t *msg) ### Endpoint N/A (Function Call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c int osip_sendmsg(osip_transaction_t *transaction, osip_message_t *msg) { osip_event_t *evt; // Create a new outgoing SIP message event evt = osip_new_outgoing_sipmessage(msg); // Add the event to the transaction's FIFO osip_fifo_add(transaction->transactionff, evt); // Execute the transaction with the event osip_transaction_execute(transaction, evt); return 0; } ``` ### Response None (This is a function call, not an API endpoint) #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Get osip_uri_uparam by Name (C) Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Retrieves a URI parameter by its name from a given URI structure. This function is used to access specific parameters within a SIP URI. It returns 0 on success. ```c int osip_uri_uparam_get_byname(osip_uri_t *url, char *pname, osip_uri_param_t **osip_uri_param); ``` -------------------------------- ### Include libosip2 Header Parsers Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/doxygen/ht2-parser.dox Demonstrates how to include specific header parser definitions from the libosip2 library. This allows for structured parsing and manipulation of various built-in SIP headers. ```c #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include ``` -------------------------------- ### INITIALIZE /osip_init Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Allocates and initializes an osip_t structure, which acts as a container for SIP transactions and agent instances. ```APIDOC ## INITIALIZE /osip_init ### Description Allocates and initializes an osip_t element. This structure is required for managing SIP transactions for UAS, UAC, registrar, or redirect servers. ### Method FUNCTION ### Endpoint osip_init(osip_t **osip) ### Parameters #### Path Parameters - **osip** (osip_t**) - Required - Pointer to the osip_t structure to be initialized. ### Request Example osip_t *osip; osip_init(&osip); ### Response #### Success Response (0) - **status** (int) - Returns 0 on success, -1 if mutex initialization fails. ``` -------------------------------- ### Get URL Parameter by Name - C Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Retrieves a URL parameter from an osip_uri_t structure based on its name. This function is used to access specific parameters within a SIP URI. The description is incomplete in the provided text. ```c #include // Function signature is incomplete in the provided text. ``` -------------------------------- ### Get SIP Header by Name (with short name fallback) Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/doxygen/ht2-parser.dox Retrieves a SIP header by its full name, and if not found, attempts to retrieve it using a common short name. This is useful for headers like 'session-expires' which can also be represented by 'x'. ```c osip_message_header_get_byname (msg, "session-expires", 0, &exp); if (exp == NULL) osip_message_header_get_byname (msg, "x", 0, &exp); ``` -------------------------------- ### Initialize libosip2 Parser Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Initializes the oSIP parser at runtime. This function must be called exactly once before using any other parser features. ```C int parser_init(); ``` -------------------------------- ### Add SIP Headers and Body Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/man/osip.html Illustrates how to create and add various SIP headers (To, From, Via, CSeq, Call-ID) and a message body to an existing osip_message_t structure. ```C osip_to_t *to; osip_to_init(&to); osip_to_set_url(to,url); osip_to_set_displayname(to,osip_strdup("Aymeric MOIZARD")); osip_message_set_to(msg, to); osip_message_set_header(msg,osip_strdup("SuBjecT"),osip_strdup("Need support for oSIP!")); osip_message_set_body(msg,"v=0\r\no=user1 53655765 2353687637 IN IP4 128.3.4.5\r\ns=Mbone Audio\r\ni=Discussion of Mbone Engineering Issues\r\ne=mbone@somewhere.com\r\nc=IN IP4 128.3.4.5\r\nt=0 0\r\nm=audio 3456 RTP/AVP 0\r\na=rtpmap:0 PCMU/8000\r\n"); ``` -------------------------------- ### Create SIP Dialog as UAS with libosip2 Source: https://context7.com/distrotech/libosip2/llms.txt Illustrates how to initialize a SIP dialog as a User Agent Server (UAS) using libosip2. This function is used when receiving an incoming call, creating a dialog based on the initial INVITE request and the subsequent 200 OK response. It signifies the establishment of a dialog for an incoming call. Requires the osip2/osip_dialog.h header. ```c #include int create_dialog_as_uas(osip_message_t *invite, osip_message_t *response_200ok) { osip_dialog_t *dialog; int ret; ret = osip_dialog_init_as_uas(&dialog, invite, response_200ok); if (ret != 0) { return -1; } /* Dialog is now established for incoming call */ printf("Dialog established for incoming call\n"); osip_dialog_free(dialog); return 0; } ``` -------------------------------- ### Handle Incoming SIP Events and Transactions Source: https://context7.com/distrotech/libosip2/llms.txt Shows how to parse raw network buffers into SIP events and route them to transaction state machines. It handles both incoming requests and responses, ensuring the appropriate transaction layer (ICT, IST, NICT, NIST) is executed. ```c #include int handle_incoming_message(osip_t *osip, const char *buffer, size_t length) { osip_event_t *evt = osip_parse(buffer, length); if (evt == NULL) return -1; if (EVT_IS_INCOMINGREQ(evt)) { osip_create_transaction(osip, evt); } else if (EVT_IS_INCOMINGRESP(evt)) { if (osip_find_transaction_and_add_event(osip, evt) != 0) { osip_event_free(evt); } } osip_ict_execute(osip); osip_ist_execute(osip); osip_nict_execute(osip); osip_nist_execute(osip); return 0; } ``` -------------------------------- ### Include libosip2 Portability Headers Source: https://github.com/distrotech/libosip2/blob/distrotech-libosip2/help/doxygen/ht5-portability.dox Includes necessary headers for using libosip2's portability features, such as thread management, FIFO queues, condition variables, and time functions. ```c #include #include #include #include ```