Exemplo n.º 1
0
/*
 * This handler takes a single parameter, which is an array containing 
 * between 100 and 200 elements.  Each of the items is a string, your handler 
 * must return a string containing the concatenated text of the first and 
 * last elements.  
 */
XMLRPC_VALUE validator1_moderateSizeArrayCheck (XMLRPC_SERVER server, XMLRPC_REQUEST xRequest, void* userData) {
   XMLRPC_VALUE xReturn = NULL;

   simplestring buf;
   simplestring_init(&buf);

   if(xRequest) {
      XMLRPC_VALUE xArray = XMLRPC_VectorRewind(XMLRPC_RequestGetData(xRequest));
      if(xArray) {
         XMLRPC_VALUE xIter = XMLRPC_VectorRewind(xArray), xPrev = 0;

         simplestring_add(&buf, XMLRPC_GetValueString(xIter));

         /* TODO: Should add XMLRPC_VectorLast() call.  Much more efficient */
         while(xIter) {
            xPrev = xIter;
            xIter = XMLRPC_VectorNext(xArray);
         }

         simplestring_add(&buf, XMLRPC_GetValueString(xPrev));
      }
   }

   xReturn = XMLRPC_CreateValueString(0, buf.str, buf.len);

   return xReturn;
}
Exemplo n.º 2
0
/****f* xml_element/xml_elem_new
 * NAME
 *   xml_elem_new
 * SYNOPSIS
 *   xml_element* xml_elem_new()
 * FUNCTION
 *   allocates and initializes a new xml_element
 * INPUTS
 *   none
 * RESULT
 *   xml_element* or NULL.  NULL indicates an out-of-memory condition.
 * NOTES
 * SEE ALSO
 *   xml_elem_free ()
 *   xml_elem_free_non_recurse ()
 * SOURCE
 */
xml_element* xml_elem_new() {
   xml_element* elem = calloc(1, sizeof(xml_element));
   if(elem) {
      Q_Init(&elem->children);
      Q_Init(&elem->attrs);
      simplestring_init(&elem->text);

      /* init empty string in case we don't find any char data */
      simplestring_addn(&elem->text, "", 0);
   }
   return elem;
}
Exemplo n.º 3
0
/****f* xml_element/xml_elem_serialize_to_string
 * NAME
 *   xml_elem_serialize_to_string
 * SYNOPSIS
 *   void xml_element_serialize_to_string(xml_element *el, XML_ELEM_OUTPUT_OPTIONS options, int *buf_len)
 * FUNCTION
 *   writes element tree as XML into a newly allocated buffer
 * INPUTS
 *   el      - root element of tree
 *   options - options determining how output is written.  see XML_ELEM_OUTPUT_OPTIONS
 *   buf_len - length of returned buffer, if not null.
 * RESULT
 *   char* or NULL. Must be free'd by caller.
 * NOTES
 * SEE ALSO
 *   xml_elem_serialize_to_stream ()
 *   xml_elem_parse_buf ()
 * SOURCE
 */
char* xml_elem_serialize_to_string(xml_element *el, XML_ELEM_OUTPUT_OPTIONS options, int *buf_len)
{
   simplestring buf;
   simplestring_init(&buf);

   xml_element_serialize(el, simplestring_out_fptr, (void *)&buf, options, 0);

   if(buf_len) {
      *buf_len = buf.len;
   }

   return buf.str;
}