JunkBox_Lib  1.10.2
sip_tool.h File Reference

SIP用ライブラリヘッダ More...

#include "protocol.h"
Include dependency graph for sip_tool.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SIP_NOMAXFORWARDS   1000
 
#define get_sip_header_list(b)   get_protocol_header_list((b), ':', TRUE, TRUE)
 
#define restore_sip_header(l)   restore_protocol_header((l), ": ", ON, NULL)
 
#define restore_sip_contents(l)   restore_protocol_contents((l))
 

Functions

void set_sip_contents (tList *ls, Buffer sdp)
 
Buffer get_sip_via_address (tList *lp, int no)
 
void insert_sip_via (tList *lp, char *host, unsigned short port, char *branch, int mode)
 
void del_sip_via (tList *lp, char *host, unsigned short port)
 
void insert_sip_record_route (tList *lp, char *host, unsigned short port, int mode)
 
void del_sip_record_route (tList *lp, char *host, unsigned short port)
 
void del_sip_record_route_all (tList *lp)
 
void replace_sip_contact (tList *lp, char *host, unsigned short port)
 
Buffer get_sip_contact_uri (tList *lp)
 
Buffer get_sip_domain (Buffer cturi)
 
int get_max_forwards (tList *lp)
 
void set_max_forwards (tList *lp, int nm)
 
tListget_sdp_body_list (tList *lp)
 
Buffer restore_sdp_body (tList *ls)
 
int replace_sdp_invite_addr (tList *lp, tList *ls, char *host, unsigned short port, int del_candi)
 
unsigned short get_valid_rtp_pair_sockets (int min, int max, int *rtp, int *rtcp)
 
Buffer replace_sip_via (tList *lp, char *host, unsigned short port, int no)
 
int replace_sip_contact_dstipport (tList *lp, char *ipaddr, unsigned short port)
 

Detailed Description

Author
Fumi.Iseki (C)
Date
2009 2/15
Example) How to use header decompose and compose functions.
.........
.........
.........
set_sip_contents(lp, sdp);
del_tList(&lp);
void free_Buffer(Buffer *buf)
Buffer型変数のバッファ部を解放する
Definition: buffer.c:128
unsigned char ** buf
Definition: jpeg_tool.h:96
#define restore_sip_header(l)
Definition: sip_tool.h:52
#define restore_sip_contents(l)
Definition: sip_tool.h:53
#define get_sip_header_list(b)
Definition: sip_tool.h:51
Definition: buffer.h:35
tList * del_tList(tList **pp)
指定したリストノード以降のリストを削除.
Definition: tlist.c:735
or
.........
......... // SDPリストに対する処理が可能
.........
Buffer sdp = restore_sdp_body(ls);
.........
.........
.........
set_sip_contents(lp, sdp);
del_tList(&ls);
del_tList(&lp);
Buffer restore_sdp_body(tList *ls)
Definition: sip_tool.c:488
tList * get_sdp_body_list(tList *lp)
Definition: sip_tool.c:473

Definition in file sip_tool.h.

Macro Definition Documentation

◆ get_sip_header_list

#define get_sip_header_list (   b)    get_protocol_header_list((b), ':', TRUE, TRUE)

Definition at line 51 of file sip_tool.h.

◆ restore_sip_contents

#define restore_sip_contents (   l)    restore_protocol_contents((l))

Definition at line 53 of file sip_tool.h.

◆ restore_sip_header

#define restore_sip_header (   l)    restore_protocol_header((l), ": ", ON, NULL)

Definition at line 52 of file sip_tool.h.

◆ SIP_NOMAXFORWARDS

#define SIP_NOMAXFORWARDS   1000

Definition at line 45 of file sip_tool.h.

Function Documentation

◆ del_sip_record_route()

void del_sip_record_route ( tList lp,
char *  host,
unsigned short  port 
)

void del_sip_record_route(tList* lp, char* host, unsigned short port)

Record-Routeヘッダでアドレス部が host:port (port==0の場合は host) で始まるものを全て削除する.

Definition at line 256 of file sip_tool.c.

