Ejemplo n.º 1
0
Archivo: ctx.c Proyecto: velter/OpenSC
static void load_reader_driver_options(sc_context_t *ctx)
{
	struct sc_reader_driver *driver = ctx->reader_driver;
	scconf_block *conf_block = NULL;
	sc_reader_t *reader;
	int max_send_size;
	int max_recv_size;

	conf_block = sc_get_conf_block(ctx, "reader_driver", driver->short_name, 1);

	if (conf_block != NULL) {
		max_send_size = scconf_get_int(conf_block, "max_send_size", -1);
		max_recv_size = scconf_get_int(conf_block, "max_recv_size", -1);
		if (max_send_size >= 0 || max_recv_size >= 0) {
			if (list_iterator_start(&ctx->readers)) {
				reader = list_iterator_next(&ctx->readers);
				while (reader) {
					if (max_send_size >= 0)
						reader->max_send_size = max_send_size;
					if (max_recv_size >= 0)
						reader->max_recv_size = max_recv_size;
					reader = list_iterator_next(&ctx->readers);
				}
				list_iterator_stop(&ctx->readers);
			}
		}
	}
}
Ejemplo n.º 2
0
int list__tail(data_t **args, argc_t argc, data_t *ret, scope_t *scope)
{
    (void) argc;

    list_node_t *node;
    list_iterator_t *it = list_iterator_new(args[0]->value.list, LIST_HEAD);
    check_mem(it);

    ret->type = typedup(args[0]->type, scope->gc);
    ret->value.list = gc_add_list(scope->gc, list_new());

    node = list_iterator_next(it);

    while ((node = list_iterator_next(it))) {
        list_rpush(ret->value.list, list_node_new(node->val));
    }

    if (it) list_iterator_destroy(it);

    return 0;

error:
    if (it) list_iterator_destroy(it);
    return -1;
}
Ejemplo n.º 3
0
Server* schedule_weighted_round_robin(Service* service, Endpoint* client_endpoint) {
	uint32_t count = list_size(service->active_servers);
	RoundRobin* roundrobin = service->priv;
	if(count == 0)
		return NULL; 

	uint32_t whole_weight = 0;
	ListIterator iter;
	list_iterator_init(&iter, service->active_servers);
	while(list_iterator_has_next(&iter)) {
		Server* server = list_iterator_next(&iter);
		whole_weight += server->weight;
	}

	uint32_t _index = (roundrobin->robin++) & whole_weight;
	list_iterator_init(&iter, service->active_servers);
	while(list_iterator_has_next(&iter)) {
		Server* server = list_iterator_next(&iter);
		if(_index < server->weight)
			return server;
		else
			_index -= server->weight;
	}

	return NULL;
}
Ejemplo n.º 4
0
void free_policy(bool runtime, policy_t* policy)
{
    if (runtime)
        return;
    if (policy->name != NULL)
        bdestroy(policy->name);
    if (policy->instructions != NULL)
    {
        list_iterator_start(policy->instructions);
        while (list_iterator_hasnext(policy->instructions))
            free_policy_instruction(runtime, list_iterator_next(policy->instructions));
        list_iterator_stop(policy->instructions);
        list_destroy(policy->instructions);
        free(policy->instructions);
    }
    if (policy->settings != NULL)
    {
        list_iterator_start(policy->settings);
        while (list_iterator_hasnext(policy->settings))
            free_policy_setting(runtime, list_iterator_next(policy->settings));
        list_iterator_stop(policy->settings);
        list_destroy(policy->settings);
        free(policy->settings);
    }
    free(policy);
}
Ejemplo n.º 5
0
static void	find_speaker(fd_set *set,
			     t_list *list,
			     SOCKET (*extract)(void *),
			     void (*execute)(void *))
{
  t_list_iterator       *it;
  int                   ret;
  void			*tmp;

  if (!set || !list || !extract || !execute)
    return;
  it = list_iterator_begin(list);
  ret = (list_empty(list))?EXIT_FAILURE:EXIT_SUCCESS;
  while (ret != EXIT_FAILURE)
    {
      tmp = list_iterator_get(it);
      if (FD_ISSET(extract(tmp), set) && tmp)
	{
	  logger_verbose("[NETWORK] message from fd : %d", extract(tmp));
	  ret = list_iterator_next(it);
	  (*execute)(tmp);
	}
      else
	ret = list_iterator_next(it);
    }
  flush_list();
  list_iterator_destroy(it);
}
Ejemplo n.º 6
0
/**
 * Free stream data.
 *
 * @param sd
 */
void free_stream_data(stream_data *sd) {
    if (sd == NULL) return;

    // Free stream chunks, if any
    if (sd->chunks != NULL) {
        chunk_t *chunk = NULL;

        list_iterator_reset(sd->chunks);
        while((chunk = list_iterator_next(sd->chunks)) != NULL) {
            free(chunk->data);
            free(chunk);
        }

        list_destroy(&sd->chunks);
    }

    // Free inbound chunks, if any
    if (sd->inbound_chunks != NULL) {
        chunk_t *chunk = NULL;

        list_iterator_reset(sd->inbound_chunks);
        while((chunk = list_iterator_next(sd->inbound_chunks)) != NULL) {
            free(chunk->data);
            free(chunk);
        }

        list_destroy(&sd->inbound_chunks);
    }

    // Free outbound chunks, if any
    if (sd->outbound_chunks != NULL) {
        chunk_t *chunk = NULL;

        list_iterator_reset(sd->outbound_chunks);
        while((chunk = list_iterator_next(sd->outbound_chunks)) != NULL) {
            free(chunk->data);
            free(chunk);
        }

        list_destroy(&sd->outbound_chunks);
    }

    // Close the stream file, if we have it open
    if (sd->fd != -1) {
        close(sd->fd);
    }

    free(sd);
}
Ejemplo n.º 7
0
/*
====================================================================
Functions to access a PData tree. 
'name' is the pass within tree 'pd' where subtrees are separated 
by '/' (e.g.: name = 'config/graphics/animations')
parser_get_pdata   : get pdata entry associated with 'name'
parser_get_entries : get list of subtrees (PData structs) in 'name'
parser_get_values  : get value list of 'name'
parser_get_value   : get a single value from value list of 'name'
parser_get_int     : get first value of 'name' converted to integer
parser_get_double  : get first value of 'name' converted to double
parser_get_string  : get first value of 'name' _duplicated_
If an error occurs result is set NULL, False is returned and
parse_error is set.
====================================================================
*/
int parser_get_pdata  ( PData *pd, const char *name, PData  **result )
{
    int i, found;
    PData *pd_next = pd;
    PData *entry = 0;
    char *sub = 0;
    List *path = parser_explode_string( name, '/' );
    for ( i = 0, list_reset( path ); i < path->count; i++ ) {
        ListIterator it;
        sub = list_next( path );
        if ( !pd_next->entries ) {
            sprintf( parser_sub_error, tr("%s: no subtrees"), pd_next->name );
            goto failure;
        }
        it = list_iterator( pd_next->entries ); found = 0;
        while ( ( entry = list_iterator_next( &it ) ) )
            if ( strlen( entry->name ) == strlen( sub ) && !strncmp( entry->name, sub, strlen( sub ) ) ) {
                pd_next = entry;
                found = 1;
                break;
            }
        if ( !found ) {
            sprintf( parser_sub_error, tr("%s: subtree '%s' not found"), pd_next->name, sub );
            goto failure;
        }
    }
    list_delete( path );
    *result = pd_next;
    return 1;
failure:
    sprintf( parser_error, "parser_get_pdata: %s/%s: %s", pd->name, name, parser_sub_error );
    list_delete( path );
    *result = 0;
    return 0;
}
Ejemplo n.º 8
0
int dbg_lua_handle_lines(lua_State* L)
{
    struct dbg_state* state = dbg_lua_extract_state(L, 1);
    void* ud = dbg_lua_extract_state_ud(L, 1);
    list_t* symbols = state->dbg_lua_get_symbols();
    struct dbg_sym* current = NULL;
    struct dbg_sym_payload_line* payload = NULL;
    int tbl;
    lua_newtable(L);
    if (symbols == NULL)
        return 1;
    tbl = lua_gettop(L);
    list_iterator_start(symbols);
    while (list_iterator_hasnext(symbols))
    {
        current = (struct dbg_sym*)list_iterator_next(symbols);
        if (current->type != DBGFMT_SYMBOL_LINE)
            continue;
        payload = (struct dbg_sym_payload_line*)current->payload;
        if (payload->path == NULL)
            continue;
        lua_newtable(L);
        lua_pushstring(L, payload->path->data);
        lua_setfield(L, -2, "file");
        lua_pushnumber(L, payload->lineno);
        lua_setfield(L, -2, "line");
        lua_pushnumber(L, payload->address);
        lua_setfield(L, -2, "address");
        lua_rawseti(L, tbl, lua_objlen(L, tbl) + 1);
    }
    list_iterator_stop(symbols);
    return 1;
}
Ejemplo n.º 9
0
int list__length(data_t **args, argc_t argc, data_t *ret, scope_t *scope)
{
    (void) argc;
    (void) scope;

    list_node_t *node;
    list_iterator_t *it = list_iterator_new(args[0]->value.list, LIST_HEAD);

    check_mem(it);

    int length = 0;

    while ((node = list_iterator_next(it))) {
        ++length;
    }
    
    ret->type = construct_type(tid_integral, NULL, scope->gc);
    ret->value.integral = length;

    if (it) list_iterator_destroy(it);

    return 0;

error:
    if (it) list_iterator_destroy(it);
    return -1;
}
Ejemplo n.º 10
0
static inline int
install_packages(list_t *list, const char *dir, int verbose) {
  if (!list || !dir) return 0;

  list_node_t *node;
  list_iterator_t *it = list_iterator_new(list, LIST_HEAD);
  while ((node = list_iterator_next(it))) {
    clib_package_dependency_t *dep = node->val;
    char *slug = clib_package_slug(dep->author, dep->name, dep->version);
    clib_package_t *pkg = clib_package_new_from_slug(slug, verbose);

    free(slug);

    if (NULL == pkg) {
      return -1;
    }

    int rc = clib_package_install(pkg, dir, verbose);
    clib_package_free(pkg);
    if (-1 == rc) {
      list_iterator_destroy(it);
      return -1;
    }
  }

  list_iterator_destroy(it);
  return 0;
}
Ejemplo n.º 11
0
int procauth_isauthoritative(int service_code, pid_t pid) {
    procpid *pp;

    list_iterator_start(&proclist);
    while (list_iterator_hasnext(&proclist)) {
        pp = (procpid *)list_iterator_next(&proclist);
        if (pp->service_code == service_code) {
            /* wanted service found, compare pids... */
            list_iterator_stop(&proclist);
            if (pp->current_pid == pid) /* authoritative */
                return 1;
            else {
                pp->current_pid = procauth_getprocpid(pp->filename);
                if (pp->current_pid == -1) {        /* error accessing pidfile */
                    return 0;
                } else {
                    if (pp->current_pid != pid) {
                        /* check if this is a child of the parent pid */
                        return procauth_ischildof(pid, pp->current_pid);
                    }
                    /* pid correctly updated and matching */
                    return 1;
                }
            }
        }
    }
    list_iterator_stop(&proclist);

    /* service_code was unknown */
    return 0;
}
Ejemplo n.º 12
0
static void stdio_callback(uint32_t vmid, int thread_id, int fd, char* buffer, volatile size_t* head, volatile size_t* tail, size_t size) {
	size_t len0, len1, len2;
	bool wrapped;

	if(*head <= *tail) {
		wrapped = false;
		len0 = *tail - *head;
	} else {
		wrapped = true;
		len1 = size - *head;
		len2 = *tail;
	}

	if(!manager_core) return;
	ListIterator iter;
	list_iterator_init(&iter, manager_core->clients);
	while(list_iterator_has_next(&iter)) {
		RPC* rpc = list_iterator_next(&iter);

		if(wrapped) {
			rpc_stdio(rpc, vmid, thread_id, fd, buffer + *head, len1, NULL, NULL);
			rpc_stdio(rpc, vmid, thread_id, fd, buffer, len2, NULL, NULL);

		} else {
			rpc_stdio(rpc, vmid, thread_id, fd, buffer + *head, len0, NULL, NULL);
		}

		rpc_loop(rpc);
	}

	if(wrapped)
		*head = (*head + len1 + len2) % size;
	else
		*head += len0;
}
Ejemplo n.º 13
0
struct lprov_entry* list_revert(list_t* list)
{
	struct lprov_entry* first = NULL;
	struct lprov_entry* previous = NULL;
	struct lprov_entry* current = NULL;
	struct lconv_entry* entry = NULL;

