JunkBox_Lib  1.10.2
protocol.h File Reference

プロトコル解析ライブラリ ヘッダ More...

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

Go to the source code of this file.

Macros

#define HDLIST_FIRST_LINE_KEY   "FIRST_LINE"
 
#define HDLIST_CONTENTS_KEY   "CONTENTS_DATA"
 
#define HDLIST_CONTINUE   "HEADER_CONTINUE"
 
#define HDLIST_END_KEY   "HEADER_END"
 
#define create_protocol_header(p, k, v)   add_tList_node_bystr((p), 0, 0, (char*)(k), (char*)(v), NULL, 0)
 
#define add_protocol_header(p, k, v)   add_tList_node_bystr((p), 0, 0, (char*)(k), (char*)(v), NULL, 0)
 
#define create_protocol_header_Buffer(p, k, v)   add_tList_node_byBuffer((p), 0, 0, (k), (v), NULL, 0)
 
#define add_protocol_header_Buffer(p, k, v)   add_tList_node_byBuffer((p), 0, 0, (k), (v), NULL, 0)
 
#define delete_protocol_header(p, k, n)   del_tList_key((p), (k), (n))
 
#define get_protocol_header(l, k, n)   search_protocol_header((l), (k), (n))
 
#define get_protocol_header_item(l, k, n, d, m)   search_protocol_header_item((l), (k), (n), (d), (m))
 
#define get_protocol_header_value(l, k, d, n)   search_protocol_header_value((l), (k), (d), (n))
 
#define get_protocol_header_partvalue(l, k, d, n)   search_protocol_header_partvalue((l), (k), (d), (n))
 
#define set_protocol_record_item(l, d, m, v)   set_item_tList_node((l), (d), (m), (v))
 
#define replace_protocol_record_item(l, d, m, s, v)   replace_item_tList_node((l), (d), (m), (s), (v))
 
#define replace_protocol_header(list, key, no, srcval, value)   replace_value_tList((list), (key), (no), (srcval), (value))
 
#define replace_protocol_header_item(list, key, no, deli, nm, srcval, value)   replace_item_tList((list), (key), (no), (deli), (nm), (srcval), (value))
 
#define set_protocol_header_item(list, key, no, deli, nm, value)   set_item_tList((list), (key), (no), (deli), (nm), (value))
 

Functions

tListget_protocol_header_list (Buffer buf, char deli, int fstline, int rcntnt)
 
Buffer restore_protocol_header (tList *pp, char *deli, int mode, int *hdsz)
 
Buffer restore_protocol_contents (tList *pp)
 
void set_protocol_contents (tList *pp, Buffer cnt)
 
tListget_protocol_header_list_seq (tList *list, Buffer buf, char deli, int fstline, int rcntnt)
 
tListget_protocol_header_list_file (char *fname, char deli, int fstline, int rcntnt)
 
Buffer search_protocol_header (tList *list, char *key, int no)
 
Buffer search_protocol_header_item (tList *list, char *key, int no, char deli, int nm)
 
Buffer search_protocol_header_value (tList *list, char *key, char *data, int no)
 
Buffer search_protocol_header_partvalue (tList *list, char *key, char *data, int no)
 
int set_protocol_header (tList *list, char *key, char *value, int no, int mode)
 
int search_crlfcrlf (char *mesg)
 
int is_header_continue (tList *lp)
 
void print_protocol_header (tList *lp, int content)
 
tListfind_protocol_end (tList *lp)
 

Detailed Description

Author
Fumi.Iseki (C)
Date
2009 2/5

Example)

.........
.........
.........
set_protocol_contents(lp, cnt);
Buffer snd = restore_protocol_header(lp, ": ", ON, NULL);
del_tList(&lp);
void free_Buffer(Buffer *buf)
Buffer型変数のバッファ部を解放する
Definition: buffer.c:128
#define TRUE
Definition: common.h:226
#define ON
Definition: common.h:230
unsigned char ** buf
Definition: jpeg_tool.h:96
Buffer restore_protocol_header(tList *list, char *deli, int mode, int *hdsz)
Definition: protocol.c:55
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
Definition: buffer.h:35
tList * del_tList(tList **pp)
指定したリストノード以降のリストを削除.
Definition: tlist.c:735

Definition in file protocol.h.

Macro Definition Documentation

◆ add_protocol_header

#define add_protocol_header (   p,
  k,
 
)    add_tList_node_bystr((p), 0, 0, (char*)(k), (char*)(v), NULL, 0)

Definition at line 51 of file protocol.h.

◆ add_protocol_header_Buffer

#define add_protocol_header_Buffer (   p,
  k,
 
)    add_tList_node_byBuffer((p), 0, 0, (k), (v), NULL, 0)

Definition at line 53 of file protocol.h.

◆ create_protocol_header

#define create_protocol_header (   p,
  k,
 
)    add_tList_node_bystr((p), 0, 0, (char*)(k), (char*)(v), NULL, 0)

Definition at line 50 of file protocol.h.

◆ create_protocol_header_Buffer

#define create_protocol_header_Buffer (   p,
  k,
 
)    add_tList_node_byBuffer((p), 0, 0, (k), (v), NULL, 0)