257 {
258  char sipuri[LBUF];
259 
260  if (lp==NULL || host==NULL) return;
261 
262  if (port!=0) snprintf(sipuri, LBUF, "sip:%s:%d", host, port);
263  else snprintf(sipuri, LBUF, "sip:%s", host);
264  sipuri[LBUF-1] = '\0'; // to make sure
265 
266  while (lp!=NULL) {
267  if (lp->ldat.key.buf!=NULL && !strcasecmp((char*)lp->ldat.key.buf, "Record-Route")) {
268  char* rrt = (char*)lp->ldat.val.buf;
269  if (rrt[0]=='<') rrt++;
270 
271  if (!strncmp(sipuri, rrt, strlen(sipuri))) {
272  lp = del_tList_node(&lp);
273  }
274  else lp = lp->next;
275  }
276  else lp = lp->next;
277  }
278 
279  return;
280 }
#define LBUF
Definition: common.h:146
tList * del_tList_node(tList **node)
リスト用のノードを削除.
Definition: tlist.c:270

References del_tList_node(), and LBUF.

Here is the call graph for this function:

◆ del_sip_record_route_all()

void del_sip_record_route_all ( tList lp)

void del_sip_record_route_all(tList* lp)

全ての Record-Routeヘッダを削除する.余計な情報を中継しないように.

Definition at line 288 of file sip_tool.c.

289 {
290  while (lp!=NULL) {
291  if (lp->ldat.key.buf!=NULL && !strcasecmp((char*)lp->ldat.key.buf, "Record-Route")) {
292  lp = del_tList_node(&lp);
293  }
294  else lp = lp->next;
295  }
296 }

References del_tList_node().

Here is the call graph for this function:

◆ del_sip_via()

void del_sip_via ( tList lp,
char *  host,
unsigned short  port 
)

void del_sip_via(tList* lp, char* host, unsigned short port)

Viaヘッダでアドレス部が host:port (port==0の場合は host) で始まるものを全て削除する.

Definition at line 171 of file sip_tool.c.

172 {
173  char hostport[LBUF];
174 
175  if (lp==NULL || host==NULL) return;
176 
177  if (port!=0) snprintf(hostport, LBUF, "%s:%d", host, port);
178  else snprintf(hostport, LBUF, "%s", host);
179  hostport[LBUF-1] = '\0'; // to make sure
180 
181  while (lp!=NULL) {
182  if (lp->ldat.key.buf!=NULL && !strcasecmp((char*)lp->ldat.key.buf, "Via")) {
183  Buffer via_hostport = cawk_Buffer(lp->ldat.val, ' ', 2);
184  if (!strncmp(hostport, (char*)via_hostport.buf, strlen(hostport))) {
185  lp = del_tList_node(&lp);
186  }
187  else lp = lp->next;
188  free_Buffer(&via_hostport);
189  }
190  else lp = lp->next;
191  }
192 
193  return;
194 }
Buffer cawk_Buffer(Buffer str, char cc, int n)
Buffer文字列に対する(変形の)awk.
Definition: buffer.c:1094
unsigned char * buf
バッファの先頭へのポインタ.str[bufsz]は必ず 0x00となる.
Definition: buffer.h:39

References Buffer::buf, cawk_Buffer(), del_tList_node(), free_Buffer(), and LBUF.

Here is the call graph for this function:

◆ get_max_forwards()

int get_max_forwards ( tList lp)

int get_max_forwards(tList* lp)

Max-Forwardsヘッダの値を得る.ヘッダが無い場合は SIP_NOMAXFORWARDS が返る.

Definition at line 424 of file sip_tool.c.

425 {
426  int mxfd = SIP_NOMAXFORWARDS;
427 
428  if (lp==NULL) return mxfd;
429 
430  tList* lt = strncasecmp_tList(lp, (char*)"Max-Forwards", 0, 1);
431  if (lt!=NULL) {
432  mxfd = atoi((char*)lt->ldat.val.buf);
433  }
434 
435  return mxfd;
436 }
#define SIP_NOMAXFORWARDS
Definition: sip_tool.h:45
tList * strncasecmp_tList(tList *pl, const char *key, int len, int no)
char* 型変数によるノードのサーチ.大文字小文字を無視する
Definition: tlist.c:1094

References SIP_NOMAXFORWARDS, and strncasecmp_tList().

Here is the call graph for this function:

◆ get_sdp_body_list()

tList* get_sdp_body_list ( tList lp)

tList* get_sdp_body_list(tList* lp)

SDPボディをリスト構造に分解する.

Definition at line 473 of file sip_tool.c.

