mirror of
https://github.com/openappsec/openappsec.git
synced 2025-09-29 19:24:26 +03:00
Feb 15th 2023 update
This commit is contained in:
3
external/graphqlparser/c/.gitignore
vendored
Normal file
3
external/graphqlparser/c/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
GraphQLAst.h
|
||||
GraphQLAst.cpp
|
||||
GraphQLAstForEachConcreteType.h
|
25
external/graphqlparser/c/GraphQLAstNode.cpp
vendored
Normal file
25
external/graphqlparser/c/GraphQLAstNode.cpp
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Copyright 2019-present, GraphQL Foundation
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "GraphQLAstNode.h"
|
||||
#include "../AstNode.h"
|
||||
|
||||
using facebook::graphql::ast::Node;
|
||||
|
||||
void graphql_node_get_location(const struct GraphQLAstNode *node,
|
||||
struct GraphQLAstLocation *location) {
|
||||
const auto *realNode = reinterpret_cast<const Node *>(node);
|
||||
const auto &loc = realNode->getLocation();
|
||||
location->beginLine = loc.begin.line;
|
||||
location->beginColumn = loc.begin.column;
|
||||
location->endLine = loc.end.line;
|
||||
location->endColumn = loc.end.column;
|
||||
}
|
||||
|
||||
void graphql_node_free(struct GraphQLAstNode *node) {
|
||||
delete reinterpret_cast<Node *>(node);
|
||||
}
|
33
external/graphqlparser/c/GraphQLAstNode.h
vendored
Normal file
33
external/graphqlparser/c/GraphQLAstNode.h
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Copyright 2019-present, GraphQL Foundation
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Opaque type representing a generic AST node. */
|
||||
struct GraphQLAstNode;
|
||||
|
||||
/* A location in the AST. */
|
||||
struct GraphQLAstLocation {
|
||||
unsigned int beginLine;
|
||||
unsigned int beginColumn;
|
||||
unsigned int endLine;
|
||||
unsigned int endColumn;
|
||||
};
|
||||
|
||||
/* Fills location with location information for the given node. */
|
||||
void graphql_node_get_location(const struct GraphQLAstNode *node,
|
||||
struct GraphQLAstLocation *location);
|
||||
|
||||
void graphql_node_free(struct GraphQLAstNode *node);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
21
external/graphqlparser/c/GraphQLAstToJSON.cpp
vendored
Normal file
21
external/graphqlparser/c/GraphQLAstToJSON.cpp
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2019-present, GraphQL Foundation
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "GraphQLAstToJSON.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "../JsonVisitor.h"
|
||||
#include "../AstNode.h"
|
||||
|
||||
|
||||
const char *graphql_ast_to_json(const struct GraphQLAstNode *node)
|
||||
{
|
||||
facebook::graphql::ast::visitor::JsonVisitor visitor;
|
||||
reinterpret_cast<const facebook::graphql::ast::Node *>(node)->accept(&visitor);
|
||||
return strdup(visitor.getResult().c_str());
|
||||
}
|
24
external/graphqlparser/c/GraphQLAstToJSON.h
vendored
Normal file
24
external/graphqlparser/c/GraphQLAstToJSON.h
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright 2019-present, GraphQL Foundation
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct GraphQLAstNode;
|
||||
|
||||
/**
|
||||
* Serialize the given AST to JSON. The returned C string must be
|
||||
* freed with free().
|
||||
*/
|
||||
const char *graphql_ast_to_json(const struct GraphQLAstNode *node);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
55
external/graphqlparser/c/GraphQLAstVisitor.cpp
vendored
Normal file
55
external/graphqlparser/c/GraphQLAstVisitor.cpp
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright 2019-present, GraphQL Foundation
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "c/GraphQLAstVisitor.h"
|
||||
#include "AstVisitor.h"
|
||||
|
||||
using namespace facebook::graphql::ast; // NOLINT
|
||||
|
||||
#include "c/GraphQLAstForEachConcreteType.h"
|
||||
|
||||
#define DECLARE_VISIT(type, snake_type) \
|
||||
bool visit##type(const type &node) override; \
|
||||
void endVisit##type(const type &node) override;
|
||||
|
||||
class CVisitorBridge : public visitor::AstVisitor {
|
||||
const struct GraphQLAstVisitorCallbacks *callbacks_;
|
||||
void *userData_;
|
||||
public:
|
||||
explicit CVisitorBridge(const struct GraphQLAstVisitorCallbacks *callbacks,
|
||||
void *userData)
|
||||
: callbacks_(callbacks), userData_(userData) {}
|
||||
|
||||
FOR_EACH_CONCRETE_TYPE(DECLARE_VISIT)
|
||||
};
|
||||
|
||||
#define IMPLEMENT_VISIT(type, snake_type) \
|
||||
bool CVisitorBridge::visit##type(const type &node) { \
|
||||
if (callbacks_->visit_##snake_type) { \
|
||||
return callbacks_->visit_##snake_type( \
|
||||
(const struct GraphQLAst##type *)&node, userData_); \
|
||||
} \
|
||||
return true; \
|
||||
} \
|
||||
void CVisitorBridge::endVisit##type(const type &node) { \
|
||||
if (callbacks_->end_visit_##snake_type) { \
|
||||
callbacks_->end_visit_##snake_type( \
|
||||
(const struct GraphQLAst##type *)&node, userData_); \
|
||||
} \
|
||||
}
|
||||
|
||||
FOR_EACH_CONCRETE_TYPE(IMPLEMENT_VISIT)
|
||||
|
||||
void graphql_node_visit(const struct GraphQLAstNode *node,
|
||||
const struct GraphQLAstVisitorCallbacks *callbacks,
|
||||
void *userData)
|
||||
{
|
||||
CVisitorBridge visitor(callbacks, userData);
|
||||
if (node) {
|
||||
reinterpret_cast<const facebook::graphql::ast::Node *>(node)->accept(&visitor);
|
||||
}
|
||||
}
|
53
external/graphqlparser/c/GraphQLAstVisitor.h
vendored
Normal file
53
external/graphqlparser/c/GraphQLAstVisitor.h
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Copyright 2019-present, GraphQL Foundation
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "c/GraphQLAst.h"
|
||||
#include "c/GraphQLAstForEachConcreteType.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define TYPEDEFS(type, snake_type) \
|
||||
typedef int (*visit_##snake_type##_func)(const struct GraphQLAst##type *snake_type, void *user_data); \
|
||||
typedef void (*end_visit_##snake_type##_func)(const struct GraphQLAst##type *snake_type, void *user_data);
|
||||
|
||||
FOR_EACH_CONCRETE_TYPE(TYPEDEFS)
|
||||
|
||||
#define FUNC_MEMBER(type, snake_type) \
|
||||
visit_##snake_type##_func visit_##snake_type; \
|
||||
end_visit_##snake_type##_func end_visit_##snake_type;
|
||||
/**
|
||||
* Functions to be called when particular AST nodes are encountered.
|
||||
* visit_* functions are called in pre-order, and may return non-zero to
|
||||
* continue recursing into children (if any), or zero to skip them. end_visit_*
|
||||
* functions are called in post-order. Any particular function may be set to
|
||||
* NULL to indicate that the caller is not interested in the corresponding type
|
||||
* of AST node. (NULL visit_* functions act as though they simply returned
|
||||
* non-zero.)
|
||||
*/
|
||||
struct GraphQLAstVisitorCallbacks {
|
||||
FOR_EACH_CONCRETE_TYPE(FUNC_MEMBER)
|
||||
};
|
||||
|
||||
struct GraphQLAstNode;
|
||||
|
||||
/**
|
||||
* Walk the AST rooted at the given node, issuing callbacks from the given
|
||||
* callbacks struct as appropriate. userData will be passed as the userData
|
||||
* argument to each callback.
|
||||
*/
|
||||
void graphql_node_visit(const struct GraphQLAstNode *node,
|
||||
const struct GraphQLAstVisitorCallbacks *callbacks,
|
||||
void *userData);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
35
external/graphqlparser/c/GraphQLParser.cpp
vendored
Normal file
35
external/graphqlparser/c/GraphQLParser.cpp
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright 2019-present, GraphQL Foundation
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "GraphQLParser.h"
|
||||
#include "../GraphQLParser.h"
|
||||
#include "../AstNode.h"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
struct GraphQLAstNode *graphql_parse_string(const char *text, const char **error) {
|
||||
return reinterpret_cast<struct GraphQLAstNode *>(facebook::graphql::parseString(text, error).release());
|
||||
}
|
||||
|
||||
struct GraphQLAstNode *graphql_parse_string_with_experimental_schema_support(
|
||||
const char *text, const char **error) {
|
||||
return reinterpret_cast<struct GraphQLAstNode *>(facebook::graphql::parseStringWithExperimentalSchemaSupport(
|
||||
text, error).release());
|
||||
}
|
||||
|
||||
struct GraphQLAstNode *graphql_parse_file(FILE *file, const char **error) {
|
||||
return reinterpret_cast<struct GraphQLAstNode *>(facebook::graphql::parseFile(file, error).release());
|
||||
}
|
||||
|
||||
struct GraphQLAstNode *graphql_parse_file_with_experimental_schema_support(
|
||||
FILE *file, const char **error) {
|
||||
return reinterpret_cast<struct GraphQLAstNode *>(facebook::graphql::parseFileWithExperimentalSchemaSupport(file, error).release());
|
||||
}
|
||||
|
||||
void graphql_error_free(const char *error) {
|
||||
std::free((void *)(error)); // NOLINT
|
||||
}
|
54
external/graphqlparser/c/GraphQLParser.h
vendored
Normal file
54
external/graphqlparser/c/GraphQLParser.h
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Copyright 2019-present, GraphQL Foundation
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This file provides C wrappers for ../GraphQLParser.h.
|
||||
*/
|
||||
|
||||
struct GraphQLAstNode;
|
||||
|
||||
/**
|
||||
* Parse the given GraphQL source string, returning an AST. Returns
|
||||
* NULL on error. Return value must be freed with
|
||||
* graphql_node_free(). If NULL is returned and error is not NULL, an
|
||||
* error message is placed in error and must be freed with
|
||||
* graphql_error_free().
|
||||
*/
|
||||
struct GraphQLAstNode *graphql_parse_string(
|
||||
const char *text, const char **error);
|
||||
|
||||
struct GraphQLAstNode *graphql_parse_string_with_experimental_schema_support(
|
||||
const char *text, const char **error);
|
||||
|
||||
/**
|
||||
* Read and parse GraphQL source from the given file, returning an
|
||||
* AST. Returns nullptr on error. Return value must be freed with
|
||||
* graphql_node_free(). If NULL is returned and error is not NULL, an
|
||||
* error message is placed in error and must be freed with
|
||||
* graphql_error_free().
|
||||
*/
|
||||
struct GraphQLAstNode *graphql_parse_file(FILE *file, const char **error);
|
||||
|
||||
struct GraphQLAstNode *graphql_parse_file_with_experimental_schema_support(
|
||||
FILE *file, const char **error);
|
||||
|
||||
/**
|
||||
* Frees an error.
|
||||
*/
|
||||
void graphql_error_free(const char *error);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user