/* This file is part of gacopyz.
Copyright (C) 2006, 2007 Sergey Poznyakoff
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301 USA */
#include <gacopyz_priv.h>
#define TRACE(conn,cmd,size,buf) do { \
gacopyz_log(conn, SMI_LOG_DEBUG, \
_("send header: size=%lu, cmd=%c"),\
size, cmd); \
gacopyz_logdump(conn, SMI_LOG_DEBUG, \
_("send data"), buf, size); \
} while (0)
int
gacopyz_init(gacopyz_conn_t *pconn, struct smfiDesc *desc)
{
size_t len;
char *name;
gacopyz_conn_t conn;
name = desc->xxfi_name ? desc->xxfi_name : "Unknown";
len = strlen(name);
if (desc->xxfi_version != SMFI_VERSION) {
gacopyz_logmsg(SMI_LOG_ERR,
_("smfi_register: %s: version mismatch; "
"application %d != implementation %d"),
name, desc->xxfi_version, SMFI_VERSION);
return MI_FAILURE;
}
conn = malloc(sizeof(*conn) + len + 1);
if (!conn) {
gacopyz_logmsg(SMI_LOG_ERR,
"smfi_register: %s: %s", name,
strerror(errno));
return MI_FAILURE;
}
memset(conn, 0, sizeof(*conn));
conn->sd = -1;
conn->master_timeout.tv_usec = 0;
conn->master_timeout.tv_sec = 5;
conn->ctx_timeout.tv_usec = 0;
conn->ctx_timeout.tv_sec = GACOPYZ_TIMEOUT;
conn->logmask = SMI_DEFAULT_LOG_MASK;
conn->desc = *desc;
conn->desc.xxfi_name = (char*)(conn + 1);
strcpy(conn->desc.xxfi_name, name);
*pconn = conn;
return MI_SUCCESS;
}
void
gacopyz_free(gacopyz_conn_t conn)
{
if (conn) {
free(conn->pidtab);
free(conn);
}
}
int
gacopyz_parse_connection(const char *cstr,
char **pproto, char **pport, char **ppath)
{
const char *p;
size_t len;
p = strchr(cstr, ':');
if (!p)
*pproto = NULL;
else {
len = p - cstr;
*pproto = malloc(len + 1);
if (!*pproto)
return MI_FAILURE;
memcpy(*pproto, cstr, len);
(*pproto)[len] = 0;
cstr = p + 1;
}
p = strchr(cstr, '@');
if (!p)
*pport = NULL;
else {
len = p - cstr;
*pport = malloc(len + 1);
if (!*pport) {
free(*pproto);
return MI_FAILURE;
}
memcpy(*pport, cstr, len);
(*pport)[len] = 0;
cstr = p + 1;
}
*ppath = strdup(cstr);
if (!*ppath) {
free(*pproto);
free(*pport);
free(*ppath);
return MI_FAILURE;
}
return
|