474 {
476  tList* ls = get_protocol_header_list(cnt, '=', FALSE, FALSE);
477 
478  free_Buffer(&cnt);
479  return ls;
480 }
#define FALSE
Definition: common.h:223
Buffer restore_protocol_contents(tList *list)
Definition: protocol.c:109
tList * get_protocol_header_list(Buffer buf, char deli, int fstline, int rcntnt)
Definition: protocol.c:34

References FALSE, free_Buffer(), get_protocol_header_list(), and restore_protocol_contents().

Referenced by replace_sdp_invite_addr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_sip_contact_uri()

Buffer get_sip_contact_uri ( tList lp)

Buffer get_sip_contact_uri(tList* lp)

Contactヘッダの内容から SIP URI部分を抜き出す.

Contact: <sip:ABCDEFG@WWW.XXX.YYY.ZZZ:12345>;...... の <sip:ABCDEFG@WWW.XXX.YYY.ZZZ:12345> 部分を得る.
Parameters
lpSIPヘッダの情報のリスト形式
Returns
SIP URI

Definition at line 365 of file sip_tool.c.

366 {
367  Buffer cturi = init_Buffer();
368  Buffer cntct = search_protocol_header(lp, (char*)"Contact", 1);
369 
370  if (cntct.buf!=NULL) {
371  int i = 0;
372  while (cntct.buf[i]!='\0' && cntct.buf[i]!=';' && cntct.buf[i]!=',' && cntct.buf[i]!=CHAR_LF && cntct.buf[i]!=CHAR_CR) i++;
373  cntct.buf[i] = '\0';
374 
375  cturi = cntct;
376  }
377 
378  return cturi;
379 }
Buffer init_Buffer()
初期化したBuffer型変数を返す.
Definition: buffer.c:47
Buffer search_protocol_header(tList *list, char *key, int no)
Definition: protocol.c:372
#define CHAR_CR
改行
Definition: tools.h:78
#define CHAR_LF
ラインフィード
Definition: tools.h:79

References Buffer::buf, CHAR_CR, CHAR_LF, init_Buffer(), and search_protocol_header().

Here is the call graph for this function:

◆ get_sip_domain()

Buffer get_sip_domain ( Buffer  sipuri)

Buffer get_sip_domain(Buffer sipuri)

SIP URI からドメイン情報を抜き出す.

 <sip:ABCDEFG@WWW.XXX.YYY.ZZZ:12345> のドメイン部分 WWW.XXX.YYY.ZZZ:12345 を得る.
Parameters
sipuriSIP URI 例:<sip:ABCDE.nosp@m.FG@W.nosp@m.WW.XX.nosp@m.X.YY.nosp@m.Y.ZZZ:12345>
Returns
SIP URIのドメイン部分.

Definition at line 392 of file sip_tool.c.

393 {
394  Buffer sipdmn = init_Buffer();
395  Buffer siptmp = dup_Buffer(sipuri);
396 
397  if (siptmp.buf!=NULL) {
398  int i = 0;
399  char* pp = NULL;
400  while (siptmp.buf[i]!='\0' && siptmp.buf[i]!='>' && siptmp.buf[i]!=';' &&
401  siptmp.buf[i]!=',' && siptmp.buf[i]!=CHAR_LF && siptmp.buf[i]!=CHAR_CR) {
402  if (siptmp.buf[i]=='@') pp = (char*)&siptmp.buf[i+1];
403  i++;
404  }
405  siptmp.buf[i] = '\0';
406 
407  if (pp!=NULL) sipdmn = make_Buffer_bystr(pp);
408  free_Buffer(&siptmp);
409  }
410 
411  return sipdmn;
412 }
Buffer dup_Buffer(Buffer buf)
Buffer型変数のコピーをつくる.
Definition: buffer.c:211
#define make_Buffer_bystr(str)
set_Buffer()
Definition: buffer.h:57

References Buffer::buf, CHAR_CR, CHAR_LF, dup_Buffer(), free_Buffer(), init_Buffer(), and make_Buffer_bystr.

Here is the call graph for this function:

◆ get_sip_via_address()

Buffer get_sip_via_address ( tList lp,
int  no 
)

Buffer get_sip_via_address(tList* lp, int no)

no番目の Viaヘッダから有効なレスポンスアドレスを獲得する.received=,rport= 対応.

Returns
host:port 形式のアドレス.

