Beispiel #1
0
/*
 * Prepare buffer for outgoing call/reply
 * idata - buffer data
 * ilen - data len (if needed)
 * obuf - place where to copy prepared buffer
 * olen - the actual lenght of data that should sent. Also this may represent
 *          space for the buffer to copy to.
 */
public int JSON_prepare_outgoing (typed_buffer_descr_t *descr, char *idata, long ilen, 
                    char *obuf, long *olen, long flags)
{
    int ret=SUCCEED;
    int str_used;
    char fn[]="JSON_prepare_outgoing";
    
    str_used = strlen(idata)+1; /* include EOS */
    
    /* Check that we have space enought to prepare for send */
    if (NULL!=olen && 0!=*olen && *olen < str_used)
    {
        _TPset_error_fmt(TPEINVAL, "%s: Internal buffer space: %d, "
                "but requested: %d", fn, *olen, str_used);
        ret=FAIL;
        goto out;
    }

    memcpy(obuf, idata, str_used);
    
    /* return the actual length! */
    if (NULL!=olen)
        *olen = str_used;
    
out:
    return ret;
}
Beispiel #2
0
/**
 * Parse service argument (-s)
 * @param argc
 * @param argv
 * @return
 */
int parse_svc_arg(char *arg)
{
    char alias_name[XATMI_SERVICE_NAME_LENGTH+1]={EOS};
    char *p;
    svc_entry_t *entry=NULL;

    NDRX_LOG(log_debug, "Parsing service entry: [%s]", arg);
    
    if (NULL!=(p=strchr(arg, ':')))
    {
        NDRX_LOG(log_debug, "Aliasing requested");
        /* extract alias name out */
        strncpy(alias_name, p+1, XATMI_SERVICE_NAME_LENGTH);
        alias_name[XATMI_SERVICE_NAME_LENGTH] = 0;
        /* Put the EOS in place of : */
        *p=EOS;
    }
    
    /* Now loop thourght services and add them to the list. */
    p = strtok(arg, ",");
    while (NULL!=p)
    {
        /* allocate memory for entry */
        if ( (entry = (svc_entry_t*)malloc(sizeof(svc_entry_t))) == NULL)
        {
                _TPset_error_fmt(TPMINVAL, "Failed to allocate %d bytes while parsing -s",
                                    sizeof(svc_entry_t));
                return FAIL; /* <<< return FAIL! */
        }

        strncpy(entry->svc_nm, p, XATMI_SERVICE_NAME_LENGTH);
        entry->svc_nm[XATMI_SERVICE_NAME_LENGTH] = EOS;

        if (EOS!=alias_name[0])
        {
            strcpy(entry->svc_alias, alias_name);
        }
        
        /*
         * Should we check duplicate names here?
         */
        DL_APPEND(G_server_conf.svc_list, entry);

        NDRX_LOG(log_debug, "-s [%s]:[%s]", entry->svc_nm,
                                                         entry->svc_alias);
        p = strtok(NULL, ",");
    }
}
Beispiel #3
0
/**
 * Basic init data structure allocator
 * @param subtype
 * @param len
 * @return
 */
public char	* TPINIT_tpalloc (typed_buffer_descr_t *descr, long len)
{
    char *ret=NULL;
    char fn[] = "UBF_tpalloc";

    /* Allocate UBF buffer */
    ret=malloc(sizeof(TPINIT));

    if (NULL==ret)
    {
        NDRX_LOG(log_error, "%s: Failed to allocate TPINIT buffer!", fn);
        _TPset_error_fmt(TPEOS, "TPINIT failed to allocate: %d bytes", sizeof(TPINIT));
        goto out;
    }

out:
    return ret;
}