Definition at line 52 of file protocol.h.

◆ delete_protocol_header

#define delete_protocol_header (   p,
  k,
 
)    del_tList_key((p), (k), (n))

Definition at line 54 of file protocol.h.

◆ get_protocol_header

#define get_protocol_header (   l,
  k,
 
)    search_protocol_header((l), (k), (n))

Definition at line 62 of file protocol.h.

◆ get_protocol_header_item

#define get_protocol_header_item (   l,
  k,
  n,
  d,
 
)    search_protocol_header_item((l), (k), (n), (d), (m))

Definition at line 63 of file protocol.h.

◆ get_protocol_header_partvalue

#define get_protocol_header_partvalue (   l,
  k,
  d,
 
)    search_protocol_header_partvalue((l), (k), (d), (n))

Definition at line 65 of file protocol.h.

◆ get_protocol_header_value

#define get_protocol_header_value (   l,
  k,
  d,
 
)    search_protocol_header_value((l), (k), (d), (n))

Definition at line 64 of file protocol.h.

◆ HDLIST_CONTENTS_KEY

#define HDLIST_CONTENTS_KEY   "CONTENTS_DATA"

Definition at line 32 of file protocol.h.

◆ HDLIST_CONTINUE

#define HDLIST_CONTINUE   "HEADER_CONTINUE"

Definition at line 33 of file protocol.h.

◆ HDLIST_END_KEY

#define HDLIST_END_KEY   "HEADER_END"

Definition at line 34 of file protocol.h.

◆ HDLIST_FIRST_LINE_KEY

#define HDLIST_FIRST_LINE_KEY   "FIRST_LINE"

Definition at line 31 of file protocol.h.

◆ replace_protocol_header

#define replace_protocol_header (   list,
  key,
  no,
  srcval,
  value 
)    replace_value_tList((list), (key), (no), (srcval), (value))

int replace_protocol_header(tList* list, char* key, int no, char* srcval, char* value)

リスト(lt)中の no番目の keyノードの値の srcvalの部分を value に置き換える. no が 0以下の場合は,全ての keyノードの値に対して置き換えが行われる.
replace_valute_tList() と同じ関数 (in Lib/tlist.c)

Parameters
list処理対象のリスト
key置き換えを行うノードのキー部
no何個目の項目を置き換えるか.1から数える.0以下の場合はkeyが一致する全ての項目を置き換える
srcval置き換え対象の文字列.
value置き換えを行う文字列.
Return values
0以上変更されたノードの数.指定されたノードが存在しないは(追加された場合も)0
負数エラー.

Definition at line 90 of file protocol.h.

◆ replace_protocol_header_item

#define replace_protocol_header_item (   list,
  key,
  no,
  deli,
  nm,
  srcval,
  value 
)    replace_item_tList((list), (key), (no), (deli), (nm), (srcval), (value))

int replace_protocol_header_item(tList* list, char* key, int no, char deli, int nm, char* srcval, char* value)

key をキーにした no番目のノードの値の中で,deliを区切りにした nm番目の項目(文字列)の srcval部分を valueで置き換える.

Parameters
list検索対象のヘッダ方向を格納したリスト
keyヘッダ種別.
no同じヘッダ種別が複数ある場合,何番目のノードかを指定する.1から数える. noが 0以下の場合は keyが一致する全てのノードに対して操作を行う.
deliノード値(文字列)の区切り文字.
nmdeli を区切り文字として何番目の項目か? 1から数える.
srcval置き換え対象の文字列.NULLなら指定した項目の文字列全体
value置き換える文字列.
Returns
置き換えを行ったノード数.

Definition at line 107 of file protocol.h.

◆ replace_protocol_record_item

#define replace_protocol_record_item (   l,
  d,
  m,
  s,
 
)    replace_item_tList_node((l), (d), (m), (s), (v))

Definition at line 72 of file protocol.h.

◆ set_protocol_header_item

#define set_protocol_header_item (   list,
  key,
  no,
  deli,
  nm,
  value 
)    set_item_tList((list), (key), (no), (deli), (nm), (value))

int set_protocol_header_item(tList* list, char* key, int no, char deli, int nm, char* value)

key をキーにした no番目のノードの値の中で,deliを区切りにした nm番目の項目(文字列)にvalue を設定する.

Parameters
list検索対象のヘッダ方向を格納したリスト
keyヘッダ種別.
no同じヘッダ種別が複数ある場合,何番目のノードかを指定する.1から数える. noが 0以下の場合は keyが一致する全てのノードに対して操作を行う.
deliノード値(文字列)の区切り文字.
nmdeli を区切り文字として何番目の項目か? 1から数える.
value設定する文字列.
Returns
設定を行ったノード数.

Definition at line 123 of file protocol.h.

◆ set_protocol_record_item

#define set_protocol_record_item (   l,
  d,
  m,
 
)    set_item_tList_node((l), (d), (m), (v))

Definition at line 71 of file protocol.h.

Function Documentation

◆ find_protocol_end()

tList* find_protocol_end ( tList lp)