Definition at line 83 of file sip_tool.c.

84 {
85  char* pp;
87 
88  if (lp==NULL) return buf;
89  if (no<=0) no = 1;
90 
91  buf = search_protocol_header_item(lp, (char*)"Via", no, ' ', 2);
92  if (buf.buf!=NULL) {
93  // received, rport
94  Buffer wrk = dup_Buffer(buf);
95  pp = strstrcase((char*)wrk.buf, "received=");
96  if (pp!=NULL) {
97  char* pa = pp = pp + 9;
98  while (*pp!=';' && *pp!='\0') pp++;
99  if (*pp==';') *pp = '\0';
100 
101  pp = strstrcase((char*)buf.buf, "rport=");
102  if (pp!=NULL) {
103  char* pt = pp = pp + 6;
104  while (*pp!=';' && *pp!='\0') pp++;
105  if (*pp==';') *pp = '\0';
106 
107  Buffer hostport = comp_hostport(pa, (unsigned short)atoi(pt));
108  free_Buffer(&buf);
109  free_Buffer(&wrk);
110  return hostport;
111  }
112  }
113  free_Buffer(&wrk);
114 
115  //
116  pp = (char*)buf.buf;
117  while (*pp!=';' && *pp!='\0') pp++;
118  if (*pp==';') *pp = '\0';
119  }
120 
121  return buf;
122 }
Buffer search_protocol_header_item(tList *list, char *key, int no, char deli, int nm)
Definition: protocol.c:408
char * strstrcase(const char *buf, const char *nd)
文字列 bufの中に文字列 ndがあるかどうかをチェックする.大文字小文字は区別しない.
Definition: tools.c:736
Buffer comp_hostport(char *host, unsigned short port)
ホスト名とポート番号から,"ホスト名:ポート番号" の文字列を生成する.
Definition: xtools.c:687

References buf, Buffer::buf, comp_hostport(), dup_Buffer(), free_Buffer(), init_Buffer(), search_protocol_header_item(), and strstrcase().

Here is the call graph for this function:

◆ get_valid_rtp_pair_sockets()

unsigned short get_valid_rtp_pair_sockets ( int  min,
int  max,
int *  rtp,
int *  rtcp 
)

unsigned short get_valid_rtp_pair_sockets(int min, int max, int* rtp, int* rtcp)

min〜max でランダムなポート番号を持った RTPとRTCPのソケットを生成する.

Parameters
min使用可能なポート番号の最小値
max使用可能なポート番号の最大値
rtpRTP のソケット番号が入る.
rtcpRTCPのソケット番号が入る.
Returns
RTPのポート番号(偶数).RTCPのポート番号は + 1 する.

Definition at line 573 of file sip_tool.c.

574 {
575  int i = 1;
576  int range, sock1, sock2, port;
577 
578  max = max - 1;
579  min = min + 1;
580 
581  range = max - min + 1;
582  port = ((rand()%range + min)/2)*2;
583 
584  sock1 = udp_server_socket(port, NULL); // RTP
585  sock2 = udp_server_socket(port+1, NULL); // RTCP
586  if (sock1<=0 || sock2<=0) {
587  if (sock1>0) socket_close(sock1);
588  if (sock2>0) socket_close(sock2);
589  sock1 = sock2 = 0;
590  }
591 
592  while(sock1==0 && i<range) {
593  port = port + 2;
594  if (port>max) port = ((port%max + min - 1)/2)*2;
595 
596  sock1 = udp_server_socket(port, NULL); // RTP
597  sock2 = udp_server_socket(port+1, NULL); // RTCP
598  if (sock1<=0 || sock2<=0) {
599  if (sock1>0) socket_close(sock1);
600  if (sock2>0) socket_close(sock2);
601  sock1 = sock2 = 0;
602  }
603  i = i + 2;
604  }
605 
606  if (sock1==0) {
607  port = 0;
608  *rtp = *rtcp =0;
609  }
610  else {
611  *rtp = sock1;
612  *rtcp = sock2;
613  }
614 
615  return (unsigned short)port;
616 }
int socket_close(int sofd)
call shutdown(), close()
Definition: network.c:1022
#define udp_server_socket(p, a)
Definition: network.h:82

References socket_close(), and udp_server_socket.

Here is the call graph for this function:

◆ insert_sip_record_route()

