Beispiel #1
0
/* map threshold directive to the internal representation */
static int klog_logopt (const char *options)
{
    char *o2 = NULL;    /* 'options' dupped for safe u_tokenize() */
    int i, logopt = 0;
    enum { NOPTS = 4 };
    char *optv[NOPTS + 1];
    
    dbg_return_if (options == NULL, 0);
    dbg_return_if ((o2 = u_strdup(options)) == NULL, 0);

    dbg_err_if (u_tokenize(o2, " \t", optv, NOPTS + 1));
    
    for (i = 0; optv[i] != NULL; i++)
    {
        if (!strcasecmp(optv[i], "LOG_CONS"))
            logopt |= LOG_CONS;
        else if (!strcasecmp(optv[i], "LOG_NDELAY"))
            logopt |= LOG_NDELAY;
#ifdef HAVE_LOG_PERROR
        else if (!strcasecmp(optv[i], "LOG_PERROR"))
            logopt |= LOG_PERROR;
#endif  /* HAVE_LOG_PERROR */
        else if (!strcasecmp(optv[i], "LOG_PID"))
            logopt |= LOG_PID;
        else
            warn("bad log option: \'%s\'", optv[i]);
    }

    U_FREE(o2);
    return logopt;

err:
    U_FREE(o2);
    return 0;
}
Beispiel #2
0
void klog_args_free (klog_args_t *ka)
{
    U_FREE(ka->ident);
    U_FREE(ka->fbasename);
    U_FREE(ka);
    return;
}
Beispiel #3
0
static void free_code_block(code_block_t *node)
{
    if(node)
    {
        U_FREE(node->buf);
        U_FREE(node);
    }
}
Beispiel #4
0
/* add an atom to the list of global atoms */
static int session_mem_add(session_opt_t *so, const char *filename, char *buf, 
    size_t size, time_t mtime)
{
    atom_t *atom = NULL;
    enc_ses_mem_t *esm = NULL;
    ppc_t *ppc;
    size_t esize;

    dbg_err_if (so == NULL);
    dbg_err_if (filename == NULL);
    dbg_err_if (buf == NULL);

    if(ctx->pipc)
    {   /* children context */
        ppc = server_get_ppc(ctx->server);
        dbg_err_if(ppc == NULL);

        /* build the encoded parameters structure */
        esize = size + sizeof(enc_ses_mem_t);
        esm = (enc_ses_mem_t*)u_malloc(esize);
        dbg_err_if(esm == NULL);

        /* fill esm fields */
        esm->mtime = time(0);
        esm->size = size;
        dbg_err_if(strlen(filename) > SESSION_FILENAME_MAX_LENGTH); 
        u_strlcpy(esm->filename, filename, sizeof esm->filename);
        memcpy(esm->data, buf, size);

        /* send the command request */
        dbg_err_if(ppc_write(ppc, ctx->pipc, PPC_CMD_MSES_SAVE, 
            (char*)esm, esize) < 0);

        U_FREE(esm);

        /* add it to the local copy of atom list */
        dbg_err_if(so_atom_add(so, filename, buf, size, (void*)mtime));

    } else {
        /* parent context */
        dbg_err_if(so_atom_add(so, filename, buf, size, (void*)mtime));
    }

    return 0;
err:
    U_FREE(esm);
    if(atom)
        atom_free(atom);
    return ~0;
}
Beispiel #5
0
/* [parent] get session data */
static int session_cmd_get(ppc_t *ppc, int fd, unsigned char cmd, char *data, 
    size_t size, void *vso)
{
    enum { BUFSZ = 4096 };
    session_opt_t *so = vso;
    enc_ses_mem_t *esm = NULL;
    atom_t *atom = NULL;
    char buf[BUFSZ];
    size_t esm_size;

    u_unused_args(cmd, size);

    dbg_err_if (ppc == NULL);
    dbg_err_if (vso == NULL);
    dbg_err_if (data == NULL);
    dbg_err_if (strlen(data) > SESSION_FILENAME_MAX_LENGTH);

    /* find the atom whose name is stored into 'data' buffer */
    nop_err_if(atoms_get(so->atoms, data, &atom));

    /* if the buffer on the stack is big enough use it, otherwise alloc a 
       bigger one on the heap */
    if((esm_size = sizeof(enc_ses_mem_t) + atom->size) > BUFSZ)
    {
        esm = u_malloc(1 + esm_size);
        dbg_err_if(esm == NULL);
    } else
        esm = (enc_ses_mem_t*)buf;
        
    /* fill the enc_ses_mem_t struct */
    esm->mtime = (time_t)atom->arg;
    u_strlcpy(esm->filename, data, sizeof esm->filename);
    esm->size = atom->size;
    memcpy(esm->data, atom->data, atom->size);

    dbg_err_if(ppc_write(ppc, fd, PPC_CMD_RESPONSE_OK, (char*)esm,
        esm_size) <= 0);

    if(esm && esm != (void*)buf)
        U_FREE(esm);

    return 0;
err:
    if(ppc)
        ppc_write(ppc, fd, PPC_CMD_RESPONSE_ERROR, (char *)"", 1);
    if(esm && esm != (void *)buf)
        U_FREE(esm);
    return ~0;
}
Beispiel #6
0
/**
 * \ingroup vars
 * \brief   Set binary value of a variable
 *
 * Set binary value of variable \p v.
 *
 * \param v      variable object
 * \param data   value data
 * \param size   value size
 *
 * \return \c 0 if successful, non-zero on error
 */