HDLIST_END_KEY のひとつ前のリストへのリンクを返す. HDLIST_END_KEY が無ければ HDLIST_CONTENTS_KEY のひとつ前,HDLIST_CONTENTS_KEY もなければ最後のリストへのリンクを返す.

Definition at line 665 of file protocol.c.

666 {
667  tList* end = search_key_tList(lp, HDLIST_END_KEY, 1);
668  if (end==NULL) end = search_key_tList(lp, HDLIST_CONTENTS_KEY, 1);
669  //
670  if (end!=NULL) end = end->prev;
671  else end = find_tList_end(lp);
672 
673  return end;
674 }
#define HDLIST_CONTENTS_KEY
Definition: protocol.h:32
#define HDLIST_END_KEY
Definition: protocol.h:34
tList * find_tList_end(tList *pl)
リストの最後のノードを探す.
Definition: tlist.c:1023
tList * search_key_tList(tList *pl, const char *key, int no)
リストの中から no番目の keyノード(ldat.key)を探し出し,tListへのポインタを返す.大文字小文字を無視.
Definition: tlist.c:1571

References find_tList_end(), HDLIST_CONTENTS_KEY, HDLIST_END_KEY, and search_key_tList().

Here is the call graph for this function:

◆ get_protocol_header_list()

tList* get_protocol_header_list ( Buffer  buf,
char  deli,
int  fstline,
int  rcntnt 
)

tList* get_protocol_header_list(Buffer buf, char deli, int fstline, int rcntnt)

buf内の プロトコルヘッダ(key'deli' data の形式)を分解してリストに格納する.'deli'は境界文字. fstlineが TRUEの場合,ヘッダの一行目は HDLIST_FIRST_LINE_KEY のキーをつけてリストに格納する.

また,この関数はバッファリングなどは行わないので,ヘッダにコンテンツの最初の部分が紛れ込む可能性がある. rcntntが TRUEの場合は,HDLIST_CONTENTS_KEY をキーにしてコンテンツをリストに格納する.FALSEの場合は無視. コンテンツのサイズが大きく,順次読み込まれる場合,HDLIST_CONTENTS_KEYノードは複数生成される.

ヘッダの値が複数行になる場合,ヘッダ種別 HDLIST_CONTINUE として,次のノードに格納される.

Parameters
bufヘッダを格納した変数
deliヘッダの見出し(Key)との境界文字.HTTPや SMTPでは ':'
fstline一行目を特別扱いにするか? 一行目が key'deli' data の形式でないプロトコル用, ex) HTTP, SIP
rcntntコンテンツも読むか?
Returns
ヘッダ情報を格納したリストへのポインタ.

Definition at line 34 of file protocol.c.

35 {
36  tList* lp;
37 
38  if (buf.buf==NULL) return NULL;
39 
40  lp = get_protocol_header_list_seq(NULL, buf, deli, fstline, rcntnt);
41  if (lp!=NULL) lp = find_tList_top(lp);
42 
43  return lp;
44 }
tList * get_protocol_header_list_seq(tList *lp, Buffer buf, char deli, int fstline, int rcntnt)
Definition: protocol.c:181
tList * find_tList_top(tList *pl)
リストの最初のノードを探す.
Definition: tlist.c:1002

References buf, find_tList_top(), and get_protocol_header_list_seq().

Referenced by get_protocol_header_list_file(), and get_sdp_body_list().

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

◆ get_protocol_header_list_file()

tList* get_protocol_header_list_file ( char *  fname,
char  deli,
int  fstline,
int  rcntnt 
)

tList* get_protocol_header_list_file(char* fname, char deli, int fstline, int rcntnt)

ファイル fname からヘッダ情報を読み込んで分解し,リストに格納して返す.

Parameters
fname読み込むファイル名
deliヘッダの見出し(Key)との境界文字.HTTPや SMTPでは ':'
fstline一行目を特別扱いにするか? 一行目が key'境界文字' data の形式でないプロトコル用, ex) HTTP, SIP
rcntntコンテンツも読むか?
Returns
ヘッダ情報を格納したリストへのポインタ.

Definition at line 341 of file protocol.c.

342 {
343  Buffer buf;
344  tList* lp;
345 
346  if (fname==NULL) return NULL;
347 
348  buf = read_Buffer_file(fname);
349  lp = get_protocol_header_list(buf, deli, fstline, rcntnt);
350 
351  return lp;
352 }
Buffer read_Buffer_file(const char *fn)
ファイル fn の内容を Buffer型変数に読み込む.
Definition: buffer.c:1467

References buf, get_protocol_header_list(), and read_Buffer_file().

Here is the call graph for this function:

◆ get_protocol_header_list_seq()

tList* get_protocol_header_list_seq ( tList lp,
Buffer  buf,
char  deli,
int  fstline,
int  rcntnt 
)

tList* get_protocol_header_list_seq(tList* lp, Buffer buf, char deli, int fstline, int rcntnt)

buf内の プロトコルヘッダ(key'deli' data の形式)を分解してリストに格納する.'deli'は境界文字. シーケンシャルに随時呼び出すことが可能.
lp==NULL で状態(静的変数)がリセットされので,最初は lpを NULLにすること.

fstlineが TRUEの場合,ヘッダの一行目は HDLIST_FIRST_LINE_KEY のキーをつけてリストに格納する.

