Пример #1
0
void test_remove1(void)
{
  sll_node *list = NULL;

  list = sll_add(list, 1, "one");
  list = sll_add(list, 2, "two");
  list = sll_add(list, 3, "three");
  list = sll_add(list, 4, "four");
  list = sll_add(list, 5, "five");
  list = sll_add(list, 6, "six");
  list = sll_add(list, 7, "seven");
  sll_dump(list);

  list = sll_remove(list, 4);
  sll_dump(list);

  list = sll_remove(list, 5);
  sll_dump(list);

  list = sll_remove(list, 1);
  sll_dump(list);

  list = sll_remove(list, 7);
  sll_dump(list);

  sll_destroy(list);
}
Пример #2
0
int 
main(void)
{
	NODE *p_root = NULL;
	int del_val;

	p_root = creat_list(); /*创建一个非循环单链表,返回根指针*/
	traverse_linkedlist(p_root);	/*遍历链表*/
	
	/*插入新结点*/
	if (0 == sll_insert(&p_root, 19))
	{
		printf("插入节点失败,请重试!");
	}

	printf("插入后的链表");
	traverse_linkedlist(p_root);

	printf("现在节点个数为:%d\n", sll_count_nodes(p_root->link));
	
	/*删除节点*/
	if (sll_remove(&p_root, p_root->link->link, &del_val))
	{
		printf("删除节点成功,被删除的节点的值为:%d\n", del_val);
	}
	
	printf("删除后的链表为:\n");
	traverse_linkedlist(p_root);

	free(p_root);
	return 0;
}
Пример #3
0
/*
 *  Function: ccsip_deregister_info_package_handler
 *
 *  Parameters:
 *      info_package - the Info Package for the handler
 *      content_type - the Content Type for the handler
 *      handler - the handler
 *
 *  Description:
 *      Deregisters the handler for the Info Package/Content Type pair.
 *
 *  Return:
 *      SIP_OK - the handler was registered successfully
 *      SIP_ERROR - otherwise
 */
int
ccsip_deregister_info_package_handler(const char *info_package,
                                      const char *content_type,
                                      info_package_handler_t handler)
{
    static const char *fname = "ccsip_deregister_info_package_handler";
    info_index_t info_index;
    type_index_t type_index;
    handler_record_t *record;

    if (s_handler_registry == NULL) {
        CCSIP_DEBUG_TASK("%s: Info Package handler was not initialized", fname);
        return SIP_ERROR;
    }

    /* Find the info_index for the info_package */
    info_index = find_info_index(info_package);
    if (info_index == INDEX_NOT_FOUND) {
        CCSIP_DEBUG_ERROR("%s: handler was not registered (%s)",
                          fname, info_package);
        return SIP_ERROR;
    }

    /* Find the type_index for the content_type */
    type_index = find_type_index(content_type);
    if (type_index == INDEX_NOT_FOUND) {
        CCSIP_DEBUG_ERROR("%s: handler was not registered (%s)",
                          fname, content_type);
        return SIP_ERROR;
    }

    /* Find the handler record */
    record = find_handler_record(info_index, type_index);
    if ((record == NULL) || (record->handler != handler)) {
        CCSIP_DEBUG_ERROR("%s: handler was not registered (%p)",
                          fname, handler);
        return SIP_ERROR;
    }

    (void)sll_remove(s_handler_registry, record);

    cpr_free(record);

    if (!is_info_package_registered(info_index)) {
        /* The info_package was not found in the registry, meaning we're
         * the last one who registered for this particular info_package */
        cpr_free(g_registered_info[info_index]);
        g_registered_info[info_index] = NULL;
    }

    if (!is_content_type_registered(type_index)) {
        /* The content_type was not found in the registry, meaning we're
         * the last one who registered for this particular content_type */
        cpr_free(s_registered_type[type_index]);
        s_registered_type[type_index] = NULL;
    }

    return SIP_OK;
}
Пример #4
0
void test_stress1(void)
{
  #define SIZE 4500
  sll_node *list = NULL;
  int i, count = 0;
  int *a = malloc(2 * SIZE * sizeof(int));
  char buf[LABEL_SIZE];

  for (i = 0; i < SIZE; i++)
  {
    a[count++] = i + 1;
    sprintf(buf, "%08i", a[i]);
    list = sll_add(list, a[i], buf);  
  }
  #ifdef VERBOSE
  sll_dump(list);
  #endif

  for (i = 0; i < SIZE; i++)
  {
    int r1 = RandomInt(0, 1);
    int r2 = RandomInt(1, count);
    a[count] = count + 1;
    count++;
    sprintf(buf, "%08i", count);

    if (r1)
      list = sll_insert_before(list, r2, count, buf);
    else
      sll_insert_after(list, r2, count, buf);

    #ifdef VERBOSE
    sll_dump(list);
    printf("%s %i", r1 ? "before" : "after", r2);
    #endif
  }
  #ifdef VERBOSE
  sll_dump(list);
  #endif

  /*PrintArray(a, count);*/
  Shuffle(a, count);
  /*PrintArray(a, count);*/

  for (i = 0; i < 2 * SIZE - 20; i++)
  {
    list = sll_remove(list, a[i]);
    #ifdef VERBOSE
    sll_dump(list);
    #endif
  }

  sll_dump(list);
  sll_destroy(list);

  free(a);
}
Пример #5
0
/**
 * This function will process if there are any pending notifications.
 *
 * @param none.
 *
 * @return none.
 */
static void sub_handler_initialized (void)
{
    static const char fname[] = "sub_handler_initialized";
    pres_pending_notify_t *pending_notify_p;
    char  *presentity_url = NULL;
    char  presentity_user[CC_MAX_DIALSTRING_LEN];
    Presence_ext_t *event_body_p = NULL;

    BLF_DEBUG("MSC: 0/0: %s: invoked", fname);
    s_subs_hndlr_initialized = TRUE;

    if (s_pending_notify_list == NULL) {
        BLF_DEBUG("MSC: 0/0: %s: no pending notfications", fname);
        return;
    }

    /*
     * process the pending NOTIFYs.
     */
    pending_notify_p = (pres_pending_notify_t *)sll_next(s_pending_notify_list, NULL);
    while (pending_notify_p != NULL) {
        /* strip of the "sip:" */
        presentity_url = strchr(pending_notify_p->presentity, ':');
        if (presentity_url == NULL)
        {
            BLF_ERROR("MSC: %s: Error parsing presentity_url", fname);
            return;
        }

        presentity_url = presentity_url + 1;

        /*
         * look for long from (user@host) matches first. if none found, look
         * for short form (user) matches.
         */
        event_body_p = &(pending_notify_p->event_data_p->u.presence_rpid);
        if (apply_presence_state_to_matching_feature_keys(presentity_url, event_body_p)
            != TRUE) {
            ccsip_util_extract_user(pending_notify_p->presentity, presentity_user);
            if (apply_presence_state_to_matching_feature_keys(presentity_user,
                event_body_p) != TRUE) {
                BLF_DEBUG("MSC: 0/0: %s: no matching BLF feature keys found", fname);
            }
        }
        BLF_DEBUG("MSC: 0/0: %s: processed a pending notfication for %s",
                  fname, presentity_url);
        free_event_data(pending_notify_p->event_data_p);
        (void) sll_remove(s_pending_notify_list, (void *)pending_notify_p);
        cpr_free(pending_notify_p);

        pending_notify_p = (pres_pending_notify_t *)sll_next(s_pending_notify_list,
                                                             NULL);
    }
    (void)sll_destroy(s_pending_notify_list);
    s_pending_notify_list = NULL;
}
Пример #6
0
/**
 *
 * This is called by gsm to cleanup the cac data. If there are any
 * pending CAC requests and far end cancels the call, the pending
 * request has to be canceled.
 *
 * @param call_id - call_id of the request
 *
 * @return  none.
 *
 * @pre     (NULL)
 */
