Forgot to add the first stab implementation.
This commit is contained in:
74
src/oocontext.cpp
Normal file
74
src/oocontext.cpp
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "strophe.h"
|
||||||
|
#include "strophepp.h"
|
||||||
|
|
||||||
|
XMPP::Context::Context()
|
||||||
|
{
|
||||||
|
m_mem.alloc = callAlloc;
|
||||||
|
m_mem.realloc = callRealloc;
|
||||||
|
m_mem.free = callFree;
|
||||||
|
m_mem.userdata = (void *)this;
|
||||||
|
|
||||||
|
m_log.handler = callLog;
|
||||||
|
m_log.userdata = (void *)this;
|
||||||
|
|
||||||
|
m_ctx = ::xmpp_ctx_new(&m_mem, &m_log);
|
||||||
|
}
|
||||||
|
|
||||||
|
XMPP::Context::~Context()
|
||||||
|
{
|
||||||
|
::xmpp_ctx_free(m_ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *XMPP::Context::alloc(const size_t size)
|
||||||
|
{
|
||||||
|
return ::malloc(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *XMPP::Context::realloc(void *p, const size_t size)
|
||||||
|
{
|
||||||
|
return ::realloc(p, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void XMPP::Context::free(void *p)
|
||||||
|
{
|
||||||
|
::free(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
void XMPP::Context::log(const xmpp_log_level_t level,
|
||||||
|
const char * const area,
|
||||||
|
const char * const msg)
|
||||||
|
{
|
||||||
|
/* do nothing by default */
|
||||||
|
}
|
||||||
|
|
||||||
|
xmpp_ctx_t *XMPP::Context::getContext()
|
||||||
|
{
|
||||||
|
return m_ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *XMPP::Context::callAlloc(const size_t size, void * const userdata)
|
||||||
|
{
|
||||||
|
return reinterpret_cast<Context *>(userdata)->alloc(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *XMPP::Context::callRealloc(void *p, const size_t size,
|
||||||
|
void * const userdata)
|
||||||
|
{
|
||||||
|
return reinterpret_cast<Context *>(userdata)->realloc(p, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void XMPP::Context::callFree(void *p, void * const userdata)
|
||||||
|
{
|
||||||
|
reinterpret_cast<Context *>(userdata)->free(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
void XMPP::Context::callLog(void * const userdata,
|
||||||
|
const xmpp_log_level_t level,
|
||||||
|
const char * const area,
|
||||||
|
const char * const msg)
|
||||||
|
{
|
||||||
|
reinterpret_cast<Context *>(userdata)->log(level, area, msg);
|
||||||
|
}
|
||||||
|
|
||||||
46
src/oostanza.cpp
Normal file
46
src/oostanza.cpp
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
#include "strophe.h"
|
||||||
|
#include "strophepp.h"
|
||||||
|
|
||||||
|
using namespace XMPP;
|
||||||
|
|
||||||
|
void *Stanza::operator new(size_t size, Context *ctx)
|
||||||
|
{
|
||||||
|
return ctx->alloc(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Stanza::operator delete(void *p, Context *ctx)
|
||||||
|
{
|
||||||
|
ctx->free(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
Stanza::Stanza(Context *ctx)
|
||||||
|
{
|
||||||
|
m_ctx = ctx;
|
||||||
|
m_stanza = ::xmpp_stanza_new(ctx->getContext());
|
||||||
|
// TODO: check for errors
|
||||||
|
}
|
||||||
|
|
||||||
|
Stanza::~Stanza()
|
||||||
|
{
|
||||||
|
::xmpp_stanza_release(m_stanza);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Stanza::release()
|
||||||
|
{
|
||||||
|
if (::xmpp_stanza_release(m_stanza))
|
||||||
|
delete(m_ctx) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Stanza *Stanza::clone()
|
||||||
|
{
|
||||||
|
::xmpp_stanza_clone(m_stanza);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Stanza *Stanza::copy()
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user