Exemple #1
0
Key*
plan9authkey(Attr *a)
{
	char *dom;
	Key *k;

	/*
	 * The only important part of a is dom.
	 * We don't care, for example, about user name.
	 */
	dom = strfindattr(a, "dom");
	if(dom)
		k = keylookup("proto=p9sk1 role=server user? dom=%q", dom);
	else
		k = keylookup("proto=p9sk1 role=server user? dom?");
	if(k == nil)
		werrstr("could not find plan 9 auth key dom %q", dom);
	return k;
}
Exemple #2
0
//Query an auction - the system returns the status of a specified
//auction: if it's a success and if so who's the winner.
auctionErrorCode queryAuction(const char *auctionItemName, bool *itemSold, int *winningBidder)
{
  auctionData *thisAuction;

  if ((winningBidder == NULL) || (itemSold == NULL)) {
    return AUCTION_ERR_INPUT_NULL;
  }

  thisAuction = keylookup(auctionItemName);

  if (thisAuction == NULL) {
    return AUCTION_ERR_KEY;
  }

  //update return values with stored data
  *itemSold = thisAuction->itemSold;
  *winningBidder = thisAuction->highBidNum;

  return AUCTION_SUCCESS;
}
Exemple #3
0
/*
 * read in empire configuration
 */
int
emp_config(char *file)
{
    FILE *fp;
    char scanspace[1024];
    char *av[128];
    char buf[1024];
    struct keymatch *kp;
    int lno = 0;
    int errors = 0;
    int i;

    if (!file)
	file = dflt_econfig;
    errno = 0;
    if ((fp = fopen(file, "r")) == NULL) {
	if (file == dflt_econfig && errno == ENOENT)
	    goto done;
	fprintf(stderr, "Can't open %s for reading (%s)\n",
		file, strerror(errno));
	return -1;
    }

    while (fgets(buf, sizeof(buf), fp) != NULL) {
	++lno;
	for (i = 0; buf[i] && isspace(buf[i]); ++i) ;
	if (!buf[i] || buf[i] == '#')
	    continue;
	if (parse(buf, scanspace, av, NULL, NULL, NULL) < 0) {
	    fprintf(stderr, "%s:%d: Can't parse line %s", file, lno, buf);
	    errors = 1;
	    continue;
	}
	if ((kp = keylookup(av[0], configkeys)) == NULL) {
	    fprintf(stderr, "%s:%d: Unknown config key %s\n",
		    file, lno, av[0]);
	    errors = 1;
	    continue;
	}
	if (av[1] == NULL) {
	    fprintf(stderr, "%s:%d: Config key %s needs a value\n",
		    file, lno, av[0]);
	    errors = 1;
	    continue;
	}
	i = 2;
	switch (kp->km_type) {
	case NSC_INT:
	    *(int *)kp->km_data = atoi(av[1]);
	    break;
	case NSC_FLOAT:
	    *(float *)kp->km_data = atof(av[1]);
	    break;
	case NSC_DOUBLE:
	    *(double *)kp->km_data = atof(av[1]);
	    break;
	case NSC_LONG:
	    *(long *)kp->km_data = atol(av[1]);
	    break;
	case NSC_STRING:
	    if (kp->km_flags & KM_ALLOC)
		free(*(char **)kp->km_data);
	    *(char **)kp->km_data = strdup(av[1]);
	    kp->km_flags |= KM_ALLOC;
	    break;
	default:
	    assert(0);
	}
	if (av[i] != NULL) {
	    fprintf(stderr, "%s:%d: Junk after value of config key %s\n",
		    file, lno, av[0]);
	    errors = 1;
	}
    }

    fclose(fp);

done:
    WORLD_X &= ~1;		/* force even */
    if (set_paths(file) < 0)
	return -1;

    return -errors;
}