Home --> Documentations --> PJSIP Reference
This is about the simplest SIP application with PJSIP, all it does is respond all incoming requests with 501 (Not Implemented) response statelessly.
31#include <pjlib-util.h>
36#define HAS_UDP_TRANSPORT
39#define HAS_TCP_TRANSPORT (1 && PJ_HAS_TCP)
42#define THIS_FILE "sipstateless.c"
49static int code = PJSIP_SC_NOT_IMPLEMENTED;
55static void usage( void)
58 puts( " sipstateless [code] [-H HDR] ..");
61 puts( " code SIP status code to send (default: 501/Not Implemented");
62 puts( " -H HDR Specify additional headers to send with response");
63 puts( " This option may be specified more than once.");
65 puts( " -H 'Expires: 300' -H 'Contact: <sip:localhost>'");
89int main( int argc, char *argv[])
140 while ((c=pj_getopt(argc, argv , "H:")) != -1) {
150 name = strtok(pj_optarg, ":");
152 puts( "Error: invalid header format");
155 char *val = strtok(NULL, "\r\n");
166 PJ_LOG(4,(THIS_FILE, "Header %s: %s added", name, val));
171 puts( "Error: invalid argument");
177 if (pj_optind != argc) {
178 code = atoi(argv[pj_optind]);
179 if (code < 200 || code > 699) {
180 puts( "Error: invalid status code");
186 PJ_LOG(4,(THIS_FILE, "Returning %d to incoming requests", code));
192#ifdef HAS_UDP_TRANSPORT
203 "Error starting UDP transport (port in use?)"));
223 "Error starting TCP transport (port in use?)"));
237 PJ_LOG(3,(THIS_FILE, "Press Ctrl-C to quit.."));
pj_status_t pjlib_util_init(void)
pj_status_t pjsip_endpt_respond_stateless(pjsip_endpoint *endpt, pjsip_rx_data *rdata, int st_code, const pj_str_t *st_text, const pjsip_hdr *hdr_list, const pjsip_msg_body *body)
pj_status_t pjsip_endpt_register_module(pjsip_endpoint *endpt, pjsip_module *module)
pj_status_t pjsip_endpt_handle_events(pjsip_endpoint *endpt, const pj_time_val *max_timeout)
pj_status_t pjsip_endpt_create(pj_pool_factory *pf, const char *name, pjsip_endpoint **endpt)
@ PJSIP_MOD_PRIORITY_APPLICATION Definition: sip_module.h:210
pjsip_generic_string_hdr * pjsip_generic_string_hdr_create(pj_pool_t *pool, const pj_str_t *hname, const pj_str_t *hvalue)
@ PJSIP_ACK_METHOD Definition: sip_msg.h:58
pj_status_t pjsip_tcp_transport_start(pjsip_endpoint *endpt, const pj_sockaddr_in *local, unsigned async_cnt, pjsip_tpfactory **p_factory)
pj_status_t pjsip_udp_transport_start(pjsip_endpoint *endpt, const pj_sockaddr_in *local, const pjsip_host_port *a_name, unsigned async_cnt, pjsip_transport **p_transport)
struct pjsip_endpoint pjsip_endpoint Definition: sip_types.h:111
pj_status_t pj_init(void)
void pj_caching_pool_init(pj_caching_pool *ch_pool, const pj_pool_factory_policy *policy, pj_size_t max_capacity)
void pj_list_init(pj_list_type *node)
void pj_list_push_back(pj_list_type *list, pj_list_type *node)
#define PJ_LOG(level, arg)
pj_pool_factory_policy pj_pool_factory_default_policy
pj_pool_t * pj_pool_create(pj_pool_factory *factory, const char *name, pj_size_t initial_size, pj_size_t increment_size, pj_pool_callback *callback)
pj_str_t pj_str(char *str)
pj_uint16_t pj_htons(pj_uint16_t hostshort)
#define PJ_ASSERT_RETURN(expr, retval)
Definition: sip_msg.h:1070
Definition: sip_msg.h:324
pj_str_t name Definition: sip_msg.h:325
pjsip_method_e id Definition: sip_msg.h:78
Definition: sip_module.h:54
struct pjsip_request_line req Definition: sip_msg.h:868
union pjsip_msg::@19 line
pjsip_method method Definition: sip_msg.h:434
Definition: sip_transport.h:295
struct pjsip_rx_data::@26 msg_info
pjsip_msg * msg Definition: sip_transport.h:364
PJSIP Open Source, high performance, small footprint, and very very portable SIP stack
Copyright (C) 2006-2008 Teluu Inc.
|