void insert_sip_record_route ( tList lp,
char *  host,
unsigned short  port,
int  add_mode 
)

void insert_sip_record_route(tList* lp, char* host, unsigned short port, int add_mode)

Record-Route ヘッダを追加する.

Definition at line 205 of file sip_tool.c.

206 {
207  char ftag[LBUF];
208  char sipuri[LBUF];
209  tList* pm;
210 
211  if (lp==NULL || host==NULL) return;
212 
213  ftag[0] = '\0';
214 
215  pm = strncasecmp_tList(lp, (char*)"Record-Route", 0, 1);
216  if (pm==NULL) {
217  if (add_mode) pm = strncmp_tList(lp, (char*)HDLIST_FIRST_LINE_KEY, 0, 1);
218  if (pm==NULL) return;
219  }
220  else if (pm->prev!=NULL) {
221  char* pp = strstrcase((char*)pm->ldat.val.buf, "ftag=");
222  if (pp!=NULL) {
223  pp = pp + 5;
224  int i = 0;
225  while (pp[i]!='\0' && pp[i]!=';' && pp[i]!='>' && i<LBUF) {
226  ftag[i] = pp[i];
227  i++;
228  }
229  ftag[i] = '\0';
230  }
231  pm = pm->prev;
232  }
233  else return;
234 
235  if (port!=0) {
236  if (ftag[0]!='\0') snprintf(sipuri, LBUF, "<sip:%s:%d;ftag=%s;lr=on>", host, port, ftag);
237  else snprintf(sipuri, LBUF, "<sip:%s:%d;lr=on>", host, port);
238  }
239  else {
240  if (ftag[0]!='\0') snprintf(sipuri, LBUF, "<sip:%s;ftag=%s;lr=on>", host, ftag);
241  else snprintf(sipuri, LBUF, "<sip:%s;lr=on>", host);
242  }
243  sipuri[LBUF-1] = '\0'; // to make sure
244 
245  add_tList_node_str(pm, "Record-Route", sipuri);
246 
247  return;
248 }
#define HDLIST_FIRST_LINE_KEY
Definition: protocol.h:31
tList * strncmp_tList(tList *pl, const char *key, int len, int no)
char* 型変数によるノードのサーチ.
Definition: tlist.c:1056
#define add_tList_node_str(p, k, v)
add_tList_node_bystr()
Definition: tlist.h:142

References add_tList_node_str, HDLIST_FIRST_LINE_KEY, LBUF, strncasecmp_tList(), strncmp_tList(), and strstrcase().

Here is the call graph for this function:

◆ insert_sip_via()

void insert_sip_via ( tList lp,
char *  host,
unsigned short  port,
char *  branch,
int  add_mode 
)

void insert_sip_via(tList* lp, char* host, unsigned short port, char* branch, int add_mode)

Viaヘッダを追加する.received=,rport= 未対応.

Definition at line 130 of file sip_tool.c.

131 {
132  char sipver[] = "SIP/2.0/UDP ";
133  char hostport[LBUF];
134  Buffer buf;
135  tList* pm;
136 
137  if (lp==NULL || host==NULL) return;
138 
139  pm = strncasecmp_tList(lp, (char*)"Via", 0, 1);
140  if (pm==NULL) {
141  if (add_mode) pm = strncmp_tList(lp, (char*)HDLIST_FIRST_LINE_KEY, 0, 1);
142  if (pm==NULL) return;
143  }
144  else if (pm->prev!=NULL) pm = pm->prev;
145  else return;
146 
147  buf = make_Buffer(LBUF);
148  if (port!=0) snprintf(hostport, LBUF, "%s:%d", host, port);
149  else snprintf(hostport, LBUF, "%s", host);
150  hostport[LBUF-1] = '\0'; // to make sure
151 
152  copy_s2Buffer(sipver, &buf);
153  cat_s2Buffer (hostport, &buf);
154  if (branch!=NULL) {
155  cat_s2Buffer(";branch=z9hG4bK", &buf);
156  cat_s2Buffer(branch, &buf);
157  }
158 
159  add_tList_node_str(pm, "Via", (char*)buf.buf);
160  free_Buffer(&buf);
161 
162  return;
163 }
Buffer make_Buffer(int sz)
Buffer型変数のバッファ部をつくり出す.
Definition: buffer.c:71
#define copy_s2Buffer(src, dst)
copy_b2Buffer()
Definition: buffer.h:108
#define cat_s2Buffer(src, dst)
cat_b2Buffer()
Definition: buffer.h:122

