<commit_before>/* global process, global, GLOBAL */
var connect = require('connect'),
    log4js = require('log4js'),
    logger = log4js.getLogger();

var cluster = require('cluster');
var argv = process.argv.slice(2);

if (argv.indexOf('--debug') >= 0) {
    logger.setLevel('DEBUG');
    global.debug = true;
} else {
    logger.setLevel('INFO');
}

if (argv.indexOf('--project') >= 0) {
    GLOBAL.pjconfig = require('./project.debug.json');
} else {
    GLOBAL.pjconfig = require('./project.json');
}

if (cluster.isMaster) {

    var clusters = [];
    // Fork workers.
    for (var i = 0; i < 4; i++) {
        var forkCluster = cluster.fork();
        clusters.push(forkCluster);
    }

    setTimeout(function() {
        require('./service/ProjectService')(clusters);
    }, 1000);

    return;
}

var interceptor = require('c-interceptor')();
var interceptors = GLOBAL.pjconfig.interceptors;

interceptors.forEach(function(value, key) {
    var one = require(value)();
    interceptor.add(one);
});
interceptor.add(require(GLOBAL.pjconfig.dispatcher.module)());

var forbiddenData = '403 forbidden';

global.projectsId = '';

process.on('message', function(data) {
    var json = data;
    if (json.projectsId) {
        global.projectsId = json.projectsId;
    }
});

connect()
    .use('/badjs', connect.query())
    .use('/badjs', function(req, res) {

        logger.debug('===== get a message =====');

        var responseHeader = {
            'Access-Control-Allow-Origin': '*',
            'Content-Type': 'image/jpeg',
            'Connection': 'close'
        };

        var id = req.query.id - 0;
        if (isNaN(id) ||
            id <= 0 ||
            id >= 9999 ||
            global.projectsId.split('_').indexOf(id) < 0) {

            responseHeader['Content-length'] = forbiddenData.length;
            res.writeHead(403, responseHeader);
            res.write(forbiddenData);
            logger.debug('forbidden :' + req.query.id);
            res.end();
            return;
        }

        req.query.id = id;

        try {
            interceptor.invoke({
                req: req,
                data: req.query
            });
        } catch (err) {
            responseHeader['Content-length'] = forbiddenData.length;
            res.writeHead(403, responseHeader);
            res.write(forbiddenData);
            logger.info('parse param  error :' + err);
            res.end();
            return;
        }

        // responseHeader end with 204
        responseHeader['Content-length'] = 0;
        res.writeHead(204, responseHeader);

        logger.debug('===== complete a message =====');
        res.end();
    })
    .listen(GLOBAL.pjconfig.port);

logger.info('start badjs-accepter , listen ' + GLOBAL.pjconfig.port + ' ...');<commit_msg>use string match<commit_after>/* global process, global, GLOBAL */
var connect = require('connect'),
    log4js = require('log4js'),
    logger = log4js.getLogger();

var cluster = require('cluster');
var argv = process.argv.slice(2);

if (argv.indexOf('--debug') >= 0) {
    logger.setLevel('DEBUG');
    global.debug = true;
} else {
    logger.setLevel('INFO');
}

if (argv.indexOf('--project') >= 0) {
    GLOBAL.pjconfig = require('./project.debug.json');
} else {
    GLOBAL.pjconfig = require('./project.json');
}

if (cluster.isMaster) {

    var clusters = [];
    // Fork workers.
    for (var i = 0; i < 4; i++) {
        var forkCluster = cluster.fork();
        clusters.push(forkCluster);
    }

    setTimeout(function() {
        require('./service/ProjectService')(clusters);
    }, 1000);

    return;
}

var interceptor = require('c-interceptor')();
var interceptors = GLOBAL.pjconfig.interceptors;

interceptors.forEach(function(value, key) {
    var one = require(value)();
    interceptor.add(one);
});
interceptor.add(require(GLOBAL.pjconfig.dispatcher.module)());

var forbiddenData = '403 forbidden';

global.projectsId = '';

process.on('message', function(data) {
    var json = data;
    if (json.projectsId) {
        global.projectsId = json.projectsId;
    }
});

connect()
    .use('/badjs', connect.query())
    .use('/badjs', function(req, res) {

        logger.debug('===== get a message =====');

        var responseHeader = {
            'Access-Control-Allow-Origin': '*',
            'Content-Type': 'image/jpeg',
            'Connection': 'close'
        };

        var id = req.query.id - 0;
        if (isNaN(id) ||
            id <= 0 ||
            id >= 9999 ||
            global.projectsId.split('_').indexOf(id+"") < 0) {

            responseHeader['Content-length'] = forbiddenData.length;
            res.writeHead(403, responseHeader);
            res.write(forbiddenData);
            logger.debug('forbidden :' + req.query.id);
            res.end();
            return;
        }

        req.query.id = id;

        try {
            interceptor.invoke({
                req: req,
                data: req.query
            });
        } catch (err) {
            responseHeader['Content-length'] = forbiddenData.length;
            res.writeHead(403, responseHeader);
            res.write(forbiddenData);
            logger.info('parse param  error :' + err);
            res.end();
            return;
        }

        // responseHeader end with 204
        responseHeader['Content-length'] = 0;
        res.writeHead(204, responseHeader);

        logger.debug('===== complete a message =====');
        res.end();
    })
    .listen(GLOBAL.pjconfig.port);

logger.info('start badjs-accepter , listen ' + GLOBAL.pjconfig.port + ' ...');
{'fraction_non_alphanumeric': 0.16666666666666666, 'fraction_numerical': 0.012504465880671669, 'mean_word_length': 2.186681844052362, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5569668', 'n_tokens_mistral': 1758, 'n_tokens_neox': 1673, 'n_words': 320}