Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
postwait committed May 15, 2009
1 parent f5e593b commit ea6ba41
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/Makefile.in
Expand Up @@ -38,12 +38,12 @@ NOIT_OBJS=noitd.o noit_listener.o \
noit_console_complete.o \
noit_check.o noit_check_log.o noit_check_tools.o \
noit_module.o noit_conf.o noit_conf_checks.o noit_tokenizer.o \
noit_capabilities_listener.o \
noit_capabilities_listener.o noit_xml.o \
noit_jlog_listener.o noit_livestream_listener.o noit_filters.o

STRATCON_OBJS=stratcond.o noit_listener.o \
noit_console.o noit_console_state.o noit_console_telnet.o \
noit_console_complete.o \
noit_console_complete.o noit_xml.o \
noit_conf.o noit_http.o noit_tokenizer.o \
stratcon_realtime_http.o \
stratcon_jlog_streamer.o stratcon_datastore.o \
Expand Down
12 changes: 3 additions & 9 deletions src/noit_capabilities_listener.c
Expand Up @@ -39,6 +39,7 @@
#include "noit_capabilities_listener.h"
#include "noit_module.h"
#include "noit_check.h"
#include "noit_xml.h"

#include <unistd.h>
#include <sys/ioctl.h>
Expand Down Expand Up @@ -92,8 +93,6 @@ noit_capabilities_handler(eventer_t e, int mask, void *closure,

xmlDocPtr xmldoc;
xmlNodePtr root, cmds;
xmlBufferPtr xmlbuffer;
xmlSaveCtxtPtr savectx;

cl = ac->service_ctx = calloc(1, sizeof(*cl));
/* fill out capabilities */
Expand Down Expand Up @@ -149,15 +148,10 @@ noit_capabilities_handler(eventer_t e, int mask, void *closure,
}

/* Write it out to a buffer and copy it for writing */
xmlbuffer = xmlBufferCreate();
savectx = xmlSaveToBuffer(xmlbuffer, "utf8", 1);
xmlSaveDoc(savectx, xmldoc);
xmlSaveClose(savectx);
cl->buff = strdup((const char *)xmlBufferContent(xmlbuffer));
cl->towrite = xmlBufferLength(xmlbuffer);
cl->buff = noit_xmlSaveToBuffer(xmldoc);
cl->towrite = strlen(cl->buff);

/* Clean up after ourselves */
xmlBufferFree(xmlbuffer);
xmlFreeDoc(xmldoc);
}

Expand Down
57 changes: 57 additions & 0 deletions src/noit_xml.c
@@ -0,0 +1,57 @@

#include "noit_xml.h"

struct noit_xml_buffer_ptr {
char *buff;
int raw_len;
int len;
int allocd;
};
static int
noit_xml_save_writer(void *vstr, const char *buffer, int len) {
struct noit_xml_buffer_ptr *clv = vstr;
if(!clv->buff) {
clv->allocd = 8192;
clv->buff = malloc(clv->allocd);
}
while(len + clv->len > clv->allocd) {
char *newbuff;
int newsize = clv->allocd;
newsize <<= 1;
newbuff = realloc(clv->buff, newsize);
if(!newbuff) {
return -1;
}
clv->allocd = newsize;
clv->buff = newbuff;
}
memcpy(clv->buff + clv->len, buffer, len);
clv->len += len;
return len;
}
static int
noit_xml_save_closer(void *vstr) {
struct noit_xml_buffer_ptr *clv = vstr;
if(clv->buff == NULL) return 0;
clv->buff[clv->len] = '\0';
return 0;
}

char *
noit_xmlSaveToBuffer(xmlDocPtr doc) {
char *outbuff;
xmlOutputBufferPtr out;
xmlCharEncodingHandlerPtr enc;
struct noit_xml_buffer_ptr *buf;

buf = calloc(1, sizeof(*buf));
enc = xmlGetCharEncodingHandler(XML_CHAR_ENCODING_UTF8);
out = xmlOutputBufferCreateIO(noit_xml_save_writer,
noit_xml_save_closer,
buf, enc);
xmlSaveFormatFileTo(out, doc, "utf8", 1);
outbuff = buf->buff;
free(buf);
return outbuff;
}

42 changes: 42 additions & 0 deletions src/noit_xml.h
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2007, OmniTI Computer Consulting, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name OmniTI Computer Consulting, Inc. nor the names
* of its contributors may be used to endorse or promote products
* derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef _NOIT_XML_H
#define _NOIT_XML_H

#include "noit_defines.h"
#include <libxml/tree.h>

API_EXPORT(char *)
noit_xmlSaveToBuffer(xmlDocPtr doc);

#endif
17 changes: 2 additions & 15 deletions src/stratcon_iep.c
Expand Up @@ -40,6 +40,7 @@
#include "stratcon_iep.h"
#include "noit_conf.h"
#include "noit_check.h"
#include "noit_xml.h"

#include <unistd.h>
#include <sys/fcntl.h>
Expand Down Expand Up @@ -266,20 +267,6 @@ void stratcon_iep_submit_queries() {
}
}

static char *
stratcon__xml_doc_to_str(xmlDocPtr doc) {
char *rv;
xmlSaveCtxtPtr savectx;
xmlBufferPtr xmlbuffer;
xmlbuffer = xmlBufferCreate();
savectx = xmlSaveToBuffer(xmlbuffer, "utf8", 1);
xmlSaveDoc(savectx, doc);
xmlSaveClose(savectx);
rv = strdup((const char *)xmlBufferContent(xmlbuffer));
xmlBufferFree(xmlbuffer);
return rv;
}

static
struct iep_thread_driver *stratcon_iep_get_connection() {
apr_status_t rc;
Expand Down Expand Up @@ -382,7 +369,7 @@ stratcon_iep_submitter(eventer_t e, int mask, void *closure,
}
job->doc = stratcon_iep_doc_from_line(job->line, job->remote);
if(job->doc) {
job->doc_str = stratcon__xml_doc_to_str(job->doc);
job->doc_str = noit_xmlSaveToBuffer(job->doc);
if(job->doc_str) {
/* Submit */
struct iep_thread_driver *driver;
Expand Down

0 comments on commit ea6ba41

Please sign in to comment.