1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
|
/* Automatically generated by autoxml, do not edit. */
#include "myx_public_interface.h"
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include "myx_xml_util_functions.h"
#include <glib.h>
/* foward declarations */
static int myx_charset_store(const char *filename, MYX_DBM_CHARSETS *obj);
static MYX_DBM_CHARSETS *myx_charset_load(const char *filename,
MYX_LIB_ERROR *error_code);
static int myx_free_charset(MYX_DBM_CHARSETS *obj);
/* wrappers */
int myx_charsets_store(const char *filename, MYX_DBM_CHARSETS *obj)
{
return myx_charset_store(filename, obj);
}
MYX_DBM_CHARSETS *myx_charsets_load(const char *filename,
MYX_LIB_ERROR *error_code)
{
return myx_charset_load(filename, error_code);
}
int myx_free_charsets(MYX_DBM_CHARSETS *obj)
{
return myx_free_charset(obj);
}
/* only static functions now */
///////////////////////////////////////////////////////////////////////////////
/** @brief Create a new xml-node, contained information from MYX_DBM_COLLATION
@param obj MYX_DBM_COLLATION to store in xml-node
@param parent parent for created node
*//////////////////////////////////////////////////////////////////////////////
static void store_charset_MYX_DBM_COLLATION(MYX_DBM_COLLATION *obj,
xmlNodePtr parent)
{
xmlNodePtr node;
node= xmlNewTextChild(parent, NULL, (xmlChar*)"collation", NULL);
xmlNewTextChild(node, NULL, (xmlChar*)"name", (xmlChar*)obj->name);
NewTextChild_int_content(node, NULL, (xmlChar*)"id", obj->id);
NewTextChild_int_content(node, NULL, (xmlChar*)"is_default", obj->is_default);
NewTextChild_int_content(node, NULL, (xmlChar*)"is_compiled", obj->is_compiled);
NewTextChild_int_content(node, NULL, (xmlChar*)"sort_len", obj->sort_len);
}
///////////////////////////////////////////////////////////////////////////////
/** @brief Create a new xml-node, contained information from MYX_DBM_CHARSET
@param obj MYX_DBM_CHARSET to store in xml-node
@param parent parent for created node
*//////////////////////////////////////////////////////////////////////////////
static void store_charset_MYX_DBM_CHARSET(MYX_DBM_CHARSET *obj,
xmlNodePtr parent)
{
xmlNodePtr node;
unsigned int i;
node= xmlNewTextChild(parent, NULL, (xmlChar*)"charset", NULL);
for (i= 0; i < obj->collations_num; i++)
store_charset_MYX_DBM_COLLATION(obj->collations+i, node);
xmlNewTextChild(node, NULL, (xmlChar*)"name", (xmlChar*)obj->name);
xmlNewTextChild(node, NULL, (xmlChar*)"desc", (xmlChar*)obj->desc);
xmlNewTextChild(node, NULL, (xmlChar*)"default_collation", (xmlChar*)obj->default_collation);
NewTextChild_int_content(node, NULL, (xmlChar*)"max_len", obj->max_len);
}
///////////////////////////////////////////////////////////////////////////////
/** @brief prepare an xml-document with MYX_DBM_CHARSETS struct stored in it
@param obj MYX_DBM_CHARSETS struct to store
@return created document
*//////////////////////////////////////////////////////////////////////////////
static xmlDocPtr make_xml_for_charset(MYX_DBM_CHARSETS *obj)
{
xmlDocPtr doc;
xmlNodePtr parent;
unsigned int i;
g_return_val_if_fail(obj, NULL);
doc = xmlNewDoc((xmlChar*)"1.0");
parent = doc->children = xmlNewDocRawNode(doc, NULL, (xmlChar*)"charsets", NULL);
for (i= 0; i < obj->charsets_num; i++)
store_charset_MYX_DBM_CHARSET(obj->charsets+i, parent);
return doc;
}
///////////////////////////////////////////////////////////////////////////////
/** @brief store MYX_DBM_CHARSETS in an XML file
@param filename path to file to store in
@param obj MYX_DBM_CHARSETS struct to store
@return -1 if file was not written, else 0
*//////////////////////////////////////////////////////////////////////////////
static int myx_charset_store(const char *filename, MYX_DBM_CHARSETS *obj)
{
xmlDocPtr doc;
int res;
g_return_val_if_fail(obj, -1);
g_return_val_if_fail(filename, -1);
doc= make_xml_for_charset(obj);
res= myx_xmlSaveFile(filename, doc);
xmlFreeDoc(doc);
return (res == -1) ? -1 : 0;
}
///////////////////////////////////////////////////////////////////////////////
/** @brief read MYX_DBM_COLLATION struct from xml node
@param parent node to read from
@param obj MYX_DBM_COLLATION struct to fill
*//////////////////////////////////////////////////////////////////////////////
static void read_charset_MYX_DBM_COLLATION(xmlNodePtr parent,
MYX_DBM_COLLATION *obj)
{
xmlNodePtr node;
xmlDocPtr doc= parent->doc;
for (node= parent->children; node != NULL; node= node->next)
{
try_to_get_string_field(doc, node, "name", &obj->name);
try_to_get_int_field (doc, node, "id", (int*)&obj->id);
try_to_get_char_field (doc, node, "is_default", (char*)&obj->is_default);
try_to_get_char_field (doc, node, "is_compiled", (char*)&obj->is_compiled);
try_to_get_int_field (doc, node, "sort_len", (int*)&obj->sort_len);
}
}
///////////////////////////////////////////////////////////////////////////////
/** @brief read MYX_DBM_CHARSET struct from xml node
@param parent node to read from
@param obj MYX_DBM_CHARSET struct to fill
*//////////////////////////////////////////////////////////////////////////////
static void read_charset_MYX_DBM_CHARSET(xmlNodePtr parent,
MYX_DBM_CHARSET *obj)
{
xmlNodePtr node;
xmlDocPtr doc= parent->doc;
MYX_DBM_COLLATION * collation= NULL;
obj->collations_num= get_child_count(parent, (xmlChar*)"collation");
if (obj->collations_num > 0)
{
collation= obj->collations=
(MYX_DBM_COLLATION*)g_malloc0(obj->collations_num *
sizeof(MYX_DBM_COLLATION));
}
for (node = parent->children; node != NULL; node= node->next)
{
if (!xmlStrcmp(node->name, (xmlChar*)"collation"))
{
read_charset_MYX_DBM_COLLATION(node, collation);
collation->charset= obj;
collation++;
}
try_to_get_string_field(doc, node, "name", &obj->name);
try_to_get_string_field(doc, node, "desc", &obj->desc);
try_to_get_string_field(doc, node, "default_collation",
&obj->default_collation);
try_to_get_int_field (doc, node, "max_len", (int*)&obj->max_len);
}
}
///////////////////////////////////////////////////////////////////////////////
/** @brief read MYX_DBM_DATATYPES struct from xml document
@param doc document to read from
@param error_code returned error code, <BR>
possible values are:
- \link MYX_LIB_ERROR::MYX_XML_EMPTY_DOCUMENT
MYX_XML_EMPTY_DOCUMENT \endlink
- unchanged..
@return loaded MYX_DBM_DATATYPES
*//////////////////////////////////////////////////////////////////////////////
static MYX_DBM_CHARSETS *process_xml_for_charset(xmlDocPtr doc,
MYX_LIB_ERROR *error_code)
{
xmlNodePtr parent;
MYX_DBM_CHARSETS *obj;
parent= xmlDocGetRootElement(doc);
if (parent == NULL)
{
*error_code= MYX_XML_EMPTY_DOCUMENT;
return NULL;
}
obj= (MYX_DBM_CHARSETS*)g_malloc0(sizeof(MYX_DBM_CHARSETS));
obj->charsets_num= get_child_count(parent, (xmlChar*)"charset");
if (obj->charsets_num > 0)
{
xmlNodePtr node;
MYX_DBM_CHARSET * charset= obj->charsets=
(MYX_DBM_CHARSET*)g_malloc0(obj->charsets_num *
sizeof(MYX_DBM_CHARSET));
for (node= parent->children; node != NULL; node= node->next)
{
if (!xmlStrcmp(node->name, (xmlChar*)"charset"))
{
read_charset_MYX_DBM_CHARSET(node, charset);
charset++;
}
}
}
return obj;
}
///////////////////////////////////////////////////////////////////////////////
/** @ brief loads MYX_DBM_CHARSETS struct from an XML file
@param filename path to a xml-file with stored MYX_DBM_CHARSETS struct
@param error_code returned error code, <BR>
possible values are:
- \link MYX_LIB_ERROR::MYX_NO_ERROR MYX_NO_ERROR \endlink
- \link MYX_LIB_ERROR::MYX_ERROR_CANT_OPEN_FILE
MYX_ERROR_CANT_OPEN_FILE \endlink
- \link MYX_LIB_ERROR::MYX_XML_PARSE_ERROR
MYX_XML_PARSE_ERROR \endlink
- \link MYX_LIB_ERROR::MYX_XML_EMPTY_DOCUMENT
MYX_XML_EMPTY_DOCUMENT \endlink
- \link MYX_LIB_ERROR::MYX_ALLOC_CHANGE_ERROR
MYX_ALLOC_CHANGE_ERROR \endlink
@return loaded MYX_DBM_CHARSETS
*//////////////////////////////////////////////////////////////////////////////
static MYX_DBM_CHARSETS *myx_charset_load(const char *filename,
MYX_LIB_ERROR *error_code)
{
xmlDocPtr doc;
MYX_DBM_CHARSETS *obj;
xmlFreeFunc org_free;
xmlMallocFunc org_malloc;
xmlReallocFunc org_realloc;
xmlStrdupFunc org_strdup;
*error_code = MYX_NO_ERROR;
if (!file_exists(filename))
{
*error_code = MYX_ERROR_CANT_OPEN_FILE;
return NULL;
}
if (xmlMemGet(&org_free, &org_malloc, &org_realloc, &org_strdup) ||
xmlMemSetup(g_free, (xmlMallocFunc)g_malloc,
(xmlReallocFunc)g_realloc, g_strdup))
{
*error_code= MYX_ALLOC_CHANGE_ERROR;
return NULL;
}
doc= myx_xmlParseFile(filename);
if (doc == NULL)
{
*error_code = MYX_XML_PARSE_ERROR;
return NULL;
}
obj= process_xml_for_charset(doc, error_code);
xmlFreeDoc(doc);
if (xmlMemSetup(org_free, org_malloc, org_realloc, org_strdup))
{
*error_code= MYX_ALLOC_CHANGE_ERROR;
//should we free anything here?
return NULL;
}
return obj;
}
///////////////////////////////////////////////////////////////////////////////
/** @brief free memory for the MYX_DBM_COLLATION struct
@param obj MYX_DBM_COLLATION struct to free
@return 0 always
*//////////////////////////////////////////////////////////////////////////////
static int free_charset_MYX_DBM_COLLATION(MYX_DBM_COLLATION *obj)
{
xmlFree(obj->name);
return 0;
}
///////////////////////////////////////////////////////////////////////////////
/** @brief free memory for the MYX_DBM_CHARSET struct
@param obj MYX_DBM_CHARSET struct to free
@return 0 always
*//////////////////////////////////////////////////////////////////////////////
static int free_charset_MYX_DBM_CHARSET(MYX_DBM_CHARSET *obj)
{
unsigned int i;
for (i= 0; i < obj->collations_num; i++)
free_charset_MYX_DBM_COLLATION(obj->collations+i);
g_free(obj->collations);
xmlFree(obj->name);
xmlFree(obj->desc);
xmlFree(obj->default_collation);
return 0;
}
///////////////////////////////////////////////////////////////////////////////
/** @brief free memory for the MYX_DBM_CHARSETS struct
@param obj MYX_DBM_CHARSETS struct to free
@return 0 always
*//////////////////////////////////////////////////////////////////////////////
static int myx_free_charset(MYX_DBM_CHARSETS *obj)
{
unsigned int i;
for (i= 0; i < obj->charsets_num; i++)
free_charset_MYX_DBM_CHARSET(obj->charsets+i);
g_free(obj->charsets);
return 0;
}
|