Beispiel #1
0
/* read apilog for given class, return the count of log entries in the file */
_Use_decl_annotations_
int readAPIlog(Config* config, char* logs[MAXLOGENTRY])
{
    FILE* apilogfile = File_Open(config->APIlogFilepath, "r");
    int entrycount = 0;
    static size_t nbufsize = 128;
    char* buf = (char*)Batch_Get(g_batch, nbufsize);
    memset(logs, 0, sizeof(logs));
    if (!apilogfile || !buf)
    {
        return 0;
    }
    while(fscanf(apilogfile, "%s\r\n", buf) > 0)
    {
        logs[entrycount++] = buf;
        if (entrycount >= MAXLOGENTRY)
            break;
        buf = (char*)Batch_Get(g_batch, nbufsize);
        if (!buf)
            break;
    }
    File_Close(apilogfile);
    return entrycount;
}
Beispiel #2
0
ProvRegNamespaceNode* _FindOrCreateNamespace(
    ProvReg* self,
    MI_ConstString ns,
    MI_Boolean extraClass)
{
    ProvRegNamespaceNode* item = _FindNamespace(self,ns, extraClass);

    if (item)
        return item;

    item = (ProvRegNamespaceNode*)Batch_GetClear(
        &self->batch, sizeof(ProvRegNamespaceNode));

    if (item)
    {
        if(extraClass)
        {
            size_t size;
            size = Tcslen(ns) + 1;

            {
                ZChar* nameSpace = Batch_Get(&self->batch, size * sizeof(ZChar));
                if(nameSpace == NULL)
                {
                    trace_OutOfMemory();
                    return NULL;
                }
                Tcslcpy(nameSpace, ns, size);
                
                item->ns = nameSpace;
                item->next = self->namespacesForExtraClasses;
                self->namespacesForExtraClasses = item;
            }
        }
        else
        {
            item->ns = ns; /* no need to strdup, since it's already in batch*/
            item->next = self->namespaces;
            self->namespaces = item;
        }
    }

    return item;
}
Beispiel #3
0
/*=============================================================================
**
** Append Ptr, allocate memory from batch
**
=============================================================================*/
int PtrArray_Append_Batch(_In_ void *mofbatch, _Inout_ PtrArray* self, _In_ void* ptr)
{
    void * olddata;
    Batch * batch = (Batch *)mofbatch;
    size_t newsize;
    newsize = GetSize(self->size);
    if (newsize > 0)
    {
        /* Allocate memory */
        olddata = self->data;
        self->data = (void**)Batch_Get(batch, sizeof(void*) * (newsize));
        if (!self->data)
        {
            return -1;
        }
        memcpy(self->data, olddata, sizeof(void*) * self->size);
    }
    /* else the capacity of olddata is enough */
    self->data[self->size++] = ptr;
    return 0;
}
Beispiel #4
0
_Use_decl_annotations_
void readconfig(const char* classname, Config* config)
{
    static size_t nbufsize = 256;
    FILE* configfile;
    char* configfilepath = (char*)Batch_Get(g_batch, nbufsize);
    char* apilogfilepath = (char*)Batch_Get(g_batch, nbufsize);

    config->className = classname;
    
    if (!configfilepath)
    {
        config->configFilepath = "outofmemory";
        return;
    }
    if (!apilogfilepath)
    {
        config->APIlogFilepath = "outofmemory";
        return;
    }

    sprintf(configfilepath, filenameformat, g_dirpath, classname, "config");
    sprintf(apilogfilepath, filenameformat, g_dirpath, config->className, "apilog");
    config->configFilepath = configfilepath;
    config->APIlogFilepath = apilogfilepath;

    configfile = File_Open(configfilepath, "r");
    if (!configfile)
    {
        /* create one */
        config->subscribeBookmark = ".";
        config->providerBookmark = ".";
        config->dialect = ".";
        config->expression = ".";
        config->failAfterCount = MAX_UINT32;
        config->intervalMS = 1000;
        writeconfig(config);
    }
    else
    {
        config->subscribeBookmark = (char*)Batch_GetClear(g_batch, nbufsize);
        config->providerBookmark = (char*)Batch_GetClear(g_batch, nbufsize);
        config->dialect = (char*)Batch_GetClear(g_batch, nbufsize);
        config->expression = (char*)Batch_GetClear(g_batch, nbufsize);
        
        if (!config->subscribeBookmark || !config->providerBookmark  ||
            !config->dialect || !config->expression)
        {
            config->configFilepath = "FAILED";
            File_Close(configfile);
            return;
        }
        /* read config from file */
        fscanf(configfile, gformat1,
            &config->testGroup,
            &config->intervalMS,
            &config->failAfterCount,
            &config->failResult,
            &config->initBehavior,
            &config->initResultCode,
            &config->initTimeoutMS,
            &config->finalizeBehavior,
            &config->finalizeResultCode,
            &config->postBehavior,
            &config->miscTestSubGroup,
            &config->evalResult,
            &config->logLoadUnloadCall);

        fscanf(configfile, "subscribeBookmark=%[^\r\n]", config->subscribeBookmark);
        fscanf(configfile, "\r\n");
        fscanf(configfile, "providerBookmark=%[^\r\n]", config->providerBookmark);
        fscanf(configfile, "\r\n");
        fscanf(configfile, "dialect=%[^\r\n]", config->dialect);
        fscanf(configfile, "\r\n");
        fscanf(configfile, "expression=%[^\r\n]", config->expression);
        File_Close(configfile);
    }
    config->apicallseqcount = readAPIlog(config, config->apicallseq);
    Config_Reopenlogfile(config);
    LOGMSG(("read config file (%s)", config->configFilepath));
}
Beispiel #5
0
MI_Result Initialize()
{
    MI_Result r;
    static size_t nbufsize = 256;
    g_batch = Batch_New(64);
    if (!g_batch)
        return MI_RESULT_SERVER_LIMITS_EXCEEDED;

    g_dirpath = (char*)Batch_Get(g_batch, nbufsize);
    g_logfilepath = (char*)Batch_Get(g_batch, nbufsize);
    if (!g_logfilepath || !g_dirpath)
    {
        r = MI_RESULT_SERVER_LIMITS_EXCEEDED;
        goto error;
    }

    sprintf(g_dirpath, dirformat, gethomedir(), "indicationlog");
    if (Isdir(g_dirpath) == PAL_FALSE)
    {
        if (Mkdir(g_dirpath, 0777) != 0)
        {
            r = MI_RESULT_FAILED;
            goto error;
        }
    }
    sprintf(g_logfilepath, filenameformat, g_dirpath, "provider", "log");

#if !defined(_MSC_VER)
    {
        //
        // Delete file if larger than certain size
        //
        struct stat buf;
        if (stat(g_logfilepath, &buf) == 0)
        {
            if ( (unsigned long)buf.st_size > 0x800000UL )
                File_Remove(g_logfilepath);
        }
    }
#endif

    g_logfile = File_Open(g_logfilepath, "a+");
    if (!g_logfile)
    {
        r = MI_RESULT_FAILED;
        goto error;
    }

    Config_Initialize(&cfgTest_Indication);
    Config_Initialize(&cfgL_IndicationC1);
    Config_Initialize(&cfgL_IndicationC2);
    Config_Initialize(&cfgL_IndicationC3);
    Config_Initialize(&cfgR_IndicationC1);
    Config_Initialize(&cfgR_IndicationC2);
    Config_Initialize(&cfgR_IndicationC3);
    Config_Initialize(&cfgTest_Class);
    Config_Initialize(&cfgL_LifecycleC1);
    Config_Initialize(&cfgL_LifecycleC2);
    Config_Initialize(&cfgR_LifecycleC1);
    Config_Initialize(&cfgR_LifecycleC2);
    

    ReloadConfig();

    LOGMSG(("\r\n\r\n\r\n\r\n==================================================="));
    LOGMSG(("Initialize"));

    return MI_RESULT_OK;

error:
    if (g_logfile)
    {
        File_Close(g_logfile);
        g_logfile = NULL;
    }
    if (g_batch)
    {
        Batch_Delete(g_batch);
        g_batch = NULL;
    }
    return r;
}