Version 3.3.0.
[pwmd.git] / src / xml.h
blobe518bd14c224c4e3614072597b2ff3228930a120
1 /*
2 Copyright (C) 2006-2021 Ben Kibbey <bjk@luxsci.net>
4 This file is part of pwmd.
6 Pwmd is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
11 Pwmd is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Pwmd. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef XML_H
20 #define XML_H
22 #include <libxml/tree.h>
23 #include <libxml/parser.h>
24 #include <libxml/xpath.h>
26 #include "util-misc.h"
27 #include "common.h"
28 #include "util-string.h"
30 struct element_list_s
32 struct slist_s *list; // The list of elements to be returned
33 char *target; // Placeholder for the current elements target
34 struct string_s *prefix; // Previous elements in the path.
35 int recurse; // Recurse into children of the current element
36 int root_only; // List only root elements.
37 unsigned depth; // Current recursion level
38 unsigned flags; // To determine which list flags too append
41 typedef enum {
42 XML_CMD_NONE, // No special processing in xml_find_elements()
43 XML_CMD_REALPATH,
44 XML_CMD_STORE,
45 XML_CMD_LIST,
46 XML_CMD_DELETE,
47 XML_CMD_RENAME,
48 XML_CMD_MOVE,
49 XML_CMD_ATTR,
50 XML_CMD_ATTR_TARGET,
51 XML_CMD_ATTR_LIST,
52 XML_CMD_ATTR_EXPIRE
53 } xml_command_t;
55 struct xml_request_s {
56 xmlDocPtr doc; // The document this request belongs to
57 xml_command_t cmd; // For special processing in xml_find_elements()
58 char **args; // The arguments passed to a command
59 unsigned depth; // Current depth of recursion
60 void *data; // Pointer for command data (LIST)
63 gpg_error_t xml_init ();
64 void xml_deinit ();
65 gpg_error_t xml_valid_username (const char *str);
66 gpg_error_t xml_new_request (struct client_s *client, const char *line,
67 xml_command_t cmd, struct xml_request_s **result);
68 void xml_free_request (struct xml_request_s *);
69 gpg_error_t xml_new_root_element (struct client_s *, xmlDocPtr doc, char *name);
70 xmlDocPtr xml_new_document (void);
71 int xml_valid_element (xmlChar * element);
72 xmlNodePtr xml_find_elements (struct client_s *client,
73 struct xml_request_s *req, xmlNodePtr node,
74 gpg_error_t *rc);
75 int xml_valid_element_path (char **path, int content);
76 xmlNodePtr xml_find_text_node (xmlNodePtr node);
77 gpg_error_t xml_create_path_list (struct client_s *, xmlDocPtr doc, xmlNodePtr,
78 struct element_list_s *elements, char *path,
79 gpg_error_t);
80 void xml_free_element_list (struct element_list_s *);
81 gpg_error_t xml_recurse_xpath_nodeset (struct client_s *, xmlDocPtr doc,
82 xmlNodeSetPtr nodes, xmlChar * value,
83 xmlBufferPtr * result, int,
84 const xmlChar *);
85 gpg_error_t xml_add_attribute (struct client_s *, xmlNodePtr node,
86 const char *name, const char *value);
87 xmlChar *xml_attribute_value (xmlNodePtr n, xmlChar * attr);
88 gpg_error_t xml_delete_attribute (struct client_s *, xmlNodePtr n,
89 const xmlChar * name);
90 gpg_error_t xml_validate_import (struct client_s *, xmlNodePtr);
91 xmlNodePtr xml_find_element (struct client_s *, xmlNodePtr node,
92 const char *element, gpg_error_t *);
93 gpg_error_t xml_update_element_mtime (struct client_s *, xmlNodePtr n);
94 gpg_error_t xml_parse_doc (const char *xml, size_t len, xmlDocPtr *doc);
95 xmlNodePtr xml_resolve_path (struct client_s *client, xmlDocPtr doc,
96 xmlChar *path, char ***result, gpg_error_t *rc);
97 gpg_error_t xml_validate_target (struct client_s *, xmlDocPtr doc,
98 const char *src, xmlNodePtr dst);
99 gpg_error_t xml_check_recursion (struct client_s *client,
100 struct xml_request_s *req);
101 int xml_valid_attribute (const char *str);
102 int xml_valid_attribute_value (const char *str);
103 gpg_error_t xml_is_element_owner (struct client_s *, xmlNodePtr);
104 gpg_error_t xml_unlink_node (struct client_s *, xmlNodePtr);
105 xmlNodePtr xml_create_element_path (struct client_s *client,
106 struct xml_request_s *req, xmlNodePtr node,
107 char **path, gpg_error_t *rc);
108 int xml_reserved_attribute (const char *);
109 gpg_error_t xml_acl_check (struct client_s *, xmlNodePtr);
110 gpg_error_t xml_remove_user_attributes (struct client_s *, xmlNodePtr);
111 gpg_error_t xml_protected_attr (const char *a);
113 #endif