- XML:
. Moved utf8_encode() and utf8_decode() to the Standard extension. (Andrea)
+- XMLRPC:
+ . Use Zend MM for allocation in bundled libxmlrpc (Joe)
+
<<< NOTE: Insert NEWS from last stable release here prior to actual release! >>>
/* ENCODE -- Encode binary file into base64. */
#include <stdlib.h>
#include <ctype.h>
+#include <php.h>
#include "base64.h"
void buffer_new(struct buffer_st *b)
{
b->length = 512;
- b->data = malloc(sizeof(char)*(b->length));
+ b->data = emalloc(sizeof(char)*(b->length));
b->data[0] = 0;
b->ptr = b->data;
b->offset = 0;
b->offset++;
if (b->offset == b->length) {
b->length += 512;
- b->data = realloc(b->data, b->length);
+ b->data = erealloc(b->data, b->length);
b->ptr = b->data + b->offset;
}
}
void buffer_delete(struct buffer_st *b)
{
- free(b->data);
+ efree(b->data);
b->length = 0;
b->offset = 0;
b->ptr = NULL;
#include <stdlib.h>
#endif
+#include <php.h>
+
static const char rcsid[] = "#(@) $Id$";
#include <errno.h>
ic = iconv_open(to_enc, from_enc);
if(ic != (iconv_t)-1) {
size_t st;
- outbuf = (char*)malloc(outlen + 1);
+ outbuf = (char*)emalloc(outlen + 1);
if(outbuf) {
out_ptr = (char*)outbuf;
int diff = out_ptr - outbuf;
outlen += inlenleft;
outlenleft += inlenleft;
- outbuf = (char*)realloc(outbuf, outlen + 1);
+ outbuf = (char*)erealloc(outbuf, outlen + 1);
if(!outbuf) {
break;
}
out_ptr = outbuf + diff;
}
else {
- free(outbuf);
+ efree(outbuf);
outbuf = 0;
break;
}
#include "xmlrpc_win32.h"
#endif
#include <stdlib.h>
+#include <php.h>
#include "queue.h"
-
static void QuickSort(void *list[], int low, int high,
int (*Comp)(const void *, const void *));
static int Q_BSearch(queue *q, void *key,
/* The index: a pointer to pointers */
-static void **index;
-static datanode **posn_index;
+static void **queue_index;
+static datanode **queue_posn_index;
/***
node *n;
datanode *p;
- p = malloc(sizeof(datanode));
+ p = emalloc(sizeof(datanode));
if(p == NULL)
return False_;
node *p;
datanode *n;
- n = malloc(sizeof(datanode));
+ n = emalloc(sizeof(datanode));
if(n == NULL)
return False_;
d = q->head->data;
n = q->head->next;
- free(q->head);
+ efree(q->head);
q->size--;
d = q->tail->data;
p = q->tail->prev;
- free(q->tail);
+ efree(q->tail);
q->size--;
if(q->size == 0)
p = ((node*)iter)->prev;
d = ((node*)iter)->data;
- free(iter);
+ efree(iter);
if(p) {
p->next = n;
/* if already sorted free memory for tag array */
if(q->sorted) {
- free(index);
- free(posn_index);
+ efree(queue_index);
+ efree(queue_posn_index);
q->sorted = False_;
}
/* Now allocate memory of array, array of pointers */
- index = malloc(q->size * sizeof(q->cursor->data));
+ queue_index = emalloc(q->size * sizeof(q->cursor->data));
if(index == NULL)
return False_;
- posn_index = malloc(q->size * sizeof(q->cursor));
- if(posn_index == NULL) {
- free(index);
+ queue_posn_index = emalloc(q->size * sizeof(q->cursor));
+ if(queue_posn_index == NULL) {
+ efree(queue_index);
return False_;
}
d = Q_Head(q);
for(i=0; i < q->size; i++) {
- index[i] = d;
- posn_index[i] = q->cursor;
+ queue_index[i] = d;
+ queue_posn_index[i] = q->cursor;
d = Q_Next(q);
}
/* Now sort the index */
- QuickSort(index, 0, q->size - 1, Comp);
+ QuickSort(queue_index, 0, q->size - 1, Comp);
/* Rearrange the actual queue into correct order */
dn = q->head;
i = 0;
while(dn != NULL) {
- dn->data = index[i++];
+ dn->data = queue_index[i++];
dn = dn->next;
}
while(low <= hi) {
mid = (low + hi) / 2;
- val = Comp(key, index[ mid ]);
+ val = Comp(key, queue_index[ mid ]);
if(val < 0)
hi = mid - 1;
if(idx < 0)
return NULL;
- q->cursor = posn_index[idx];
+ q->cursor = queue_posn_index[idx];
- return index[idx];
+ return queue_index[idx];
}
*/
+#include <php.h>
static const char rcsid[] = "#(@) $Id$";
#include <string.h>
#include "simplestring.h"
-#define my_free(thing) if(thing) {free(thing); thing = 0;}
+#define my_free(thing) if(thing) {efree(thing); thing = 0;}
/*----------------------**
* Begin String Functions *
/******/
static void simplestring_init_str(simplestring* string) {
- string->str = (char*)malloc(SIMPLESTRING_INCR);
+ string->str = (char*)emalloc(SIMPLESTRING_INCR);
if(string->str) {
string->str[0] = 0;
string->len = 0;
/* some kind of overflow happened */
return;
}
- target->str = (char*)realloc(target->str, newsize);
+ target->str = (char*)erealloc(target->str, newsize);
target->size = target->str ? newsize : 0;
}
#include "queue.h"
#include "encodings.h"
-#define my_free(thing) if(thing) {free(thing); thing = NULL;}
+#define my_free(thing) if(thing) {efree(thing); thing = NULL;}
#define XML_DECL_START "<?xml"
#define XML_DECL_START_LEN sizeof(XML_DECL_START) - 1
Q_Destroy(&root->children);
Q_Destroy(&root->attrs);
if(root->name) {
- free((char *)root->name);
+ efree((char *)root->name);
root->name = NULL;
}
simplestring_free(&root->text);
* SOURCE
*/
xml_element* xml_elem_new() {
- xml_element* elem = calloc(1, sizeof(xml_element));
+ xml_element* elem = ecalloc(1, sizeof(xml_element));
if(elem) {
Q_Init(&elem->children);
Q_Init(&elem->attrs);
if(ToBeXmlEscaped) {
- NewBuffer= malloc(iLength+1);
+ NewBuffer= emalloc(iLength+1);
if(NewBuffer) {
bufcopy=buf;
while(*bufcopy) {
c = mydata->current;
mydata->current = xml_elem_new();
- mydata->current->name = (char*)strdup(name);
+ mydata->current->name = (char*)estrdup(name);
mydata->current->parent = c;
/* init attrs */
while(p && *p) {
- xml_element_attr* attr = malloc(sizeof(xml_element_attr));
+ xml_element_attr* attr = emalloc(sizeof(xml_element_attr));
if(attr) {
- attr->key = strdup(*p);
- attr->val = strdup(*(p+1));
+ attr->key = estrdup(*p);
+ attr->val = estrdup(*(p+1));
Q_PushTail(&mydata->current->attrs, attr);
p += 2;
if(add_text) {
len = new_len;
simplestring_addn(&mydata->current->text, add_text, len);
- free(add_text);
+ efree(add_text);
return;
}
}
xml_element* elem_val = xml_elem_new();
const char* pAttrType = NULL;
- xml_element_attr* attr_type = bNoAddType ? NULL : malloc(sizeof(xml_element_attr));
+ xml_element_attr* attr_type = bNoAddType ? NULL : emalloc(sizeof(xml_element_attr));
if(attr_type) {
- attr_type->key = strdup(ATTR_TYPE);
+ attr_type->key = estrdup(ATTR_TYPE);
attr_type->val = 0;
Q_PushTail(&elem_val->attrs, attr_type);
}
- elem_val->name = (type == xmlrpc_vector) ? strdup(ATTR_VECTOR) : strdup(ATTR_SCALAR);
+ elem_val->name = (type == xmlrpc_vector) ? estrdup(ATTR_VECTOR) : estrdup(ATTR_SCALAR);
if(id && *id) {
- xml_element_attr* attr_id = malloc(sizeof(xml_element_attr));
+ xml_element_attr* attr_id = emalloc(sizeof(xml_element_attr));
if(attr_id) {
- attr_id->key = strdup(ATTR_ID);
- attr_id->val = strdup(id);
+ attr_id->key = estrdup(ATTR_ID);
+ attr_id->val = estrdup(id);
Q_PushTail(&elem_val->attrs, attr_id);
}
}
break;
}
if(pAttrType && attr_type && !bNoAddType) {
- attr_type->val = strdup(pAttrType);
+ attr_type->val = estrdup(pAttrType);
}
root = elem_val;
}
if(request) {
XMLRPC_REQUEST_TYPE request_type = XMLRPC_RequestGetRequestType(request);
const char* pStr = NULL;
- xml_element_attr* version = malloc(sizeof(xml_element_attr));
- version->key = strdup(ATTR_VERSION);
- version->val = strdup(VAL_VERSION_0_9);
+ xml_element_attr* version = emalloc(sizeof(xml_element_attr));
+ version->key = estrdup(ATTR_VERSION);
+ version->val = estrdup(VAL_VERSION_0_9);
wrapper = xml_elem_new();
pStr = ELEM_METHODCALL;
}
if(pStr) {
- wrapper->name = strdup(pStr);
+ wrapper->name = estrdup(pStr);
}
root = xml_elem_new();
- root->name = strdup(ELEM_ROOT);
+ root->name = estrdup(ELEM_ROOT);
Q_PushTail(&root->attrs, version);
Q_PushTail(&root->children, wrapper);
if(pStr) {
xml_element* method = xml_elem_new();
- method->name = strdup(ELEM_METHODNAME);
+ method->name = estrdup(ELEM_METHODNAME);
simplestring_add(&method->text, pStr);
Q_PushTail(&wrapper->children, method);
}
/* utility func to generate a new attribute. possibly should be in xml_element.c?? */
static xml_element_attr* new_attr(const char* key, const char* val) {
- xml_element_attr* attr = malloc(sizeof(xml_element_attr));
+ xml_element_attr* attr = emalloc(sizeof(xml_element_attr));
if (attr) {
- attr->key = key ? strdup(key) : NULL;
- attr->val = val ? strdup(val) : NULL;
+ attr->key = key ? estrdup(key) : NULL;
+ attr->val = val ? estrdup(val) : NULL;
}
return attr;
}
static struct array_info* parse_array_type_info(const char* array_type) {
struct array_info* ai = NULL;
if (array_type) {
- ai = (struct array_info*)calloc(1, sizeof(struct array_info));
+ ai = (struct array_info*)ecalloc(1, sizeof(struct array_info));
if (ai) {
char buf[128], *p;
snprintf(buf, sizeof(buf), "%s", array_type);
}
/* cleanup */
if (ai) {
- free(ai);
+ efree(ai);
}
}
}
}
}
}
- elem_val->name = strdup(pName);
+ elem_val->name = estrdup(pName);
/* cleanup */
if (bFreeNode) {
/* safety first. */
if (root) {
xml_element* body = xml_elem_new();
- root->name = strdup("SOAP-ENV:Envelope");
+ root->name = estrdup("SOAP-ENV:Envelope");
/* silly namespace stuff */
Q_PushTail(&root->attrs, new_attr("xmlns:SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/"));
/* if we are making a request, we want to use the methodname as is. */
if (rtype == xmlrpc_request_call) {
if (methodname) {
- rpc->name = strdup(methodname);
+ rpc->name = estrdup(methodname);
}
}
/* if it's a response, we append "Response". Also, given xmlrpc-epi
methodname ? methodname : "",
"Response");
- rpc->name = strdup(buf);
+ rpc->name = estrdup(buf);
}
/* add serialized data to method call/response.
}
}
}
- body->name = strdup("SOAP-ENV:Body");
+ body->name = estrdup("SOAP-ENV:Body");
Q_PushTail(&root->children, body);
}
}
if (next_el) {
Q_PushTail(&elem_val->children, next_el);
}
- elem_val->name = strdup(bIsFault ? ELEM_FAULT : ELEM_PARAMS);
+ elem_val->name = estrdup(bIsFault ? ELEM_FAULT : ELEM_PARAMS);
}
else {
switch (type) {
case xmlrpc_empty: /* treat null value as empty string in xmlrpc. */
case xmlrpc_string:
- elem_val->name = strdup(ELEM_STRING);
+ elem_val->name = estrdup(ELEM_STRING);
simplestring_addn(&elem_val->text, XMLRPC_GetValueString(node), XMLRPC_GetValueStringLen(node));
break;
case xmlrpc_int:
- elem_val->name = strdup(ELEM_INT);
+ elem_val->name = estrdup(ELEM_INT);
snprintf(buf, BUF_SIZE, "%i", XMLRPC_GetValueInt(node));
simplestring_add(&elem_val->text, buf);
break;
case xmlrpc_boolean:
- elem_val->name = strdup(ELEM_BOOLEAN);
+ elem_val->name = estrdup(ELEM_BOOLEAN);
snprintf(buf, BUF_SIZE, "%i", XMLRPC_GetValueBoolean(node));
simplestring_add(&elem_val->text, buf);
break;
case xmlrpc_double:
{
- elem_val->name = strdup(ELEM_DOUBLE);
+ elem_val->name = estrdup(ELEM_DOUBLE);
ap_php_snprintf(buf, BUF_SIZE, "%.*G", (int) EG(precision), XMLRPC_GetValueDouble(node));
simplestring_add(&elem_val->text, buf);
}
break;
case xmlrpc_datetime:
- elem_val->name = strdup(ELEM_DATETIME);
+ elem_val->name = estrdup(ELEM_DATETIME);
simplestring_add(&elem_val->text, XMLRPC_GetValueDateTime_ISO8601(node));
break;
case xmlrpc_base64:
{
struct buffer_st buf;
- elem_val->name = strdup(ELEM_BASE64);
+ elem_val->name = estrdup(ELEM_BASE64);
base64_encode_xmlrpc(&buf, XMLRPC_GetValueBase64(node), XMLRPC_GetValueStringLen(node));
simplestring_addn(&elem_val->text, buf.data, buf.offset );
buffer_delete(&buf);
case xmlrpc_vector_array:
{
if(depth == 0) {
- elem_val->name = strdup(ELEM_PARAMS);
+ elem_val->name = estrdup(ELEM_PARAMS);
}
else {
/* Hi my name is Dave and I like to make things as confusing
* GRRRRRRRRR!
*/
xml_element* data = xml_elem_new();
- data->name = strdup(ELEM_DATA);
+ data->name = estrdup(ELEM_DATA);
- elem_val->name = strdup(ELEM_ARRAY);
+ elem_val->name = estrdup(ELEM_ARRAY);
Q_PushTail(&elem_val->children, data);
root_vector_elem = data;
}
break;
case xmlrpc_vector_mixed: /* not officially supported */
case xmlrpc_vector_struct:
- elem_val->name = strdup(ELEM_STRUCT);
+ elem_val->name = estrdup(ELEM_STRUCT);
break;
default:
break;
if (depth == 1) {
xml_element* value = xml_elem_new();
- value->name = strdup(ELEM_VALUE);
+ value->name = estrdup(ELEM_VALUE);
/* yet another hack for the "fault" crap */
if (XMLRPC_VectorGetValueWithID(node, ELEM_FAULTCODE)) {
}
else {
xml_element* param = xml_elem_new();
- param->name = strdup(ELEM_PARAM);
+ param->name = estrdup(ELEM_PARAM);
Q_PushTail(¶m->children, value);
xml_element* name = xml_elem_new();
xml_element* value = xml_elem_new();
- member->name = strdup(ELEM_MEMBER);
- name->name = strdup(ELEM_NAME);
- value->name = strdup(ELEM_VALUE);
+ member->name = estrdup(ELEM_MEMBER);
+ name->name = estrdup(ELEM_NAME);
+ value->name = estrdup(ELEM_VALUE);
simplestring_add(&name->text, XMLRPC_GetValueID(node));
else if (vtype == xmlrpc_vector_array) {
xml_element* value = xml_elem_new();
- value->name = strdup(ELEM_VALUE);
+ value->name = estrdup(ELEM_VALUE);
Q_PushTail(&value->children, elem_val);
else {
xml_element* value = xml_elem_new();
- value->name = strdup(ELEM_VALUE);
+ value->name = estrdup(ELEM_VALUE);
Q_PushTail(&value->children, elem_val);
pStr = ELEM_METHODRESPONSE;
}
if (pStr) {
- wrapper->name = strdup(pStr);
+ wrapper->name = estrdup(pStr);
}
if(request_type == xmlrpc_request_call) {
if (pStr) {
xml_element* method = xml_elem_new();
- method->name = strdup(ELEM_METHODNAME);
+ method->name = estrdup(ELEM_METHODNAME);
simplestring_add(&method->text, pStr);
Q_PushTail(&wrapper->children, method);
}
else {
/* Despite the spec, the xml-rpc list folk want me to send an empty params element */
xml_element* params = xml_elem_new();
- params->name = strdup(ELEM_PARAMS);
+ params->name = estrdup(ELEM_PARAMS);
Q_PushTail(&wrapper->children, params);
}
}
* SOURCE
*/
XMLRPC_REQUEST XMLRPC_RequestNew() {
- XMLRPC_REQUEST xRequest = calloc(1, sizeof(STRUCT_XMLRPC_REQUEST));
+ XMLRPC_REQUEST xRequest = ecalloc(1, sizeof(STRUCT_XMLRPC_REQUEST));
if(xRequest) {
simplestring_init(&xRequest->methodName);
}
* SOURCE
*/
XMLRPC_VALUE XMLRPC_CreateValueEmpty() {
- XMLRPC_VALUE v = calloc(1, sizeof(STRUCT_XMLRPC_VALUE));
+ XMLRPC_VALUE v = ecalloc(1, sizeof(STRUCT_XMLRPC_VALUE));
if(v) {
#ifdef XMLRPC_DEBUG_REFCOUNT
printf ("calloc'd 0x%x\n", v);
}
}
else {
- value->v = calloc(1, sizeof(STRUCT_XMLRPC_VECTOR));
+ value->v = ecalloc(1, sizeof(STRUCT_XMLRPC_VECTOR));
if(value->v) {
- value->v->q = (queue*)malloc(sizeof(queue));
+ value->v->q = (queue*)emalloc(sizeof(queue));
if(value->v->q) {
Q_Init(value->v->q);
value->v->type = type;
* SOURCE
*/
XMLRPC_SERVER XMLRPC_ServerCreate() {
- XMLRPC_SERVER server = calloc(1, sizeof(STRUCT_XMLRPC_SERVER));
+ XMLRPC_SERVER server = ecalloc(1, sizeof(STRUCT_XMLRPC_SERVER));
if(server) {
Q_Init(&server->methodlist);
Q_Init(&server->docslist);
dm = Q_Next(&server->docslist);
}
while( sm ) {
- if(sm->name) {
- my_free(sm->name);
- }
+ my_free(sm->name);
if(sm->desc) {
XMLRPC_CleanupValue(sm->desc);
}
int XMLRPC_ServerRegisterMethod(XMLRPC_SERVER server, const char *name, XMLRPC_Callback cb) {
if(server && name && cb) {
- server_method* sm = malloc(sizeof(server_method));
+ server_method* sm = emalloc(sizeof(server_method));
if(sm) {
- sm->name = strdup(name);
+ sm->name = estrdup(name);
sm->method = cb;
sm->desc = NULL;
/* includes */
#include "xml_element.h"
#include <time.h> /* for time_t */
+#include <php.h>
#ifdef __cplusplus
extern "C" {
int bSuccess = 0;
if(server && cb) {
- doc_method* dm = calloc(1, sizeof(doc_method));
+ doc_method* dm = ecalloc(1, sizeof(doc_method));
if(dm) {
dm->method = cb;
/*----------------------------------------------------------------------------
* Macros
*/
-#define my_free(thing) if(thing) {free(thing); thing = 0;}
+#define my_free(thing) if(thing) {efree(thing); thing = 0;}
#ifdef __cplusplus
outBuf = XMLRPC_REQUEST_ToXML(xRequest, 0);
if (outBuf) {
RETVAL_STRING(outBuf);
- free(outBuf);
+ efree(outBuf);
}
XMLRPC_RequestFree(xRequest, 1);
}
if (xOut) {
if (outBuf) {
RETVAL_STRING(outBuf);
- free(outBuf);
+ efree(outBuf);
}
/* cleanup */
XMLRPC_CleanupValue(xOut);
outBuf = XMLRPC_REQUEST_ToXML(xResponse, &buf_len);
if (outBuf) {
RETVAL_STRINGL(outBuf, buf_len);
- free(outBuf);
+ efree(outBuf);
}
/* cleanup after ourselves. what a sty! */
XMLRPC_RequestFree(xResponse, 0);