References add_tList_node_str, buf, cat_s2Buffer, copy_s2Buffer, free_Buffer(), HDLIST_FIRST_LINE_KEY, LBUF, make_Buffer(), strncasecmp_tList(), and strncmp_tList().

Here is the call graph for this function:

◆ replace_sdp_invite_addr()

int replace_sdp_invite_addr ( tList lp,
tList ls,
char *  host,
unsigned short  port,
int  del_candi 
)

int replace_sdp_invite_addr(tList*lp, tList* ls, char* host, unsigned short port, int del_candi)

INVITE用 SDPボディ内のアドレス情報を書き換える.

Parameters
lpSIPデータのリスト構造.
lsSDPデータのリスト構造.NULLの場合は lpから得る.
host書き換え先のIPアドレス
port書き換え先のポート番号
del_candiTRUE: a=candidate行を削除する.(余計な情報を相手に送らないため)

Definition at line 515 of file sip_tool.c.

516 {
517  tList* lsdp;
518  Buffer num, sdp;
519 
520  if (lp==NULL || host==NULL || port==0) return FALSE;
521 
522  num = make_Buffer(LEN_INT);
523  copy_i2Buffer((int)port, &num);
524 
525  if (ls==NULL) lsdp = get_sdp_body_list(lp);
526  else lsdp = ls;
527 
528  if (del_candi) {
529  tList* pm = lsdp;
530  while (pm!=NULL) {
531  if (pm->ldat.key.buf!=NULL && !strcasecmp("a", (char*)pm->ldat.key.buf)) {
532  if (pm->ldat.val.buf!=NULL && !strncasecmp("candidate ", (char*)pm->ldat.val.buf, 10)) {
533  pm = del_tList_node(&pm);
534  }
535  else pm = pm->next;
536  }
537  else pm = pm->next;
538  }
539  }
540 
541  set_protocol_header_item(lsdp, (char*)"o", 1, ' ', 6, host);
542  set_protocol_header_item(lsdp, (char*)"c", 1, ' ', 3, host);
543  set_protocol_header_item(lsdp, (char*)"m", 1, ' ', 2, (char*)num.buf);
544 
545  sdp = restore_sdp_body(lsdp);
546  set_sip_contents(lp, sdp);
547 
548  if (ls==NULL) del_tList(&lsdp);
549  free_Buffer(&sdp);
550  free_Buffer(&num);
551 
552  return TRUE;
553 }
int copy_i2Buffer(int src, Buffer *dst)
整数 srcを文字列に変換して,dstへ copyする.
Definition: buffer.c:664
#define TRUE
Definition: common.h:226
#define LEN_INT
log 2^64 + '\0' + 1(予備)
Definition: common.h:171
#define set_protocol_header_item(list, key, no, deli, nm, value)
Definition: protocol.h:123
void set_sip_contents(tList *lp, Buffer sdp)
Definition: sip_tool.c:52

References Buffer::buf, copy_i2Buffer(), del_tList(), del_tList_node(), FALSE, free_Buffer(), get_sdp_body_list(), LEN_INT, make_Buffer(), restore_sdp_body(), set_protocol_header_item, set_sip_contents(), and TRUE.

Here is the call graph for this function:

◆ replace_sip_contact()

void replace_sip_contact ( tList lp,
char *  host,
unsigned short  port 
)

int replace_sip_contact(tList* lp, char* host, unsigned short port)

Contactヘッダのアドレス部を host:portまたは hostに書き換える.

Definition at line 308 of file sip_tool.c.

