psmb_ctx_t *psmb_new(void);
psmb_ctx_t *psmb_new_mm(void *(*malloc)(size_t size),
- void (*free)(void *ptr),
- void *(*realloc)(void *ptr, size_t size));
+ void (*free)(void *ptr),
+ void *(*realloc)(void *ptr, size_t size));
+psmb_result_t psmb_set_logf(psmb_ctx_t *ctx,
+ void (*logf)(void *log_priv, int priority, const char *format, ...),
+ void *log_priv);
psmb_result_t psmb_set_pmtu(psmb_ctx_t *ctx, unsigned int pmtu);
psmb_result_t psmb_set_port(psmb_ctx_t *ctx, unsigned short pmtu);
psmb_result_t psmb_set_mgrp(psmb_ctx_t *ctx, struct {unsigned char _uc[16];} pfx, unsigned char bits);
psmb_result_t psmb_ev_ex(psmb_ctx_t *ctx);
psmb_result_t psmb_subscribe(psmb_ctx_t *ctx, char *channel);
psmb_result_t psmb_publish(psmb_ctx_t *ctx, char *channel,
- void *data, size_t size);
+ void *data, size_t size);
bool psmb_message(psmb_ctx_t *ctx, char **channel,
- void **data, size_t *size);
+ void **data, size_t *size);
#endif
void *(*malloc)(size_t size);
void (*free)(void *ptr);
void *(*realloc)(void *ptr, size_t size);
+ void (*logf)(void *log_priv, int priority, const char *format, ...);
+ void *log_priv;
unsigned short port;
int pmtu;
/* subscription set here */
#include <psmb.h>
#include "psmb_priv.h"
+static void dummy_log(void *log_priv, int priority, const char *format, ...) {}
+
psmb_ctx_t *psmb_new(void)
{
return psmb_new_mm(malloc, free, realloc);
*ctx = (psmb_ctx_t){
.fd = -1,
.malloc = malloc, .free = free, .realloc = realloc,
- .pmtu = PSMB_DEFAULT_PMTU, .port = PSMB_DEFAULT_PORT};
+ .logf = dummy_log,
+ .pmtu = PSMB_DEFAULT_PMTU,
+ .port = PSMB_DEFAULT_PORT};
return ctx;
}
+psmb_result_t psmb_set_logf(psmb_ctx_t *ctx,
+ void (*logf)(void *log_priv, int priority, const char *format, ...),
+ void *log_priv)
+{
+ if (ctx->fd == -1) {
+ ctx->logf = logf;
+ ctx->log_priv = log_priv;
+ return (psmb_result_t){PSMB_OK};
+ } else {
+ errno = EBUSY;
+ return (psmb_result_t){PSMB_ERROR};
+ }
+}
+
psmb_result_t psmb_set_pmtu(psmb_ctx_t *ctx, unsigned int pmtu)
{
if (ctx->fd == -1) {