Example #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();
}
Example #2
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();
}
Example #3
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();
}
Example #4
0
void sll_destroy( struct simpleLinkedList *element ) {
  if( element && ( element != NULL ) ) {
    o_log(SQLDEBUG, "preparing to delete element: %x, with prev=%x, and next=%x", element, element->prev, element->next);
    sll_destroy( sll_getNext( element ) );
    sll_delete( element );
  }
}
Example #5
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);
}
Example #6
0
void test_insert_after1(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");
  sll_dump(list);

  sll_insert_after(list, 2, 101, "fred");
  sll_dump(list);

  sll_insert_after(list, 4, 102, "barney");
  sll_dump(list);

  sll_insert_after(list, 1, 103, "wilma");
  sll_dump(list);

  sll_insert_after(list, 102, 104, "betty");
  sll_dump(list);

  sll_insert_after(list, 1000, 105, "dino");
  sll_dump(list);

  sll_destroy(list);
}
Example #7
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();
}
Example #8
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();
}
Example #9
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);
}
Example #10
0
/**
 *
 * Shutdown cac module, clears all the pending cac requests
 *
 * @param void
 *
 * @return  void
 *
 * @pre     (NULL)
 */
void fsm_cac_shutdown (void)
{

    fsm_cac_clear_list();

    sll_destroy(s_cac_list);

    s_cac_list = NULL;
}
/**
 * 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;
}
Example #12
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;
}
Example #13
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);
}
Example #14
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();
}
Example #15
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);
}
Example #16
0
// Delete session that have not been accessed since 'oldest_allowed'
void clear_sessions_older_than( time_t oldest_allowed ) {
  struct simpleLinkedList *session = NULL;
  struct simpleLinkedList *sess_data = NULL;
  int session_expiration_count = 0;

  session = sll_findFirstElement( sessions );
  while( session != NULL ) {

    struct simpleLinkedList *this_session = session;
    session = sll_getNext( session );

    if( 0 == strcmp( this_session->key, "placeholder" ) )
      continue;

    struct session_data *sessions_element = (struct session_data *)this_session->data;
    if( sessions_element->last_accessed < oldest_allowed ) {

      for( sess_data = sll_findFirstElement( sessions_element->session_container ) ; sess_data != NULL ; sess_data = sll_getNext( sess_data ) ) {
        free( sess_data->key );
        free( sess_data->data );
      }
      sll_destroy( sll_findFirstElement( sessions_element->session_container ) );
      sessions_element->session_container = NULL;

      free( sessions_element );
      this_session->data = NULL;

      o_log( DEBUGM, "Deleting session: %s", this_session->key );
      free( this_session->key );
      this_session->key = NULL;

      sll_delete( this_session );
      session_expiration_count++;
    }
  }
  if( session_expiration_count >= 1 ) {
    o_log( DEBUGM, "Expired %d sessions", session_expiration_count);
  }

}
Example #17
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();
}
Example #18
0
/*
 *  Function: ccsip_info_package_handler_shutdown
 *
 *  Parameters:
 *      None
 *
 *  Description:
 *      Shuts down the Info Package handler framework.
 *
 *  Return:
 *      None
 */