また,この関数はバッファリングなどは行わないので,ヘッダにコンテンツの最初の部分が紛れ込む可能性がある. rcntntが TRUEの場合は,HDLIST_CONTENTS_KEY をキーにしてコンテンツをリストに格納する.FALSEの場合は無視. コンテンツのサイズが大きく,順次読み込まれる場合,HDLIST_CONTENTS_KEYノードは複数生成される.

ヘッダの値が複数行になる場合,ヘッダ種別 HDLIST_CONTINUE として,次のノードに格納される.

lp!=NULL または fstlineがFALSE の場合は一行目の処理は行わない.

Parameters
lpヘッダ情報を格納するリストへのポインタ. NULLの場合はリストが新しく作成される.NULLでない場合はそのリストにヘッダ情報が追加される.
bufヘッダを格納した変数
deliヘッダの見出し(Key)との境界文字.HTTPや SMTPでは ':'
fstline一行目を特別扱いにするか? 一行目が key'deli' data の形式でないプロトコル用, ex) HTTP, SIP
rcntntコンテンツも読むか?
Returns
一番最後に作成したリストノードへのポインタ. リストのトップを得るには find_tList_top(tList* pp) を用いる.
変数
in_contents コンテンツ内を処理中であることを表す.
crlfCount 処理中の CR,LFの数

Definition at line 181 of file protocol.c.

182 {
183  static int crlfCount = 0;
184  static int inContents = FALSE;
185  int i=0, n=0, size;
186  Buffer key, data;
187 
188  if (buf.buf==NULL) return NULL;
189 
190  size = buf.vldsz;
191  data = make_Buffer(size+1);
192  key = make_Buffer(LBUF);
193 
194  if (lp==NULL) {
195  crlfCount = 0;
196  inContents = FALSE;
197  }
198 
199  // FIRST LINE
200  if (fstline && lp==NULL) {
201  while(buf.buf[i]!=0x0a && buf.buf[i]!='\0' && i<size && n<size) {
202  data.buf[n++] = buf.buf[i++];
203  }
204  if (data.buf[n-1]==0x0d) {
205  i--;
206  n--;
207  }
208 
209  data.buf[n] = '\0';
210  data.vldsz = n;
212  lp = add_tList_node_Buffer(NULL, key, data);
213 
214  if (buf.buf[i]=='\0' || i==size) {
215  free_Buffer(&key);
216  free_Buffer(&data);
217  return lp;
218  }
219  clear_Buffer(&key);
220  clear_Buffer(&data);
221  }
222 
223  // HEADER
224  while(buf.buf[i]!='\0' && i<size && !inContents) {
225  // Check Previous Line's CR & LF
226  if (i+1<size && buf.buf[i]==0x0d && buf.buf[i+1]==0x0a) {
227  i = i + 2;
228  if (crlfCount==1) { // for previous called function
230  lp = add_tList_node_Buffer(lp, key, data);
231  crlfCount = 0;
232  inContents = TRUE;
233  break;
234  }
235  else crlfCount = 1;
236  }
237  else if (buf.buf[i]==0x0a) {
238  i = i + 1;
239  if (crlfCount==1) { // for previous called function
241  lp = add_tList_node_Buffer(lp, key, data);
242  crlfCount = 0;
243  inContents = TRUE;
244  break;
245  }
246  else crlfCount = 1;
247  }
248 
249  //
250  if (i+1<size && buf.buf[i]==0x0d && buf.buf[i+1]==0x0a) {
251  i = i + 2;
252  if (crlfCount==1) {
254  lp = add_tList_node_Buffer(lp, key, data);
255  crlfCount = 0;
256  inContents = TRUE;
257  break;
258  }
259  }
260  else if (i<size && buf.buf[i]==0x0a) {
261  i = i + 1;
262  if (crlfCount==1) {
264  lp = add_tList_node_Buffer(lp, key, data);
265  crlfCount = 0;
266  inContents = TRUE;
267  break;
268  }
269  }
270 
271  if (buf.buf[i]=='\0' || i==size) break;
272 
273  // HEADER KEY
274  n = 0;
275  if (buf.buf[i]==CHAR_TAB || buf.buf[i]==' ') {
277  }
278  else {
279  while(buf.buf[i]!=deli && buf.buf[i]!='\0' && i<size && n<LBUF) {
280  key.buf[n++] = buf.buf[i++];
281  }
282  key.buf[n] = '\0';
283  key.vldsz = n;
284  }
285  while ((buf.buf[i]==deli ||buf.buf[i]==' '||buf.buf[i]==CHAR_TAB) && i<size) i++;
286 
287  // HEADER VALUE
288  n = 0;
289  while(buf.buf[i]!=0x0a && buf.buf[i]!='\0' && i<size && n<size) {
290  data.buf[n++] = buf.buf[i++];
291  }
292  if (data.buf[n-1]==0x0d) {
293  i--;
294  n--;
295  }
296  data.buf[n] = '\0';
297  data.vldsz = n;
298 
299  lp = add_tList_node_Buffer(lp, key, data);
300 
301  crlfCount = 0;
302  clear_Buffer(&key);
303  clear_Buffer(&data);
304  }
305 
306  // CONTENTS (Text or Binary)
307  if (rcntnt && i<size && inContents) {
308  crlfCount = 0;
309  clear_Buffer(&key);
310  clear_Buffer(&data);
312 
313  n = 0;
314  while(i<size && n<size) {
315  data.buf[n++] = buf.buf[i++];
316  }
317  data.vldsz = n;
318 
319  lp = add_tList_node_Buffer(lp, key, data);
320  }
321 
322  free_Buffer(&key);
323  free_Buffer(&data);
324 
325  return lp;
326 }
Buffer make_Buffer(int sz)
Buffer型変数のバッファ部をつくり出す.
Definition: buffer.c:71
void clear_Buffer(Buffer *str)
Buffer型変数 のバッファ部を 0クリアする.
Definition: buffer.c:272
#define copy_s2Buffer(src, dst)
copy_b2Buffer()
Definition: buffer.h:108
#define LBUF
Definition: common.h:146
#define FALSE
Definition: common.h:223
#define HDLIST_CONTINUE
Definition: protocol.h:33
#define HDLIST_FIRST_LINE_KEY
Definition: protocol.h:31
int vldsz
データの長さ.バイナリデータの場合も使用可能.文字列の場合は 0x00 を含まない.
Definition: buffer.h:37
unsigned char * buf
バッファの先頭へのポインタ.str[bufsz]は必ず 0x00となる.
Definition: buffer.h:39
#define add_tList_node_Buffer(p, k, v)
add_tList_node_byBuffer()
Definition: tlist.h:144
#define CHAR_TAB
タブ
Definition: tools.h:80

