reSIProcate添加对自定义头字段的支持

首先在SourceInsight中查找User-Agent,参考该头字段实现对自定义头字段的支持,以下是详细步骤:

1. resip/stack/HeaderTypes.hxx;

    resip/stack/Headers.hxx;

    resip/stack/SipMessage.hxx;

    resip/stack/Headers.cxx;

    resip/stack/SipMessage.cxx;

 以上五个文件分别加上语句:

      defineHeader(TransIPPort, "TransIPPort", StringCategory, "RFC 3261");

 

2. resip/stack/HeaderHash.cxx:

  a. 数组wordlist添加新的头字段(例如{"transipport", Headers::TransIPPort} );

  b. 修改数组lookup中对应位置(通过对后续语句 register int index = lookup[key] 的调试得到,我的情况是111 )如果是-1,则修改为相应的值(该值也不是固定的,应该是{"transipport", Headers::TransIPPort}在wordlist数组中的索引值,我的情况是103,也就是TransIPPort在wordlist中的索引值 )。

 

3. resip/stack/TransactionState.cxx: 中添加测试代码

  if (sip->exists(h_TransIPPort)) {
    DebugLog( << "transipport exists here ");
    Data transipport;
    transipport = sip->header(h_TransIPPort).value();
    DebugLog( << "the value of h_TransIPPort is " << transipport);
} else {
    DebugLog( << "transipport does not exists here ");
}

 

4. resip/stack/HeaderHash.gperf 中添加新的头字段:

  transipport, Headers::TransIPPort

 

注:

1. 其中步骤1,3,4和步骤2中的wordlist都可以直接添加,但是步骤2中的lookup对应位置的值需要通过调试确定位置(现在还不了解其原理,这种完全是硬生生调试出来的)

2.详细的diff文件如下所示:其中有一些是调试语句

 

 

Index: resip/stack/MsgHeaderScanner.cxx
===================================================================
--- resip/stack/MsgHeaderScanner.cxx    (revision 101)
+++ resip/stack/MsgHeaderScanner.cxx    (working copy)
@@ -822,7 +822,7 @@
    //.jacob. Don't ignore fieldNameTextPropBitMask.
    *fieldKind = Headers::getType(fieldName, *fieldNameLength);
    // Added by xutm on 2009.11.17 for sending file
-   //printf("xutmm the fieldName is '%d'-'%s'/n", *fieldKind, fieldName);
+   printf("xutmm the fieldName is '%d'-'%d'-'%s'/n", *fieldKind, *fieldNameLength, fieldName);
    *isMultiValueAllowed =
       Headers::isCommaTokenizing(static_cast(*fieldKind));
 }
@@ -868,9 +868,9 @@
 {
    //.jacob. Don't ignore valueTextPropBitMask, particularly for '/r' & '/n'.
    // 这边当碰到TransType时,fieldKind 是-1,所以出错啦
-   //printf("xutmmm the fieldkind is '%d'/n", fieldKind);
-   //printf("xutmmm ready to call addHeader - '%d'-'%s'/n", fieldNameLength, fieldName);
-   //printf("xutmmm the value is '%d'-'%s'/n", valueTextLength, valueText);
+   printf("xutmmm the fieldkind is '%d'/n", fieldKind);
+   printf("xutmmm ready to call addHeader - '%d'-'%s'/n", fieldNameLength, fieldName);
+   printf("xutmmm the value is '%d'-'%s'/n", valueTextLength, valueText);
    msg->addHeader(static_cast(fieldKind),
                   fieldName,
                   fieldNameLength,
Index: resip/stack/HeaderTypes.hxx
===================================================================
--- resip/stack/HeaderTypes.hxx    (revision 101)
+++ resip/stack/HeaderTypes.hxx    (working copy)
@@ -95,7 +95,7 @@
          defineHeader(UserAgent, "User-Agent", StringCategory, "RFC 3261"),
        
          // Added by xutm on 2009.11.13 for sending file
-         //defineHeader(TransType, "TransType", StringCategory, "RFC 3261"),
+         defineHeader(TransIPPort, "TransIPPort", StringCategory, "RFC 3261"),
           
          defineMultiHeader(Warning, "Warning", WarningCategory, "RFC 3261"),
          defineMultiHeader(WWWAuthenticate, "WWW-Authenticate", Auth, "RFC 3261"),
Index: resip/stack/HeaderHash.cxx
===================================================================
--- resip/stack/HeaderHash.cxx    (revision 96)
+++ resip/stack/HeaderHash.cxx    (working copy)
@@ -383,7 +383,9 @@
 #line 56 "HeaderHash.gperf"
       {"mime-version", Headers::MIMEVersion},
 #line 111 "HeaderHash.gperf"
-      {"session-expires", Headers::SessionExpires}
+      {"session-expires", Headers::SessionExpires},
+#line 115 "HeaderHash.gperf"
+      {"transipport", Headers::TransIPPort}
     };
 
   static short lookup[] =
@@ -401,7 +403,7 @@
         -1,   -1,   -1,   -1,   -1,   26,   -1,   -1,
         -1,   -1,   27,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   28,   -1,   29,   -1,   30,
-        -1,   -1,   -1,   -1,   31,   32,   33,   -1,
+        -1,   -1,   -1,   -1,   31,   32,   33,   103,
         34,   35,   36,   37,   -1,   -1,   -1,   38,
         -1,   -1,   39,   40,   41,   -1,   42,   43,
         44,   45,   -1,   46,   -1,   -1,   -1,   -1,
@@ -444,14 +446,21 @@
         -1,   -1,   -1,   -1,   -1,   -1,  102
     };
 
