Example #1
0
static struct ospf6_vertex *
ospf6_vertex_create (struct ospf6_lsa *lsa)
{
  struct ospf6_vertex *v;
  int i;

  v = (struct ospf6_vertex *)
    XMALLOC (MTYPE_OSPF6_VERTEX, sizeof (struct ospf6_vertex));

  /* type */
  if (ntohs (lsa->header->type) == OSPF6_LSTYPE_ROUTER)
    v->type = OSPF6_VERTEX_TYPE_ROUTER;
  else if (ntohs (lsa->header->type) == OSPF6_LSTYPE_NETWORK)
    v->type = OSPF6_VERTEX_TYPE_NETWORK;
  else
    assert (0);

  /* vertex_id */
  ospf6_linkstate_prefix (lsa->header->adv_router, lsa->header->id,
                          &v->vertex_id);

  /* name */
  ospf6_linkstate_prefix2str (&v->vertex_id, v->name, sizeof (v->name));

  /* Associated LSA */
  v->lsa = lsa;

  /* capability bits + options */
  v->capability = *(u_char *)(OSPF6_LSA_HEADER_END (lsa->header));
  v->options[0] = *(u_char *)(OSPF6_LSA_HEADER_END (lsa->header) + 1);
  v->options[1] = *(u_char *)(OSPF6_LSA_HEADER_END (lsa->header) + 2);
  v->options[2] = *(u_char *)(OSPF6_LSA_HEADER_END (lsa->header) + 3);

  for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++)
    ospf6_nexthop_clear (&v->nexthop[i]);

  v->parent = NULL;
  v->child_list = list_new ();
  v->child_list->cmp = ospf6_vertex_id_cmp;

  return v;
}
Example #2
0
// insert a node at specified position
int _list_insert_node (struct list_simple **list, struct list_node *node, size_t pos)
{
    struct list_node *pNode;
    struct list_node *head;
    size_t i;

    if (!list || !node)
        return -1;
    if (!*list)
        *list = list_new();
    if ((*list)->size < pos)
        return -1;

    head = (*list)->head;

    // we traverse the linked list
    for (pNode = head, i = 0; pNode != NULL; pNode = pNode->next, i++) {
        if (i == pos) {
            if (!pNode->next)
                _list_append_node(list, node);
            else {
                node->next = pNode;
                node->prev = pNode->prev;

                if (node->prev)
                    node->prev->next = node;
                else
                    (*list)->head = node;

                pNode->prev = node;
            }

            (*list)->size++;

            return 0;
        }
    }

    printf("failed insertion tat\n");
    // failed to insert node
    return -1;
}
Example #3
0
void test_list(void) {
    int valuebuf[] = { 1 };
    size_t i;
    ListObject *lp = list_new();
    assert(list_is_empty(lp));
    for(i = 0; i < 10; i++) {
        *valuebuf = i;
        list_add(lp, valuebuf);
    }
    list_print(list_rsslice(lp, 0, 10, 1));
    list_print(list_sslice(lp, 9, -11, -1));
    list_print(list_rsslice(lp, -1, -1, -1));
    list_print(list_rsslice(lp, -1, -110, -1));
    list_print(list_rsslice(lp, -1, -11, -2));
    list_print(list_sslice(lp, -1, -3, -1));
    list_print(list_sslice(lp, -3, -1, 1));
    list_print(list_sslice(lp, -1, 7, -1));
    printf("get: %d\n", *(int*)list_get(lp, 2));
    printf("pop: %d\n", *(int*)list_popi(lp, 0));
    *valuebuf = -2;
    list_insert(lp, 0, valuebuf);
    *valuebuf = -200;
    list_insert(lp, -1, valuebuf);
    list_print(lp);
    list_del(lp, 0);
    list_rinsert(lp, -1, valuebuf);
    list_rinsert(lp, -1, valuebuf);
    printf("get: %d\n", *(int*)list_get(lp, 0));
    list_print(lp);
    ListObject *nlp = list_copy(lp);
    printf("new copy's size is %u, allocated is %u\n", nlp->used, nlp->allocated);
    list_print(nlp);
    printf("count %d: %d\n", *valuebuf, list_count(lp, valuebuf));
    *valuebuf=12333;
    printf("change index 0's value to 12333\n");
    list_set(nlp,0,valuebuf);
    *valuebuf=2;
    printf("remove first value equals 2\n");
    list_remove(nlp,valuebuf);
    list_print(nlp);
    list_free(nlp);
}
Example #4
0
int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
{
	int i, len;
	char* name;
	char* path;
	RDPDR_SERIAL* device;
	SERIAL_DEVICE* serial;

	device = (RDPDR_SERIAL*) pEntryPoints->device;
	name = device->Name;
	path = device->Path;

	if (name[0] && path[0])
	{
		serial = (SERIAL_DEVICE*) malloc(sizeof(SERIAL_DEVICE));
		ZeroMemory(serial, sizeof(SERIAL_DEVICE));

		serial->device.type = RDPDR_DTYP_SERIAL;
		serial->device.name = name;
		serial->device.IRPRequest = serial_irp_request;
		serial->device.Free = serial_free;

		len = strlen(name);
		serial->device.data = stream_new(len + 1);

		for (i = 0; i <= len; i++)
			stream_write_BYTE(serial->device.data, name[i] < 0 ? '_' : name[i]);

		serial->path = path;
		serial->queue = Queue_New(TRUE, -1, -1);
		serial->pending_irps = list_new();
		serial->in_event = CreateEvent(NULL, TRUE, FALSE, NULL);

		serial->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

		pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) serial);

		serial->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) serial_thread_func, (void*) serial, 0, NULL);
	}

	return 0;
}
Example #5
0
static void rdpsnd_process_connect(rdpSvcPlugin* plugin)
{
	rdpsndPlugin* rdpsnd = (rdpsndPlugin*)plugin;
	RDP_PLUGIN_DATA* data;
	RDP_PLUGIN_DATA default_data[2] = { { 0 }, { 0 } };

	DEBUG_SVC("connecting");

	plugin->interval_callback = rdpsnd_process_interval;

	rdpsnd->data_out_list = list_new();
	rdpsnd->latency = -1;

	data = (RDP_PLUGIN_DATA*)plugin->channel_entry_points.pExtendedData;
	while (data && data->size > 0)
	{
		rdpsnd_process_plugin_data(rdpsnd, data);
		data = (RDP_PLUGIN_DATA*) (((void*) data) + data->size);
	}

	if (rdpsnd->device == NULL)
	{
		default_data[0].size = sizeof(RDP_PLUGIN_DATA);
		default_data[0].data[0] = "pulse";
		default_data[0].data[1] = "";
		if (!rdpsnd_load_device_plugin(rdpsnd, "pulse", default_data))
		{
			default_data[0].data[0] = "alsa";
			default_data[0].data[1] = "default";
			if (!rdpsnd_load_device_plugin(rdpsnd, "alsa", default_data))
			{
				default_data[0].data[0] = "macaudio";
				default_data[0].data[1] = "default";
				rdpsnd_load_device_plugin(rdpsnd, "macaudio", default_data);
			}
		}
	}
	if (rdpsnd->device == NULL)
	{
		DEBUG_WARN("no sound device.");
	}
}
Example #6
0
void server_file(socket_t * client, http_request_t * req)
{
    list_t * list = list_new();
    if(strcmp(req->method, "GET") == 0)
    {
        char * str;
        str = strtok(req->uri, "/");
        while (str != NULL)
        {
            list_push_back(list, str);
            str = strtok(NULL,"/");
        }

        char * word = list_get(list, 3);
        char * fileName = list_get(list, 2);
        int fileSt = file_exists(fileName);
        if(fileSt == 1)
        {
            text_t * text = text_new();
            text_readFile(text, fileName);
            text_onSentences(text);
            int cntW = text_counting(text, word);

            cJSON * Words = cJSON_CreateObject();
            cJSON_AddItemToObject(Words, "FileName", cJSON_CreateString(fileName));
            cJSON_AddItemToObject(Words, "CountWord", cJSON_CreateNumber(cntW));
            cJSON_AddItemToObject(Words, "experience", cJSON_CreateString(word));
            char * Jtext = cJSON_Print(Words);
            server_sent(client, Jtext);
            free(Jtext);

        }
        else
        {
            printf("Error! Wrong file");
            return;
        }


    }
    list_free(list);
}
reactor_t *reactor_new(void) {
  reactor_t *ret = (reactor_t *)osi_calloc(sizeof(reactor_t));
  if (!ret)
    return NULL;

  ret->epoll_fd = INVALID_FD;
  ret->event_fd = INVALID_FD;

  ret->epoll_fd = epoll_create(MAX_EVENTS);
  if (ret->epoll_fd == INVALID_FD) {
    LOG_ERROR("%s unable to create epoll instance: %s", __func__, strerror(errno));
    goto error;
  }

  ret->event_fd = eventfd(0, 0);
  if (ret->event_fd == INVALID_FD) {
    LOG_ERROR("%s unable to create eventfd: %s", __func__, strerror(errno));
    goto error;
  }

  pthread_mutex_init(&ret->list_lock, NULL);
  ret->invalidation_list = list_new(NULL);
  if (!ret->invalidation_list) {
    LOG_ERROR("%s unable to allocate object invalidation list.", __func__);
    goto error;
  }

  struct epoll_event event;
  memset(&event, 0, sizeof(event));
  event.events = EPOLLIN;
  event.data.ptr = NULL;
  if (epoll_ctl(ret->epoll_fd, EPOLL_CTL_ADD, ret->event_fd, &event) == -1) {
    LOG_ERROR("%s unable to register eventfd with epoll set: %s", __func__, strerror(errno));
    goto error;
  }

  return ret;

error:;
  reactor_free(ret);
  return NULL;
}
Example #8
0
struct ospf_neighbor *
ospf_elect_dr (struct ospf_interface *oi, struct list *el_list)
{
  struct list *dr_list;
  struct listnode *node;
  struct ospf_neighbor *nbr, *dr = NULL, *bdr = NULL;

  dr_list = list_new ();

  /* Add neighbors to the list. */
  for (node = listhead (el_list); node; nextnode (node))
    {
      nbr = getdata (node);

      /* neighbor declared to be DR. */
      if (NBR_IS_DR (nbr))
	listnode_add (dr_list, nbr);

      /* Preserve neighbor BDR. */
      if (IPV4_ADDR_SAME (&BDR (oi), &nbr->address.u.prefix4))
	bdr = nbr;
    }

  /* Elect Designated Router. */
  if (listcount (dr_list) > 0)
    dr = ospf_dr_election_sub (dr_list);
  else
    dr = bdr;

  /* Set DR to interface. */
  if (dr)
    {
      DR (oi) = dr->address.u.prefix4;
      dr->d_router = dr->address.u.prefix4;
    }
  else
      DR (oi).s_addr = 0;

  list_delete (dr_list);

  return dr;
}
Example #9
0
list_t* rio_files(const char* path)
{
    list_t* files = list_new();
    char* upath = unipath(path);
    listitem_t* it;

    files->item_free = free;

    for (it=dirs->first; it; it=it->next) {
        const char* dir = it->ptr;
        char* tmpath = malloc(strlen(upath) + strlen(dir) + 1);
        sprintf(tmpath, "%s%s", dir, upath);
        rio_files_scandir(files, tmpath);
        free(tmpath);
    }

    free(upath);

    return files;
}
Example #10
0
void trie_insert_element(Trie * node, char *tema, Foto * element)
{
    assert(tema != NULL && *tema != '\0' && node != NULL && POS(tema) >= 0 && element != NULL);

    //apenas procurar se o proximo char nao for o fim da palavra
    if(*(tema+1) != '\0' && node->table[POS(tema)] != NULL)
    {
        trie_insert_element(node->table[POS(tema)], tema+1, element);
    }
    //e a ultima letra da palavra, verificar se esta marcado como uma palavra.
    else if( node->table[POS(tema)] != NULL && node->table[POS(tema)]->word == 1 )
    {
        //A lista ligada ainda nao foi criada, alocar memoria
        if(node->table[POS(tema)]->element == NULL)
        {
            node->table[POS(tema)]->element = list_new();
        }
        list_insert(element, node->table[POS(tema)]->element);
    }
}
Example #11
0
File: main.c Project: Madsen90/BOSC
int main(int argc, char* argv[])
{
  fifo = list_new();

  list_add(fifo, node_new_str("s1"));
  list_add(fifo, node_new_str("s2"));

  Node *n1 = list_remove(fifo);
  if (n1 == NULL) { printf("Error no elements in list\n"); exit(-1);}
  
  Node *n2 = list_remove(fifo);
  if (n2 == NULL) { printf("Error no elements in list\n"); exit(-1);}
  
  printf("%s\n%s\n", n1->elm, n2->elm);

  Node *n3 = list_remove(fifo);
  if (n3 == NULL) { printf("Error no elements in list\n"); exit(-1);}

  return 0;
}
Example #12
0
config_t *config_new_empty(void)
{
    config_t *config = osi_calloc(sizeof(config_t));
    if (!config) {
        LOG_ERROR("%s unable to allocate memory for config_t.\n", __func__);
        goto error;
    }

    config->sections = list_new(section_free);
    if (!config->sections) {
        LOG_ERROR("%s unable to allocate list for sections.\n", __func__);
        goto error;
    }

    return config;

error:;
    config_free(config);
    return NULL;
}
Example #13
0
LIST *
compile_setcomp(
	PARSE	*parse,
	LOL	*args,
	int	*jmp )
{
	RULE	*rule = bindrule( parse->string );
	LIST	*params = 0;
	PARSE	*p;

	/* Build param list */

	for( p = parse->left; p; p = p->left )
	    params = list_new( params, p->string, 1 );

	if( DEBUG_COMPILE )
	{
	    debug_compile( 0, "rule" );
	    printf( "%s ", parse->string );
	    list_print( params );
	    printf( "\n" );
	}

	/* Free old one, if present */

	if( rule->procedure )
	    parse_free( rule->procedure );

	if( rule->params )
	    list_free( rule->params );

	rule->procedure = parse->right;
	rule->params = params;

	/* we now own this parse tree */
	/* don't let parse_free() release it */

	parse_refer( parse->right );

	return L0;
}
Example #14
0
void cache_read(const char *path)
{
	FILE *f;
	char buf[1024];
	int vmajor, vminor;
	HDR *h = 0;
	int n;
	time_t timeval;

	if (check_cache_file(path, &vmajor, &vminor) != CACHE_OK)
		return;

	if ((vmajor != DEPS_MAJOR) || (vminor != DEPS_MINOR))
		return;

	if (!(f = fopen(path, "r")))
		return;

	/* Skip magic */
	fgets(buf, sizeof(buf), f);

	while (fgets(buf, sizeof (buf), f))
	{
		buf[strlen(buf) - 1] = '\0'; /* zap newline */

		if (!buf[0])
			continue;

		if (buf[0] == '\t')
		{
			h->includes = list_new(h->includes, buf + 1, 0);
			continue;
		}
		
		sscanf(buf, "%ld %n", &timeval, &n);
		h = hdr_enter (buf + n);
		h->time = timeval;
	}

	fclose(f);
}
Example #15
0
static int hci_layer_init_env(void)
{
    command_waiting_response_t *cmd_wait_q;

    // The host is only allowed to send at most one command initially,
    // as per the Bluetooth spec, Volume 2, Part E, 4.4 (Command Flow Control)
    // This value can change when you get a command complete or command status event.
    hci_host_env.command_credits = 1;
    hci_host_env.command_queue = fixed_queue_new(SIZE_MAX);
    if (hci_host_env.command_queue) {
        fixed_queue_register_dequeue(hci_host_env.command_queue, event_command_ready);
    } else {
        LOG_ERROR("%s unable to create pending command queue.", __func__);
        return -1;
    }

    hci_host_env.packet_queue = fixed_queue_new(SIZE_MAX);
    if (hci_host_env.packet_queue) {
        fixed_queue_register_dequeue(hci_host_env.packet_queue, event_packet_ready);
    } else {
        LOG_ERROR("%s unable to create pending packet queue.", __func__);
        return -1;
    }

    // Init Commands waiting response list and timer
    cmd_wait_q = &hci_host_env.cmd_waiting_q;
    cmd_wait_q->timer_is_set = false;
    cmd_wait_q->commands_pending_response = list_new(NULL);
    if (!cmd_wait_q->commands_pending_response) {
        LOG_ERROR("%s unable to create list for commands pending response.", __func__);
        return -1;
    }
    pthread_mutex_init(&cmd_wait_q->commands_pending_response_lock, NULL);
    cmd_wait_q->command_response_timer = osi_alarm_new("cmd_rsp_to", command_timed_out, cmd_wait_q, COMMAND_PENDING_TIMEOUT);
    if (!cmd_wait_q->command_response_timer) {
        LOG_ERROR("%s unable to create command response timer.", __func__);
        return -1;
    }

    return 0;
}
Example #16
0
list_t *
list_copy(list_t *to_copy)
{
  node_t *n;
  list_t *l;

  LIST_CHECK(to_copy);
  l = list_new();
  if (!l)
    return NULL;
  
  for (n = to_copy->first; n != NULL; n = n->next) {
    if (!list_append(l, n->ptr)) {
      list_free(l);
      return NULL;
    }
  }
  
  LIST_CHECK(l);
  return l;
}
Example #17
0
void ht_insert(ht H, ht_elem e)
{ REQUIRES(is_ht(H));
  assert(e != NULL);		/* cannot insert NULL element */
  ht_key k = H->elem_key(e);
  int h = H->key_hash(k, H->size);
  list l = H->A[h];
  while (l != NULL)
    //@loop_invariant is_chain(H, l, h);
    {
      if (H->key_equal(H->elem_key(l->data), k)) {
	l->data = e;		/* modify in place if k already there */
	return;
      }
      l = l->next;
    }
  /* k is not already in the hash table */
  /* insert at the beginning of the chain at A[h] */
  H->A[h] = list_new(e, H->A[h]);
  ENSURES(is_ht(H));
  return;
}
Example #18
0
int main() {
	list* list = list_new(sizeof(int), 4);
	
	int* val = list_create_elem(list);
	*val = 50;
	int* val2 = list_create_elem(list);
	*val2 = 100;
	list_add(list, val, sizeof(int));
	list_add(list, val2, sizeof(int));

	int *end = list_end(list);
	for (int i = 0; i < list->count; i++) {
		int *val = list->buf[i];
		printf("%d\n", *val);
	}
	

	list_free(list);
	
	return 0;
}
Example #19
0
radio_t * db_getRadioLead(db_t * self, int id){
	list_t * list = list_new();
	radio_t * radio = malloc(sizeof(radio_t*));
	sqlite3_stmt * stmt = NULL;
	sqlite3_prepare_v2(self->db, "SELECT * FROM RadioLead ;", -1, &stmt, 0);
	sqlite3_bind_int(stmt, 1, id);
	int rc = sqlite3_step(stmt);
	while (1){
		if (SQLITE_ERROR == rc){
			printf("Can't select radio Lead\n");
			exit(EXIT_SUCCESS);
		}
		else if (SQLITE_DONE == rc){
			break;
		}
		else if (SQLITE_ROW == rc){
			list_add(list, SQLITE_ROW);
		}
	}
	sqlite3_finalize(stmt);
}
Example #20
0
File: list.c Project: dyama/supoo
/* リストのサイズを変更する */
value* list_resize(value* list, int size)
{
  if (list == NULL) {
    list = list_new();
  }
  if (size == 0) {
    free(list->a);
    list->size = 0;
  }
  else {
    if (list->size == 0) {
      list->a = (value**)malloc(sizeof(value) * size);
    }
    else {
      list->a = (value**)realloc(list->a, sizeof(value) * size);
    }
    list->size = size;
  }
  list->type = AT_LIST;
  return list;
}
Example #21
0
static struct isis_route_info *
isis_route_info_new (uint32_t cost, uint32_t depth, u_char family,
                     struct list *adjacencies)
{
  struct isis_route_info *rinfo;
  struct isis_adjacency *adj;
  struct listnode *node;