int var_set_bin_value(var_t *v, const unsigned char *data, size_t size)
{
    dbg_err_if (v == NULL);
    dbg_err_if (data == NULL);
    
    U_FREE(v->data);

    if(data && size)
    {
        v->size = size;
        v->data = u_malloc(size+1);
        dbg_err_if(v->data == NULL);

        memcpy(v->data, data, size);
        v->data[size] = 0; /* zero-term v->data so it can be used as a string */
    } else {
        v->size = 0;
        v->data = NULL;
    }

    if(v->svalue)
        dbg_err_if(u_string_set(v->svalue, v->data, v->size));

    return 0; 
err:
    return ~0;
}
Beispiel #7
0
/* remove a child process whose pid is 'pid' to children list */
static int server_reap_child(server_t *s, pid_t pid)
{
    child_t *child;
    backend_t *be;

    dbg_err_if (s == NULL);
    
    /* get the child object */
    dbg_err_if(children_get_by_pid(s->children, pid, &child));

    /* remove the child from the list */
    dbg_err_if(children_del(s->children, child));
    be = child->be;

    /* check that the minimum number of process are active */
    be->nchild--;
    if(be->nchild < be->start_child)
        be->fork_child = be->start_child - be->nchild;

    U_FREE(child);

    return 0;
err:
    return ~0;
}
Beispiel #8
0
Datei: buf.c Projekt: fdotli/libu
/**
 *  \brief  Free a buffer
 *
 *  Release all resources and free the given buffer object.
 *
 *  \param  ubuf    buffer object
 *
 *  \retval  0  on success
 *  \retval ~0  on error
 */
int u_buf_free (u_buf_t *ubuf)
{
    dbg_return_if (ubuf == NULL, ~0);

    U_FREE(ubuf->data);
    u_free(ubuf);

    return 0;
}
Beispiel #9
0
/*
 * \ingroup vars
 * \brief   Free a variable
 *
 * \return \c 0, always
 */
