Changeset 1937 for pjproject/trunk
- Timestamp:
- Apr 22, 2008 6:32:53 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/samples/sipstateless.c
r1405 r1937 48 48 /* What response code to be sent (default is 501/Not Implemented) */ 49 49 static int code = PJSIP_SC_NOT_IMPLEMENTED; 50 51 /* Additional header list */ 52 struct pjsip_hdr hdr_list; 53 54 /* usage() */ 55 static void usage(void) 56 { 57 puts("Usage:"); 58 puts(" sipstateless [code] [-H HDR] .."); 59 puts(""); 60 puts("Options:"); 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."); 64 puts(" Example:"); 65 puts(" -H 'Expires: 300' -H 'Contact: <sip:localhost>'"); 66 } 50 67 51 68 … … 59 76 pjsip_endpt_respond_stateless( sip_endpt, rdata, 60 77 code, NULL, 61 NULL, NULL);78 &hdr_list, NULL); 62 79 } 63 80 return PJ_TRUE; … … 73 90 { 74 91 pj_caching_pool cp; 92 pj_pool_t *pool = NULL; 75 93 pjsip_module mod_app = 76 94 { … … 89 107 NULL, /* on_tsx_state() */ 90 108 }; 91 92 109 int c; 93 110 pj_status_t status; 94 111 95 if (argc == 2)96 code = atoi(argv[1]);97 98 112 /* Must init PJLIB first: */ 99 113 status = pj_init(); … … 107 121 /* Must create a pool factory before we can allocate any memory. */ 108 122 pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0); 109 110 123 111 124 /* Create global endpoint: */ … … 122 135 } 123 136 137 /* Parse arguments */ 138 pj_optind = 0; 139 pj_list_init(&hdr_list); 140 while ((c=pj_getopt(argc, argv , "H:")) != -1) { 141 switch (c) { 142 case 'H': 143 if (pool == NULL) { 144 pool = pj_pool_create(&cp.factory, "sipstateless", 1000, 145 1000, NULL); 146 } 147 148 if (pool) { 149 char *name; 150 name = strtok(pj_optarg, ":"); 151 if (name == NULL) { 152 puts("Error: invalid header format"); 153 return 1; 154 } else { 155 char *val = strtok(NULL, "\r\n"); 156 pjsip_generic_string_hdr *h; 157 pj_str_t hname, hvalue; 158 159 hname = pj_str(name); 160 hvalue = pj_str(val); 161 162 h = pjsip_generic_string_hdr_create(pool, &hname, &hvalue); 163 164 pj_list_push_back(&hdr_list, h); 165 166 PJ_LOG(4,(THIS_FILE, "Header %s: %s added", name, val)); 167 } 168 } 169 break; 170 default: 171 puts("Error: invalid argument"); 172 usage(); 173 return 1; 174 } 175 } 176 177 if (pj_optind != argc) { 178 code = atoi(argv[pj_optind]); 179 if (code < 200 || code > 699) { 180 puts("Error: invalid status code"); 181 usage(); 182 return 1; 183 } 184 } 185 186 PJ_LOG(4,(THIS_FILE, "Returning %d to incoming requests", code)); 187 188 124 189 /* 125 190 * Add UDP transport, with hard-coded port
Note: See TracChangeset
for help on using the changeset viewer.