References add_tList_node_Buffer, buf, Buffer::buf, CHAR_TAB, clear_Buffer(), copy_s2Buffer, FALSE, free_Buffer(), HDLIST_CONTENTS_KEY, HDLIST_CONTINUE, HDLIST_END_KEY, HDLIST_FIRST_LINE_KEY, LBUF, make_Buffer(), TRUE, and Buffer::vldsz.

Referenced by get_mime_filename(), get_protocol_header_list(), and recv_http_header().

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

◆ is_header_continue()

int is_header_continue ( tList pp)

int is_header_continue(tList* pp)

pp が指しているヘッダ値が次のリストへ続いているかどうか判定する. プロトコル上では,ヘッダ値が複数行に渡る場合に相当する.

Definition at line 631 of file protocol.c.

632 {
633  if (pp==NULL || pp->next==NULL || pp->next->ldat.key.buf==NULL) return FALSE;
634  if (!strcmp((const char*)pp->next->ldat.key.buf, HDLIST_CONTINUE)) return TRUE;
635  return FALSE;
636 }

References FALSE, HDLIST_CONTINUE, and TRUE.

Referenced by search_protocol_header(), search_protocol_header_partvalue(), search_protocol_header_value(), and set_protocol_contents().

Here is the caller graph for this function:

◆ print_protocol_header()

void print_protocol_header ( tList pp,
int  content 
)

int print_protocol_header(tList* pp)

pp のヘッダ部分(以外)を stderr に出力する.

Definition at line 644 of file protocol.c.

645 {
646  if (pp==NULL) return;
647 
648  if (pp->ldat.id==TLIST_ANCHOR_NODE) pp = pp->next;
649  while (pp!=NULL) { /*&& !ex_strcmp(HDLIST_END_KEY, (char*)pp->ldat.key.buf) */
650  //&& !ex_strcmp(HDLIST_CONTENTS_KEY, (char*)pp->ldat.key.buf)) {
651  if (content==ON || !ex_strcmp(HDLIST_CONTENTS_KEY, (char*)pp->ldat.key.buf)) {
652  PRINT_MESG("[%s] [%s]\n", (char*)pp->ldat.key.buf, (char*)pp->ldat.val.buf);
653  }
654  pp = pp->next;
655  }
656  return;
657 }
#define TLIST_ANCHOR_NODE
アンカーノード
Definition: tlist.h:92
#define ex_strcmp(a, b)
文字列 aの長さに合わせて比較する.大文字小文字を区別しない.一致するなら TRUE
Definition: tools.h:283
#define PRINT_MESG
環境依存用の出力関数.print_message()
Definition: tools.h:475

References ex_strcmp, HDLIST_CONTENTS_KEY, ON, PRINT_MESG, and TLIST_ANCHOR_NODE.

◆ restore_protocol_contents()

Buffer restore_protocol_contents ( tList list)

Buffer restore_protocol_contents(tList* list)

リスト listに保存されたデータからコンテンツを復元する.

Definition at line 109 of file protocol.c.

110 {
111  Buffer buf;
112  tList* lp;
113  int nn = 1;
114 
115  buf = make_Buffer(BUFSZ);
116 
117  lp = strncmp_tList(list, (char*)HDLIST_CONTENTS_KEY, 0, nn);
118  while (lp!=NULL && lp->ldat.val.buf!=NULL) {
119  cat_Buffer(&(lp->ldat.val), &buf);
120  lp = strncmp_tList(list, (char*)HDLIST_CONTENTS_KEY, 0, ++nn);
121  }
122 
123  return buf;
124 }
int cat_Buffer(Buffer *src, Buffer *dst)
Buffer変数 srcから dstへバッファを catする.
Definition: buffer.c:384
#define BUFSZ
16K
Definition: common.h:138
tList * strncmp_tList(tList *pl, const char *key, int len, int no)
char* 型変数によるノードのサーチ.
Definition: tlist.c:1056

