xLib/protocol.c File Reference

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

#include "protocol.h"
Include dependency graph for protocol.c:

Go to the source code of this file.

Functions

tListget_protocol_header_list (Buffer buf, char deli, int fstline, int rcntnt)
Buffer restore_protocol_header (tList *list, char *deli, int mode, int *hdsz)
Buffer restore_protocol_contents (tList *list)
void set_protocol_contents (tList *list, Buffer contents)
tListget_protocol_header_list_seq (tList *lp, 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 add_mode)
int search_crlfcrlf (char *mesg)
int is_header_continue (tList *pp)
void print_protocol_header (tList *pp, int content)
tListfind_protocol_end (tList *lp)

Detailed Description

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

Definition in file protocol.c.


Function Documentation

tList* find_protocol_end ( tList lp  ) 

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

Definition at line 681 of file protocol.c.

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

00682 {
00683     tList* end = search_key_tList(lp, HDLIST_END_KEY, 1);
00684     if (end==NULL) end = search_key_tList(lp, HDLIST_CONTENTS_KEY, 1);
00685     //
00686     if (end!=NULL) end = end->prev;
00687     else           end = find_tList_end(lp);
00688 
00689     return end;
00690 }

Here is the call graph for this function:

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 36 of file protocol.c.

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

Referenced by get_protocol_header_list_file(), and get_sdp_body_list().

00037 {
00038     tList* lp;
00039 
00040     if (buf.buf==NULL) return NULL;
00041 
00042     lp = get_protocol_header_list_seq(NULL, buf, deli, fstline, rcntnt);
00043     if (lp!=NULL) lp = find_tList_top(lp);
00044 
00045     return lp;
00046 }

Here is the call graph for this function:

Here is the caller graph for this function:

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 348 of file protocol.c.

References get_protocol_header_list(), and read_Buffer_file().

00349 {
00350     Buffer buf;
00351     tList* lp;
00352 
00353     if (fname==NULL) return NULL;
00354 
00355     buf = read_Buffer_file(fname);
00356     lp  = get_protocol_header_list(buf, deli, fstline, rcntnt);
00357 
00358     return lp;
00359 }

Here is the call graph for this function:

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 187 of file protocol.c.

References add_tList_node_Buffer, 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(), recv_http_header(), and recv_https_header().