309 {
310  char contct[LBUF];
311  char hostport[LBUF];
312 
313  if (lp==NULL || host==NULL) return;
314 
315  tList* lc = strncasecmp_tList(lp, (char*)"Contact", 0, 1);
316  if (lc==NULL || lc->ldat.val.buf==NULL) return;
317 
318  char* pa = (char*)lc->ldat.val.buf;
319  char* ps = strstrcase(pa, "sip:");
320 
321  while (ps!=NULL) {
322  char* pp = strstr(ps, "@");
323  if (pp==NULL) pp = ps + 3;
324 
325  pp++;
326  //int i, cnt=0;
327  int i;
328  for (i=0; i<LBUF-1; i++) {
329  //if (*pp==':') cnt++;
330  if (*pp=='\0' || *pp=='>' || *pp==' ' || *pp==';') break;
331  contct[i] = *pp;
332  pp++;
333  }
334  contct[i] = '\0';
335 
336  if (i<LBUF-1) {
337  //if (cnt==1 && port!=0) snprintf(hostport, LBUF, "%s:%d", host, port);
338  //else snprintf(hostport, LBUF, "%s", host);
339  if (port!=0) snprintf(hostport, LBUF, "%s:%d", host, port);
340  else snprintf(hostport, LBUF, "%s", host);
341  hostport[LBUF-1] = '\0';
342 
343  Buffer buf = replace_sBuffer(lc->ldat.val, contct, hostport);
344  free_Buffer(&lc->ldat.val);
345  lc->ldat.val = buf;
346  }
347 
348  ps = strstrcase(pp, "sip:");
349  }
350 
351  return;
352 }
#define replace_sBuffer(buf, f, t)
replace_sBuffer()
Definition: buffer.h:175

References buf, free_Buffer(), LBUF, replace_sBuffer, strncasecmp_tList(), and strstrcase().

Here is the call graph for this function:

◆ replace_sip_contact_dstipport()

int replace_sip_contact_dstipport ( tList lp,
char *  ipaddr,
unsigned short  port 
)

int replace_sip_contact_dstipport(tList* lp, char* ipaddr, unsigned short port)

Definition at line 658 of file sip_tool.c.

659 {
660  int i;
661  char dstip[] = "dstip=";
662  char dstport[] = "dstport=";
663  char* ip = NULL;
664  char* pt = NULL;
665 
666  Buffer frip, frpt;
667  Buffer toip, topt;
668 
669  if (lp==NULL || ipaddr==NULL || port==0) return FALSE;
670 
671  tList* lc = strncasecmp_tList(lp, (char*)"Contact", 0, 1);
672  if (lc==NULL || lc->ldat.val.buf==NULL) return FALSE;
673 
674  frip = search_protocol_header_partvalue(lp, (char*)"Contact", dstip, 1);
675  frpt = search_protocol_header_partvalue(lp, (char*)"Contact", dstport, 1);
676  if (frip.buf==NULL || frpt.buf==NULL) {
677  free_Buffer(&frip);
678  free_Buffer(&frpt);
679  return FALSE;
680  }
681 
682  i = 0;
683  ip = strstr((char*)frip.buf, dstip);
684  while (ip[i]!='\0' && ip[i]!=';' && ip[i]!='"') i++;
685  ip[i] = '\0';
686 
687  i = 0;
688  pt = strstr((char*)frpt.buf, dstport);
689  while (pt[i]!='\0' && pt[i]!=';' && pt[i]!='"') i++;
690  pt[i] = '\0';
691 
692  toip = make_Buffer(LBUF);
693  topt = make_Buffer(LBUF);
694 
695  copy_s2Buffer(dstip, &toip);
696  cat_s2Buffer (ipaddr, &toip);
697  copy_s2Buffer(dstport, &topt);
698  cat_i2Buffer (port, &topt);
699 
700  Buffer buftemp = replace_sBuffer(lc->ldat.val, ip, (char*)toip.buf);
701  Buffer nwcntct = replace_sBuffer(buftemp, pt, (char*)topt.buf);
702 
703  free_Buffer(&lc->ldat.val);
704  lc->ldat.val = nwcntct;
705 
706  free_Buffer(&frip);
707  free_Buffer(&frpt);
708  free_Buffer(&toip);
709  free_Buffer(&topt);
710  free_Buffer(&buftemp);
711 
712  return TRUE;
713 }
int cat_i2Buffer(int src, Buffer *dst)
整数 srcを文字列に変換して,dstへ catする.
Definition: buffer.c:678
Buffer search_protocol_header_partvalue(tList *list, char *key, char *data, int no)
Definition: protocol.c:500

References Buffer::buf, cat_i2Buffer(), cat_s2Buffer, copy_s2Buffer, FALSE, free_Buffer(), LBUF, make_Buffer(), replace_sBuffer, search_protocol_header_partvalue(), strncasecmp_tList(), and TRUE.

Here is the call graph for this function:

◆ replace_sip_via()

Buffer replace_sip_via ( tList lp,
char *  host,
unsigned short  port,
int  no 
)

