コード例 #1
0
ファイル: client.c プロジェクト: Nyrii/-EPITECH-my_irc
char			*read_all(int fd, fd_set *readf,
				  t_buffs *buffs, char **chan_nick)
{
  t_list                *tmp_cmd;
  int			ret;

  buffs->cmds ? free_content(buffs->cmds) : 0;
  buffs->cmds ? buffs->cmds->destroy(buffs->cmds) : 0;
  buffs->cmds = NULL;
  if (FD_ISSET(fd, readf))
    {
      if ((ret = get_cmd_buff(fd, buffs)) == -1)
	return (NULL);
      else if (ret == -3)
	return (NULL);
      else if (ret == -2)
	puterr("Reply too long\n", 0);
    }
  tmp_cmd = buffs->cmds;
  while (tmp_cmd)
    {
      fprintf(stderr, "%s\n", (char *)tmp_cmd->struc);
      change_channel((char *)tmp_cmd->struc, chan_nick[0], chan_nick[1]);
      tmp_cmd = tmp_cmd->next;
    }
  if (FD_ISSET(0, readf))
    return (get_next_line(0));
  return ("");
}
コード例 #2
0
ファイル: tests.c プロジェクト: michalliu/rkchrome_uboot
static int load_file(const char* file_path, int offset_block, int blocks) {
    printf("Try to load:%s", file_path);
    if (blocks) {
        printf(", offset block:%d, blocks:%d\n", offset_block, blocks);
    } else {
        printf("\n");
    }
    bool ret = false;
    resource_content content;
    snprintf(content.path, sizeof(content.path), "%s", file_path);
    content.load_addr = 0;
    if (!get_content(&content)) {
        goto end;
    }
    if (!blocks) {
        if (!load_content(&content)) {
            goto end;
        }
    } else {
        void* data = malloc(blocks * BLOCK_SIZE);
        if (!data)
            goto end;
        if (!load_content_data(&content, offset_block, data, blocks)) {
            goto end;
        }
    }
    ret = true;
end:
    free_content(&content);
    return ret;
}
コード例 #3
0
ファイル: get_data.c プロジェクト: Morefaya/ft_ls
t_list			*get_link(char *d_name, struct stat *f_stat, char *path)
{
	t_ls			content;
	t_list			*lst;

	if (!f_stat || !d_name)
		return (NULL);
	errno = 0;
	content.nb_hlink = (int)(f_stat->st_nlink);
	content.size = (int)(f_stat->st_size);
	content.nb_blk = (int)(f_stat->st_blocks);
	time_asm(f_stat, &content);
	if (!(content.name = ft_strdup(d_name))
		|| !(content.u_name = get_uname(f_stat->st_uid))
		|| !(content.g_name = get_gname(f_stat->st_gid))
		|| !(content.rights = get_rights(f_stat, path))
		|| !(content.type = get_type(f_stat)))
		return (NULL);
	content.link = f_readlink(content, path);
	if (!(lst = ft_lstnew(&content, sizeof(content))))
	{
		free_content(&content, content.size);
		return (NULL);
	}
	return (lst);
}
コード例 #4
0
ファイル: debug_next.c プロジェクト: weryp/Tetris
void	delete_elem(t_tetris *elem)
{
  elem->prev->next = elem->next;
  elem->next->prev = elem->prev;
  free_content(elem);
  free(elem);
}
コード例 #5
0
int			check_and_read_clients(fd_set *readf, t_list list,
					       unsigned int i)
{
  t_client		*client;
  int			ret;

  while (++i < list_get_size(list))
    {
      if ((client = list_get_elem_at_position(list, i)) != NULL)
	{
	  client->buffs.cmds ? free_content(client->buffs.cmds) : 0;
	  client->buffs.cmds ? client->buffs.cmds->destroy(client->buffs.cmds) : 0;
	  client->buffs.cmds = NULL;
	  if (FD_ISSET(client->sock, readf))
	    {
	      if ((ret = get_cmd_buff(client->sock, &client->buffs)) == -1)
		return (fprintf(stderr, ERR_COMMAND), -1);
	      else if (ret == -2)
		{
		  store_answer_c(client, strdup(RPL_OVERFLOW), 0);
		  fprintf(stderr, ERR_OVERFLOW);
		}
	    }
	}
    }
  return (0);
}
コード例 #6
0
ファイル: tui-data.c プロジェクト: ChrisG0x20/gdb
void
tui_free_data_content (tui_win_content content, 
		       int content_size)
{
  int i;

  /* Remember that data window content elements are of type struct
     tui_gen_win_info *, each of which whose single element is a data
     element.  */
  for (i = 0; i < content_size; i++)
    {
      struct tui_gen_win_info *generic_win
	= &content[i]->which_element.data_window;

      if (generic_win != (struct tui_gen_win_info *) NULL)
	{
	  tui_delete_win (generic_win->handle);
	  generic_win->handle = NULL;
	  tui_free_win_content (generic_win);
	}
    }
  free_content (content,
		content_size,
		DATA_WIN);
}
コード例 #7
0
ファイル: ccnl-core.c プロジェクト: AnonMall/RIOT
struct ccnl_content_s *
ccnl_content_remove(struct ccnl_relay_s *ccnl, struct ccnl_content_s *c)
{
    struct ccnl_content_s *c2;
    DEBUGMSG(99, "ccnl_content_remove: %s\n", ccnl_prefix_to_path(c->name));

    c2 = c->next;
    DBL_LINKED_LIST_REMOVE(ccnl->contents, c);
    free_content(c);
    ccnl->contentcnt--;
    return c2;
}
コード例 #8
0
ファイル: tui-data.c プロジェクト: ChrisG0x20/gdb
void
tui_free_win_content (struct tui_gen_win_info *win_info)
{
  if (win_info->content != NULL)
    {
      free_content ((tui_win_content) win_info->content,
		   win_info->content_size,
		   win_info->type);
      win_info->content = NULL;
    }
  win_info->content_size = 0;
}
コード例 #9
0
ファイル: sharefarm.c プロジェクト: bentglasstube/secretfs
int
sharefarm_stat(const char *path, struct stat *sbuf)
{
  sharefarm_content *c = NULL, *cc = NULL;
  int ret = 0;
  
  if ((ret = find_all_shares(&c)) < 0)
    return ret;
  
  cc = find_content(c, path);
  
  if (cc == NULL) {
    free_content(c);
    return -ENOENT;
  }
  
  memcpy(sbuf, &cc->statinfo, sizeof(*sbuf));
  
  free_content(c);
  
  return 0;
}
コード例 #10
0
ファイル: ccn-lite-relay.c プロジェクト: A-L-E-X/RIOT
void ccnl_populate_cache(struct ccnl_relay_s *ccnl, unsigned char *buf, int datalen)
{
    if (buf[0] == 0x04 && buf[1] == 0x82) {
        struct ccnl_prefix_s *prefix = 0;
        struct ccnl_content_s *c = 0;
        struct ccnl_buf_s *nonce = 0, *ppkd = 0, *pkt = 0;
        unsigned char *content, *data = buf + 2;
        int contlen;

        datalen -= 2;

        pkt = ccnl_extract_prefix_nonce_ppkd(&data, &datalen, 0, 0,
                                             0, 0, &prefix, &nonce, &ppkd, &content, &contlen);

        if (!pkt) {
            DEBUGMSG(6, "  parsing error\n");
            goto Done;
        }

        if (!prefix) {
            DEBUGMSG(6, "  no prefix error\n");
            goto Done;
        }

        printf("populating: %s\n", ccnl_prefix_to_path(prefix));

        c = ccnl_content_new(ccnl, &pkt, &prefix, &ppkd, content,
                             contlen);

        if (!c) {
            goto Done;
        }

        c->flags |= CCNL_CONTENT_FLAGS_STATIC;
        if (!ccnl_content_add2cache(ccnl, c)) {
            // content store error
            free_content(c);
        }

    Done:
        free_prefix(prefix);
        ccnl_free(pkt);
        ccnl_free(nonce);
        ccnl_free(ppkd);
    }
    else {
        DEBUGMSG(6, "  not a content object\n");
    }
}
コード例 #11
0
ファイル: tests.c プロジェクト: michalliu/rkchrome_uboot
static bool load_content(resource_content* content) {
    if (content->load_addr)
        return true;
    int blocks = fix_blocks(content->content_size);
    content->load_addr = malloc(blocks * BLOCK_SIZE);
    if (!content->load_addr)
        return false;
    if (!StorageReadLba(get_ptn_offset() +
                content->content_offset, content->load_addr, blocks)) {
        free_content(content);
        return false;
    }

    dump_file(content->path, content->load_addr, content->content_size);
    return true;
}
コード例 #12
0
ファイル: sharefarm.c プロジェクト: bentglasstube/secretfs
int
sharefarm_enumerate_helper(sharefarm_enumerate_helper_cb_f cb, void *ctx)
{
  sharefarm_content *c = NULL;
  sharefarm_content *cc;
  int ret = 0;
  
  if ((ret = find_all_shares(&c)) < 0)
    return ret;
  
  for (cc = c; cc != NULL; cc = cc->next) {
    cb(ctx, cc->stem, &cc->statinfo);
  }
  
  free_content(c);
  
  return 0;
}
コード例 #13
0
ファイル: x_alloc.c プロジェクト: Janesak1977/ali3602
INT32 x_free(void *addr)
{
	struct content_t *node;

	if (addr == NULL)
		return -1;

	alloc_enter_mutex();

	node = (struct content_t*)((UINT32)addr-sizeof(struct content_t));

	free_content(&alloc_obj.free_list, node);

	alloc_obj.status = STATUS_AVAILABLE;
	alloc_leave_mutex();

	return 0;
}
コード例 #14
0
ファイル: free_buffer.c プロジェクト: Nyrii/-EPITECH-Zappy
void		free_player_buffers(void *value)
{
  t_player	*tmp;

  tmp = (t_player *) value;
  if (tmp == NULL)
    return ;
  tmp->buffs.in.buff ? free(tmp->buffs.in.buff) : 0;
  tmp->buffs.in.buff = NULL;
  tmp->buffs.in.cmd ? free(tmp->buffs.in.cmd) : 0;
  tmp->buffs.in.cmd = NULL;
  tmp->buffs.out.buff ? free(tmp->buffs.out.buff) : 0;
  tmp->buffs.out.buff = NULL;
  tmp->buffs.out.cmd ? free(tmp->buffs.out.cmd) : 0;
  tmp->buffs.out.cmd = NULL;
  tmp->buffs.cmds ? free_content(tmp->buffs.cmds) : 0;
  tmp->buffs.cmds ? tmp->buffs.cmds->destroy(tmp->buffs.cmds) : 0;
  tmp->buffs.cmds = NULL;
}
コード例 #15
0
ファイル: x_alloc.c プロジェクト: jinfeng-geeya/3202C
INT32 x_free(void *addr)
{
	struct content_t *node;

	if (addr == NULL)
		return -1;

	alloc_enter_mutex();

	node = (struct content_t*)((UINT32)addr-sizeof(struct content_t));

	free_content(&alloc_obj.free_list, node);

	alloc_obj.status = STATUS_AVAILABLE;
	alloc_leave_mutex();

#if (X_ALLOC_DEBUG_LEVEL > 0)
	print_freemem_size();
#endif
	return 0;
}
コード例 #16
0
ファイル: ccnl-core.c プロジェクト: AnonMall/RIOT
int ccnl_core_RX_i_or_c(struct ccnl_relay_s *relay, struct ccnl_face_s *from,
                        unsigned char **data, int *datalen)
{
    int rc = -1, scope = 3, aok = 3, minsfx = 0, maxsfx = CCNL_MAX_NAME_COMP,
        contlen;
    struct ccnl_buf_s *buf = 0, *nonce = 0, *ppkd = 0;
    struct ccnl_interest_s *i = 0;
    struct ccnl_content_s *c = 0;
    struct ccnl_prefix_s *p = 0;
    unsigned char *content = 0;
    DEBUGMSG(1, "ccnl_core_RX_i_or_c: (%d bytes left)\n", *datalen);

    buf = ccnl_extract_prefix_nonce_ppkd(data, datalen, &scope, &aok, &minsfx,
                                         &maxsfx, &p, &nonce, &ppkd, &content, &contlen);

    if (!buf) {
        DEBUGMSG(6, "  parsing error or no prefix\n");
        goto Done;
    }

    if (nonce && ccnl_nonce_find_or_append(relay, nonce)) {
        DEBUGMSG(6, "  dropped because of duplicate nonce\n");
        goto Skip;
    }

    if (buf->data[0] == 0x01 && buf->data[1] == 0xd2) { // interest
        DEBUGMSG(1, "ccnl_core_RX_i_or_c: interest=<%s>\n", ccnl_prefix_to_path(p));
        from->stat.received_interest++;

        if (p->compcnt > 0 && p->comp[0][0] == (unsigned char) 0xc1) {
            goto Skip;
        }

        if (p->compcnt == 4 && !memcmp(p->comp[0], "ccnx", 4)) {
            DEBUGMSG(1, "it's a mgnt msg!\n");
            rc = ccnl_mgmt(relay, buf, p, from);
            DEBUGMSG(1, "mgnt processing done!\n");
            goto Done;
        }

        // CONFORM: Step 1:
        if (aok & 0x01) { // honor "answer-from-existing-content-store" flag
            for (c = relay->contents; c; c = c->next) {
                if (!ccnl_i_prefixof_c(p, ppkd, minsfx, maxsfx, c)) {
                    continue;
                }

                // FIXME: should check stale bit in aok here
                DEBUGMSG(7, "  matching content for interest, content %p\n",
                         (void *) c);
                from->stat.send_content[c->served_cnt % CCNL_MAX_CONTENT_SERVED_STAT]++;
                c->served_cnt++;

                if (from->ifndx >= 0) {
                    ccnl_face_enqueue(relay, from, buf_dup(c->pkt));
                }

                goto Skip;
            }
        }

        // CONFORM: Step 2: check whether interest is already known
        for (i = relay->pit; i; i = i->next) {
            if (!ccnl_prefix_cmp(i->prefix, NULL, p, CMP_EXACT)
                && i->minsuffix == minsfx && i->maxsuffix == maxsfx
                && ((!ppkd && !i->ppkd) || buf_equal(ppkd, i->ppkd))) {
                break;
            }
        }

        if (!i) { // this is a new/unknown I request: create and propagate
            i = ccnl_interest_new(relay, from, &buf, &p, minsfx, maxsfx, &ppkd);

            if (i) { // CONFORM: Step 3 (and 4)
                DEBUGMSG(7, "  created new interest entry %p\n", (void *) i);

                if (scope > 2) {
                    ccnl_interest_propagate(relay, i);
                }
            }
        }
        else if (scope > 2 && (from->flags & CCNL_FACE_FLAGS_FWDALLI)) {
            DEBUGMSG(7, "  old interest, nevertheless propagated %p\n",
                     (void *) i);
            ccnl_interest_propagate(relay, i);
        }

        if (i) { // store the I request, for the incoming face (Step 3)
            DEBUGMSG(7, "  appending interest entry %p\n", (void *) i);
            ccnl_interest_append_pending(i, from);
        }
    }
    else {   // content
        DEBUGMSG(6, "  content=<%s>\n", ccnl_prefix_to_path(p));
        from->stat.received_content++;

        // CONFORM: Step 1:
        for (c = relay->contents; c; c = c->next) {
            if (buf_equal(c->pkt, buf)) {
                DEBUGMSG(1, "content is dup: skip\n");
                goto Skip;
            }
        }

        c = ccnl_content_new(relay, &buf, &p, &ppkd, content, contlen);

        if (c) { // CONFORM: Step 2 (and 3)
            if (!ccnl_content_serve_pending(relay, c, from)) { // unsolicited content
                // CONFORM: "A node MUST NOT forward unsolicited data [...]"
                DEBUGMSG(7, "  removed because no matching interest\n");
                free_content(c);
                goto Skip;
            }
#if CCNL_DYNAMIC_FIB
            else {
                /* content has matched an interest, we consider this name as available on this face */
                ccnl_content_learn_name_route(relay, c->name, from, relay->fib_threshold_prefix, 0);
            }
#endif

            if (relay->max_cache_entries != 0) { // it's set to -1 or a limit
                DEBUGMSG(7, "  adding content to cache\n");
                ccnl_content_add2cache(relay, c);
            }
            else {
                DEBUGMSG(7, "  content not added to cache\n");
                free_content(c);
            }
        }
    }

Skip:
    rc = 0;
Done:
    free_prefix(p);
    free_3ptr_list(buf, nonce, ppkd);
    DEBUGMSG(1, "leaving\n");
    return rc;
}
コード例 #17
0
ファイル: mhstore.c プロジェクト: dscho/nmh
int
main (int argc, char **argv)
{
    int msgnum, *icachesw;
    char *cp, *file = NULL, *outfile = NULL, *folder = NULL;
    char *maildir, buf[100], **argp;
    char **arguments;
    struct msgs_array msgs = { 0, 0, NULL };
    struct msgs *mp = NULL;
    CT ct, *ctp;
    FILE *fp;

    if (nmh_init(argv[0], 1)) { return 1; }

    done=freects_done;

    arguments = getarguments (invo_name, argc, argv, 1);
    argp = arguments;

    /*
     * Parse arguments
     */
    while ((cp = *argp++)) {
	if (*cp == '-') {
	    switch (smatch (++cp, switches)) {
	    case AMBIGSW: 
		ambigsw (cp, switches);
		done (1);
	    case UNKWNSW: 
		adios (NULL, "-%s unknown", cp);

	    case HELPSW: 
		snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]",
			invo_name);
		print_help (buf, switches, 1);
		done (0);
	    case VERSIONSW:
		print_version(invo_name);
		done (0);

	    case AUTOSW:
		autosw++;
		continue;
	    case NAUTOSW:
		autosw = 0;
		continue;

	    case RCACHESW:
		icachesw = &rcachesw;
		goto do_cache;
	    case WCACHESW:
		icachesw = &wcachesw;
do_cache:
		if (!(cp = *argp++) || *cp == '-')
		    adios (NULL, "missing argument to %s", argp[-2]);
		switch (*icachesw = smatch (cp, caches)) {
		case AMBIGSW:
		    ambigsw (cp, caches);
		    done (1);
		case UNKWNSW:
		    adios (NULL, "%s unknown", cp);
		default:
		    break;
		}
		continue;

	    case CHECKSW:
		checksw++;
		continue;
	    case NCHECKSW:
		checksw = 0;
		continue;

	    case PARTSW:
		if (!(cp = *argp++) || *cp == '-')
		    adios (NULL, "missing argument to %s", argp[-2]);
		if (npart >= NPARTS)
		    adios (NULL, "too many parts (starting with %s), %d max",
			   cp, NPARTS);
		parts[npart++] = cp;
		continue;

	    case TYPESW:
		if (!(cp = *argp++) || *cp == '-')
		    adios (NULL, "missing argument to %s", argp[-2]);
		if (ntype >= NTYPES)
		    adios (NULL, "too many types (starting with %s), %d max",
			   cp, NTYPES);
		types[ntype++] = cp;
		continue;

	    case FILESW:
		if (!(cp = *argp++) || (*cp == '-' && cp[1]))
		    adios (NULL, "missing argument to %s", argp[-2]);
		file = *cp == '-' ? cp : path (cp, TFILE);
		continue;

	    case OUTFILESW:
		if (!(cp = *argp++) || (*cp == '-' && cp[1]))
		    adios (NULL, "missing argument to %s", argp[-2]);
		outfile = *cp == '-' ? cp : path (cp, TFILE);
		continue;

	    case VERBSW: 
		verbosw = 1;
		continue;
	    case NVERBSW: 
		verbosw = 0;
		continue;
            case CLOBBERSW:
		if (!(cp = *argp++) || *cp == '-')
		    adios (NULL, "missing argument to %s", argp[-2]);
                if (save_clobber_policy (cp)) {
                  adios (NULL, "invalid argument, %s, to %s", argp[-1],
                         argp[-2]);
                }
		continue;
	    case DEBUGSW:
		debugsw = 1;
		continue;
	    }
	}
	if (*cp == '+' || *cp == '@') {
	    if (folder)
		adios (NULL, "only one folder at a time!");
	    else
		folder = pluspath (cp);
	} else
		app_msgarg(&msgs, cp);
    }

    /* null terminate the list of acceptable parts/types */
    parts[npart] = NULL;
    types[ntype] = NULL;

    /*
     * Check if we've specified an additional profile
     */
    if ((cp = getenv ("MHSTORE"))) {
	if ((fp = fopen (cp, "r"))) {
	    readconfig ((struct node **) 0, fp, cp, 0);
	    fclose (fp);
	} else {
	    admonish ("", "unable to read $MHSTORE profile (%s)", cp);
	}
    }

    /*
     * Read the standard profile setup
     */
    if ((fp = fopen (cp = etcpath ("mhn.defaults"), "r"))) {
	readconfig ((struct node **) 0, fp, cp, 0);
	fclose (fp);
    }

    /* Check for public cache location */
    if ((cache_public = context_find (nmhcache)) && *cache_public != '/')
	cache_public = NULL;

    /* Check for private cache location */
    if (!(cache_private = context_find (nmhprivcache)))
	cache_private = ".cache";
    cache_private = getcpy (m_maildir (cache_private));

    /*
     * Cache the current directory before we do any chdirs()'s.
     */
    cwd = getcpy (pwd());

    if (!context_find ("path"))
	free (path ("./", TFOLDER));

    if (file && msgs.size)
	adios (NULL, "cannot specify msg and file at same time!");

    /*
     * check if message is coming from file
     */
    if (file) {
	if (!(cts = (CT *) calloc ((size_t) 2, sizeof(*cts))))
	    adios (NULL, "out of memory");
	ctp = cts;

	if ((ct = parse_mime (file))) {
	    *ctp++ = ct;
	    if (outfile) {
		ct->c_storage = outfile;
	    }
        }
    } else {
	/*
	 * message(s) are coming from a folder
	 */
	if (!msgs.size)
	    app_msgarg(&msgs, "cur");
	if (!folder)
	    folder = getfolder (1);
	maildir = m_maildir (folder);

	if (chdir (maildir) == NOTOK)
	    adios (maildir, "unable to change directory to");

	/* read folder and create message structure */
	if (!(mp = folder_read (folder, 1)))
	    adios (NULL, "unable to read folder %s", folder);

	/* check for empty folder */
	if (mp->nummsg == 0)
	    adios (NULL, "no messages in %s", folder);

	/* parse all the message ranges/sequences and set SELECTED */
	for (msgnum = 0; msgnum < msgs.size; msgnum++)
	    if (!m_convert (mp, msgs.msgs[msgnum]))
		done (1);
	seq_setprev (mp);	/* set the previous-sequence */

	if (!(cts = (CT *) calloc ((size_t) (mp->numsel + 1), sizeof(*cts))))
	    adios (NULL, "out of memory");
	ctp = cts;

	for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
	    if (is_selected(mp, msgnum)) {
		char *msgnam;

		msgnam = m_name (msgnum);
		if ((ct = parse_mime (msgnam))) {
		    *ctp++ = ct;
		    if (outfile) {
			ct->c_storage = add (outfile, NULL);
		    }
                }
	    }
	}
    }

    if (!*cts)
	done (1);

    userrs = 1;
    SIGNAL (SIGQUIT, quitser);
    SIGNAL (SIGPIPE, pipeser);

    /*
     * Get the associated umask for the relevant contents.
     */
    for (ctp = cts; *ctp; ctp++) {
	struct stat st;

	ct = *ctp;
	if (type_ok (ct, 1) && !ct->c_umask) {
	    if (stat (ct->c_file, &st) != NOTOK)
		ct->c_umask = ~(st.st_mode & 0777);
	    else
		ct->c_umask = ~m_gmprot();
	}
    }

    /*
     * Store the message content
     */
    store_all_messages (cts);

    /* Now free all the structures for the content */
    for (ctp = cts; *ctp; ctp++)
	free_content (*ctp);

    free ((char *) cts);
    cts = NULL;

    /* If reading from a folder, do some updating */
    if (mp) {
	context_replace (pfolder, folder);/* update current folder  */
	seq_setcur (mp, mp->hghsel);	  /* update current message */
	seq_save (mp);			  /* synchronize sequences  */
	context_save ();		  /* save the context file  */
    }

    done (files_not_clobbered);
    return 1;
}
コード例 #18
0
ファイル: sharefarm.c プロジェクト: bentglasstube/secretfs
int
sharefarm_read(const char *path, size_t *len, char **buf)
{
  sharefarm_content *c = NULL, *cc = NULL;
  int ret, i;
  gfshare_ctx *gfc = NULL;
  unsigned char *sharenrs = NULL;
  unsigned char *sparebuf = NULL;
  
  if ((ret = find_all_shares(&c)) < 0)
    return ret;
  
  cc = find_content(c, path);
  
  if (cc == NULL) {
    free_content(c);
    return -ENOENT;
  }
  
  sharenrs = malloc(cc->sharecount);
  if (sharenrs == NULL) {
    free_content(c);
    return -ENOMEM;
  }
  
  for (i = 0; i < cc->sharecount; ++i)
    sharenrs[i] = (unsigned char)(cc->shares[i].sharenum);
  
  *len = cc->statinfo.st_size;
  *buf = calloc(1, *len);
  if (*buf == NULL) {
    ret = -ENOMEM;
    goto out;
  }
  
  mlock(*buf, *len);
  
  sparebuf = malloc(*len);
  if (sparebuf == NULL) {
    ret = -ENOMEM;
    goto out;
  }
  
  gfc = gfshare_ctx_init_dec(sharenrs, cc->sharecount, cc->statinfo.st_size);
  
  if (gfc == NULL) {
    ret = -ENOMEM;
    goto out;
  }
  
  for (i = 0; i < cc->sharecount; ++i) {
    int fd = open(cc->shares[i].fname, O_RDONLY);
    
    if (fd == -1) {
      ret = -errno;
      goto out;
    }
    
    if (read(fd, sparebuf, *len) != *len) {
      ret = -errno;
      close(fd);
      goto out;
    }
    
    close(fd);
    
    gfshare_ctx_dec_giveshare(gfc, i, sparebuf);
  }
  
  gfshare_ctx_dec_extract(gfc, (unsigned char *)*buf);

  out: 
  if (ret < 0 ) {
    if (*buf != NULL) {
      munlock(*buf, *len);
      free(*buf);
    }
  }
  if (gfc != NULL) {
    gfshare_ctx_free(gfc);
  }
  free(sharenrs);
  free_content(c);
  return ret;
}
コード例 #19
0
ファイル: tests.c プロジェクト: michalliu/rkchrome_uboot
int test_charge(int argc, char** argv) {
    const char* desc;
    if (argc > 0) {
        desc = argv[0];
    } else {
        desc = DEF_CHARGE_DESC_PATH;
    }

    resource_content content;
    snprintf(content.path, sizeof(content.path), "%s", desc);
    content.load_addr = 0;
    if (!get_content(&content)) {
        goto end;
    }
    if (!load_content(&content)) {
        goto end;
    }

    char* buf = (char*)content.load_addr;
    char* end = buf + content.content_size - 1;
    *end = '\0';
    LOGD("desc:\n%s", buf);

    int pos = 0;
    while (1) {
        char* line = (char*) memchr(buf + pos, '\n', strlen(buf + pos));
        if (!line)
            break;
        *line = '\0';
        LOGD("splite:%s", buf + pos);
        pos += (strlen(buf + pos) + 1);
    }

    int delay = 900;
    int only_current_level = false;
    anim_level_conf* level_confs = NULL;
    int level_conf_pos = 0;
    int level_conf_num = 0;

    while (true) {
        if (buf >= end)
            break;
        const char* arg = buf;
        buf += (strlen(buf) + 1);

        LOGD("parse arg:%s", arg);
        if (!memcmp(arg, OPT_CHARGE_ANIM_LEVEL_CONF,
                    strlen(OPT_CHARGE_ANIM_LEVEL_CONF))) {
            if (!level_confs) {
                LOGE("Found level conf before levels!");
                goto end;
            }
            if (level_conf_pos >= level_conf_num) {
                LOGE("Too many level confs!(%d >= %d)", level_conf_pos, level_conf_num);
                goto end;
            }
            if (!parse_level_conf(arg, level_confs + level_conf_pos)) {
                LOGE("Failed to parse level conf:%s", arg);
                goto end;
            }
            level_conf_pos ++;
        } else if (!memcmp(arg, OPT_CHARGE_ANIM_DELAY,
                    strlen(OPT_CHARGE_ANIM_DELAY))) {
            delay = atoi(arg + strlen(OPT_CHARGE_ANIM_DELAY));
            LOGD("Found delay:%d", delay);
        } else if (!memcmp(arg, OPT_CHARGE_ANIM_LOOP_CUR,
                    strlen(OPT_CHARGE_ANIM_LOOP_CUR))) {
            only_current_level =
                !memcmp(arg + strlen(OPT_CHARGE_ANIM_LOOP_CUR), "true", 4);
            LOGD("Found only_current_level:%d", only_current_level);
        } else if (!memcmp(arg, OPT_CHARGE_ANIM_LEVELS,
                    strlen(OPT_CHARGE_ANIM_LEVELS))) {
            if (level_conf_num) {
                goto end;
            }
            level_conf_num = atoi(arg + strlen(OPT_CHARGE_ANIM_LEVELS));
            if (!level_conf_num) {
                goto end;
            }
            level_confs =
                (anim_level_conf*) malloc(level_conf_num * sizeof(anim_level_conf));
            LOGD("Found levels:%d", level_conf_num);
        } else {
            LOGE("Unknown arg:%s", arg);
            goto end;
        }
    }

    if (level_conf_pos != level_conf_num || !level_conf_num) {
        LOGE("Something wrong with level confs!");
        goto end;
    }

    int i = 0, j = 0, k = 0;
    for (i = 0; i < level_conf_num; i++) {
        if (!level_confs[i].delay) {
            level_confs[i].delay = delay;
        }
        if (!level_confs[i].delay) {
            LOGE("Missing delay in level conf:%d", i);
            goto end;
        }
        for (j = 0; j < i; j++) {
            if (level_confs[j].max_level == level_confs[i].max_level) {
                LOGE("Dup level conf:%d", i);
                goto end;
            }
            if (level_confs[j].max_level > level_confs[i].max_level) {
                anim_level_conf conf = level_confs[i];
                memmove(level_confs + j + 1, level_confs + j,
                        (i - j) * sizeof(anim_level_conf));
                level_confs[j] = conf;
            }
        }
    }

    printf("Parse anim desc(%s):\n", desc);
    printf("only_current_level=%d\n", only_current_level);
    printf("level conf:\n");
    for (i = 0; i < level_conf_num; i++) {
        printf("\tmax=%d, delay=%d, num=%d, prefix=%s\n",
                level_confs[i].max_level, level_confs[i].delay,
                level_confs[i].num, level_confs[i].prefix);
    }

end:
    free_content(&content);
    return 0;
}
コード例 #20
0
ファイル: fwd-ccnb.c プロジェクト: truedat101/ccn-lite
int
ccnl_ccnb_forwarder(struct ccnl_relay_s *relay, struct ccnl_face_s *from,
		    unsigned char **data, int *datalen)
{
    int rc= -1, scope=3, aok=3, minsfx=0, maxsfx=CCNL_MAX_NAME_COMP, contlen;
    struct ccnl_buf_s *buf = 0, *nonce=0, *ppkd=0;
    struct ccnl_interest_s *i = 0;
    struct ccnl_content_s *c = 0;
    struct ccnl_prefix_s *p = 0;
    unsigned char *content = 0;
    DEBUGMSG(99, "ccnl/ccnb forwarder (%d bytes left)\n", *datalen);

    buf = ccnl_ccnb_extract(data, datalen, &scope, &aok, &minsfx,
			    &maxsfx, &p, &nonce, &ppkd, &content, &contlen);
    if (!buf) {
	    DEBUGMSG(6, "  parsing error or no prefix\n"); goto Done;
    }
    if (nonce && ccnl_nonce_find_or_append(relay, nonce)) {
	DEBUGMSG(6, "  dropped because of duplicate nonce\n"); goto Skip;
    }
    if (buf->data[0] == 0x01 && buf->data[1] == 0xd2) { // interest
	DEBUGMSG(6, "  interest=<%s>\n", ccnl_prefix_to_path(p));
	ccnl_print_stats(relay, STAT_RCV_I); //log count recv_interest
	if (p->compcnt > 0 && p->comp[0][0] == (unsigned char) 0xc1) goto Skip;
	if (p->compcnt == 4 && !memcmp(p->comp[0], "ccnx", 4)) {
	    rc = ccnl_mgmt(relay, buf, p, from); goto Done;
	}
	// CONFORM: Step 1:
	if ( aok & 0x01 ) { // honor "answer-from-existing-content-store" flag
	    for (c = relay->contents; c; c = c->next) {
		if (c->suite != CCNL_SUITE_CCNB) continue;
		if (!ccnl_i_prefixof_c(p, minsfx, maxsfx, c)) continue;
		if (ppkd && !buf_equal(ppkd, c->details.ccnb.ppkd)) continue;
		// FIXME: should check stale bit in aok here
		DEBUGMSG(7, "  matching content for interest, content %p\n", (void *) c);
		ccnl_print_stats(relay, STAT_SND_C); //log sent_c
		if (from->ifndx >= 0)
		    ccnl_face_enqueue(relay, from, buf_dup(c->pkt));
		else
		    ccnl_app_RX(relay, c);
		goto Skip;
	    }
	}
	// CONFORM: Step 2: check whether interest is already known
	for (i = relay->pit; i; i = i->next) {
	    if (i->suite == CCNL_SUITE_CCNB &&
		!ccnl_prefix_cmp(i->prefix, NULL, p, CMP_EXACT) &&
		i->details.ccnb.minsuffix == minsfx &&
		i->details.ccnb.maxsuffix == maxsfx && 
		((!ppkd && !i->details.ccnb.ppkd) ||
		   buf_equal(ppkd, i->details.ccnb.ppkd)) )
		break;
	}
	if (!i) { // this is a new/unknown I request: create and propagate
	    i = ccnl_interest_new(relay, from, CCNL_SUITE_CCNB,
				  &buf, &p, minsfx, maxsfx);
	    if (ppkd)
		i->details.ccnb.ppkd = ppkd, ppkd = NULL;
	    if (i) { // CONFORM: Step 3 (and 4)
		DEBUGMSG(7, "  created new interest entry %p\n", (void *) i);
		if (scope > 2)
		    ccnl_interest_propagate(relay, i);
	    }
	} else if (scope > 2 && (from->flags & CCNL_FACE_FLAGS_FWDALLI)) {
	    DEBUGMSG(7, "  old interest, nevertheless propagated %p\n", (void *) i);
	    ccnl_interest_propagate(relay, i);
	}
	if (i) { // store the I request, for the incoming face (Step 3)
	    DEBUGMSG(7, "  appending interest entry %p\n", (void *) i);
	    ccnl_interest_append_pending(i, from);
	}
    } else { // content
	DEBUGMSG(6, "  content=<%s>\n", ccnl_prefix_to_path(p));
	ccnl_print_stats(relay, STAT_RCV_C); //log count recv_content
        
#ifdef USE_SIGNATURES
        if (p->compcnt == 2 && !memcmp(p->comp[0], "ccnx", 4)
                && !memcmp(p->comp[1], "crypto", 6) &&
                from == relay->crypto_face) {
	    rc = ccnl_crypto(relay, buf, p, from); goto Done;
	}
#endif /*USE_SIGNATURES*/
        
        // CONFORM: Step 1:
	for (c = relay->contents; c; c = c->next)
	    if (buf_equal(c->pkt, buf)) goto Skip; // content is dup
	c = ccnl_content_new(relay, CCNL_SUITE_CCNB,
			     &buf, &p, &ppkd, content, contlen);
	if (c) { // CONFORM: Step 2 (and 3)
	    if (!ccnl_content_serve_pending(relay, c)) { // unsolicited content
		// CONFORM: "A node MUST NOT forward unsolicited data [...]"
		DEBUGMSG(7, "  removed because no matching interest\n");
		free_content(c);
		goto Skip;
	    }
	    if (relay->max_cache_entries != 0) { // it's set to -1 or a limit
		DEBUGMSG(7, "  adding content to cache\n");
		ccnl_content_add2cache(relay, c);
	    } else {
		DEBUGMSG(7, "  content not added to cache\n");
		free_content(c);
	    }
	}
    }
Skip:
    rc = 0;
Done:
    free_prefix(p);
    free_3ptr_list(buf, nonce, ppkd);
    return rc;
}
コード例 #21
0
ファイル: mhbuild.c プロジェクト: ella13/nmh
int
main (int argc, char **argv)
{
    int sizesw = 1, headsw = 1;
    int *icachesw;
    char *cp, buf[BUFSIZ];
    char buffer[BUFSIZ], *compfile = NULL;
    char **argp, **arguments;
    CT ct, cts[2];
    FILE *fp = NULL;
    FILE *fp_out = NULL;

    done=unlink_done;

#ifdef LOCALE
    setlocale(LC_ALL, "");
#endif
    invo_name = r1bindex (argv[0], '/');

    /* read user profile/context */
    context_read();

    arguments = getarguments (invo_name, argc, argv, 1);
    argp = arguments;

    while ((cp = *argp++)) {
	if (cp[0] == '-' && cp[1] == '\0') {
	    if (compfile)
		adios (NULL, "cannot specify both standard input and a file");
	    else
		compfile = cp;
	    listsw = 0;		/* turn off -list if using standard in/out */
	    verbosw = 0;	/* turn off -verbose listings */
	    break;
	}
	if (*cp == '-') {
	    switch (smatch (++cp, switches)) {
	    case AMBIGSW: 
		ambigsw (cp, switches);
		done (1);
	    case UNKWNSW: 
		adios (NULL, "-%s unknown", cp);

	    case HELPSW: 
		snprintf (buf, sizeof(buf), "%s [switches] file", invo_name);
		print_help (buf, switches, 1);
		done (1);
	    case VERSIONSW:
		print_version(invo_name);
		done (1);

	    case RCACHESW:
		icachesw = &rcachesw;
		goto do_cache;
	    case WCACHESW:
		icachesw = &wcachesw;
	    do_cache: ;
		if (!(cp = *argp++) || *cp == '-')
		    adios (NULL, "missing argument to %s", argp[-2]);
		switch (*icachesw = smatch (cp, caches)) {
		case AMBIGSW:
		    ambigsw (cp, caches);
		    done (1);
		case UNKWNSW:
		    adios (NULL, "%s unknown", cp);
		default:
		    break;
		}
		continue;

	    case CHECKSW:
		checksw++;
		continue;
	    case NCHECKSW:
		checksw = 0;
		continue;

	    case EBCDICSW:
		ebcdicsw++;
		continue;
	    case NEBCDICSW:
		ebcdicsw = 0;
		continue;

	    case HEADSW:
		headsw++;
		continue;
	    case NHEADSW:
		headsw = 0;
		continue;

	    case LISTSW:
		listsw++;
		continue;
	    case NLISTSW:
		listsw = 0;
		continue;

	    case RFC934SW:
		rfc934sw++;
		continue;
	    case NRFC934SW:
		rfc934sw = 0;
		continue;

	    case SIZESW:
		sizesw++;
		continue;
	    case NSIZESW:
		sizesw = 0;
		continue;

	    case CONTENTIDSW:
		contentidsw = 1;
		continue;
	    case NCONTENTIDSW:
		contentidsw = 0;
		continue;

	    case VERBSW: 
		verbosw++;
		continue;
	    case NVERBSW: 
		verbosw = 0;
		continue;
	    case DEBUGSW:
		debugsw = 1;
		continue;
	    }
	}
	if (compfile)
	    adios (NULL, "only one composition file allowed");
	else
	    compfile = cp;
    }

    set_endian ();

    if ((cp = getenv ("MM_NOASK")) && !strcmp (cp, "1"))
	listsw  = 0;

    /*
     * Check if we've specified an additional profile
     */
    if ((cp = getenv ("MHBUILD"))) {
	if ((fp = fopen (cp, "r"))) {
	    readconfig ((struct node **) 0, fp, cp, 0);
	    fclose (fp);
	} else {
	    admonish ("", "unable to read $MHBUILD profile (%s)", cp);
	}
    }

    /*
     * Read the standard profile setup
     */
    if ((fp = fopen (cp = etcpath ("mhn.defaults"), "r"))) {
	readconfig ((struct node **) 0, fp, cp, 0);
	fclose (fp);
    }

    /* Check for public cache location */
    if ((cache_public = context_find (nmhcache)) && *cache_public != '/')
	cache_public = NULL;

    /* Check for private cache location */
    if (!(cache_private = context_find (nmhprivcache)))
	cache_private = ".cache";
    cache_private = getcpy (m_maildir (cache_private));

    /*
     * Check for storage directory.  If defined, we
     * will store temporary files there.  Else we
     * store them in standard nmh directory.
     */
    if ((cp = context_find (nmhstorage)) && *cp)
	tmp = concat (cp, "/", invo_name, NULL);
    else
	tmp = add (m_maildir (invo_name), NULL);

    if (!context_find ("path"))
	free (path ("./", TFOLDER));

    /* Check if we have a file to process */
    if (!compfile)
	adios (NULL, "need to specify a %s composition file", invo_name);

    /*
     * Process the composition file from standard input.
     */
    if (compfile[0] == '-' && compfile[1] == '\0') {
	/* copy standard input to temporary file */
	strncpy (infile, m_mktemp(invo_name, NULL, &fp), sizeof(infile));
	while (fgets (buffer, BUFSIZ, stdin))
	    fputs (buffer, fp);
	fclose (fp);
	unlink_infile = 1;

	/* build the content structures for MIME message */
	ct = build_mime (infile);
	cts[0] = ct;
	cts[1] = NULL;

	/* output MIME message to this temporary file */
	strncpy (outfile, m_mktemp(invo_name, NULL, &fp_out), sizeof(outfile));
	unlink_outfile = 1;

	/* output the message */
	output_message_fp (ct, fp_out, outfile);
        fclose(fp_out);

	/* output the temp file to standard output */
	if ((fp = fopen (outfile, "r")) == NULL)
	    adios (outfile, "unable to open");
	while (fgets (buffer, BUFSIZ, fp))
	    fputs (buffer, stdout);
	fclose (fp);

	unlink (infile);
	unlink_infile = 0;

	unlink (outfile);
	unlink_outfile = 0;

	free_content (ct);
	done (0);
    }

    /*
     * Process the composition file from a file.
     */

    /* build the content structures for MIME message */
    ct = build_mime (compfile);
    cts[0] = ct;
    cts[1] = NULL;

    /* output MIME message to this temporary file */
    strncpy(outfile, m_mktemp2(compfile, invo_name, NULL, &fp_out),
            sizeof(outfile));
    unlink_outfile = 1;

    /* output the message */
    output_message_fp (ct, fp_out, outfile);
    fclose(fp_out);

    /*
     * List the message info
     */
    if (listsw)
	list_all_messages (cts, headsw, sizesw, verbosw, debugsw);

    /* Rename composition draft */
    snprintf (buffer, sizeof(buffer), "%s.orig", m_backup (compfile));
    if (rename (compfile, buffer) == NOTOK) {
	adios (compfile, "unable to rename comp draft %s to", buffer);
    }

    /* Rename output file to take its place */
    if (rename (outfile, compfile) == NOTOK) {
	advise (outfile, "unable to rename output %s to", compfile);
	rename (buffer, compfile);
	done (1);
    }
    unlink_outfile = 0;

    free_content (ct);
    done (0);
    return 1;
}