00188 {
00189     static int crlfCount  = 0;
00190     static int inContents = FALSE;
00191     int i=0, n=0, size;
00192     Buffer key, data;
00193 
00194     if (buf.buf==NULL) return NULL;
00195 
00196     size = buf.vldsz;
00197     data = make_Buffer(size+1);
00198     key  = make_Buffer(LBUF);
00199 
00200     if (lp==NULL) {
00201         crlfCount  = 0;
00202         inContents = FALSE;
00203     }
00204 
00205     // FIRST LINE 
00206     if (fstline && lp==NULL) {
00207         while(buf.buf[i]!=0x0a && buf.buf[i]!='\0' && i<size && n<size) {
00208             data.buf[n++] = buf.buf[i++];
00209         }
00210         if (data.buf[n-1]==0x0d) {
00211             i--;
00212             n--;
00213         }
00214 
00215         data.buf[n] = '\0';
00216         data.vldsz  = n;
00217         copy_s2Buffer(HDLIST_FIRST_LINE_KEY, &key);
00218         lp = add_tList_node_Buffer(NULL, key, data);
00219 
00220         if (buf.buf[i]=='\0' || i==size) {
00221             free_Buffer(&key);
00222             free_Buffer(&data);
00223             return lp;
00224         }
00225         clear_Buffer(&key);
00226         clear_Buffer(&data);
00227     }
00228 
00229     // HEADER
00230     while(buf.buf[i]!='\0' && i<size && !inContents) {
00231         // Check Previous Line's CR & LF
00232         if (i+1<size && buf.buf[i]==0x0d && buf.buf[i+1]==0x0a) {
00233             i = i + 2;
00234             if (crlfCount==1) {         // for previous called function
00235                 copy_s2Buffer(HDLIST_END_KEY, &key);
00236                 lp = add_tList_node_Buffer(lp, key, data);
00237                 crlfCount  = 0;
00238                 inContents = TRUE;
00239                 break;  
00240             }
00241             else crlfCount = 1;
00242         }
00243         else if (buf.buf[i]==0x0a) {
00244             i = i + 1;
00245             if (crlfCount==1) {         // for previous called function
00246                 copy_s2Buffer(HDLIST_END_KEY, &key);
00247                 lp = add_tList_node_Buffer(lp, key, data);
00248                 crlfCount  = 0;
00249                 inContents = TRUE;
00250                 break;  
00251             }
00252             else crlfCount = 1;
00253         }
00254 
00255         // 
00256         if (i+1<size && buf.buf[i]==0x0d && buf.buf[i+1]==0x0a) {
00257             i = i + 2;
00258             if (crlfCount==1) {
00259                 copy_s2Buffer(HDLIST_END_KEY, &key);
00260                 lp = add_tList_node_Buffer(lp, key, data);
00261                 crlfCount  = 0;
00262                 inContents = TRUE;
00263                 break;  
00264             }
00265         }
00266         else if (i<size && buf.buf[i]==0x0a) {
00267             i = i + 1;
00268             if (crlfCount==1) {
00269                 copy_s2Buffer(HDLIST_END_KEY, &key);
00270                 lp = add_tList_node_Buffer(lp, key, data);
00271                 crlfCount  = 0;
00272                 inContents = TRUE;
00273                 break;  
00274             }
00275         }
00276 
00277         if (buf.buf[i]=='\0' || i==size) break;
00278 
00279         // HEADER KEY
00280         n = 0;
00281         if (buf.buf[i]==CHAR_TAB || buf.buf[i]==' ') {
00282             copy_s2Buffer(HDLIST_CONTINUE, &key);
00283         }
00284         else {
00285             while(buf.buf[i]!=deli && buf.buf[i]!='\0' && i<size && n<LBUF) {
00286                 key.buf[n++] = buf.buf[i++];
00287             }
00288             key.buf[n] = '\0';
00289             key.vldsz  = n;
00290         }
00291         while ((buf.buf[i]==deli ||buf.buf[i]==' '||buf.buf[i]==CHAR_TAB) && i<size) i++;
00292 
00293         // HEADER VALUE
00294         n = 0;
00295         while(buf.buf[i]!=0x0a && buf.buf[i]!='\0' && i<size && n<size) {
00296             data.buf[n++] = buf.buf[i++];
00297         }
00298         if (data.buf[n-1]==0x0d) {
00299             i--;
00300             n--;
00301         }
00302         data.buf[n] = '\0';
00303         data.vldsz  = n;
00304 
00305         lp = add_tList_node_Buffer(lp, key, data);
00306 
00307         crlfCount = 0;
00308         clear_Buffer(&key);
00309         clear_Buffer(&data);
00310     }
00311 
00312     // CONTENTS (Text or Binary)
00313     if (rcntnt && i<size && inContents) {
00314         crlfCount = 0;
00315         clear_Buffer(&key);
00316         clear_Buffer(&data);
00317         copy_s2Buffer(HDLIST_CONTENTS_KEY, &key);
00318 
00319         n = 0;
00320         while(i<size && n<size) {
00321             data.buf[n++] = buf.buf[i++];
00322         }
00323         data.vldsz = n;
00324 
00325         lp = add_tList_node_Buffer(lp, key, data);
00326     }
00327     
00328     free_Buffer(&key);
00329     free_Buffer(&data);
00330 
00331     return lp;
00332 }

Here is the call graph for this function:

Here is the caller graph for this function:

int is_header_continue ( tList pp  ) 

int is_header_continue(tList* pp)

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

Definition at line 645 of file protocol.c.

References FALSE, HDLIST_CONTINUE, and TRUE.

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

00646 {
00647     if (pp==NULL || pp->next==NULL || pp->next->ldat.key.buf==NULL) return FALSE;
00648     if (!strcmp((const char*)pp->next->ldat.key.buf, HDLIST_CONTINUE)) return TRUE;
00649     return FALSE;
00650 }

Here is the caller graph for this function:

void print_protocol_header ( tList pp,
int  content 
)

int print_protocol_header(tList* pp)

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

Definition at line 659 of file protocol.c.

References ex_strcmp, HDLIST_CONTENTS_KEY, ON, print_message(), and TLIST_ANCHOR_NODE.

00660 {
00661     if (pp==NULL) return;
00662 
00663     if (pp->ldat.id==TLIST_ANCHOR_NODE) pp = pp->next;
00664     while (pp!=NULL) { /*&& !ex_strcmp(HDLIST_END_KEY,      (char*)pp->ldat.key.buf) */
00665                     //&& !ex_strcmp(HDLIST_CONTENTS_KEY, (char*)pp->ldat.key.buf)) {
00666         if (content==ON || !ex_strcmp(HDLIST_CONTENTS_KEY, (char*)pp->ldat.key.buf)) {
00667             print_message("[%s] [%s]\n", (char*)pp->ldat.key.buf, (char*)pp->ldat.val.buf);
00668         }
00669         pp = pp->next;
00670     }
00671     return;
00672 }

Here is the call graph for this function:

Buffer restore_protocol_contents ( tList list  ) 

Buffer restore_protocol_contents(tList* list)

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

Definition at line 113 of file protocol.c.

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

Referenced by get_sdp_body_list().

00114 {
00115     Buffer buf;
00116     tList* lp;
00117     int nn = 1;
00118 
00119     buf = make_Buffer(BUFSZ);
00120 
00121     lp = strncmp_tList(list, (char*)HDLIST_CONTENTS_KEY, 0, nn);
00122     while (lp!=NULL && lp->ldat.val.buf!=NULL) {
00123         cat_Buffer(&(lp->ldat.val), &buf);
00124         lp = strncmp_tList(list, (char*)HDLIST_CONTENTS_KEY, 0, ++nn);
00125     }
00126 
00127     return buf;
00128 }

Here is the call graph for this function:

Here is the caller graph for this function:

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 58 of file protocol.c.

References Buffer::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, strncmp_tList(), and Buffer::vldsz.

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

00059 {
00060     Buffer buf;
00061 
00062     buf = init_Buffer();
00063     if (list==NULL) return buf;
00064 
00065     buf = make_Buffer(RECVBUFSZ);
00066 
00067     while(list!=NULL) {
00068         if (!strcmp((const char*)(list->ldat.key.buf), HDLIST_FIRST_LINE_KEY)) {
00069             copy_Buffer(&(list->ldat.val), &buf);
00070             cat_s2Buffer("\r\n", &buf);
00071         }
00072         else if (!strcmp((const char*)(list->ldat.key.buf), HDLIST_CONTINUE)) {
00073             buf.buf[buf.vldsz] = CHAR_TAB;
00074             buf.vldsz++;
00075             cat_Buffer(&(list->ldat.val), &buf);
00076             cat_s2Buffer("\r\n", &buf);
00077         }
00078         else if (!strcmp((const char*)(list->ldat.key.buf), HDLIST_END_KEY)) {
00079             break;
00080         }
00081         else if (strcmp((const char*)(list->ldat.key.buf), HDLIST_CONTENTS_KEY)) {
00082             cat_Buffer(&(list->ldat.key), &buf);
00083             cat_s2Buffer(deli, &buf);
00084             cat_Buffer(&(list->ldat.val), &buf);
00085             cat_s2Buffer("\r\n", &buf);
00086         }
00087 
00088         list = list->next;
00089     }
00090     if (buf.vldsz>0) cat_s2Buffer("\r\n", &buf);
00091 
00092     if (hdsz!=NULL) *hdsz = buf.vldsz;
00093 
00094     if (mode==ON) {
00095         int nn = 1;
00096         tList* pl = strncmp_tList(list, (char*)HDLIST_CONTENTS_KEY, 0, nn);
00097         while (pl!=NULL && pl->ldat.val.buf!=NULL) {
00098             cat_Buffer(&(pl->ldat.val), &buf);
00099             pl = strncmp_tList(list, (char*)HDLIST_CONTENTS_KEY, 0, ++nn);
00100         }
00101     }
00102 
00103     return buf;
00104 }

Here is the call graph for this function:

Here is the caller graph for this function:

int search_crlfcrlf ( char *  mesg  ) 

int search_crlfcrlf(char* mesg)

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

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

Definition at line 613 of file protocol.c.

References JBXL_ARGS_ERROR.

00614 {
00615     int cr = 0;     // dummy
00616     int lf = 0;
00617     int i;
00618 
00619     if (mesg==NULL)    return JBXL_ARGS_ERROR;
00620     if (mesg[0]==0x0a) return 2;
00621     if (mesg[0]==0x0d && mesg[1]==0x0a) return 2;
00622 
00623     i = 0;
00624     while(mesg[i]!='\0') {
00625         if      (mesg[i]==0x0d) cr++;   // not used
00626         else if (mesg[i]==0x0a) lf++;
00627         else {
00628             cr = lf = 0;
00629         }
00630 
00631         if (lf==2) return i+1;
00632         i++;
00633     }
00634     return 0;
00635 }

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 380 of file protocol.c.

References 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(), recv_https_Buffer(), recv_https_file(), recv_https_header(), save_http_xml(), save_https_xml(), search_protocol_header_item(), search_protocol_header_partvalue(), and search_protocol_header_value().

00381 {
00382     tList* pp;
00383     Buffer buf;
00384 
00385     buf = init_Buffer();
00386     if (list==NULL || key==NULL) return buf;
00387     
00388     pp = strncasecmp_tList(list, key, 0, no);       // 完全一致
00389     if (pp!=NULL) {
00390         buf = dup_Buffer(pp->ldat.val);
00391 
00392         while (is_header_continue(pp)) {
00393             cat_s2Buffer("\r\n", &buf);
00394             pp = pp->next;
00395             cat_Buffer(&(pp->ldat.val), &buf);
00396         }
00397     }
00398     
00399     return buf;
00400 }

Here is the call graph for this function:

Here is the caller graph for this function:

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 ノード値(文字列)の区切り文字.
nm deli を区切り文字として何番目の項目か? 1から数える.
Returns:
指定した項目(文字列)のコピー.

Definition at line 417 of file protocol.c.

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

Referenced by get_sip_via_address(), and replace_sip_via().

00418 {
00419     Buffer buf, itm;
00420 
00421     buf = search_protocol_header(list, key, no);
00422     if (buf.buf==NULL) return buf;
00423     
00424     itm = cawk_Buffer(buf, deli, nm);
00425     free_Buffer(&buf);
00426 
00427     return itm;
00428 }

Here is the call graph for this function:

Here is the caller graph for this function:

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 511 of file protocol.c.

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

Referenced by replace_sip_contact_dstipport().

00512 {
00513     Buffer buf;
00514     char*  str;
00515     int    nm;
00516 
00517     buf = init_Buffer();
00518     if (list==NULL || key==NULL) return buf;
00519 
00520     if (data==NULL) {
00521         buf = search_protocol_header(list, key, no);
00522         return buf;
00523     }
00524 
00525     buf = init_Buffer();
00526     //len = (int)strlen(data); 
00527     
00528     nm = 0;
00529     while (list!=NULL) {
00530         if (list->ldat.key.buf!=NULL && !strcasecmp((char*)list->ldat.key.buf, key)) {
00531             str = (char*)list->ldat.val.buf;
00532 
00533             if (str!=NULL && strstrcase(str, data)) {
00534                 nm++;
00535                 if (no==nm) {
00536                     buf = make_Buffer_bystr(str);
00537                     return buf;
00538                 }
00539             }
00540 
00541             while (is_header_continue(list)) {
00542                 list = list->next;
00543                 str  = (char*)list->ldat.val.buf;
00544                 if (str!=NULL && strstrcase(str, data)) {
00545                     nm++;
00546                     if (no==nm) {
00547                         buf = make_Buffer_bystr(str);
00548                         return buf;
00549                     }
00550                 }
00551             }
00552         }
00553 
00554         list = list->next;
00555     }
00556 
00557     return buf;
00558 }

Here is the call graph for this function:

Here is the caller graph for this function:

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 446 of file protocol.c.

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

Referenced by get_mime_boundary().

00447 {
00448     Buffer buf;
00449     char*  str;
00450     int    len, nm;
00451 
00452     buf = init_Buffer();
00453     if (list==NULL || key==NULL) return buf;
00454 
00455     if (data==NULL) {
00456         buf = search_protocol_header(list, key, no);
00457         return buf;
00458     }
00459 
00460     buf = init_Buffer();
00461     len = (int)strlen(data); 
00462     
00463     nm = 0;
00464     while (list!=NULL) {
00465         if (list->ldat.key.buf!=NULL && !strcasecmp((char*)list->ldat.key.buf, key)) {
00466             str = (char*)list->ldat.val.buf;
00467 
00468             if (str!=NULL && !strncasecmp(str, data, len)) {
00469                 nm++;
00470                 if (no==nm) {
00471                     buf = make_Buffer_bystr(str);
00472                     return buf;
00473                 }
00474             }
00475 
00476             while (is_header_continue(list)) {
00477                 list = list->next;
00478                 str  = (char*)list->ldat.val.buf;
00479                 if (str!=NULL && !strncasecmp(str, data, len)) {
00480                     nm++;
00481                     if (no==nm) {
00482                         buf = make_Buffer_bystr(str);
00483                         return buf;
00484                     }
00485                 }
00486             }
00487         }
00488 
00489         list = list->next;
00490     }
00491 
00492     return buf;
00493 }

Here is the call graph for this function:

Here is the caller graph for this function:

void set_protocol_contents ( tList list,
Buffer  contents 
)

void set_protocol_contents(tList* list, Buffer contents)

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

Definition at line 137 of file protocol.c.

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

Referenced by set_sip_contents().

00138 {
00139     while (list!=NULL) {
00140         if (list->ldat.key.buf!=NULL && !strcmp((char*)list->ldat.key.buf, HDLIST_CONTENTS_KEY)) {
00141             free_Buffer(&list->ldat.val);
00142             list->ldat.val = dup_Buffer(contents);
00143 
00144             while (is_header_continue(list)) del_tList_node(&(list->next));
00145             break;
00146         }
00147 
00148         list = list->next;
00149     }
00150 
00151     return;
00152 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 586 of file protocol.c.

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().

00587 {
00588     int cn = set_value_tList(list, key, no, value, OFF);
00589 
00590     // Not Found
00591     if (add_mode==ON && cn==0) {
00592         tList* pm = strncmp_tList(list, (char*)HDLIST_END_KEY, 0, 1);
00593         if (pm!=NULL && pm->prev!=NULL) {
00594             add_tList_node_str(pm->prev, key, value);
00595         }
00596         else {
00597             add_tList_node_str(list, key, value);
00598         }
00599     }
00600 
00601     return cn;
00602 }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on 15 Nov 2023 for JunkBox_Lib by  doxygen 1.6.1