Buffer replace_sip_via(tList* lp, char* host, unsigned short port, int no)

Viaヘッダーの IP:Port情報を書き換える

Returns
書き換えられた "IP:Port" or "FQDN:Port"

Definition at line 630 of file sip_tool.c.

631 {
632  Buffer buf = init_Buffer();
633 
634  if (lp==NULL || host==NULL || port==0) return buf;
635  if (no<=0) no = 1;
636 
637  buf = search_protocol_header_item(lp, (char*)"Via", no, ' ', 2);
638  if (buf.buf!=NULL) {
639  int i = 0;
640  char hostport[LBUF];
641 
642  while (buf.buf[i]!=';' && buf.buf[i]!='\0') i++;
643  if (buf.buf[i]!='\0') buf.buf[i] = '\0';
644 
645  snprintf(hostport, LBUF, "%s:%d", host, port);
646  hostport[LBUF-1] = '\0'; // to make sure
647 
648  replace_protocol_header(lp, (char*)"Via", 1, (char*)buf.buf, hostport);
649  }
650 
651  return buf;
652 }
#define replace_protocol_header(list, key, no, srcval, value)
Definition: protocol.h:90

References buf, init_Buffer(), LBUF, replace_protocol_header, and search_protocol_header_item().

Here is the call graph for this function:

◆ restore_sdp_body()

Buffer restore_sdp_body ( tList ls)

Buffer restore_sdp_body(tList* ls)

リストからSDPボディを復元する.

Definition at line 488 of file sip_tool.c.

489 {
490  Buffer buf = init_Buffer();
491 
492  if (ls==NULL) return buf;
493 
494  buf = restore_protocol_header(ls, (char*)"=", OFF, NULL);
495  if (buf.buf!=NULL) {
496  buf.vldsz = buf.vldsz - 2;
497  buf.buf[buf.vldsz] = '\0';
498  }
499 
500  return buf;
501 }
#define OFF
Definition: common.h:231
Buffer restore_protocol_header(tList *list, char *deli, int mode, int *hdsz)
Definition: protocol.c:55

References buf, init_Buffer(), OFF, and restore_protocol_header().

Referenced by replace_sdp_invite_addr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_max_forwards()

void set_max_forwards ( tList lp,
int  nm 
)

void set_max_forwards(tList* lp, int nm)

Max-Forwardsヘッダがあれば,nmを設定する.

Definition at line 444 of file sip_tool.c.

445 {
446  char mxfd[LEN_INT];
447 
448  if (lp==NULL) return;
449 
450  tList* lt = strncasecmp_tList(lp, (char*)"Max-Forwards", 0, 1);
451  if (lt!=NULL) {
452  snprintf(mxfd, LEN_INT, "%d", nm);
453  mxfd[LEN_INT-1] = '\0';
454  free_Buffer(&lt->ldat.val);
455  lt->ldat.val = make_Buffer_bystr(mxfd);
456  }
457 
458  return;
459 }

References free_Buffer(), LEN_INT, make_Buffer_bystr, and strncasecmp_tList().

Here is the call graph for this function:

◆ set_sip_contents()

void set_sip_contents ( tList lp,
Buffer  sdp 
)

void set_sip_contents(tList* lp, Buffer sdp)

SDPボディをSIPのヘッダリストに再登録する.サイズの設定も行う.

Definition at line 52 of file sip_tool.c.

53 {
54  char num[LEN_INT];
55 
56  set_protocol_contents(lp, sdp);
57 
58  // reset size of contents
59  snprintf(num, LEN_INT, "%d", sdp.vldsz);
60  num[LEN_INT-1] = '\0';
61  set_protocol_header(lp, (char*)"Content-Length", num, 1, ON);
62 
63  return;
64 }
#define ON
Definition: common.h:230
void set_protocol_contents(tList *list, Buffer contents)
Definition: protocol.c:132
int set_protocol_header(tList *list, char *key, char *value, int no, int add_mode)
Definition: protocol.c:574
int vldsz
データの長さ.バイナリデータの場合も使用可能.文字列の場合は 0x00 を含まない.
Definition: buffer.h:37

References LEN_INT, ON, set_protocol_contents(), set_protocol_header(), and Buffer::vldsz.

Referenced by replace_sdp_invite_addr().

Here is the call graph for this function:
Here is the caller graph for this function: