Пример #1
0
static void test_10(void) {
	sSLList *l1,*l2;
	size_t oldFree;
	test_caseStart("Testing sll_clone");
	oldFree = heapspace();

	l1 = sll_create();
	sll_append(l1,(void*)4);
	sll_append(l1,(void*)3);
	sll_append(l1,(void*)2);
	l2 = sll_clone(l1);
	test_assertSize(sll_length(l2),3);
	test_assertPtr(sll_get(l2,0),(void*)4);
	test_assertPtr(sll_get(l2,1),(void*)3);
	test_assertPtr(sll_get(l2,2),(void*)2);
	sll_destroy(l1,false);
	sll_destroy(l2,false);

	l1 = sll_create();
	l2 = sll_clone(l1);
	test_assertSize(sll_length(l2),0);
	sll_destroy(l2,false);
	sll_destroy(l1,false);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
Пример #2
0
void
stress_test_sll(int amt)
{
	sll l1;
	sll l2;
	gendata x, y;
	int i;

	l1 = sll_create();
	l2 = sll_create();
	assert(sll_empty(l1));
	assert(sll_empty(l2));
	printf("Filling two slls with 2 * %d items...\n", amt);
	for (i = 0; i < amt; ++i) {
		x.num = i;
		l1 = sll_prepend_head(l1, x);
		l2 = sll_prepend_head(l2, x);
		assert(!sll_empty(l1));
		assert(!sll_empty(l2));
		l1 = sll_append_head(l1, x);
		l2 = sll_append_head(l2, x);
		assert(!sll_empty(l1));
		assert(!sll_empty(l2));
	}
	assert(sll_count(l1) == (unsigned int)(2 * amt));
	assert(sll_count(l2) == (unsigned int)(2 * amt));

	l1 = sll_append(l1, l2);
	assert(sll_count(l1) == (unsigned int)(4 * amt));

	/* From now on, l2 is `invalid' */

	printf("Removing 2 * 2 * %d items from the appended sll...\n", amt);
	for (i = 0; i < (2 * amt); ++i) {
		x = sll_get_data(sll_next(l1));
		assert(!sll_empty(l1));
		l1 = sll_remove_next(l1, NULL);
		y = sll_get_data(l1);
		assert(!sll_empty(l1));
		l1 = sll_remove_head(l1, NULL);

		/*
		 * We have to count backwards in this check, since we're
		 * using the list like a stack, prepending all the time.
		 */
		assert(x.num == amt - (i % amt) - 1);
		assert(x.num == y.num);
	}
	assert(sll_empty(l1));
	sll_destroy(l1, NULL);
}
Пример #3
0
static void test_1(void) {
	ulong x = 0x100;
	size_t i,len,oldFree;
	bool res = true;
	sSLList *list;
	test_caseStart("Append & check & remove index 0");
	oldFree = heapspace();

	list = sll_create();
	for(i = 0; i < 20; i++) {
		sll_append(list,(void*)x++);
	}
	x = 0x100;
	for(i = 0; i < 20; i++) {
		if(sll_get(list,i) != (void*)x++) {
			res = false;
			break;
		}
	}
	if(res) {
		for(i = 0; i < 20; i++) {
			sll_removeIndex(list,0);
		}
	}
	test_assertTrue(res);

	len = sll_length(list);
	test_assertSSize(len,0);
	sll_destroy(list,false);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
Пример #4
0
static void test_9(void) {
	sSLList *list;
	size_t oldFree;

	test_caseStart("Testing sll_indexOf and sll_nodeWith");
	oldFree = heapspace();

	list = sll_create();
	sll_append(list,(void*)0x123);
	sll_append(list,(void*)0x456);
	sll_append(list,(void*)0x789);

	test_assertSSize(sll_indexOf(list,(void*)0x123),0);
	test_assertSSize(sll_indexOf(list,(void*)0x456),1);
	test_assertSSize(sll_indexOf(list,(void*)0x789),2);
	test_assertSSize(sll_indexOf(list,(void*)0x123123),-1);
	test_assertPtr(sll_nodeWith(list,(void*)0x123),sll_nodeAt(list,0));
	test_assertPtr(sll_nodeWith(list,(void*)0x456),sll_nodeAt(list,1));
	test_assertPtr(sll_nodeWith(list,(void*)0x789),sll_nodeAt(list,2));
	test_assertPtr(sll_nodeWith(list,(void*)0x123123),NULL);
	sll_destroy(list,false);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
Пример #5
0
static void test_8(void) {
	sSLList *list;
	size_t oldFree;
	sSLNode *n;

	test_caseStart("Walking through the list");
	oldFree = heapspace();

	list = sll_create();
	sll_append(list,(void*)0x123);
	sll_append(list,(void*)0x456);
	sll_append(list,(void*)0x789);

	n = sll_begin(list);
	test_assertPtr(n->data,(void*)0x123);
	n = n->next;
	test_assertPtr(n->data,(void*)0x456);
	n = n->next;
	test_assertPtr(n->data,(void*)0x789);
	n = n->next;
	test_assertPtr(n,NULL);

	n = sll_nodeAt(list,2);
	test_assertPtr(n->data,(void*)0x789);
	n = n->next;
	test_assertPtr(n,NULL);

	sll_destroy(list,false);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
Пример #6
0
static void test_6(void) {
	ulong x = 0x100;
	size_t i,oldFree;
	sSLList *list;
	bool res = true;
	test_caseStart("Create & append & set somewhere & destroy");
	oldFree = heapspace();

	list = sll_create();
	for(i = 0; i < 5; i++) {
		sll_append(list,(void*)x++);
	}
	sll_set(list,(void*)0x200,3);
	if(sll_get(list,3) != (void*)0x200)
		res = false;
	sll_set(list,(void*)0x201,2);
	if(sll_get(list,2) != (void*)0x201)
		res = false;
	sll_set(list,(void*)0x202,1);
	if(sll_get(list,1) != (void*)0x202)
		res = false;
	sll_set(list,(void*)0x203,0);
	if(sll_get(list,0) != (void*)0x203)
		res = false;
	sll_set(list,(void*)0x204,4);
	if(sll_get(list,4) != (void*)0x204)
		res = false;
	if(sll_length(list) != 5)
		res = false;
	sll_destroy(list,false);
	test_assertTrue(res);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
Пример #7
0
void strBuf_joinAllStr(NStrBuf* strBuf)
{
    char* all;
    int len = 0, c = 0;
    NStrBufSeg* seg;
    
    if (strBuf->lst == N_NULL)
        return;
    
    seg = sll_first(strBuf->lst);
    while (seg) {
        len += seg->len;
        c++;
        seg = sll_next(strBuf->lst);
    }
    
    if (len == 0 || c == 1)
        return;
    
    all = (char*)NBK_malloc(len);
    len = 0;
    seg = sll_first(strBuf->lst);
    while (seg) {
        NBK_memcpy(all + len, seg->data, seg->len);
        len += seg->len;
        seg = sll_next(strBuf->lst);
    }
    strBuf_reset(strBuf);
    
    strBuf->lst = sll_create();
    seg = (NStrBufSeg*)NBK_malloc0(sizeof(NStrBufSeg));
    seg->data = all;
    seg->len = len;
    sll_append(strBuf->lst, seg);
}
Пример #8
0
/**
 * This function will create a PCB. It will also create the PCB linked list.
 *
 * @return  NULL if there are no resources to create a PCB.
 *          Otherwise,  pointer to a new PCB is returned.
 *
 *  @pre     (key != NULL) and (data != NULL)
 */
static ccsip_publish_cb_t *get_new_pcb (void)
{
    ccsip_publish_cb_t *pcb_p;

    /*
     * If PCB list is not created yet, create the list.
     */
    if (s_PCB_list == NULL) {
        s_PCB_list = sll_create(is_matching_pcb);
        if (s_PCB_list == NULL) {
            return NULL;
        }
    }

    pcb_p = (ccsip_publish_cb_t *)cpr_malloc(sizeof(ccsip_publish_cb_t));
    if (pcb_p == NULL) {
        return NULL;
    }
    memset(pcb_p, 0, sizeof(ccsip_publish_cb_t));
    pcb_p->pub_handle = generate_new_pub_handle();
    pcb_p->hb.cb_type = PUBLISH_CB;
    pcb_p->hb.dn_line = 1; // for now set it to primary line. This will change when we do line based PUBLISH.
    /*
     * set up dest & src ip addr and port number.
     */
    ccsip_common_util_set_dest_ipaddr_port(&pcb_p->hb);
    ccsip_common_util_set_src_ipaddr(&pcb_p->hb);
    pcb_p->hb.local_port = sipTransportGetListenPort(pcb_p->hb.dn_line, NULL);
    pcb_p->retry_timer.timer = cprCreateTimer("PUBLISH retry timer",
                                              SIP_PUBLISH_RETRY_TIMER,
                                              TIMER_EXPIRATION,
                                              sip_msgq);
    if (pcb_p->retry_timer.timer == NULL) {
        cpr_free(pcb_p);
        return NULL;
    }
    pcb_p->pending_reqs = sll_create(NULL);
    if (pcb_p->pending_reqs == NULL) {
        (void)cprDestroyTimer(pcb_p->retry_timer.timer);
        cpr_free(pcb_p);
        return NULL;
    }
    (void) sll_append(s_PCB_list, pcb_p);

    return pcb_p;
}
Пример #9
0
/**
 * \brief Create a new empty association list.
 *
 * \return  A new empty alist object, or \c NULL in case of an error.
 *
 * \par Errno values:
 * - \b ENOMEM if out of memory.
 *
 * \sa alist_destroy
 */
alist
alist_create(void)
{
	alist_t *al;

	if ((al = malloc(sizeof(alist_t))) != NULL)
		al->list = sll_create();

	return (alist)al;
}
Пример #10
0
/**
 * This function will append presence notification to the pending queue.
 *
 * @param[in] event_data_p - pointer to event data.
 *
 * @return none.
 *
 * @pre (event_data_p != NULL)
 */
static void append_notification_to_pending_queue (ccsip_event_data_t *event_data_p)
{
    static const char fname[] = "append_notification_to_pending_queue";
    pres_pending_notify_t *pending_notify_p;
    Presence_ext_t *event_body_p = &(event_data_p->u.presence_rpid);

    /*
     * create pending list if it is not created yet.
     */
    if (s_pending_notify_list == NULL) {
        s_pending_notify_list = sll_create(NULL);
        if (s_pending_notify_list == NULL) {
            CSFLogError("src-common", "MSC: 0/0: %s: out of memory", fname);
            free_event_data(event_data_p);
            return;
        }
    }

    pending_notify_p = (pres_pending_notify_t *)sll_next(s_pending_notify_list, NULL);
    while (pending_notify_p != NULL) {
        if (strncmp(pending_notify_p->presentity, event_body_p->presence_body.entity,
                    CC_MAX_DIALSTRING_LEN - 1) == 0) {
            /* replace the current state with new state */
            free_event_data(pending_notify_p->event_data_p);
            pending_notify_p->event_data_p = event_data_p;
            return;
        }
        pending_notify_p = (pres_pending_notify_t *)sll_next(s_pending_notify_list,
                                                             pending_notify_p);
    }

    /*
     * To protect from DoS attacks, do not allow more than
     * MAX_REG_LINES entries in the list.
     */
    if (sll_count(s_pending_notify_list) == MAX_REG_LINES) {
        CSFLogError("src-common", "MSC: 0/0: %s: ignoring the NOTIFY "
            "to protect from DoS attack", fname);
        free_event_data(event_data_p);
        return;
    }
    pending_notify_p = (pres_pending_notify_t *)
                       cpr_malloc(sizeof(pres_pending_notify_t));
    if (pending_notify_p == NULL) {
        CSFLogError("src-common", "MSC: 0/0: %s: out of memory", fname);
        free_event_data(event_data_p);
        return;
    }
    sstrncpy(pending_notify_p->presentity, event_body_p->presence_body.entity,
             CC_MAX_DIALSTRING_LEN);
    pending_notify_p->event_data_p = event_data_p;
    (void) sll_append(s_pending_notify_list, pending_notify_p);
    return;
}
Пример #11
0
void strBuf_appendStr(NStrBuf* strBuf, const char* str, int length)
{
    int len = (length == -1) ? nbk_strlen(str) : length;
    NStrBufSeg* seg = (NStrBufSeg*)NBK_malloc0(sizeof(NStrBufSeg));
    seg->len = len;
    seg->data = (char*)NBK_malloc(len);
    NBK_memcpy(seg->data, (void*)str, len);
    
    if (strBuf->lst == N_NULL)
        strBuf->lst = sll_create();
    sll_append(strBuf->lst, seg);
}
Пример #12
0
/* Returns 1 if 'string' is a palindrom, 0 otherwise. */
int isPalindrome(char *string)
{
    int result = 0; /* set to 1 if 'string' is a palindrome */
    int i;
	int count = 0;
    
    /* Before finishing this function, you'll need to finish sll.c */
    struct sll *halfword = sll_create();
    struct sll *halfword2 = sll_create();
    for (i = 0; i < (int)strlen(string)/2; i++) {
        /* "string[i]" will retrieve the next character */
		sll_push(halfword, string[i]);
		printf("%c", sll_top(halfword));
    }
	printf(" ");
	for (i = (int)strlen(string); i > (int)strlen(string)/2; i--) {
		sll_push(halfword2, string[i]);
		printf("%c", sll_top(halfword2));
	}

    
    /* This loop will help you iterate over a string one character at time */
    for (i = 0; i < (int)strlen(string)/2; i++) {
		if (sll_top(halfword) == sll_top(halfword2)) {
			sll_pop(halfword);
			sll_pop(halfword2);
			count++;
	    }
	}
	printf("\n%d\n", count);

	if (count == (int)strlen(string)/2) {
		result = 1;
	} else {
		result = 0;
	}
    
    return result;
}
Пример #13
0
sSLList *sll_clone(const sSLList *list) {
	sSLNode *n;
	sSLList *l = sll_create();
	if(!l)
		return NULL;
	for(n = sll_begin(list); n != NULL; n = n->next) {
		if(!sll_append(l,n->data)) {
			sll_destroy(l,false);
			return NULL;
		}
	}
	return l;
}
Пример #14
0
/**
 *
 * Initialize cac module by enabling debugs and creating a cac list.
 *
 * @param void
 *
 * @return  void
 *
 * @pre     (NULL)
 */
void fsm_cac_init (void)
{
    const char fname[] = "fsm_cac_init";


    /* allocate and initialize cac list */
    s_cac_list = sll_create((sll_match_e(*)(void *, void *))
                            fsm_cac_match_call_id);

    if (s_cac_list == NULL) {
        CAC_ERROR(DEB_F_PREFIX"CAC list creation failed.",
                                    DEB_F_PREFIX_ARGS("CAC", fname));

    }
}
Пример #15
0
static void test_4(void) {
	ulong x = 0x100;
	size_t i,oldFree;
	sSLList *list;
	test_caseStart("Create & append & destroy");
	oldFree = heapspace();

	list = sll_create();
	for(i = 0; i < 200; i++) {
		sll_append(list,(void*)x++);
	}
	sll_destroy(list,false);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
Пример #16
0
void CResourceManager::ConstructL()
{
    iProbe = new CProbe();
    iTimer = CPeriodic::NewL(0);

    RFs& fs = CCoeEnv::Static()->FsSession();
    fs.MkDirAll(_L("c:\\data\\nbk\\cache\\"));
    
    iCookieMgr = cookieMgr_create();
    cookieMgr_load(iCookieMgr, COOKIE_PATH);
    
    iCacheMgr = cacheMgr_create(50);
    cacheMgr_setPath(iCacheMgr, CACHE_PATH);
    cacheMgr_load(iCacheMgr);
    
    iConnList = sll_create();

    GenPhoneID();
}
Пример #17
0
/* Returns 1 if 'string' is a palindrom, 0 otherwise. */
int isPalindrome(char *string)
{
    int result = 1; /* set to 1 if 'string' is a palindrome */
    int i;
    
    /* Before finishing this function, you'll need to finish sll.c */
    
    struct sll * s = sll_create();
	for (i = 0; i < (int)strlen(string); i++)
    {
	//sll_push(s, string[i]);
    }
    /* This loop will help you iterate over a string one character at time */
    for (i = 0; i < (int)strlen(string); i++)
    {
      //  if(sll_pop(s) != string[i]);
		//return 0;
    }
    
    return result;
}
Пример #18
0
/*
 *  Function: ccsip_info_package_handler_init
 *
 *  Parameters:
 *      None
 *
 *  Description:
 *      Initializes the Info Package handler framework.
 *
 *  Return:
 *      SIP_OK - Info Package handler framework initialized successfully
 *      SIP_ERROR - otherwise
 */
int
ccsip_info_package_handler_init(void)
{
    static const char *fname = "ccsip_info_package_handler_init";
    info_index_t info_index;
    type_index_t type_index;

    if (s_handler_registry != NULL) {
        // Is this considered an error?
        CCSIP_DEBUG_TASK("%s: Info Package handler already initialized", fname);
        return SIP_OK;
    }

    /* Create the SLL */
    s_handler_registry = sll_create(is_matching_type);
    if (s_handler_registry == NULL) {
        CCSIP_DEBUG_ERROR("%s: failed to create the registry", fname);
        return SIP_ERROR;
    }

    for (info_index = 0; info_index < MAX_INFO_HANDLER; info_index++) {
        g_registered_info[info_index] = NULL;
    }

    for (type_index = 0; type_index < MAX_INFO_HANDLER; type_index++) {
        s_registered_type[type_index] = NULL;
    }

    // XXX Where is the best place to register the application-specific handler?
#ifdef _CONF_ROSTER_
    /* Register the handler for conference & x-cisco-conference Info Packages */
    ccsip_register_info_package_handler(INFO_PACKAGE_CONFERENCE,
                                        CONTENT_TYPE_CONFERENCE_INFO,
                                        conf_info_package_handler);
    ccsip_register_info_package_handler(INFO_PACKAGE_CISCO_CONFERENCE,
                                        CONTENT_TYPE_CONFERENCE_INFO,
                                        conf_info_package_handler);
#endif
    return SIP_OK;
}
Пример #19
0
static void test_2(void) {
	ulong x = 0x100;
	size_t i,len,oldFree;
	sSLList *list;
	test_caseStart("Append & remove first (NULL)");
	oldFree = heapspace();

	list = sll_create();
	for(i = 0; i < 2; i++) {
		sll_append(list,(void*)x++);
	}
	for(i = 0; i < 2; i++) {
		sll_removeFirstWith(list,NULL);
	}

	len = sll_length(list);
	test_assertSize(len,0);
	sll_destroy(list,false);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
Пример #20
0
static void test_11(void) {
	sSLList *l1;
	size_t oldFree;
	test_caseStart("Testing sll_removeFirst");
	oldFree = heapspace();

	l1 = sll_create();
	sll_append(l1,(void*)4);
	sll_append(l1,(void*)3);
	sll_append(l1,(void*)2);
	test_assertSize(sll_length(l1),3);
	test_assertPtr(sll_removeFirst(l1),(void*)4);
	test_assertSize(sll_length(l1),2);
	test_assertPtr(sll_removeFirst(l1),(void*)3);
	test_assertSize(sll_length(l1),1);
	test_assertPtr(sll_removeFirst(l1),(void*)2);
	test_assertSize(sll_length(l1),0);
	test_assertPtr(sll_removeFirst(l1),NULL);
	sll_destroy(l1,false);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
Пример #21
0
/*
 *  Function: get_state()
 *
 *  Parameters: request_id - unique id assigned by the platform to this subscription. Platform
 *                           uses this to track the status updates and to make subsequent termination
 *                           request.
 *              duration - how long the subscription is requested to be valid.
 *              watcher - entity that is requesting the presence state.
 *              presentity - entity whose presence state is requested.
 *              app_id - application that is making the subscription.
 *                       0: indicates call list blf application.
 *                       1..n: indicates the speeddial/blf associated with (1..n)th line button.
 *              feature_mask - indicates the additional features enabled.
 *
 *  Description:  is invoked by platform side whenever it needs to susbcribe
 *                for presence state of a presentity. This stores the susbcription
 *                data in a linked list and posts SIPSPI_EV_CC_SUBSCRIBE
 *                to SIP stack. We need to store the subscription data so that
 *                SUBSCRIBE response and NOTIFYs can be mapped to subscriptions.
 *
 *  Returns: void
 */
static void
get_state (int request_id,
           int duration,
           const char *watcher,
           const char *presentity,
           int app_id,
           int feature_mask)
{
    static const char fname[] = "get_state";
    pres_subscription_req_t *sub_req_p;

    DEF_DEBUG(DEB_F_PREFIX"REQ %d: TM %d: WTR %s: PRT %s: FMSK %d: APP %d",
         DEB_F_PREFIX_ARGS(BLF_INFO, fname),
         request_id, duration, watcher, presentity, feature_mask, app_id);
    /*
     * if there is no subscription list yet, create one.
     */
    if (s_pres_req_list == NULL) {
        s_pres_req_list = sll_create(find_matching_node);
        if (s_pres_req_list == NULL) {
            /* let platform know that we can not continue */
            ui_BLF_notification(request_id, CC_SIP_BLF_REJECTED, app_id);
            BLF_ERROR(MISC_F_PREFIX"Exiting : request list creation failed", fname);
            return;
        }
    }
    /*
     * check if a request is already created by walking through the list. if not, create one.
     */
    if ((sub_req_p = (pres_subscription_req_t *)
                sll_find(s_pres_req_list, &request_id)) == NULL) {
        /*
         * populate subscription request and append it to the list.
         */
        sub_req_p = (pres_subscription_req_t *)
            cpr_malloc(sizeof(pres_subscription_req_t));
        if (sub_req_p == NULL) {
            BLF_ERROR(MISC_F_PREFIX"Exiting : malloc failed", fname);
            return;
        }

        sub_req_p->request_id = request_id;
        sub_req_p->sub_id = CCSIP_SUBS_INVALID_SUB_ID;
        sub_req_p->highest_cseq = 0;
        sub_req_p->duration = duration;
        sstrncpy(sub_req_p->presentity, presentity, CC_MAX_DIALSTRING_LEN);
        sstrncpy(sub_req_p->watcher, watcher, CC_MAX_DIALSTRING_LEN);
        sub_req_p->app_id = app_id;
        sub_req_p->feature_mask = feature_mask;
        sub_req_p->blf_state = CC_SIP_BLF_UNKNOWN;

        (void) sll_append(s_pres_req_list, sub_req_p);
    } else { /* already exists. just update the duration */
        sub_req_p->duration = duration;
    }

    /*
     * post SIPSPI_EV_CC_SUBSCRIBE to SIP stack
     */
    if (send_subscribe_ev_to_sip_task(sub_req_p) != CC_RC_SUCCESS) {
        /*
         * remove the node from the list of subscriptions.
         */
        free_sub_request(sub_req_p);
        /* let platform know that we can not continue */
        ui_BLF_notification(request_id, CC_SIP_BLF_REJECTED, app_id);
        BLF_ERROR(MISC_F_PREFIX"Exiting : Unable to send SUBSCRIBE", fname);
        return;
    }

    BLF_DEBUG(DEB_F_PREFIX"Exiting : request made successfully", DEB_F_PREFIX_ARGS(BLF, fname));
    return;
}