<commit_before>/**
 *
 * libinjection module for python
 *
 * Copyright 2012,2013  <NAME>
 * <EMAIL>
 * BSD License -- see COPYING.txt for details
 *
 */
#include <Python.h>
#include "sqlparse.h"
#include "sqli_fingerprints.h"

static PyObject *
libinjection_detectsqli(PyObject *self, PyObject *args)
{
    const char *userinput;
    int len;
    PyObject* dict = NULL;
    PyObject* value;
    int sqli;
    sfilter sf;

    if (!PyArg_ParseTuple(args, "s#|O!", &userinput, &len, &PyDict_Type, &dict))
        return NULL;

    sqli = is_sqli(&sf, userinput, len, is_sqli_pattern);

    if (dict) {
        value = Py_BuildValue("s", sf.pat);
        PyDict_SetItemString(dict, "fingerprint", value);
    }

    if (sqli) {
        Py_RETURN_TRUE;
    } else {
        Py_RETURN_FALSE;
    }
}

static PyMethodDef libinjectionMethods[] = {
    {"detectsqli",  libinjection_detectsqli, METH_VARARGS,
     "Use libinjection to detect sqli from user input."},
    {NULL, NULL, 0, NULL}        /* Sentinel */
};

PyMODINIT_FUNC
initlibinjection(void)
{
    (void) Py_InitModule("libinjection", libinjectionMethods);
}<commit_msg>add __version__ to python extention<commit_after>/**
 *
 * libinjection module for python
 *
 * Copyright 2012,2013  <NAME>
 * <EMAIL>
 * BSD License -- see COPYING.txt for details
 *
 */
#include <Python.h>
#include "sqlparse.h"
#include "sqli_fingerprints.h"

static PyObject *
libinjection_detectsqli(PyObject *self, PyObject *args)
{
    const char *userinput;
    int len;
    PyObject* dict = NULL;
    PyObject* value;
    int sqli;
    sfilter sf;

    if (!PyArg_ParseTuple(args, "s#|O!", &userinput, &len, &PyDict_Type, &dict))
        return NULL;

    sqli = is_sqli(&sf, userinput, len, is_sqli_pattern);

    if (dict) {
        value = Py_BuildValue("s", sf.pat);
        PyDict_SetItemString(dict, "fingerprint", value);
    }

    if (sqli) {
        Py_RETURN_TRUE;
    } else {
        Py_RETURN_FALSE;
    }
}

static PyMethodDef libinjectionMethods[] = {
    {"detectsqli",  libinjection_detectsqli, METH_VARARGS,
     "Use libinjection to detect sqli from user input."},
    {NULL, NULL, 0, NULL}        /* Sentinel */
};

PyMODINIT_FUNC
initlibinjection(void)
{
    PyObject* version;
    PyObject* m = Py_InitModule("libinjection", libinjectionMethods);
    if (m == NULL) {
        return;
    }

    /* PEP 396 - __version__
     * http://www.python.org/dev/peps/pep-0396/
     */
    version = Py_BuildValue("s", LIBINJECTION_VERSION);
    if (version == NULL) {
        return;
    }
    PyModule_AddObject(m, "__version__", version);
}
{'fraction_non_alphanumeric': 0.130451563103049, 'fraction_numerical': 0.0096487842531841, 'mean_word_length': 3.0690737833594977, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6682627', 'n_tokens_mistral': 940, 'n_tokens_neox': 895, 'n_words': 209}