2 Copyright (C) 2006-2023 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 version 2 as
8 published by the Free Software Foundation.
10 Pwmd is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with Pwmd. If not, see <http://www.gnu.org/licenses/>.
21 #include <libxml/tree.h>
22 #include <libxml/parser.h>
23 #include <libxml/xpath.h>
25 #include "util-misc.h"
27 #include "util-string.h"
31 struct slist_s
*list
; // The list of elements to be returned
32 char *target
; // Placeholder for the current elements target
33 struct string_s
*prefix
; // Previous elements in the path.
34 int recurse
; // Recurse into children of the current element
35 int root_only
; // List only root elements.
36 unsigned depth
; // Current recursion level
37 unsigned flags
; // To determine which list flags too append
41 XML_CMD_NONE
, // No special processing in xml_find_elements()
54 #define XML_REQUEST_FLAG_CREATED 0x0001
56 struct xml_request_s
{
57 xmlDocPtr doc
; // The document this request belongs to
58 xml_command_t cmd
; // For special processing in xml_find_elements()
59 char **args
; // The arguments passed to a command
60 unsigned depth
; // Current depth of recursion
61 unsigned flags
; // Possible request flags set when resolving
62 void *data
; // Pointer for command data (LIST)
65 gpg_error_t
xml_init ();
67 gpg_error_t
xml_valid_username (const char *str
);
68 gpg_error_t
xml_new_request (struct client_s
*client
, const char *line
,
69 xml_command_t cmd
, struct xml_request_s
**result
);
70 void xml_free_request (struct xml_request_s
*);
71 gpg_error_t
xml_new_root_element (struct client_s
*, xmlDocPtr doc
, char *name
);
72 xmlDocPtr
xml_new_document (void);
73 int xml_valid_element (xmlChar
* element
);
74 xmlNodePtr
xml_find_elements (struct client_s
*client
,
75 struct xml_request_s
*req
, xmlNodePtr node
,
77 int xml_valid_element_path (char **path
, int content
);
78 xmlNodePtr
xml_find_text_node (xmlNodePtr node
);
79 gpg_error_t
xml_create_path_list (struct client_s
*, xmlDocPtr doc
, xmlNodePtr
,
80 struct element_list_s
*elements
, char *path
,
82 void xml_free_element_list (struct element_list_s
*);
83 gpg_error_t
xml_recurse_xpath_nodeset (struct client_s
*, xmlDocPtr doc
,
84 xmlNodeSetPtr nodes
, xmlChar
* value
,
85 xmlBufferPtr
* result
, int,
87 gpg_error_t
xml_add_attribute (struct client_s
*, xmlNodePtr node
,
88 const char *name
, const char *value
);
89 xmlChar
*xml_attribute_value (xmlNodePtr n
, xmlChar
* attr
);
90 gpg_error_t
xml_delete_attribute (struct client_s
*, xmlNodePtr n
,
91 const xmlChar
* name
);
92 gpg_error_t
xml_validate_import (struct client_s
*, xmlNodePtr
);
93 xmlNodePtr
xml_find_element (struct client_s
*, xmlNodePtr node
,
94 const char *element
, gpg_error_t
*);
95 gpg_error_t
xml_update_element_mtime (struct client_s
*, xmlNodePtr n
);
96 gpg_error_t
xml_parse_doc (const char *xml
, size_t len
, xmlDocPtr
*doc
);
97 xmlNodePtr
xml_resolve_path (struct client_s
*client
, xmlDocPtr doc
,
98 xmlChar
*path
, char ***result
, gpg_error_t
*rc
);
99 gpg_error_t
xml_validate_target (struct client_s
*, xmlDocPtr doc
,
100 const char *src
, xmlNodePtr dst
);
101 gpg_error_t
xml_check_recursion (struct client_s
*client
,
102 struct xml_request_s
*req
);
103 int xml_valid_attribute (const char *str
);
104 int xml_valid_attribute_value (const char *str
);
105 gpg_error_t
xml_is_element_owner (struct client_s
*, xmlNodePtr
, int strict
);
106 gpg_error_t
xml_unlink_node (struct client_s
*, xmlNodePtr
);
107 xmlNodePtr
xml_create_element_path (struct client_s
*client
,
108 struct xml_request_s
*req
, xmlNodePtr node
,
109 char **path
, gpg_error_t
*rc
);
110 int xml_reserved_attribute (const char *);
111 gpg_error_t
xml_acl_check (struct client_s
*, xmlNodePtr
);
112 gpg_error_t
xml_remove_user_attributes (struct client_s
*, xmlNodePtr
);
113 gpg_error_t
xml_protected_attr (const char *a
);