Esempio n. 1
0
/* Get the printed form of a line from the parsed form by concatenating all of the strings together */
static DWORD GetPrintedLine(DynamicArray *dest, struct SshConf *conf, int line)
{
    DWORD ceError = ERROR_SUCCESS;
    size_t len = 0;
    char **strings[5];
    size_t stringLengths[5];
    size_t pos;
    int stringCount = 5;
    int i;

    GetLineStrings(strings, &conf->lines[line], &stringCount);
    for(i = 0; i < stringCount; i++)
    {
        stringLengths[i] = strlen(*strings[i]);
        len += stringLengths[i];
    }
    //For the terminating NULL
    len++;

    if(len > dest->capacity)
        BAIL_ON_CENTERIS_ERROR(ceError = CTSetCapacity(dest, 1, len));
    pos = 0;
    for(i = 0; i < stringCount; i++)
    {
        memcpy((char *)dest->data + pos, *strings[i], stringLengths[i]);
        pos += stringLengths[i];
    }
    ((char *)dest->data)[pos] = '\0';
    dest->size = len;

error:
    return ceError;
}
Esempio n. 2
0
DWORD
EnsureSpace(StringBuffer* buffer, unsigned int space)
{
    DWORD ceError = ERROR_SUCCESS;
    if(space <= buffer->capacity)
    {
        ceError = CTSetCapacity(buffer, 1, space + 1);
        CLEANUP_ON_DWORD(ceError);
        ceError = NullTerminate(buffer);
        CLEANUP_ON_DWORD(ceError);
    }
    
cleanup:
    return ceError;
}
Esempio n. 3
0
DWORD CTArrayInsert(DynamicArray *array, int insertPos, int itemSize, const void *data, size_t dataLen)
{
    DWORD ceError = ERROR_SUCCESS;

    if(array->size + dataLen > array->capacity)
    {
        /* Resize the array */
        ceError = CTSetCapacity(array, itemSize, array->capacity + dataLen + array->capacity);
        BAIL_ON_CENTERIS_ERROR(ceError);
    }
    /* Make room for the new value */
    memmove((char *)array->data + (insertPos + dataLen)*itemSize,
            (char *)array->data + insertPos*itemSize,
            (array->size - insertPos)*itemSize);
    memcpy((char *)array->data + insertPos*itemSize, data, dataLen*itemSize);
    array->size += dataLen;
error:
    return ceError;
}
Esempio n. 4
0
/* Get the printed form of a line from the parsed form by concatenating all of the strings together */
static DWORD GetPrintedLine(DynamicArray *dest, NsswitchConf *conf, int line)
{
    DWORD ceError = ERROR_SUCCESS;
    size_t len = 0;
    char *pos;
    int i;
    const NsswitchEntry *lineObj = GetEntry(conf, line);

    len += CTGetTokenLen(&lineObj->name);
    for(i = 0; i < lineObj->modules.size; i++)
    {
        len += CTGetTokenLen(&((CTParseToken *)lineObj->modules.data)[i]);
    }
    if(lineObj->comment != NULL)
        len += strlen(lineObj->comment);

    //For the terminating NULL
    len++;

    if(len > dest->capacity)
        GCE(ceError = CTSetCapacity(dest, 1, len));
    pos = dest->data;
    CTAppendTokenString(&pos, &lineObj->name);
    for(i = 0; i < lineObj->modules.size; i++)
    {
        CTAppendTokenString(&pos, &((CTParseToken *)lineObj->modules.data)[i]);
    }
    if(lineObj->comment != NULL)
    {
        memcpy(pos, lineObj->comment, strlen(lineObj->comment));
        pos += strlen(lineObj->comment);
    }
    *pos = '\0';
    dest->size = len;

cleanup:
    return ceError;
}