Ejemplo n.º 1
0
struct listSet *
listSetSub(struct listSet *set1, struct listSet *set2)
{
    struct listSet *ptr, *tmp;
 
    if (!set1) {
        listSetFree(set2);
        return NULL;
    }

    if (!set2)
        return(set1);

    ptr = set1;
    while (ptr && set2) {
        if (ptr->elem == set2->elem) {
           ptr->elem = -1;
           ptr  = ptr->next;
           set2 = set2->next;
        }
        else if (ptr->elem > set2->elem) 
           set2 = set2->next;
        else
           ptr = ptr->next;
    }

    listSetFree(set2);
    ptr = set1;
    while (ptr->next) {
        if (ptr->next->elem < 0) {
           tmp = ptr->next;
           ptr->next = tmp->next;
           tmp->next = NULL;
           listSetFree(tmp);
        }
        else
           ptr = ptr->next;
    }

    if (set1->elem < 0) {
        tmp = set1;
        set1 = set1->next;
        tmp->next = NULL;
        listSetFree(tmp);
    }
    
    return(set1);
} 
Ejemplo n.º 2
0
struct listSet *
listSetUnion(struct listSet *set1, struct listSet *set2)
{
    struct listSet *setPtr, *setHead;
 
    setHead = listSetAlloc(-1);
    setPtr = setHead;
    while (set1 && set2) {
        if (set1->elem <= set2->elem) {
             setPtr->next = set1;
             set1 = set1->next;
             setPtr = setPtr->next;
        }
        else {
             setPtr->next = set2;
             set2 = set2->next;
             setPtr = setPtr->next;
        }
    }
    setPtr->next = NULL;
    if (set1)
       setPtr->next = set1;
    else
       setPtr->next = set2;

    setPtr = setHead;
    setHead = setHead->next;
    setPtr->next = NULL;
    listSetFree(setPtr);   
    return(setHead);

} 
Ejemplo n.º 3
0
static struct list *createIntList()
{
    struct list *l = createList();
    listSetDup(l, dupInt);
    listSetFree(l, freeInt);
    listSetMatch(l, matchInt);
    return l;
}
Ejemplo n.º 4
0
int initStaticFile(struct protocol *p)
{
    int args, i, ret;
    wstr extensions, indexes;
    struct configuration *conf = getConfiguration("file-maxsize");
    MaxFileSize = conf->target.val;

    conf = getConfiguration("allowed-extension");
    extensions = wstrNew(conf->target.ptr);
    if (wstrIndex(extensions, '*') != -1) {
        AllowExtensions = NULL;
    } else {
        AllowExtensions = dictCreate(&wstrDictType);

        wstr *argvs = wstrNewSplit(extensions, ",", 1, &args);
        if (!argvs) {
            wheatLog(WHEAT_WARNING, "init Static File failed");
            return WHEAT_WRONG;
        }

        for (i = 0; i < args; ++i) {
            ret = dictAdd(AllowExtensions, wstrNew(argvs[i]), wstrNew("allowed"));
            if (ret == DICT_WRONG)
                break;
        }

        wstrFreeSplit(argvs, args);
    }
    wstrFree(extensions);

    conf = getConfiguration("directory-index");
    if (conf->target.ptr) {
        indexes = wstrNew(conf->target.ptr);
        DirectoryIndex = createList();
        listSetFree(DirectoryIndex, (void (*)(void*))wstrFree);
        wstr *argvs = wstrNewSplit(indexes, ",", 1, &args);
        if (!argvs) {
            wheatLog(WHEAT_WARNING, "split failed");
            return WHEAT_WRONG;
        }

        for (i = 0; i < args; ++i) {
            appendToListTail(DirectoryIndex, wstrNew(argvs[i]));
            if (ret == DICT_WRONG)
                break;
        }

        wstrFreeSplit(argvs, args);
    } else {
        DirectoryIndex = NULL;
    }

    IfModifiedSince = wstrNew(IF_MODIFIED_SINCE);
    return WHEAT_OK;
}
Ejemplo n.º 5
0
struct conn *connGet(struct client *client)
{
    if (client->pending) {
        ASSERT(client->pending->client);
        return client->pending;
    }
    struct conn *c = wmalloc(sizeof(*c));
    c->client = client;
    c->protocol_data = client->protocol->initProtocolData();
    c->app = c->app_private_data = NULL;
    appendToListTail(client->conns, c);
    c->ready_send = 0;
    c->send_queue = createList();
    listSetFree(c->send_queue, (void(*)(void*))freeSendPacket);
    c->cleanup = arrayCreate(sizeof(struct callback), 2);
    return c;
}
Ejemplo n.º 6
0
struct listSet *
listSetDuplicate(struct listSet *set)
{
    struct listSet *setPtr, *setHead;

    setHead = listSetAlloc(-1);
    setPtr = setHead;
    while (set) {
        setPtr->next = listSetAlloc(set->elem);
        setPtr = setPtr->next;
        set = set->next;
    }
    setPtr = setHead;
    setHead = setHead->next;
    setPtr->next = NULL;
    listSetFree(setPtr);
    return(setHead);
} 
Ejemplo n.º 7
0
struct client *createClient(int fd, char *ip, int port, struct protocol *p)
{
    struct client *c;
    struct listNode *node;

    node = listFirst(FreeClients);
    if (node == NULL) {
        c = wmalloc(sizeof(*c));
    } else {
        c = listNodeValue(node);
        removeListNode(FreeClients, node);
        appendToListTail(Clients, c);
    }
    if (c == NULL)
        return NULL;
    c->clifd = fd;
    c->ip = wstrNew(ip);
    c->port = port;
    c->protocol = p;
    c->conns = createList();
    listSetFree(c->conns, (void (*)(void*))connDealloc);
    c->req_buf = msgCreate(Server.mbuf_size);
    c->is_outer = 1;
    c->should_close = 0;
    c->valid = 1;
    c->pending = NULL;
    c->client_data = NULL;
    c->notify = NULL;
    c->last_io = Server.cron_time;
    c->name = wstrEmpty();

    createEvent(WorkerProcess->center, c->clifd, EVENT_READABLE,
            handleRequest, c);
    getStatVal(StatTotalClient)++;
    return c;
}
Ejemplo n.º 8
0
struct listSet *
listSetIntersect(struct listSet *set1, struct listSet *set2)
{
    struct listSet *setPtr, *setHead, *setTmp;
 
    setHead = listSetAlloc(-1);
    setPtr = setHead;
    while (set1 && set2) {
        if (set1->elem == set2->elem) {
            setPtr->next = set1;
            set1 = set1->next;
            setTmp = set2;
            set2 = set2->next;
            setTmp->next = NULL;
            listSetFree(setTmp);
            setPtr = setPtr->next;
        }
        else if (set1->elem < set2->elem) {
            setTmp = set1;
            set1 = set1->next;
            setTmp->next = NULL;
            listSetFree(setTmp);
        }
        else {
            setTmp = set2;
            set2 = set2->next;
            setTmp->next = NULL;
            listSetFree(setTmp);
        }
    }

    setPtr->next = NULL;
    if (!set1)
        listSetFree(set1);
    else
        listSetFree(set2);

    setPtr = setHead;
    setHead = setHead->next;
    setPtr->next = NULL;
    listSetFree(setPtr);
    return(setHead);
}