	if (list == NULL)
		return NULL;

	list_iterator_start(list);
	while (list_iterator_hasnext(list))
	{
		entry = list_iterator_next(list);
		current = malloc(sizeof(struct lprov_entry));
		current->address = entry->address;
		current->label = bstr2cstr(entry->label, '0');
		current->next = NULL;
		if (previous != NULL)
			previous->next = current;
		if (first == NULL)
			first = current;
		previous = current;
	}
	list_iterator_stop(list);

	return first;
}
Ejemplo n.º 14
0
void timers_handleMessage(int type, int reason, int value){
	if (type == SDK_PRC_MESSAGE_CLK){
		int nearest_id = getNearestFinishedTimer();
		while (nearest_id >= 0){
			if (nearest_id >= 0){
				// process timer
				list_node_t * node;
				list_iterator_t * it = list_iterator_new(timers_list, LIST_HEAD);
				while(node = list_iterator_next(it)){
					STR_TIMER * timer = (STR_TIMER*)node->val;
					if (timer->timer_number == nearest_id){
						timer->last_tick = sdk_clk_timeSinceBoot();
						(*timer->cback)(timer->timer_number);
						break;
					}
				}
				list_iterator_destroy(it);
			}	
			nearest_id = getNearestFinishedTimer();
		}
	
		// set next timer
		int nearest = getNearestTimerDelta();
		if (nearest >= 0)
			sdk_clk_setCountdownTimer(APP_TIMER_RESERVED, nearest, false);
	}
}
Ejemplo n.º 15
0
void free_policy_value(bool runtime, policy_value_t* value)
{
    if ((runtime && !value->runtime) ||
        (!runtime && value->runtime))
        return;
    switch (value->type)
    {
        case NUMBER:
        case TABLE:
        case FIELD:
            break;
        case WORD:
        case VARIABLE:
            bdestroy(value->string);
            break;
        case FUNCTION:
            free_policy_function_call(runtime, value->function);
            break;
        case LIST:
            list_iterator_start(value->list);
            while (list_iterator_hasnext(value->list))
                free_policy_value(runtime, list_iterator_next(value->list));
            list_iterator_stop(value->list);
            list_destroy(value->list);
            free(value->list);
            break;
        default:
            break;
    }
    free(value);
}
Ejemplo n.º 16
0
/**
 * Destroys a multipart/form-data parser.
 *
 * @param mpartp
 */