References buf, BUFSZ, cat_Buffer(), HDLIST_CONTENTS_KEY, make_Buffer(), and strncmp_tList().

Referenced by get_sdp_body_list().

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

◆ restore_protocol_header()

Buffer restore_protocol_header ( tList list,
char *  deli,
int  mode,
int *  hdsz 
)

Buffer restore_protocol_header(tList* list, char* deli, int mode, int* hdsz)

リスト listに保存されたデータからヘッダデータを復元する. mode==ON なら listに紛れ込んでいるコンテンツの内容も加えて返す.

get_protocol_header_list() の逆.

Definition at line 55 of file protocol.c.

56 {
57  Buffer buf;
58 
59  buf = init_Buffer();
60  if (list==NULL) return buf;
61 
63 
64  while(list!=NULL) {
65  if (!strcmp((const char*)(list->ldat.key.buf), HDLIST_FIRST_LINE_KEY)) {
66  copy_Buffer(&(list->ldat.val), &buf);
67  cat_s2Buffer("\r\n", &buf);
68  }
69  else if (!strcmp((const char*)(list->ldat.key.buf), HDLIST_CONTINUE)) {
70  buf.buf[buf.vldsz] = CHAR_TAB;
71  buf.vldsz++;
72  cat_Buffer(&(list->ldat.val), &buf);
73  cat_s2Buffer("\r\n", &buf);
74  }
75  else if (!strcmp((const char*)(list->ldat.key.buf), HDLIST_END_KEY)) {
76  break;
77  }
78  else if (strcmp((const char*)(list->ldat.key.buf), HDLIST_CONTENTS_KEY)) {
79  cat_Buffer(&(list->ldat.key), &buf);
80  cat_s2Buffer(deli, &buf);
81  cat_Buffer(&(list->ldat.val), &buf);
82  cat_s2Buffer("\r\n", &buf);
83  }
84 
85  list = list->next;
86  }
87  if (buf.vldsz>0) cat_s2Buffer("\r\n", &buf);
88 
89  if (hdsz!=NULL) *hdsz = buf.vldsz;
90 
91  if (mode==ON) {
92  int nn = 1;
93  tList* pl = strncmp_tList(list, (char*)HDLIST_CONTENTS_KEY, 0, nn);
94  while (pl!=NULL && pl->ldat.val.buf!=NULL) {
95  cat_Buffer(&(pl->ldat.val), &buf);
96  pl = strncmp_tList(list, (char*)HDLIST_CONTENTS_KEY, 0, ++nn);
97  }
98  }
99 
100  return buf;
101 }
Buffer init_Buffer()
初期化したBuffer型変数を返す.
Definition: buffer.c:47
int copy_Buffer(Buffer *src, Buffer *dst)
Buffer型変数 srcから dstへバッファをコピーする.
Definition: buffer.c:315
#define cat_s2Buffer(src, dst)
cat_b2Buffer()
Definition: buffer.h:122
#define RECVBUFSZ
256K
Definition: common.h:134

References buf, cat_Buffer(), cat_s2Buffer, CHAR_TAB, copy_Buffer(), HDLIST_CONTENTS_KEY, HDLIST_CONTINUE, HDLIST_END_KEY, HDLIST_FIRST_LINE_KEY, init_Buffer(), make_Buffer(), ON, RECVBUFSZ, and strncmp_tList().

Referenced by rebuild_http_Buffer(), restore_sdp_body(), send_http_file(), and send_http_header().

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

◆ search_crlfcrlf()

int search_crlfcrlf ( char *  mesg)

int search_crlfcrlf(char* mesg)

文字列中の空行を探す.改行コードは 0x0d, 0x0a または 0x0a

Returns
空行後の次の行の先頭の位置.0 の場合は空行無し.

Definition at line 600 of file protocol.c.

601 {
602  int cr = 0; // dummy
603  int lf = 0;
604  int i;
605 
606  if (mesg==NULL) return JBXL_ARGS_ERROR;
607  if (mesg[0]==0x0a) return 2;
608  if (mesg[0]==0x0d && mesg[1]==0x0a) return 2;
609 
610  i = 0;
611  while(mesg[i]!='\0') {
612  if (mesg[i]==0x0d) cr++; // not used
613  else if (mesg[i]==0x0a) lf++;
614  else {
615  cr = lf = 0;
616  }
617 
618  if (lf==2) return i+1;
619  i++;
620  }
621  return 0;
622 }
#define JBXL_ARGS_ERROR
不正な引数(NULLなど)
Definition: jbxl_state.h:42

References JBXL_ARGS_ERROR.

◆ search_protocol_header()

Buffer search_protocol_header ( tList list,
char *  key,
int  no 
)

Buffer search_protocol_header(tList* list, char* key, int no)

