mcast_comm::quote_message_ptr 
    mcast_comm::quote_messages_processor::parse_message(const std::string& m)
{
  quote_messages_processor* parser = get_parser(m);
  if (parser != NULL)
    return parser->do_parsing(m);
  return quote_message_ptr();
}
Exemple #2
0
int ds_parse(demux_stream_t *ds, uint8_t **buffer, int *len, double pts, off_t pos)
{
    AVCodecContext *avctx;
    AVCodecParserContext *parser;
    get_parser(ds->sh, &avctx, &parser);
    if (!parser)
        return *len;
    return av_parser_parse2(parser, avctx, buffer, len, *buffer, *len, pts, pts, pos);
}
/*-----------------------------------------------------------------------------------------------------------------------*/
static ERL_NIF_TERM get_version(ErlNifEnv* env, int32_t argc, ERL_NIF_TERM const argv[])
{
   ERL_NIF_TERM pres;
   ParserRes* parser = NULL;
   ERL_NIF_TERM res = get_parser(env, argv[0], &pres, &parser);
   if (res != ok_atom)
   {
      return res;
   }
   char const* ver = fix_parser_get_protocol_ver(parser->ptr);
   return enif_make_string(env, ver, ERL_NIF_LATIN1);
}
Exemple #4
0
// TODO support initialising with a file object or a string.
static int
Preprocessor_init(Preprocessor *self, PyObject *args, PyObject *kwds)
{
    if (!PyArg_ParseTuple(args, "O", &self->parser))
        return -1;

    if (!PyObject_TypeCheck(self->parser, get_parser_type()))
    {
        PyErr_SetString(PyExc_TypeError, "expected Parser as argument");
        return -1;
    }

    Py_INCREF(self->parser);
    self->preprocessor = &get_parser(self->parser).getPreprocessor();
    return 0;
}
/*-----------------------------------------------------------------------------------------------------------------------*/
static ERL_NIF_TERM binary_to_msg(ErlNifEnv* env, int32_t argc, ERL_NIF_TERM const argv[])
{
   ERL_NIF_TERM parser_res;
   ParserRes* parser = NULL;
   ERL_NIF_TERM res = get_parser(env, argv[0], &parser_res, &parser);
   if (res != ok_atom)
   {
      return res;
   }
   int32_t delimiter = 0;
   if (!enif_get_int(env, argv[1], &delimiter) || delimiter <= 0 || delimiter >= 255)
   {
      return make_error(env, FIX_FAILED, "Wrong delimiter.");
   }
   ErlNifBinary bin;
   if (!enif_inspect_binary(env, argv[2], &bin))
   {
      return make_error(env, FIX_FAILED, "Wrong binary.");
   }
   char const* stop = NULL;
   FIXError* error = NULL;
   pthread_rwlock_wrlock(&parser->lock);
   FIXMsg* fix_msg = fix_parser_str_to_msg(parser->ptr, (char const*)bin.data, bin.size, delimiter, &stop, &error);
   pthread_rwlock_unlock(&parser->lock);
   if (!fix_msg)
   {
      ERL_NIF_TERM ret = make_parser_error(env, fix_error_get_code(error), fix_error_get_text(error));
      fix_error_free(error);
      return ret;
   }
   MsgRes* msg_res = (MsgRes*)enif_alloc_resource(message_res, sizeof(MsgRes));
   msg_res->msg = fix_msg;
   msg_res->lock = &parser->lock;
   ERL_NIF_TERM msg_term = enif_make_resource(env, msg_res);
   enif_release_resource(msg_res);
   uint32_t pos = stop - (char const*)bin.data + 1;
   char const* msgType = fix_msg_get_type(fix_msg);
   return enif_make_tuple3(
         env,
         ok_atom,
         enif_make_tuple3(env,
            msg_atom,
            enif_make_string(env, msgType, ERL_NIF_LATIN1),
            enif_make_tuple2(env, parser_res, msg_term)),
         enif_make_sub_binary(env, argv[2], pos, bin.size - pos));
}
/*-----------------------------------------------------------------------------------------------------------------------*/
static ERL_NIF_TERM create_msg(ErlNifEnv* env, int32_t argc, ERL_NIF_TERM const argv[])
{
   ERL_NIF_TERM pres;
   ParserRes* parser = NULL;
   ERL_NIF_TERM res = get_parser(env, argv[0], &pres, &parser);
   if (res != ok_atom)
   {
      return res;
   }
   char msgType[12] = {};
   if (enif_get_string(env, argv[1], msgType, sizeof(msgType), ERL_NIF_LATIN1) <= 0)
   {
      return make_error(env, FIX_FAILED, "Wrong msgType.");
   }
   FIXError* error = NULL;
   pthread_rwlock_wrlock(&parser->lock);
   FIXMsg* msg = fix_msg_create(parser->ptr, msgType, &error);
   pthread_rwlock_unlock(&parser->lock);
   if (!msg)
   {
      ERL_NIF_TERM ret = make_parser_error(env, fix_error_get_code(error), fix_error_get_text(error));
      fix_error_free(error);
      return ret;
   }
   MsgRes* msg_res = (MsgRes*)enif_alloc_resource(message_res, sizeof(MsgRes));
   msg_res->msg = msg;
   msg_res->lock = &parser->lock;
   ERL_NIF_TERM msg_term = enif_make_resource(env, msg_res);
   enif_release_resource(msg_res);
   return enif_make_tuple2(
         env,
         ok_atom,
         enif_make_tuple3(env,
            msg_atom,
            enif_make_string(env, msgType, ERL_NIF_LATIN1),
            enif_make_tuple2(env, pres, msg_term)));
}
Exemple #7
0
bool udpipe_service::handle_rest_process(microrestd::rest_request& req) {
  string error;
  auto rest_id = get_rest_model_id(req);
  auto model = load_rest_model(rest_id, error);
  if (!model) return req.respond_error(error);

  auto& data = get_data(req, error); if (!error.empty()) return req.respond_error(error);
  bool tokenizer = false;
  unique_ptr<input_format> input(get_input_format(req, model, tokenizer, error)); if (!input) return req.respond_error(error);
  auto& tagger = get_tagger(req, model, error); if (!error.empty()) return req.respond_error(error);
  auto& parser = get_parser(req, model, error); if (!error.empty()) return req.respond_error(error);
  unique_ptr<output_format> output(get_output_format(req, error)); if (!output) return req.respond_error(error);

  // Try loading the input if tokenizer is not used
  if (!tokenizer) {
    input->set_text(data);
    sentence s;
    while (input->next_sentence(s, error)) {}
    if (!error.empty())
      return req.respond_error(error.insert(0, "Cannot read input data: ").append("\n"));
  }

  input->set_text(data);
  class generator : public rest_response_generator {
   public:
    generator(const model_info* model, input_format* input, const string& tagger, const string& parser, output_format* output)
        : rest_response_generator(model), input(input), tagger(tagger), parser(parser), output(output) {}

    bool generate() {
      if (!input->next_sentence(s, error)) {
        output->finish_document(os);
        json.value(os.str(), true);
        os.str(string());

        json.finish(true);

        return false;
      }

      if (tagger != "none")
        model->model->tag(s, tagger, error);
      if (parser != "none")
        model->model->parse(s, parser, error);

      output->write_sentence(s, os);
      json.value(os.str(), true);
      os.str(string());

      return true;
    }

   private:
    sentence s;
    string error;
    ostringstream os;
    unique_ptr<input_format> input;
    const string& tagger;
    const string& parser;
    unique_ptr<output_format> output;
  };
  return req.respond(generator::mime, new generator(model, input.release(), tagger, parser, output.release()));
}
Exemple #8
0
bool Elf::verify_symbols()
{
  return get_parser().verify_symbols();
}
Exemple #9
0
safe_func_offset Elf::safe_resolve_symbol(void* addr, char* buffer, size_t length)
{
  return get_parser().getsym_safe((ElfAddr) addr, buffer, length);
}
Exemple #10
0
uintptr_t Elf::resolve_addr(void* addr)
{
  auto* sym = get_parser().getaddr((uintptr_t) addr);
  if (sym) return sym->st_value;
  return (uintptr_t) addr;
}
Exemple #11
0
const char* Elf::get_strtab() {
  return get_parser().get_strtab();
}
Exemple #12
0
size_t Elf::end_of_file() {
  return get_parser().end_of_file();
}