void
ccsip_info_package_handler_shutdown(void)
{
    static const char *fname = "ccsip_info_package_handler_shutdown";
    info_index_t info_index;
    type_index_t type_index;
    handler_record_t *record;

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

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

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

    /* Deregister each Info Package handler */
    for (record = (handler_record_t *)sll_next(s_handler_registry, NULL);
         record != NULL;
         record = (handler_record_t *)sll_next(s_handler_registry, record)) {
        cpr_free(record);
    }

    /* Destroy the SLL */
    sll_destroy(s_handler_registry);
    s_handler_registry = NULL;
}
Example #19
0
int main(int argc, char ** argv)
{
	sb_sll * list;
	list = sll_init();
	int i;
	int * element = NULL;
	for (i = 0; i < 100000; i++)
	{
		element = (int *) malloc(sizeof(int));
		*element = i;
		sll_add_front(list, (void *) element);
	}

	while (!sll_empty(list)) {
		element = (int *) sll_front(list);
		printf("element: %d\n", *element);
		sll_remove_front(list);
		free(element);
	}

	sll_destroy(list);
	return EXIT_SUCCESS;
}
Example #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();
}
Example #21
0
// Delete all sessions
void cleanup_session_management() {
  clear_sessions_older_than( time(NULL) + 999 ); // 999 to ensure no race conditions.
  sll_destroy( sessions );
}
Example #22
0
extern char *internalGetScannerDetails(char *device, char *lang) {

  char *answer = NULL;
  SANE_Status status;
  char *deviceList = o_strdup("");; 
  int hlp = 0, resolution = 300, minRes=50, maxRes=50, phashAvailable=0;
  char *resolution_s, *maxRes_s, *minRes_s;
  SANE_Handle *openDeviceHandle;

  o_log(DEBUGM, "sane_open of \"%s\"", device);
  status = sane_open (device, (SANE_Handle)&openDeviceHandle);
  if(status != SANE_STATUS_GOOD) {
    o_log(ERROR, "Could not open: '%s' with error: %s", device, sane_strstatus(status));
    free(deviceList);
    return NULL;
  }


  //
  // Find resolution ranges
  //
  for (hlp = 0; hlp < 9999; hlp++) {

    const SANE_Option_Descriptor *sod;

    sod = sane_get_option_descriptor (openDeviceHandle, hlp);
    if (sod == NULL)
      break;

    // Just a placeholder
    if (sod->type == SANE_TYPE_GROUP
    || sod->name == NULL
    || hlp == 0)
      continue;

    if ( 0 == strcmp(sod->name, SANE_NAME_SCAN_RESOLUTION) ) {

      // Some kind of sliding range
      if (sod->constraint_type == SANE_CONSTRAINT_RANGE) {
        o_log(DEBUGM, "Resolution setting detected as 'range'");

        // Fixed resolution
        if (sod->type == SANE_TYPE_FIXED)
          maxRes = (int)SANE_UNFIX (sod->constraint.range->max);
        else
          maxRes = sod->constraint.range->max;
      }

      // A fixed list of options
      else if (sod->constraint_type == SANE_CONSTRAINT_WORD_LIST) {
        int lastIndex = sod->constraint.word_list[0];
        o_log(DEBUGM, "Resolution setting detected as 'word list': lastIndex = %d",lastIndex);

        // maxRes = sod->constraint.word_list[lastIndex];
        // resolution list cannot be treated as low to high ordered list 
        // remark: impl capability to select scan resolution in webInterface
        int n=0;
        maxRes = 0;
        for (n=1; n<=lastIndex; n++ ) {
          o_log(DEBUGM, "index results %d --> %d", n ,(int)sod->constraint.word_list[n]);
          if ( maxRes < sod->constraint.word_list[n] ) {
            maxRes=sod->constraint.word_list[n];
          }
        }

      }

      break; // we've found our resolution - no need to search more
    }
  }
  o_log(DEBUGM, "Determined max resultion to be %d", maxRes);


  // Define a default
  if(resolution >= maxRes)
    resolution = maxRes;
  if(resolution <= minRes)
    resolution = minRes;

  o_log(DEBUGM, "sane_cancel");
  sane_cancel(openDeviceHandle);

  o_log(DEBUGM, "sane_close");
  sane_close(openDeviceHandle);



  //
  // What languages can we OCR for?
  //
  char *availableLangs = o_strdup("");
#ifdef CAN_OCR
  struct simpleLinkedList *languages = getOCRAvailableLanguages();
  while (languages != NULL ) {
    if ( checkOCRLanguage( languages->data ) == 0 ) {
      o_concatf(&availableLangs, "<lang>%s</lang>", languages->data);
    }
    languages = sll_getNext(languages);
  }
  sll_destroy( languages );
#endif /* CAN_OCR */


  //
  // Can we give the option of doing 'find simmilar'?
  //
#ifdef CAN_PHASH
  phashAvailable = 1;
#endif /* CAN_PHASH */

  // Build Reply
  //
  resolution_s = itoa(resolution,10);
  maxRes_s = itoa(maxRes,10);
  minRes_s = itoa(minRes,10);

  o_concatf(&deviceList, "<Resolution><max>%s</max><min>%s</min><default>%s</default></Resolution><OCRLanguages>%s</OCRLanguages><phash>%d</phash>", maxRes_s, minRes_s, resolution_s, availableLangs, phashAvailable);

  free(maxRes_s);
  free(minRes_s);
  free(resolution_s);
  free(availableLangs);

  // The escaped string placeholder will be interprited in the sane dispatcher client
  answer = o_printf("<?xml version='1.0' encoding='utf-8'?>\n<Response><ScannerDetails>%s</ScannerDetails></Response>", deviceList);
  free(deviceList);

  return answer;

}