+
+  printf("xutmmmm the len is '%d'-'%s'/n", len, str);
+
   if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
     {
       register int key = hash (str, len);
 
+  printf("xutmmmmm the key is '%d'/n", key);
+
       if (key <= MAX_HASH_VALUE && key >= 0)
         {
           register int index = lookup[key];
 
+  printf("xutmmmmm the index is '%d'/n", index);
+
           if (index >= 0)
             {
               register const char *s = wordlist[index].name;
@@ -476,6 +485,11 @@
             }
         }
     }

   return 0;
 }
 #line 115 "HeaderHash.gperf"
Index: resip/stack/TransactionState.cxx
===================================================================
--- resip/stack/TransactionState.cxx    (revision 101)
+++ resip/stack/TransactionState.cxx    (working copy)
@@ -818,6 +818,15 @@
                 DebugLog( << "xutm the sender is " << srcAddr << ":" << port);
                 DebugLog( << "xutm the request line is " << req);
                 Data::size_type loc = req.find(srcAddr);
+
+                if (sip->exists(h_TransIPPort)) {
+                    DebugLog( << "transipport exists here ");
+                    Data transipport;
+                    transipport = sip->header(h_TransIPPort).value();
+                    DebugLog( << "the value of h_TransIPPort is " << transipport);
+                } else {
+                    DebugLog( << "transipport does not exists here ");
+                }
                 // here we get the TransType and check if sender and receiver are in the same network
                 // 这边本来我们应该读取数据库来决定两个客户端是否能直接相连的: MSRPP2P/P2P,或者
                 // 只能通过 MSRPRelay, 目前我们直接采用P2P或者MSRPRelay,先不考虑MSRPP2P
Index: resip/stack/Headers.hxx
===================================================================
--- resip/stack/Headers.hxx    (revision 101)
+++ resip/stack/Headers.hxx    (working copy)
@@ -214,7 +214,7 @@
 defineHeader(UserAgent, "User-Agent", StringCategory, "RFC 3261");
 
 // Added by xutm on 2009.11.13 for sending file
-//defineHeader(TransType, "TransType", StringCategory, "RFC 3261");
+defineHeader(TransIPPort, "TransIPPort", StringCategory, "RFC 3261");
 
 defineHeader(Timestamp, "Timestamp", StringCategory, "RFC 3261");
 
Index: resip/stack/HeaderHash.gperf
===================================================================
--- resip/stack/HeaderHash.gperf    (revision 96)
+++ resip/stack/HeaderHash.gperf    (working copy)
@@ -112,5 +112,6 @@
 min-se, Headers::MinSE
 refer-sub, Headers::ReferSub
 remote-party-id, Headers::RemotePartyId
+transipport, Headers::TransIPPort
 %%
 }
Index: resip/stack/SipMessage.hxx
===================================================================
--- resip/stack/SipMessage.hxx    (revision 101)
+++ resip/stack/SipMessage.hxx    (working copy)
@@ -226,7 +226,7 @@
       defineHeader(UserAgent, "User-Agent", StringCategory, "RFC 3261");
      
       // Added by xutm on 2009.11.13 for sending file
-      //defineHeader(TransType, "TransType", StringCategory, "RFC 3261");
+      defineHeader(TransIPPort, "TransIPPort", StringCategory, "RFC 3261");
 
       defineHeader(Timestamp, "Timestamp", StringCategory, "RFC 3261");
 
Index: resip/stack/Headers.cxx
===================================================================
--- resip/stack/Headers.cxx    (revision 101)
+++ resip/stack/Headers.cxx    (working copy)
@@ -225,7 +225,7 @@
 defineHeader(UserAgent, "User-Agent", StringCategory, "RFC 3261");
 
 // Added by xutm on 2009.11.13 for sending file
-//defineHeader(TransType, "TransType", StringCategory, "RFC 3261");
+defineHeader(TransIPPort, "TransIPPort", StringCategory, "RFC 3261");
 
 defineHeader(Timestamp, "Timestamp", StringCategory, "RFC 3261");
 
Index: resip/stack/SipMessage.cxx
===================================================================
--- resip/stack/SipMessage.cxx    (revision 101)
+++ resip/stack/SipMessage.cxx    (working copy)
@@ -1435,7 +1435,7 @@
 defineHeader(UserAgent, "User-Agent", StringCategory, "RFC 3261");
 
 // Added by xutm on 2009.11.13 for sending file
-//defineHeader(TransType, "TransType", StringCategory, "RFC 3261");
+defineHeader(TransIPPort, "TransIPPort", StringCategory, "RFC 3261");
 
 defineHeader(Timestamp, "Timestamp", StringCategory, "RFC 3261");

 

 


你可能感兴趣的:(reSIProcate)