void htp_mpartp_destroy(htp_mpartp_t ** _mpartp) {
    if ((_mpartp == NULL) || (*_mpartp == NULL)) return;
    htp_mpartp_t * mpartp = *_mpartp;

    if (mpartp->boundary != NULL) {
        free(mpartp->boundary);
    }

    bstr_builder_destroy(mpartp->part_pieces);
    bstr_builder_destroy(mpartp->boundary_pieces);

    // Free parts
    if (mpartp->parts != NULL) {
        htp_mpart_part_t * part = NULL;
        list_iterator_reset(mpartp->parts);
        while ((part = list_iterator_next(mpartp->parts)) != NULL) {
            htp_mpart_part_destroy(part);
        }

        list_destroy(&mpartp->parts);
    }

    free(mpartp);

    *_mpartp = NULL;
}
Ejemplo n.º 17
0
static void nl_stream_destroy(nl_stream_t *s)
{
    struct list_iterator_t  it;
    nl_buf_t                *buf;

    for (it = list_begin(s->tosend);
         !list_iterator_equal(list_end(s->tosend), it);
         it = list_iterator_next(it)) {
        buf = list_iterator_item(it);
        free(buf->buf);
    }
    list_destroy(s->tosend);

    while (s->encoders != NULL) {
        nl_stream_encoder_pop_back(s);
    }
    while (s->decoders != NULL) {
        nl_stream_decoder_pop_back(s);
    }

    log_trace("#%d destroyed", s->sock.fd);

    nl_close(&s->sock);

    if (s->cbs.on_closed != NULL) {
        s->cbs.on_closed(s);
    }
}
Ejemplo n.º 18
0
/**
 * Finalize MULTIPART processing.
 *
 * @param d
 */