void fsm_cac_call_release_cleanup (callid_t call_id)
{
    cac_data_t *cac_data;

    cac_data = fsm_cac_get_data_by_call_id(call_id);

    if (cac_data) {

        sll_remove(s_cac_list, cac_data);

        fsm_clear_cac_data(cac_data);
    }

}
Пример #7
0
/**
 * This function will free up the PCB resources and removes it from the PCB list.
 *
 * @param[in] pcb_p -  pointer to a PCB.
 *
 * @return  none
 *
 *  @pre    (pcb_p != NULL)
 */
static void free_pcb (ccsip_publish_cb_t *pcb_p)
{
   if (pcb_p->hb.authen.authorization != NULL) {
       cpr_free(pcb_p->hb.authen.authorization);
   }
   if (pcb_p->hb.authen.sip_authen != NULL) {
       sippmh_free_authen(pcb_p->hb.authen.sip_authen);
   }

    cpr_free(pcb_p->entity_tag);
    free_pending_reqs(pcb_p->pending_reqs);
    (void)cprDestroyTimer(pcb_p->retry_timer.timer);
    free_event_data(pcb_p->hb.event_data_p);
    (void)sll_remove(s_PCB_list, (void *)pcb_p);
    cpr_free(pcb_p);
}
Пример #8
0
/**
 * This function will free up entire list of pending requests
 *
 * @param[in] list -  pending requests list handle
 *
 * @return none 
 *
 */
static void free_pending_reqs (sll_handle_t list)
{
    pub_req_t *msg_p;

    if (list == NULL)  {
        return;
    }

    msg_p = (pub_req_t *)sll_next(list, NULL);
    while (msg_p != NULL) {
        free_event_data(msg_p->event_data_p);
        (void)sll_remove(list, (void *)msg_p);
        cpr_free(msg_p);
        msg_p = (pub_req_t *)sll_next(list, NULL);
    }
    sll_destroy(list);
}
Пример #9
0
/*
 * scheduler_task_remove
 * @tcb: Task control block that is needed to be removed.
 * This function removes a finished task from the global task list. Once
 * removed user can call scheduler_task_add to run a finished task.
 */
void scheduler_task_remove(TASK *tcb)
{
    /* Lock the scheduler. */
    scheduler_lock();

    /* Task should be in finished state. */
    ASSERT(tcb->state != TASK_FINISHED);

#ifdef TASK_STATS
    /* Remove this task from global task list. */
    sll_remove(&sch_task_list, tcb, OFFSETOF(TASK, next_global));
#endif /* TASK_STATS */

    /* Enable scheduling. */
    scheduler_unlock();

} /* scheduler_task_remove */
Пример #10
0
/*
 *  Function: free_sub_request()
 *
 *  Parameters: sup_req_p - pointer to subscription request
 *
 *  Description:  removes from LL, cancels timers if necessary and frees the memory
 *
 *  Returns: void
 */
static void
free_sub_request (pres_subscription_req_t *sub_req_p)
{
    /*
     * remove the node from the linked list of subscriptions.
     */
    (void) sll_remove(s_pres_req_list, (void *)sub_req_p);

    /*
     * If it is a line button subscription, cancel retry-timer if it is running
     */
    if (sub_req_p->app_id > 0) {
        (void) cprCancelTimer(s_retry_after_timers[sub_req_p->app_id - 1]);
    }

    /*
     *  free the memory
     */
    cpr_free(sub_req_p);
}
Пример #11
0
static void
fsm_clear_cac_data (cac_data_t *cac_data)
{

    if (cac_data->cac_fail_timer) {
        (void) cprCancelTimer(cac_data->cac_fail_timer);

        (void) cprDestroyTimer(cac_data->cac_fail_timer);
    }

    (void) sll_remove(s_cac_list, cac_data);

    fim_free_event(cac_data->msg_ptr);

    /* Release buffer too */
    cpr_free(cac_data->msg_ptr);

    cpr_free(cac_data);

}
Пример #12
0
/*
 * console_unregister
 * @console: Console data.
 * This function will unregister a console.
 */
