Skip to content

Commit

Permalink
Expose response_decompression option to htpy
Browse files Browse the repository at this point in the history
  • Loading branch information
Mraoul committed Apr 5, 2018
1 parent d4feff3 commit 846bc37
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ alter the parser in odd ways.
* htpy.HTP_LOG_DEBUG (5)
* htpy.HTP_LOG_DEBUG2 (6)
* tx_auto_destroy: Automatically destroy transactions when done.
* response_decompression: Determine whether response bodies are
automatically decompressed. Default value is 1 which is enabled.
To disable automatic decompression set this to 0.

Connection parser object
------------------------
Expand Down
41 changes: 32 additions & 9 deletions htpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "htp.h"
#include "htp_private.h"

#define HTPY_VERSION "0.25"
#define HTPY_VERSION "0.25.1"

static PyObject *htpy_error;
static PyObject *htpy_stop;
Expand Down Expand Up @@ -97,6 +97,23 @@ static PyObject *htpy_config_get_##ATTR(htpy_config *self, void *closure) { \
CONFIG_GET(log_level)
CONFIG_GET(tx_auto_destroy)

/**
* To get the response decompression setting there is an int
* in the config called "response_decompression_enabled". Unfortunately
* this doesn't fit with the above macro and so instead the following
* function takes care of getting the value.
*/

static PyObject *htpy_config_get_response_decompression(htpy_config *self, void *closure) {
PyObject *ret;
ret = Py_BuildValue("i", self->cfg->response_decompression_enabled);
if (!ret) {
PyErr_SetString(htpy_error, "Unable to get this attribute.");
return NULL;
}
return(ret);
}

#define CONFIG_SET(ATTR) \
static int htpy_config_set_##ATTR(htpy_config *self, PyObject *value, void *closure) { \
int v; \
Expand All @@ -114,6 +131,7 @@ static int htpy_config_set_##ATTR(htpy_config *self, PyObject *value, void *clos
}

CONFIG_SET(tx_auto_destroy)
CONFIG_SET(response_decompression)

/*
* Sadly the log level is not exposed like others. Only way to set it
Expand Down Expand Up @@ -142,14 +160,19 @@ static int htpy_config_set_log_level(htpy_config *self, PyObject *value, void *c
}

static PyGetSetDef htpy_config_getseters[] = {
{ "log_level", (getter) htpy_config_get_log_level,
(setter) htpy_config_set_log_level,
"Logs with a level less than this will be ignored.", NULL },
{ "tx_auto_destroy",
(getter) htpy_config_get_tx_auto_destroy,
(setter) htpy_config_set_tx_auto_destroy,
"Automatically destroy transactions", NULL },
{ NULL }
{"log_level",
(getter) htpy_config_get_log_level,
(setter) htpy_config_set_log_level,
"Logs with a level less than this will be ignored.", NULL},
{"tx_auto_destroy",
(getter) htpy_config_get_tx_auto_destroy,
(setter) htpy_config_set_tx_auto_destroy,
"Automatically destroy transactions", NULL},
{"response_decompression",
(getter) htpy_config_get_response_decompression,
(setter) htpy_config_set_response_decompression,
"Enable response decompression", NULL},
{NULL}
};

static PyMemberDef htpy_config_members[] = {
Expand Down
18 changes: 7 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,16 @@ def run(self):

setup (# Distribution meta-data
name = "htpy",
version = "0.25",
version = "0.25.1",
description = "python bindings for libhtp",
author = "Wesley Shields",
author_email = "wxs@atarininja.org",
license = "BSD",
long_description = "Python bindings for libhtp",
cmdclass = {'build': htpyMaker},
ext_modules = [ Extension(
"htpy",
sources=["htpy.c"],
include_dirs = INCLUDE_DIRS,
library_dirs = LIBRARY_DIRS,
extra_objects = EXTRA_OBJECTS
)
],
url = "http://github.com/MITRECND/htpy",
)
ext_modules = [Extension("htpy",
sources=["htpy.c"],
include_dirs = INCLUDE_DIRS,
library_dirs = LIBRARY_DIRS,
extra_objects = EXTRA_OBJECTS)],
url = "http://github.com/MITRECND/htpy")

0 comments on commit 846bc37

Please sign in to comment.