int var_free(var_t *v)
{
    if(v)
    {
        if(v->sname)
            u_string_free(v->sname);

        if(v->svalue)
            u_string_free(v->svalue);

        if(v->opaque)
            U_FREE(v->opaque);

        U_FREE(v->data);
        U_FREE(v);
    }

    return 0;
}
Beispiel #10
0
static int session_mem_save(session_t *ss)
{
    char *buf = NULL;
    size_t sz;

    dbg_err_if (ss == NULL);
    
    /* save the session data to freshly alloc'd buf of size sz */
    dbg_err_if(session_prv_save_to_buf(ss, &buf, &sz));

    /* add the session to the in-memory session list */
    dbg_err_if(session_mem_add(ss->so, ss->filename, buf, sz, time(0)));

    U_FREE(buf);

    return 0;
err:
    U_FREE(buf);
    return ~0;
}
Beispiel #11
0
/**
 *  \brief  Free a string
 *
 *  Release all resources allocated to the supplied ::u_string_t object \p s 
 *
 *  \param  s   the ::u_string_t object that will be destroyed
 *
 *  \retval  0  always
 */
int u_string_free (u_string_t *s)
{
    if (s)
    {
        if (s->data_sz)
            U_FREE(s->data);
        u_free(s);
    }

    return 0;
}
Beispiel #12
0
static int io_mem_free(io_mem_t *im)
{
    dbg_return_if (im == NULL, ~0);

    if(im->flags & IO_MEM_FREE_BUF)
    {
        U_FREE(im->buf);
        im->buf = NULL;
        im->size = im->off = 0;
    }

    return 0;
}
Beispiel #13
0
/** 
 * \brief   Destroy a \c klog_t object
 *
 * \param kl    The \c klog_t object to be destroyed.  When destroying a 
 *              \c KLOG_TYPE_MEM object, all log messages are lost.
 * \return nothing
 */
void klog_close (klog_t *kl)
{
    if (kl == NULL) 
        return;
    if (!IS_KLOG_TYPE(kl->type)) 
        return;

    /* call private close function */
    if (kl->cb_close)
        kl->cb_close(kl);

    U_FREE(kl);

    return;
}
Beispiel #14
0
static int gzip_free(codec_t *codec)
{
    codec_gzip_t *iz;
    int err;

    nop_return_if (codec == NULL, 0);
    
    iz = (codec_gzip_t*)codec;
    dbg_err_if((err = iz->opEnd(&iz->zstr)) != Z_OK);
    U_FREE(iz);

    return 0;
err:
    u_dbg("%s", zError(err));
    return ~0;
}
Beispiel #15
0
/**
 * \brief   Create a cipher \c codec_t object 
 *  
 * Create a gzip \c codec_t object at \p *piz suitable for compression or
 * decompression (depending on \p op).  
 *  
 * \param   op      one of \c GZIP_COMPRESS or \c GZIP_UNCOMPRESS
 * \param   piz     the created codec as a value-result arguement
 *  
 * \return \c 0 on success, \c ~0 otherwise
 */
int codec_gzip_create(int op, codec_t **piz)
{
    codec_gzip_t *iz = NULL;

    dbg_return_if (piz == NULL, ~0);

    iz = u_zalloc(sizeof(codec_gzip_t));
    dbg_err_if(iz == NULL);

    iz->codec.transform = gzip_transform;
    iz->codec.flush = gzip_flush;
    iz->codec.free = gzip_free;
    iz->action = op; 

    switch(op)
    {
    case GZIP_COMPRESS:
        iz->op = deflate;
        iz->opEnd = deflateEnd;
        dbg_err_if(deflateInit2(&iz->zstr, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
                    -MAX_WBITS, 8, Z_DEFAULT_STRATEGY));
        break;
    case GZIP_UNCOMPRESS:
        iz->op = inflate;
        iz->opEnd = inflateEnd;
        dbg_err_if(inflateInit2(&iz->zstr, -MAX_WBITS) != Z_OK);
        break;
    default:
        dbg_err_if("bad gzip op");
    }

    *piz = (codec_t*)iz;

    return 0;
err:
    U_FREE(iz);
    return ~0;
}