void console_unregister(CONSOLE *console)
{
    /* This could be a file descriptor chain, so destroy it. */
    fs_destroy_chain((FD)&console->fs);

#ifndef CONFIG_SEMAPHORE
    /* Lock the scheduler. */
    scheduler_lock();
#else
    /* Obtain the global data lock. */
    OS_ASSERT(semaphore_obtain(&console_data.lock, MAX_WAIT) != SUCCESS);

    /* Obtain the lock for the console needed to be unregistered. */
    if (semaphore_obtain(&console->lock, MAX_WAIT) == SUCCESS)
    {
#endif
        /* Resume all tasks waiting on this file descriptor. */
        fd_handle_criteria((FD)console, NULL, FS_NODE_DELETED);

#ifdef CONFIG_SEMAPHORE
        /* Delete the console lock. */
        semaphore_destroy(&console->lock);
#endif

        /* Just remove this console from console list. */
        OS_ASSERT(sll_remove(&console_data.list, console, OFFSETOF(CONSOLE, fs.next)) != console);

#ifdef CONFIG_SEMAPHORE
    }

    /* Release the global data lock. */
    semaphore_release(&console_data.lock);
#else
    /* Enable scheduling. */
    scheduler_unlock();
#endif

} /* console_unregister */
Пример #13
0
/**
 * This function will process the response to PUBLISH request sent by us.
 *
 * @param[in] pSipMessage -  pointer to received SIP response msg
 *
 * @return SIP_OK if it successfully processes the response.
 *         SIP_ERROR if it fails to process the response.
 *
 * @pre    (pSipMessage != NULL)
 */
