예제 #1
0
char *
fbs_schema_parse(ngx_pool_t *pool, ngx_str_t schema)
{
    u_char last_char;
    u_char* last;
    
    last = schema.data + schema.len;
    last_char = *last;
    *last = '\0';
    
    // clear structs
    parser.structs_.vec.clear();
    parser.structs_.dict.clear();
    // clear enums
    parser.enums_.vec.clear();
    parser.enums_.dict.clear();
    
    if (!parser.Parse((char*)schema.data, "schema/"))
    {
        *last = last_char;
        //ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, jsongen.c_str());
        return (char*)parser.error_.c_str();
    }
    
    *last = last_char;
    
    return NGX_CONF_OK;
}
예제 #2
0
파일: flatc.cpp 프로젝트: EFLql/flatbuffers
static void ParseFile(flatbuffers::Parser &parser, const std::string &filename,
                      const std::string &contents,
                      std::vector<const char *> &include_directories) {
  auto local_include_directory = flatbuffers::StripFileName(filename);
  include_directories.push_back(local_include_directory.c_str());
  include_directories.push_back(nullptr);
  if (!parser.Parse(contents.c_str(), &include_directories[0],
                     filename.c_str()))
    Error(parser.error_, false, false);
  include_directories.pop_back();
  include_directories.pop_back();
}
예제 #3
0
ngx_int_t
fbs_json_parse(ngx_http_request_t *r, 
        ngx_str_t *res, ngx_http_variable_value_t *v, ngx_http_fbs_conf_t *conf)
{
    ngx_int_t rc;
    u_char last_char;
    u_char* last;
    u_char* buf = nullptr;
    size_t len = 0;
    
    if (!parser.SetRootType((const char*)v->data))
    {
        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "Unknown root_type: %s", v->data);
        return NGX_OK;
    }
    
    if (parser.root_struct_def->fixed)
    {
        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "Non-table root_type: %s", v->data);
        return NGX_OK;
    }
    
    rc = get_body(r, res, &buf, &len);
    if (rc != NGX_OK)
        return rc;
    
    if (len == 0 || *buf != '{')
    {
        //ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "empty body");
        return NGX_OK;
    }
    
    /* ================================================== */
    
    // temporary null delim
    last = buf + len;
    last_char = *last;
    *last = '\0';
    
    if (parser.ParseJson((char*)buf))
    {
        // restore
        *last = last_char;
        
        // TODO allocate ngx_palloc and copy?
        res->data = parser.builder_.GetBufferPointer();
        res->len = parser.builder_.GetSize();
        //ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "success: %d %s %s", len, v->data, buf);
    }
    else
    {
        // restore
        *last = last_char;
        
        res->data = nullptr;
        res->len = 0;
        //ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "fail: %d %s %s %s", len, v->data, parser.error_.c_str(), buf);
    }
    
    return NGX_OK;
}