int htp_ch_multipart_callback_request_body_data(htp_tx_data_t *d) {
    if (d->data != NULL) {
        // Process one chunk of data
        htp_mpartp_parse(d->tx->request_mpartp, d->data, d->len);
    } else {
        // Finalize parsing
        htp_mpartp_finalize(d->tx->request_mpartp);

        d->tx->request_params_body =
            d->tx->cfg->create_table(list_size(d->tx->request_mpartp->parts));
        // TODO RC

        // Extract parameters
        d->tx->request_params_body_reused = 1;

        htp_mpart_part_t *part = NULL;
        list_iterator_reset(d->tx->request_mpartp->parts);
        while ((part = (htp_mpart_part_t *) list_iterator_next(d->tx->request_mpartp->parts)) != NULL) {
            // Only use text parameters
            if (part->type == MULTIPART_PART_TEXT) {
                if (d->tx->connp->cfg->parameter_processor == NULL) {
                    table_add(d->tx->request_params_body, part->name, part->value);
                } else {
                    d->tx->connp->cfg->parameter_processor(d->tx->request_params_body, part->name, part->value);
                }
            }
        }
    }

    return HOOK_OK;
}
Ejemplo n.º 19
0
void sc_initialize_boxing_cmds(sc_context_t *ctx)
{
    sc_reader_t *reader;

    if (!ctx)
        return;

    if (!list_iterator_start(&ctx->readers))
        return;

    reader = list_iterator_next(&ctx->readers);
    while (reader) {
        reader = list_iterator_next(&ctx->readers);
        sc_detect_boxing_cmds(reader);
    }
}
Ejemplo n.º 20
0
/**
 * This function will search the list of cached pattern IDs for a pattern ID according to the given filename.
 * If it finds one, the found ID will be returned.
 * If not, -1 will be returned.
 */