ヘッダリストの中から no番目の keyノードを探し出し,値(ldat.val.buf)のコピーを返す. 値が複数行に渡る場合は,\r\n を挿入して行を結合する. 検索では keyの長さに合わせる.また, keyはケースインセンシティブ.

Parameters
list検索対象のヘッダ方向を格納したリスト
keyヘッダ種別.
no同じヘッダ種別のノードが複数ある場合,何番目のノードかを指定する.1から数える.
Returns
ldat.val.buf のコピー.

Definition at line 372 of file protocol.c.

373 {
374  tList* pp;
375  Buffer buf;
376 
377  buf = init_Buffer();
378  if (list==NULL || key==NULL) return buf;
379 
380  pp = strncasecmp_tList(list, key, 0, no); // 完全一致
381  if (pp!=NULL) {
382  buf = dup_Buffer(pp->ldat.val);
383 
384  while (is_header_continue(pp)) {
385  cat_s2Buffer("\r\n", &buf);
386  pp = pp->next;
387  cat_Buffer(&(pp->ldat.val), &buf);
388  }
389  }
390 
391  return buf;
392 }
Buffer dup_Buffer(Buffer buf)
Buffer型変数のコピーをつくる.
Definition: buffer.c:211
int is_header_continue(tList *pp)
Definition: protocol.c:631
tList * strncasecmp_tList(tList *pl, const char *key, int len, int no)
char* 型変数によるノードのサーチ.大文字小文字を無視する
Definition: tlist.c:1094

References buf, cat_Buffer(), cat_s2Buffer, dup_Buffer(), init_Buffer(), is_header_continue(), and strncasecmp_tList().

Referenced by get_http_header_method(), get_http_status_num(), get_http_version_num(), get_mime_filename(), get_sip_contact_uri(), is_http_header_field(), recv_http_Buffer(), recv_http_file(), recv_http_header(), save_http_xml(), search_protocol_header_item(), search_protocol_header_partvalue(), and search_protocol_header_value().

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

◆ search_protocol_header_item()

Buffer search_protocol_header_item ( tList list,
char *  key,
int  no,
char  deli,
int  nm 
)

Buffer search_protocol_header_item(tList* list, char* key, int no, char deli, int nm)

key をキーにした no番目のノードの値の中で,deliを区切りにした nm番目の項目(文字列)を返す.

Parameters
list検索対象のヘッダ方向を格納したリスト
keyヘッダ種別.
no同じヘッダ種別が複数ある場合,何番目のノードかを指定する.1から数える.
deliノード値(文字列)の区切り文字.
nmdeli を区切り文字として何番目の項目か? 1から数える.
Returns
指定した項目(文字列)のコピー.

Definition at line 408 of file protocol.c.

409 {
410  Buffer buf, itm;
411 
412  buf = search_protocol_header(list, key, no);
413  if (buf.buf==NULL) return buf;
414 
415  itm = cawk_Buffer(buf, deli, nm);
416  free_Buffer(&buf);
417 
418  return itm;
419 }
Buffer cawk_Buffer(Buffer str, char cc, int n)
Buffer文字列に対する(変形の)awk.
Definition: buffer.c:1094
Buffer search_protocol_header(tList *list, char *key, int no)
Definition: protocol.c:372

References buf, cawk_Buffer(), free_Buffer(), and search_protocol_header().

Referenced by get_sip_via_address(), and replace_sip_via().

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

◆ search_protocol_header_partvalue()

Buffer search_protocol_header_partvalue ( tList list,
char *  key,
char *  data,
int  no 
)

Buffer search_protocol_header_partvalue(tList* list, char* key, char* data, int no)

ヘッダリストの中から no番目の keyノードを探し出し,dataの文字列を含むノードの値(ldat.val.buf)のコピーを返す.

key, dataはケースインセンシティブ.data が複数行に継続している場合は,継続している行も単独の行として検査される.

Parameters
list検索対象のヘッダ方向を格納したリスト
keyヘッダ種別.
data検索するヘッダ値の最初の文字.NULL なら全てと一致.
no同じヘッダ種別のノードが複数ある場合,何番目のノードかを指定する.1から数える.
Returns
一致したノードのノード値のコピー.

Definition at line 500 of file protocol.c.

501 {
502  Buffer buf;
503  char* str;
504  int nm;
505 
506  buf = init_Buffer();
507  if (list==NULL || key==NULL) return buf;
508 
509  if (data==NULL) {
510  buf = search_protocol_header(list, key, no);
511  return buf;
512  }
513 
514  buf = init_Buffer();
515  //len = (int)strlen(data);
516 
517  nm = 0;
518  while (list!=NULL) {
519  if (list->ldat.key.buf!=NULL && !strcasecmp((char*)list->ldat.key.buf, key)) {
520  str = (char*)list->ldat.val.buf;
521 
522  if (str!=NULL && strstrcase(str, data)) {
523  nm++;
524  if (no==nm) {
525  buf = make_Buffer_bystr(str);
526  return buf;
527  }
528  }
529 
530  while (is_header_continue(list)) {
531  list = list->next;
532  str = (char*)list->ldat.val.buf;
533  if (str!=NULL && strstrcase(str, data)) {
534  nm++;
535  if (no==nm) {
536  buf = make_Buffer_bystr(str);
537  return buf;
538  }
539  }
540  }
541  }
542 
543  list = list->next;
544  }
545 
546  return buf;
547 }
#define make_Buffer_bystr(str)
set_Buffer()
Definition: buffer.h:57
char * strstrcase(const char *buf, const char *nd)
文字列 bufの中に文字列 ndがあるかどうかをチェックする.大文字小文字は区別しない.
Definition: tools.c:736

