]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Get rid of AppLayerHtpRegisterExtraCallbacks
authorEric Leblond <eric@regit.org>
Wed, 15 Aug 2012 12:04:03 +0000 (14:04 +0200)
committerEric Leblond <eric@regit.org>
Mon, 27 Aug 2012 14:07:21 +0000 (16:07 +0200)
This patch add a early exit condition to the body handling callback.
This permits to avoid to avoid a complex system to handle htp
object change.

src/app-layer-htp.c
src/app-layer-htp.h
src/suricata.c

index 6ea25eb0bebb16d1243f4016f99c5859db52b8f0..5b8dfc5f24bd5333bc3054c5250bcc34624ad756 100644 (file)
@@ -1779,6 +1779,9 @@ int HTPCallbackRequestBodyData(htp_tx_data_t *d)
 {
     SCEnter();
 
+    if (need_htp_request_body == 0)
+        SCReturnInt(HOOK_OK);
+
 #ifdef PRINT
     printf("HTPBODY START: \n");
     PrintRawDataFp(stdout, (uint8_t *)d->data, d->len);
@@ -1899,6 +1902,9 @@ int HTPCallbackResponseBodyData(htp_tx_data_t *d)
 {
     SCEnter();
 
+    if (need_htp_response_body == 0)
+        SCReturnInt(HOOK_OK);
+
     HtpState *hstate = (HtpState *)d->tx->connp->user_data;
     if (hstate == NULL) {
         SCReturnInt(HOOK_ERROR);
@@ -2135,6 +2141,10 @@ static void HTPConfigure(void)
             HTPCallbackRequestUriNormalizeQuery);
 #endif
     htp_config_set_generate_request_uri_normalized(cfglist.cfg, 1);
+    htp_config_register_request_body_data(cfglist.cfg,
+                                          HTPCallbackRequestBodyData);
+    htp_config_register_response_body_data(cfglist.cfg,
+                                           HTPCallbackResponseBodyData);
 
     default_config = ConfGetNode("libhtp.default-config");
     if (NULL != default_config) {
@@ -2275,6 +2285,10 @@ static void HTPConfigure(void)
             htprec->response_body_limit = HTP_CONFIG_DEFAULT_REQUEST_BODY_LIMIT;
             htp_config_register_request(htp, HTPCallbackRequest);
             htp_config_register_response(htp, HTPCallbackResponse);
+            htp_config_register_request_body_data(htp,
+                                                  HTPCallbackRequestBodyData);
+            htp_config_register_response_body_data(htp,
+                                                   HTPCallbackResponseBodyData);
 #ifdef HAVE_HTP_URI_NORMALIZE_HOOK
             htp_config_register_request_uri_normalize(htp,
                     HTPCallbackRequestUriNormalizeQuery);
@@ -2475,34 +2489,6 @@ void RegisterHTPParsers(void)
     SCReturn;
 }
 
-/**
- * \brief This function is called at the end of SigLoadSignatures.  This function
- *        enables the htp layer to register a callback for the http request body.
- *        need_htp_request_body is a flag that informs the htp app layer that
- *        a module in the engine needs the http request body.
- */
-void AppLayerHtpRegisterExtraCallbacks(void) {
-    SCEnter();
-    SCLogDebug("Registering extra htp callbacks");
-
-    HTPCfgRec *p_cfglist = &cfglist;
-    while (p_cfglist != NULL) {
-        if (need_htp_request_body == 1) {
-            SCLogDebug("Registering callback htp_config_register_request_body_data on htp");
-            htp_config_register_request_body_data(p_cfglist->cfg,
-                                                  HTPCallbackRequestBodyData);
-        }
-        if (need_htp_response_body == 1) {
-            SCLogDebug("Registering callback htp_config_register_response_body_data on htp");
-            htp_config_register_response_body_data(p_cfglist->cfg,
-                                                   HTPCallbackResponseBodyData);
-        }
-        p_cfglist = p_cfglist->next;
-    }
-    SCReturn;
-}
-
-
 #ifdef UNITTESTS
 static HTPCfgRec cfglist_backup;
 
index 52bdab623d16652d1e3b9d334d45b5d1f77f0174..38a6413db22d7c0488cccc93035252d2eb7bf79a 100644 (file)
@@ -224,7 +224,6 @@ int HTPCallbackRequestBodyData(htp_tx_data_t *);
 int HtpTransactionGetLoggableId(Flow *);
 void HtpBodyPrint(HtpBody *);
 void HtpBodyFree(HtpBody *);
-void AppLayerHtpRegisterExtraCallbacks(void);
 /* To free the state from unittests using app-layer-htp */
 void HTPStateFree(void *);
 void AppLayerHtpEnableRequestBodyCallback(void);
index 7b8ee220a5ba7ab24c20bec224e0792167c07ca1..13fa3d39d6e3c6349c701342b1e518fb6d36fb76 100644 (file)
@@ -1542,7 +1542,6 @@ int main(int argc, char **argv)
 
         AppLayerHtpEnableRequestBodyCallback();
         AppLayerHtpNeedFileInspection();
-        AppLayerHtpRegisterExtraCallbacks();
 
         UtInitialize();
         UTHRegisterTests();
@@ -1786,7 +1785,6 @@ int main(int argc, char **argv)
     SCCudaPBSetUpQueuesAndBuffers();
 #endif /* __SC_CUDA_SUPPORT__ */
 
-    AppLayerHtpRegisterExtraCallbacks();
     SCThresholdConfInitContext(de_ctx,NULL);
     SCAsn1LoadConfig();