int getPatternIDFromList(const char *filename) {
	int id = -1;
#ifdef DEBUG_LOGGING
	__android_log_write(ANDROID_LOG_INFO,"AR native","trying to retrieve pattern from list");
#endif
	if (patternIDs == NULL) {
#ifdef DEBUG_LOGGING
		__android_log_write(ANDROID_LOG_INFO,"AR native","list of patterns is null!!");
#endif	
		return -1;
	}
	list_iterator_start(patternIDs);
	while (list_iterator_hasnext(patternIDs)) {
		patternID * currPatt = (patternID *) list_iterator_next(patternIDs);
#ifdef DEBUG_LOGGING
		__android_log_print(ANDROID_LOG_INFO,"AR native","current pattern fiel: %s",currPatt->filename);
#endif
		if (strcmp(filename, currPatt->filename) == 0) {
#ifdef DEBUG_LOGGING
			__android_log_write(ANDROID_LOG_INFO,"AR native","found pattern in list");
#endif
			id = currPatt->id;
			break;
		}
	}
	list_iterator_stop(patternIDs);

#ifdef DEBUG_LOGGING
	if(id==-1)
	__android_log_print(ANDROID_LOG_INFO,"AR native","found no pattern in the list for file %s",filename);
#endif
	return id;
}
Ejemplo n.º 21
0
int list__to_tuple(data_t **args, argc_t argc, data_t *ret, scope_t *scope)
{
    (void) argc;
    data_t ret1;
    checkf(list__length(args, 1, &ret1, scope) == 0, "Failed to find list length.");
    int len = ret1.value.integral;

    struct type **multiple = gc_add(scope->gc, malloc(sizeof(struct type *) * (len + 1)));
    multiple[len] = NULL;
    
    ret->value.tuple = gc_add(scope->gc, malloc(sizeof(data_t *) * (len + 1)));
    ret->value.tuple[len] = NULL;

    list_node_t *node;
    list_iterator_t *it = list_iterator_new(args[0]->value.list, LIST_HEAD);

    int i = 0;

    while ((node = list_iterator_next(it))) {
        ret->value.tuple[i] = copy_data((data_t *) node->val, scope);
        multiple[i] = ret->value.tuple[i]->type;
        check_mem(ret->value.tuple[i]);

        ++i;
    }

    ret->type = construct_type(tid_tuple, multiple, scope->gc);

    if (it) list_iterator_destroy(it);
    return 0;

error:
    if (it) list_iterator_destroy(it);
    return -1;
}
Ejemplo n.º 22
0
likedListNo* linkedList_posicao(likedList *self, int index) {
  likedListDirecao direction = LISTA_FINAL;

  if (index < 0) {
    direction = LISTA_FINAL;
    index = ~index;
  }

  if ((unsigned)index < self->len) {
    listIterator *it = list_iterator_new(self, direction);
    likedListNo*node = list_iterator_next(it);
    while (index--) node = list_iterator_next(it);
    list_iterator_destroy(it);
    return node;
  }

  return NULL;
}
Ejemplo n.º 23
0
///
/// Pops a scope from the stack.
///
void ppimpl_pop_scope(state_t* state)
{
    scope_t* scope;
    match_t* match;
    match_t* old;
    bstring name;
    size_t a, i;
    if (list_size(&state->scopes) == 0)
        return;
    scope = list_extract_at(&state->scopes, list_size(&state->scopes) - 1);

    // Delete text if this scope was silenced.
    if (!scope->active)
    {
        list_delete_range(&state->cached_output,
                scope->start_index,
                list_size(&state->cached_output) - 1);
    }

    // Delete handlers that were defined this scope.
    list_iterator_start(&scope->new_handlers);
    while (list_iterator_hasnext(&scope->new_handlers))
    {
        name = list_iterator_next(&scope->new_handlers);

        for (i = 0; i < list_size(&state->handlers); i++)
        {
            old = list_get_at(&state->handlers, i);
            if (biseq(name, old->text.ref))
            {
                // We need remove the old handler.
                // FIXME: Free the old handler.
                list_delete_at(&state->handlers, i);
                i--;
            }
        }

        bdestroy(name);
    }
    list_iterator_stop(&scope->new_handlers);
    list_destroy(&scope->new_handlers);

    // Restore handlers.
    for (a = 0; a < list_size(&scope->old_handlers); a++)
    {
        match = list_get_at(&scope->old_handlers, a);

        // Restore the old handler.
        list_append(&state->handlers, match);
        list_extract_at(&scope->old_handlers, a);
        a--;
    }
    list_destroy(&scope->old_handlers);

    // Free memory.
    free(scope);
}
Ejemplo n.º 24
0
Archivo: list.c Proyecto: brickbtv/CROS
list_node_t *
list_at(list_t *self, int index) {
  list_direction_t direction = LIST_HEAD;

  if (index < 0) {
    direction = LIST_TAIL;
    index = ~index;
  }

  if ((unsigned)index < self->len) {
    list_iterator_t *it = list_iterator_new(self, direction);
    list_node_t *node = list_iterator_next(it);
    while (index--) node = list_iterator_next(it);
    list_iterator_destroy(it);
    return node;
  }

  return NULL;
}
Ejemplo n.º 25
0
void free_policy_state(bool runtime, policy_state_t* state)
{
    if (runtime)
        return;
    list_iterator_start(&state->variables);
    while (list_iterator_hasnext(&state->variables))
        free_policy_instruction(runtime, list_iterator_next(&state->variables));
    list_iterator_stop(&state->variables);
    list_destroy(&state->variables);
    free(state);
}
Ejemplo n.º 26
0
void wr_rtp_packet_destroy(wr_rtp_packet_t * rtp_packet)
{
    list_iterator_start(&rtp_packet->data_frames);
    while(list_iterator_hasnext(&rtp_packet->data_frames)){
        wr_data_frame_t * frame = (wr_data_frame_t * ) list_iterator_next(&rtp_packet->data_frames);
        free(frame->data);
        free(frame);
    }
    list_iterator_stop(&rtp_packet->data_frames);
    list_destroy(&rtp_packet->data_frames);
}
Ejemplo n.º 27
0
int wr_rtp_packet_copy_with_data(wr_rtp_packet_t * new_packet, wr_rtp_packet_t * old_packet)
{
    wr_rtp_packet_copy(new_packet, old_packet);
    list_init(&new_packet->data_frames);
    list_iterator_start(&old_packet->data_frames);
    while(list_iterator_hasnext(&old_packet->data_frames)){
        wr_data_frame_t * frame = (wr_data_frame_t * ) list_iterator_next(&old_packet->data_frames);
        wr_rtp_packet_add_frame(new_packet, frame->data, frame->size, frame->length_in_ms);
    }
    list_iterator_stop(&old_packet->data_frames);
    return 0;
}
Ejemplo n.º 28
0
void app_chat_server(){
	canvas2 = (Canvas *)sdk_prc_getCanvas();
	
	sdk_scr_printfXY(canvas2, 0, 0, "Starting server.\n");
	while (1){
		int addr;
		char msg[1024];
		memset(msg, 0, 1024 * sizeof(char));
		int recv_size = sdk_nic_recv(msg, 1024, &addr);
		
		if ((strlen(msg) > 0) && (strcmp(msg, "> SEARCH CR CHAT SERVER") == 0)){
			sdk_scr_printf(canvas2, "New client addr: %d. Reply.\n", addr);
			sdk_nic_send(addr, "< SEARCH RESPONSE", strlen("< SEARCH RESPONSE"));
		}
		
		if ((strlen(msg) > 0) && (strncmp(msg, "> NICKNAME", 8) == 0)){
			sdk_scr_printf(canvas2, "name: %s\n", &msg[11]);
			
			ClientInfo * cl = malloc(sizeof(ClientInfo));
			memset(cl, 0, sizeof(ClientInfo));
			
			cl->addr = addr;
			strncpy(cl->name, &msg[10], strlen(&msg[10]));
			
			if (list_clients == 0){
				list_clients = list_new((void*)cl);
			}
			
			list_rpush(list_clients, list_node_new((void*)cl));			
			
			sendMsg(addr, "< NEWUSER %s", cl->name);
		}
		
		if ((strlen(msg) > 0) && (strncmp(msg, "> MESSAGE ", 8) == 0)){
			sdk_scr_printf(canvas2, "msg: %s\n", &msg[10]);
			
			//sender name
			ClientInfo * author = NULL;
			
			list_node_t *node;
			list_iterator_t *it = list_iterator_new(list_clients, LIST_HEAD);
			while ((node = list_iterator_next(it))) {
				author = (ClientInfo*)node->val;
				if (author->addr == addr){
					break;
				}
			}	
			list_iterator_destroy(it);
			
			sendMsg(addr, "< MESSAGE %s: %s", author->name, &msg[10]);
		}
	}
}
Ejemplo n.º 29
0
/**
 * Destroys an existing hook. It is all right to send a NULL
 * to this method because it will simply return straight away.
 *
 * @param hook
 */
void hook_destroy(htp_hook_t *hook) {
    if (hook == NULL) return;

    htp_callback_t *callback = NULL;
    list_iterator_reset(hook->callbacks);
    while ((callback = list_iterator_next(hook->callbacks)) != NULL) {
        free(callback);
    }

    list_destroy(&hook->callbacks);
    
    free(hook);
}
Ejemplo n.º 30
0
void free_policies(bool runtime, policies_t* policies)
{
    if (runtime)
        return;
    list_iterator_start(&policies->policies);
    while (list_iterator_hasnext(&policies->policies))
        free_policy(runtime, list_iterator_next(&policies->policies));
    list_iterator_stop(&policies->policies);
    list_destroy(&policies->policies);
    if (policies->settings != NULL)
        free_policy(runtime, policies->settings);
    free(policies);
}