  rinfo = XCALLOC (MTYPE_ISIS_ROUTE_INFO, sizeof (struct isis_route_info));
  if (!rinfo)
    {
      zlog_err ("ISIS-Rte: isis_route_info_new: out of memory!");
      return NULL;
    }

  if (family == AF_INET)
    {
      rinfo->nexthops = list_new ();
      for (ALL_LIST_ELEMENTS_RO (adjacencies, node, adj))
          adjinfo2nexthop (rinfo->nexthops, adj);
        }
Example #22
0
LIST *sequence_select_highest_ranked( FRAME *frame, int flags )
{
   /* Returns all of 'elements' for which corresponding element in parallel */
   /* list 'rank' is equal to the maximum value in 'rank'.                  */

    LIST* elements = lol_get( frame->args, 0 );    
    LIST* rank = lol_get( frame->args, 1 );    
    
    LIST* result = 0;
    LIST* tmp;
    int highest_rank = -1;

    for (tmp = rank; tmp; tmp = tmp->next)
        highest_rank = max(highest_rank, atoi(object_str(tmp->value)));

    for (; rank; rank = rank->next, elements = elements->next)
        if (atoi(object_str(rank->value)) == highest_rank)
            result = list_new(result, object_copy(elements->value));

    return result;
}
Example #23
0
File: list.c Project: Geod24/dnet
static list_t list_alloc
#if MEM_DEBUG
	(char *file,int line)
#else
	()
#endif
{   list_t list;

    if (list_freelist)
    {	list = list_freelist;
	list_freelist = list_next(list);
#if MEM_DEBUG
	mem_setnewfileline(list,file,line);
#endif
    }
    else
    {	nlist++;
	list = list_new();
    }
    return list;
}
Example #24
0
void var_expand_unit_test()
{
    LOL lol[1];
    LIST* l, *l2;
    LIST *expected = list_new( list_new( L0, newstr( "axb" ) ), newstr( "ayb" ) );
    LIST *e2;
    char axyb[] = "a$(xy)b";
    char azb[] = "a$($(z))b";
    char path[] = "$(p:W)";
    
    # ifdef OS_CYGWIN
    char cygpath[256];
    cygwin_conv_to_posix_path("c:\\foo\\bar", cygpath);
    # else
    char cygpath[] = "/cygdrive/c/foo/bar";
    # endif
        
    lol_init(lol);
    var_set("xy", list_new( list_new( L0, newstr( "x" ) ), newstr( "y" ) ), VAR_SET );
    var_set("z", list_new( L0, newstr( "xy" ) ), VAR_SET );
    var_set("p", list_new( L0, newstr( cygpath ) ), VAR_SET );

    l = var_expand( 0, axyb, axyb + sizeof(axyb) - 1, lol, 0 );
    for ( l2 = l, e2 = expected; l2 && e2; l2 = list_next(l2), e2 = list_next(e2) )
        assert( !strcmp( e2->string, l2->string ) );
    assert(l2 == 0 && e2 == 0);
    list_free(l);
    
    l = var_expand( 0, azb, azb + sizeof(azb) - 1, lol, 0 );
    for ( l2 = l, e2 = expected; l2 && e2; l2 = list_next(l2), e2 = list_next(e2) )
        assert( !strcmp( e2->string, l2->string ) );
    assert(l2 == 0 && e2 == 0);
    list_free(l);

    l = var_expand( 0, path, path + sizeof(path) - 1, lol, 0 );
    assert(l != 0);
    assert(list_next(l) == 0);
    # ifdef OS_CYGWIN
    assert( !strcmp( l->string, "c:\\foo\\bar" ) );
    # else 
    assert( !strcmp( l->string, cygpath ) );
    # endif   
    list_free(l);

    list_free(expected);
    
    lol_free(lol);
}
Example #25
0
void install_element(struct list **hash,const char *name,u32 flg)
{
	RwConfig * rec ;
	s32        len = (name) ? strlen(name) : 0;

	if( len <= 0 || KEY_NAME_MAX_LEN <= len )
		return ;
	
	rec = (RwConfig*)calloc(1,sizeof(RwConfig));
	strcpy((char*)rec->lowerCase,(char*)name);
	toLowerCase(rec->lowerCase,len);
	strcpy((char*)rec->name,(char*)name);
	rec->flg = flg ;

	if( hash[len] == NULL )
	{
		hash[len] = list_new();
		hash[len]->del = free ;
	}
	listnode_add(hash[len],rec);
}
Example #26
0
static void
test_list_iterator_t() {
  // Setup
  list_t *list = list_new();
  list_node_t *tj = list_node_new("tj");
  list_node_t *taylor = list_node_new("taylor");
  list_node_t *simon = list_node_new("simon");
  
  // tj taylor simon
  list_rpush(list, tj);
  list_rpush(list, taylor);
  list_rpush(list, simon);
  
  // Assertions
  
  // From head
  list_iterator_t *it = list_iterator_new(list, LIST_HEAD);
  list_node_t *a = list_iterator_next(it);
  list_node_t *b = list_iterator_next(it);
  list_node_t *c = list_iterator_next(it);
  list_node_t *d = list_iterator_next(it);
  
  assert(a == tj);
  assert(b == taylor);
  assert(c == simon);
  assert(d == NULL);

  // From tail
  it = list_iterator_new(list, LIST_TAIL);
  list_node_t *a2 = list_iterator_next(it);
  list_node_t *b2 = list_iterator_next(it);
  list_node_t *c2 = list_iterator_next(it);
  list_node_t *d2 = list_iterator_next(it);
  
  assert(a2 == simon);
  assert(b2 == taylor);
  assert(c2 == tj);
  assert(d2 == NULL);
  list_iterator_destroy(it);
}
Example #27
0
static struct ospf6 *
ospf6_create (void)
{
  struct ospf6 *o;

  o = XCALLOC (MTYPE_OSPF6_TOP, sizeof (struct ospf6));

  /* initialize */
  quagga_gettime (QUAGGA_CLK_MONOTONIC, &o->starttime);
  o->area_list = list_new ();
  o->area_list->cmp = ospf6_area_cmp;
  o->lsdb = ospf6_lsdb_create (o);
  o->lsdb_self = ospf6_lsdb_create (o);
  o->lsdb->hook_add = ospf6_top_lsdb_hook_add;
  o->lsdb->hook_remove = ospf6_top_lsdb_hook_remove;

  o->spf_delay = OSPF_SPF_DELAY_DEFAULT;
  o->spf_holdtime = OSPF_SPF_HOLDTIME_DEFAULT;
  o->spf_max_holdtime = OSPF_SPF_MAX_HOLDTIME_DEFAULT;
  o->spf_hold_multiplier = 1;

  o->route_table = OSPF6_ROUTE_TABLE_CREATE (GLOBAL, ROUTES);
  o->route_table->scope = o;
  o->route_table->hook_add = ospf6_top_route_hook_add;
  o->route_table->hook_remove = ospf6_top_route_hook_remove;

  o->brouter_table = OSPF6_ROUTE_TABLE_CREATE (GLOBAL, BORDER_ROUTERS);
  o->brouter_table->scope = o;
  o->brouter_table->hook_add = ospf6_top_brouter_hook_add;
  o->brouter_table->hook_remove = ospf6_top_brouter_hook_remove;

  o->external_table = OSPF6_ROUTE_TABLE_CREATE (GLOBAL, EXTERNAL_ROUTES);
  o->external_table->scope = o;

  o->external_id_table = route_table_init ();

  o->ref_bandwidth = OSPF6_REFERENCE_BANDWIDTH;

  return o;
}
Example #28
0
/*
 * Procesa el comando cre: crea una sala en el servidor;
 */
void cre(int sockfd, char *roomName) {
	Room  *room;
	listIterator roomIter;
	int found = 0;
	Room newRoom;
	msgHeader header;
	int size;

	// Busco si la sala ya existe
	listIterator_create(&Rooms,&roomIter);
	while (listIterator_hasNext(&roomIter)) {
		room = (Room *) listIterator_next(&roomIter);
		if (strcmp(room->name,roomName) == 0) {
			found = 1;
			break;
		}
	}

	// En caso de que ya exista
	if (found) {
		header.code = MSG_CODE_CRE_ALREADY;
		header.msgSize = 0;
		writeBytes(sockfd,(void *) &header,sizeof(header));
		return;
	}

	// De lo contrario se agrega la sala
	strncpy(newRoom.name,roomName,NAMES_SIZE);
	*(newRoom.name + NAMES_SIZE - 1) = '\0';
	size = strlen(newRoom.name);
	if (*(newRoom.name + size - 1) == '\n')
		*(newRoom.name + size - 1) = '\0';
	list_new(&newRoom.users,sizeof(User *));
	list_append(&Rooms,(void *) &newRoom);

	// Se envia el mensaje de correctitud
	header.code = MSG_CODE_CRE;
	header.msgSize = 0;
	writeBytes(sockfd,(void *) &header,sizeof(header));
}
Example #29
0
LIST *
compile_foreach(
	PARSE	*p,
	LOL	*args,
	int	*jmp )
{
	LIST	*nv = (*p->left->func)( p->left, args, jmp );
	LIST	*result = 0;
	LIST	*l;

	/* for each value for var */

	for( l = nv; l && *jmp == JMP_NONE; l = list_next( l ) )
	{
	    /* Reset $(p->string) for each val. */

	    var_set( p->string, list_new( L0, l->string, 1 ), VAR_SET );

	    /* Keep only last result. */

	    list_free( result );
	    result = (*p->right->func)( p->right, args, jmp );

	    /* continue loop? */

	    if( *jmp == JMP_CONTINUE )
		*jmp = JMP_NONE;
	}

	/* Here by break/continue? */

	if( *jmp == JMP_BREAK || *jmp == JMP_CONTINUE )
	    *jmp = JMP_NONE;

	list_free( nv );

	/* Returns result of last loop */

	return result;
}
Example #30
0
void install_xml_element(struct list * _hash[],
	const char*tagName,const char *atrName,u32 tagFlag,u32 flg)
{
	XmlTagnameConfig * xtc;
	struct listnode * node;
	
	s32 tagLength = (tagName)? strlen(tagName) : 0;
	
	if( tagLength < 0 || tagLength >KEY_NAME_MAX_LEN )
		return ;
	
	if(  _fast_lookup_last_ == NULL 
	  || _fast_lookup_last_->parent != _hash 
	  || _fast_lookup_last_->tagLen != tagLength
	  || _fast_lookup_last_->flg    != tagFlag
	  || (tagLength ==0|| strcmp(_fast_lookup_last_->tagName,tagName))  )
	{

		_fast_lookup_last_ = NULL;
		if( !_hash[tagLength] )
			_hash[tagLength] = list_new();
		for( ALL_LIST_ELEMENTS_RO(_hash[tagLength],node,xtc) )
		if( xtc && xtc->tagLen == tagLength && 
			(0 == tagLength || 0 == strncmp(tagName,xtc->tagName,tagLength)) )
		{
			_fast_lookup_last_ = xtc ;
			break;
		}
		if( !_fast_lookup_last_ )
		{
			_fast_lookup_last_ = (XmlTagnameConfig*)
				calloc(1,sizeof(XmlTagnameConfig));
			_fast_lookup_last_->parent=_hash;
			_fast_lookup_last_->tagLen=(u32)tagLength;
			_fast_lookup_last_->flg   = tagFlag;
			if( tagLength )
				memcpy(_fast_lookup_last_->tagName,tagName,tagLength);
			listnode_add(_hash[tagLength],_fast_lookup_last_);
		}
	}