int publish_handle_ev_sip_response (sipMessage_t *pSipMessage)
{
    static const char fname[] = "publish_handle_ev_sip_response";
    const char     *callID_p = NULL;
    int             response_code = 0;
    const char     *expires = NULL;
    const char     *sip_etag = NULL;
    long            expiry_time;
    pub_req_t      *msg_p;
    ccsip_publish_cb_t *pcb_p;
    int entity_tag_size;

    callID_p = sippmh_get_cached_header_val(pSipMessage, CALLID);
    if (!callID_p) {
        CCSIP_DEBUG_ERROR(SIP_F_PREFIX"Cannot obtain SIP Call ID.\n", fname);
        return SIP_ERROR;
    }

    /*
     * Find PCB by Call-ID. The Call-IDs generated by the phone ae unique.
     */
    pcb_p = find_pcb_by_sip_callid(callID_p);
    if (pcb_p == NULL) {
        CCSIP_DEBUG_ERROR(SIP_F_PREFIX"No matching PCB found\n", fname);
        return SIP_ERROR;
    }

    /*
     * Cancel the retry_timer and set the retx_flag to FALSE.
     */
    sip_platform_msg_timer_subnot_stop(&(pcb_p->retry_timer));
    pcb_p->hb.retx_flag = FALSE;
    
    // Parse the return code
    (void) sipGetResponseCode(pSipMessage, &response_code);

    if (response_code >= 200) {
        pcb_p->outstanding_trxn = FALSE;
    }


    if ((response_code == SIP_CLI_ERR_UNAUTH) ||
        (response_code == SIP_CLI_ERR_PROXY_REQD)) {
        CCSIP_DEBUG_TASK(DEB_F_PREFIX"Authentication Required\n", DEB_F_PREFIX_ARGS(SIP_PUB, fname));
        if (ccsip_common_util_generate_auth(pSipMessage, &pcb_p->hb, SIP_METHOD_PUBLISH,
                                            response_code, pcb_p->full_ruri) == TRUE) {
            if (sipSPISendPublish(pcb_p, TRUE) == TRUE) {
                pcb_p->outstanding_trxn = TRUE;
                CCSIP_DEBUG_TASK(DEB_F_PREFIX"sent request with Auth header\n", DEB_F_PREFIX_ARGS(SIP_PUB, fname));
                return SIP_OK;
             }
        }
        /*
         * Since we failed to resend the PUBLISH request, free up the PCB and let the app know.
         */
        send_resp_to_app(PUBLISH_FAILED_SEND, pcb_p->pub_handle, pcb_p->app_handle,
                         pcb_p->callback_task, pcb_p->resp_msg_id);
        free_pcb (pcb_p);
        CCSIP_DEBUG_ERROR(SIP_F_PREFIX"failed to respond to auth challenge\n", fname);
        return SIP_ERROR;
    }

    /*
     * if response code is 423, grab Min-Expires and send new PUBLISH with new expires value
     */
    if (response_code == SIP_CLI_ERR_INTERVAL_TOO_SMALL) {
        expires = sippmh_get_header_val(pSipMessage,
                                        (const char *)SIP_HEADER_MIN_EXPIRES,
                                        NULL);
        if (expires) {
            expiry_time = strtoul(expires, NULL, 10);
            //ensure new Min-Expires is > what we set before in Expires
            if ((long) expiry_time > pcb_p->hb.expires) {
                pcb_p->hb.expires = expiry_time;
                pcb_p->hb.orig_expiration = expiry_time;
            }
            if (sipSPISendPublish(pcb_p, FALSE) == TRUE) {
                pcb_p->outstanding_trxn = TRUE;
                CCSIP_DEBUG_TASK(DEB_F_PREFIX"sent request with increased expires\n", DEB_F_PREFIX_ARGS(SIP_PUB, fname));
                return SIP_OK;
             }
        }
        /*
         * Since we failed to resend the PUBLISH request, free up the PCB and let the app know.
         */
        send_resp_to_app(PUBLISH_FAILED_SEND, pcb_p->pub_handle, pcb_p->app_handle,
                         pcb_p->callback_task, pcb_p->resp_msg_id);
        free_pcb (pcb_p);
        CCSIP_DEBUG_ERROR(SIP_F_PREFIX"failed to respond to 423\n", fname);
        return SIP_ERROR;
    }
    
    /*
     * if the response_code is > 299, free up the PCB and let the app know.
     */
    if (response_code > 299) {
        send_resp_to_app(response_code, pcb_p->pub_handle, pcb_p->app_handle,
                         pcb_p->callback_task, pcb_p->resp_msg_id);
        free_pcb (pcb_p);
        CCSIP_DEBUG_TASK(DEB_F_PREFIX"received %d response\n", DEB_F_PREFIX_ARGS(SIP_PUB, fname), response_code);
        return SIP_OK;
    }

    /*
     * if the response is < 200, do nothing.
     */
    if (response_code < 200) {
        CCSIP_DEBUG_TASK(DEB_F_PREFIX"received %d response\n", DEB_F_PREFIX_ARGS(SIP_PUB, fname), response_code);
        return SIP_OK;
    }
    
    /*
     * If it is PUBLISH remove operation, free up PCB
     */
    if (pcb_p->hb.orig_expiration == 0) {
        send_resp_to_app(response_code, pcb_p->pub_handle, pcb_p->app_handle,
                         pcb_p->callback_task, pcb_p->resp_msg_id);
        free_pcb (pcb_p);
        CCSIP_DEBUG_TASK(DEB_F_PREFIX"removed PCB as this was a terminating PUBLISH\n", DEB_F_PREFIX_ARGS(SIP_PUB, fname));
        return SIP_OK;
    }

    /*
     * extract Expires and SIP-ETag headers and save them.
     */
    expires = sippmh_get_header_val(pSipMessage, SIP_HEADER_EXPIRES, NULL);
    if (expires) {
        expiry_time = strtoul(expires, NULL, 10);
        pcb_p->hb.expires = expiry_time;
    }
    sip_etag = sippmh_get_header_val(pSipMessage, SIP_HEADER_SIPETAG, NULL);
    if (sip_etag != NULL) {
        cpr_free(pcb_p->entity_tag);
        entity_tag_size = strlen(sip_etag) + 1;
        pcb_p->entity_tag = cpr_malloc(entity_tag_size);
        if (pcb_p->entity_tag != NULL) {
            sstrncpy(pcb_p->entity_tag, sip_etag, entity_tag_size);
        } else {
            free_pcb (pcb_p);
            send_resp_to_app(PUBLISH_FAILED_NORESOURCE, pcb_p->pub_handle, pcb_p->app_handle,
                             pcb_p->callback_task, pcb_p->resp_msg_id);
            CCSIP_DEBUG_ERROR(SIP_F_PREFIX"memory allocation failed\n", fname);
            return SIP_ERROR;
            
        }
    }

    /*
     * If there are no pending requests, provide the response to the application.
     */
    msg_p = (pub_req_t *)sll_next(pcb_p->pending_reqs, NULL);
    if (msg_p != NULL) {
        (void)sll_remove(pcb_p->pending_reqs, msg_p);
        (void)publish_handle_ev_app_publish(msg_p);
        cpr_free(msg_p);
        return SIP_OK;
    }
    send_resp_to_app(response_code, pcb_p->pub_handle, pcb_p->app_handle,
                     pcb_p->callback_task, pcb_p->resp_msg_id);
    CCSIP_DEBUG_TASK(DEB_F_PREFIX"sent response %d to app\n", DEB_F_PREFIX_ARGS(SIP_PUB, fname), response_code);
    return SIP_OK;
}
Пример #14
0
/*
 * sleep_remove_from_list
 * @tcb: Task's control block that is needed to be removed from the sleeping
 *  tasks list.
 * This function is called when a task is needed to be removed from the sleeping
 * tasks list.
 */