References buf, init_Buffer(), is_header_continue(), make_Buffer_bystr, search_protocol_header(), and strstrcase().

Referenced by replace_sip_contact_dstipport().

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

◆ search_protocol_header_value()

Buffer search_protocol_header_value ( tList list,
char *  key,
char *  data,
int  no 
)

Buffer search_protocol_header_value(tList* list, char* key, char* data, int no)

ヘッダリストの中から no番目の keyノードを探し出し,dataで始まるノードの値(ldat.val.buf)のコピーを返す.

key, dataはケースインセンシティブ.data が複数行に継続している場合は,継続している行も単独の行として検査される.

Parameters
list検索対象のヘッダ方向を格納したリスト
keyヘッダ種別.
data検索するヘッダ値の最初の文字.NULL なら全てと一致.
no同じヘッダ種別のノードが複数ある場合,何番目のノードかを指定する.1から数える.
Returns
一致したノードのノード値のコピー.

Definition at line 436 of file protocol.c.

437 {
438  Buffer buf;
439  char* str;
440  int len, nm;
441 
442  buf = init_Buffer();
443  if (list==NULL || key==NULL) return buf;
444 
445  if (data==NULL) {
446  buf = search_protocol_header(list, key, no);
447  return buf;
448  }
449 
450  buf = init_Buffer();
451  len = (int)strlen(data);
452 
453  nm = 0;
454  while (list!=NULL) {
455  if (list->ldat.key.buf!=NULL && !strcasecmp((char*)list->ldat.key.buf, key)) {
456  str = (char*)list->ldat.val.buf;
457 
458  if (str!=NULL && !strncasecmp(str, data, len)) {
459  nm++;
460  if (no==nm) {
461  buf = make_Buffer_bystr(str);
462  return buf;
463  }
464  }
465 
466  while (is_header_continue(list)) {
467  list = list->next;
468  str = (char*)list->ldat.val.buf;
469  if (str!=NULL && !strncasecmp(str, data, len)) {
470  nm++;
471  if (no==nm) {
472  buf = make_Buffer_bystr(str);
473  return buf;
474  }
475  }
476  }
477  }
478 
479  list = list->next;
480  }
481 
482  return buf;
483 }
unsigned char unsigned long * len
Definition: jpeg_tool.h:96

References buf, init_Buffer(), is_header_continue(), len, make_Buffer_bystr, and search_protocol_header().

Referenced by get_mime_boundary().

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

◆ set_protocol_contents()

void set_protocol_contents ( tList list,
Buffer  contents 
)

void set_protocol_contents(tList* list, Buffer contents)

Attention
プロトコルに依存するので,コンテンツサイズの再計算は行わない.

Definition at line 132 of file protocol.c.

133 {
134  while (list!=NULL) {
135  if (list->ldat.key.buf!=NULL && !strcmp((char*)list->ldat.key.buf, HDLIST_CONTENTS_KEY)) {
136  free_Buffer(&list->ldat.val);
137  list->ldat.val = dup_Buffer(contents);
138 
139  while (is_header_continue(list)) del_tList_node(&(list->next));
140  break;
141  }
142 
143  list = list->next;
144  }
145 
146  return;
147 }
tList * del_tList_node(tList **node)
リスト用のノードを削除.
Definition: tlist.c:270

References del_tList_node(), dup_Buffer(), free_Buffer(), HDLIST_CONTENTS_KEY, and is_header_continue().

Referenced by set_sip_contents().

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

◆ set_protocol_header()

int set_protocol_header ( tList list,
char *  key,
char *  value,
int  no,
int  mode 
)

Definition at line 574 of file protocol.c.

575 {
576  int cn = set_value_tList(list, key, no, value, OFF);
577 
578  // Not Found
579  if (add_mode==ON && cn==0) {
580  tList* pm = strncmp_tList(list, (char*)HDLIST_END_KEY, 0, 1);
581  if (pm!=NULL && pm->prev!=NULL) {
582  add_tList_node_str(pm->prev, key, value);
583  }
584  else {
585  add_tList_node_str(list, key, value);
586  }
587  }
588 
589  return cn;
590 }
#define OFF
Definition: common.h:231
int set_value_tList(tList *list, const char *key, int no, const char *value, int add_mode)
リスト(lt)中の no番目の keyノードの値に valueを設定する.
Definition: tlist.c:1675
#define add_tList_node_str(p, k, v)
add_tList_node_bystr()
Definition: tlist.h:142

References add_tList_node_str, HDLIST_END_KEY, OFF, ON, set_value_tList(), and strncmp_tList().

Referenced by set_http_host_header(), and set_sip_contents().

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