<commit_before>#include <stdio.h>

#include <iostream>
#include <sstream>

#include "classad/classad_distribution.h"
#include "classad/fnCall.h"

#include <rest/rest-proxy.h>
#include <rest/rest-xml-parser.h>

using namespace std;
#ifdef WANT_CLASSAD_NAMESPACE
using namespace classad;
#endif

#define print_value(fp, val) _print_value(fp, val, #val)
#define print_type(fp, val) _print_type(fp, val, #val)

static void _print_type(FILE *fp, Value val, const char *name)
{
  fprintf(fp, "%s type is: ", name);

  switch(val.GetType()) {
  case Value::NULL_VALUE:
    fprintf(fp, "NULL");
    break;
  case Value::ERROR_VALUE:
    fprintf(fp, "Error");
    break;
  case Value::UNDEFINED_VALUE:
    fprintf(fp, "Undefined");
    break;
  case Value::BOOLEAN_VALUE:
    fprintf(fp, "Boolean");
    break;
  case Value::INTEGER_VALUE:
    fprintf(fp, "Integer");
    break;
  case Value::REAL_VALUE:
    fprintf(fp, "Real");
    break;
  case Value::LIST_VALUE:
    fprintf(fp, "List");
    break;
  case Value::CLASSAD_VALUE:
    fprintf(fp, "Classad");
    break;
  case Value::RELATIVE_TIME_VALUE:
    fprintf(fp, "RelativeTime");
    break;
  case Value::ABSOLUTE_TIME_VALUE:
    fprintf(fp, "AbsoluteTime");
    break;
  case Value::STRING_VALUE:
    fprintf(fp, "String");
    break;
  }

  fprintf(fp, "\n");
}

static void _print_value(FILE *fp, Value val, const char *name)
{
  /* AFAICT the only way to get at the string in a 'Value' object is to use
   * the C++ stream operator <<,  so we set up a stringstream and write
   * stuff we want into that..
   */
  std::stringstream sstr;

  sstr << name << " is " << val;
  fprintf(fp, "%s\n", sstr.str().c_str());
}

static RestXmlNode *
get_xml (RestProxyCall *call)
{
  RestXmlParser *parser;
  RestXmlNode *root;
  GError *error = NULL;

  parser = rest_xml_parser_new();

  root = rest_xml_parser_parse_from_data(parser,
					 rest_proxy_call_get_payload(call),
					 rest_proxy_call_get_payload_length(call));

  g_object_unref(call);
  g_object_unref(parser);

  return root;
}


/*
 * Perform our quota check against the Aeolus Conductor database.
 * This function expects:
 *
 * - Instance executable name as handed to condor so that we can map to the
 *   instance found in the database.
 * - The username
 * - The provider url so we can map back to the provider.
 * - The realm key so we know what realm this is in.
 *
 * ... at least for now.  Need to better analyze what is required to do all
 * the quota matching but that's the idea.
 */
bool
conductor_quota_check(const char *name, const ArgumentList &arglist,
		      EvalState &state, Value &result)
{
  Value instance_id;
  Value account_id;
  FILE *fp;
  bool val = false;
  RestProxy *proxy;
  RestProxyCall *call;
  RestXmlNode *root;
  std::stringstream rest_call;
  GError *err = NULL;<commit_msg>Update the comments in the classad plugin.<commit_after>#include <stdio.h>

#include <iostream>
#include <sstream>

#include "classad/classad_distribution.h"
#include "classad/fnCall.h"

#include <rest/rest-proxy.h>
#include <rest/rest-xml-parser.h>

using namespace std;
#ifdef WANT_CLASSAD_NAMESPACE
using namespace classad;
#endif

#define print_value(fp, val) _print_value(fp, val, #val)
#define print_type(fp, val) _print_type(fp, val, #val)

static void _print_type(FILE *fp, Value val, const char *name)
{
  fprintf(fp, "%s type is: ", name);

  switch(val.GetType()) {
  case Value::NULL_VALUE:
    fprintf(fp, "NULL");
    break;
  case Value::ERROR_VALUE:
    fprintf(fp, "Error");
    break;
  case Value::UNDEFINED_VALUE:
    fprintf(fp, "Undefined");
    break;
  case Value::BOOLEAN_VALUE:
    fprintf(fp, "Boolean");
    break;
  case Value::INTEGER_VALUE:
    fprintf(fp, "Integer");
    break;
  case Value::REAL_VALUE:
    fprintf(fp, "Real");
    break;
  case Value::LIST_VALUE:
    fprintf(fp, "List");
    break;
  case Value::CLASSAD_VALUE:
    fprintf(fp, "Classad");
    break;
  case Value::RELATIVE_TIME_VALUE:
    fprintf(fp, "RelativeTime");
    break;
  case Value::ABSOLUTE_TIME_VALUE:
    fprintf(fp, "AbsoluteTime");
    break;
  case Value::STRING_VALUE:
    fprintf(fp, "String");
    break;
  }

  fprintf(fp, "\n");
}

static void _print_value(FILE *fp, Value val, const char *name)
{
  /* AFAICT the only way to get at the string in a 'Value' object is to use
   * the C++ stream operator <<,  so we set up a stringstream and write
   * stuff we want into that..
   */
  std::stringstream sstr;

  sstr << name << " is " << val;
  fprintf(fp, "%s\n", sstr.str().c_str());
}

static RestXmlNode *
get_xml (RestProxyCall *call)
{
  RestXmlParser *parser;
  RestXmlNode *root;
  GError *error = NULL;

  parser = rest_xml_parser_new();

  root = rest_xml_parser_parse_from_data(parser,
					 rest_proxy_call_get_payload(call),
					 rest_proxy_call_get_payload_length(call));

  g_object_unref(call);
  g_object_unref(parser);

  return root;
}


/*
 * Perform our quota check against the Aeolus Conductor database.
 * The arglist to this function is expected to contain:
 *
 * - Instance ID as handed to condor so that we can map to the instance found
 *   in the database.
 * - Account ID of the user that wants to launch the instance so we can check
 *   the quota.
 */
bool
conductor_quota_check(const char *name, const ArgumentList &arglist,
		      EvalState &state, Value &result)
{
  Value instance_id;
  Value account_id;
  FILE *fp;
  bool val = false;
  RestProxy *proxy;
  RestProxyCall *call;
  RestXmlNode *root;
  std::stringstream rest_call;
  GError *err = NULL;
{'fraction_non_alphanumeric': 0.12096046217728831, 'fraction_numerical': 0.0, 'mean_word_length': 3.846894138232721, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '4221992', 'n_tokens_mistral': 1953, 'n_tokens_neox': 1923, 'n_words': 556}