void sleep_remove_from_list(TASK *tcb)
{
    /* Remove this task from the list of sleeping tasks. */
    sll_remove(&sleep_scheduler.ready_tasks, tcb, OFFSETOF(TASK, next_sleep));

} /* sleep_remove_from_list */
Пример #15
0
/**
 *
 * Called when the bandwidth response with failed bw is received. This
 * also process held ccapi messages through fim event chain
 *
 * @param none
 *
 * @return  CC_CAUSE_NO_RESOURCE No bandwidth
 *          CC_CAUSE_OK if ok
 *
 *
 * @pre     (NULL)
 */
cc_causes_t
fsm_cac_process_bw_failed_resp (void)
{
    const char      fname[] = "fsm_cac_process_bw_avail_resp";
    cac_data_t      *cac_data = NULL;
    cac_data_t      *next_cac_data = NULL;


    cac_data = (cac_data_t *) sll_next(s_cac_list, NULL);

    if (cac_data != NULL) {

        switch (cac_data->cac_state) {
        default:
        case FSM_CAC_IDLE:
            DEF_DEBUG(DEB_F_PREFIX"No Pending request.",
                DEB_F_PREFIX_ARGS("CAC", fname));
            /*
            * Make sure sufficient bandwidth available to make a outgoing call. This
            * should be done before allocating other resources.
            */
            if (fsm_cac_process_bw_allocation(cac_data) == CC_CAUSE_CONGESTION) {

                sll_remove(s_cac_list, cac_data);

                return(CC_CAUSE_NO_RESOURCE);
            }

            break;
        case FSM_CAC_REQ_PENDING:

            next_cac_data = (cac_data_t *) sll_next(s_cac_list, cac_data);

            sll_remove(s_cac_list, cac_data);

            /* Request for the next bandwidth */
            DEF_DEBUG(DEB_F_PREFIX"Process pending responses even after failure.",
                DEB_F_PREFIX_ARGS("CAC", fname));

            /* Let GSM process completed request */
            fsm_cac_notify_failure(cac_data);

            fsm_clear_cac_data(cac_data);

            if (next_cac_data != NULL) {

                /*
                 * Make sure sufficient bandwidth available to make a outgoing call. This
                 * should be done before allocating other resources.
                 */
                if (fsm_cac_process_bw_allocation(next_cac_data) == CC_CAUSE_CONGESTION) {

                    /* If the next data was in idle state and the request fialed
                     * then clean up the remaining list
                     */
                    if (next_cac_data->cac_state == FSM_CAC_IDLE) {
                        /* Clear all remaining data */
                        fsm_cac_clear_list();
                    } else {

                        sll_remove(s_cac_list, next_cac_data);
                    }

                    return(CC_CAUSE_NO_RESOURCE);
                }

            }

            break;
        }

    }

    return(CC_CAUSE_NO_RESOURCE);
}