<commit_before>/*
 * JSON web bridge for PMAPI.
 *
 * Copyright (c) 2011-2013 Red Hat Inc.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 */

#include "pmwebapi.h"

/* ------------------------------------------------------------------------ */

char *pmnsfile = NULL;         /* set by -n option */
char *uriprefix = "/pmapi";    /* overridden by -a option */
char *resourcedir = NULL;      /* set by -r option */
unsigned verbosity = 0;        /* set by -v option */
unsigned maxtimeout = 300;     /* set by -t option */
unsigned exit_p;               /* counted by SIG* handler */


/* Respond to a new incoming HTTP request.  It may be
   one of three general categories:
   (a) creation of a new PMAPI context: do it
   (b) operation an existing context: do it
   (c) access to some non-API URI: serve it from $resourcedir/ if configured.
*/
int mhd_respond (void *cls, struct MHD_Connection *connection,
                 const char *url,
                 const char *method, const char *version,
                 const char *upload_data,
                 size_t *upload_data_size, void **con_cls)
{
  static int dummy;

  /* MHD calls us at least twice per request.  Skip the first one,
     since it only gives us headers, and not any POST content. */
  if (& dummy != *con_cls) {
    *con_cls = &dummy;
    return MHD_YES;
  }
  *con_cls = NULL;

  if (verbosity > 1)
    pmweb_notify (LOG_INFO, connection, "%s %s %s", version, method, url);

  /* Determine whether request is a pmapi or a resource call. */
  if (0 == strncmp(url, uriprefix, strlen(uriprefix)))
    return pmwebapi_respond (cls, connection,
                             & url[strlen(uriprefix)+1], /* strip prefix */
                             method, upload_data, upload_data_size);

  else if (0 == strcmp(method, "GET") && resourcedir != NULL)
    return pmwebres_respond (cls, connection, url);

  return MHD_NO;<commit_msg>pmwebapi: print url arguments with verbosity 3<commit_after>/*
 * JSON web bridge for PMAPI.
 *
 * Copyright (c) 2011-2013 Red Hat Inc.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 */

#include "pmwebapi.h"

/* ------------------------------------------------------------------------ */

char *pmnsfile = NULL;         /* set by -n option */
char *uriprefix = "/pmapi";    /* overridden by -a option */
char *resourcedir = NULL;      /* set by -r option */
unsigned verbosity = 0;        /* set by -v option */
unsigned maxtimeout = 300;     /* set by -t option */
unsigned exit_p;               /* counted by SIG* handler */



static int mhd_log_args (void *connection, enum MHD_ValueKind kind, 
                         const char *key, const char *value)
{
  (void) kind;
  pmweb_notify (LOG_DEBUG, connection, "%s:%s", key, value);
  return MHD_YES;
}



/* Respond to a new incoming HTTP request.  It may be
   one of three general categories:
   (a) creation of a new PMAPI context: do it
   (b) operation an existing context: do it
   (c) access to some non-API URI: serve it from $resourcedir/ if configured.
*/
int mhd_respond (void *cls, struct MHD_Connection *connection,
                 const char *url,
                 const char *method, const char *version,
                 const char *upload_data,
                 size_t *upload_data_size, void **con_cls)
{
  static int dummy;

  /* MHD calls us at least twice per request.  Skip the first one,
     since it only gives us headers, and not any POST content. */
  if (& dummy != *con_cls) {
    *con_cls = &dummy;
    return MHD_YES;
  }
  *con_cls = NULL;

  if (verbosity > 1)
    pmweb_notify (LOG_INFO, connection, "%s %s %s", version, method, url);
  if (verbosity > 2) /* Print arguments too. */
    (void) MHD_get_connection_values (connection, MHD_GET_ARGUMENT_KIND,
                                      &mhd_log_args, connection);

  /* Determine whether request is a pmapi or a resource call. */
  if (0 == strncmp(url, uriprefix, strlen(uriprefix)))
    return pmwebapi_respond (cls, connection,
                             & url[strlen(uriprefix)+1], /* strip prefix */
                             method, upload_data, upload_data_size);

  else if (0 == strcmp(method, "GET") && resourcedir != NULL)
    return pmwebres_respond (cls, connection, url);

  return MHD_NO;
{'fraction_non_alphanumeric': 0.11745805069617994, 'fraction_numerical': 0.011424491253123885, 'mean_word_length': 2.4227244960293217, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6845201', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1568, 'n_words': 681}