Exemplo n.º 1
0
Arquivo: chat.c Projeto: bmybbs/bmybbs
static void
chat_load_alias()
{
	char buf[256];
	int i;
	chat_alias_count = 0;
	chat_aliases =
	    (struct chatalias *) malloc(sizeof (struct chatalias) *
					MAXDEFINEALIAS);
	for (i = 0; i < MAXDEFINEALIAS; i++)
		chat_aliases[i].cmd[0] = 0;
	setuserfile(buf, "chatalias");
	chat_alias_count = get_num_records(buf, sizeof (struct chatalias));
	if (chat_alias_count > MAXDEFINEALIAS)
		chat_alias_count = MAXDEFINEALIAS;
	if (chat_alias_count != 0)
		get_records(buf, chat_aliases, sizeof (struct chatalias), 1,
			    chat_alias_count);
	for (i = 0; i < chat_alias_count; i++) {
		if (chat_aliases[i].cmd[0] == 0) {
			chat_alias_count = i;
			break;
		}
		chat_aliases[i].cmd[8] = 0;
		chat_aliases[i].action[80] = 0;
	}
}
Exemplo n.º 2
0
/* These are functions to be called from unix.c for audio system
 * ifaces (alsa, gstreamer, etc.) */
gboolean gateway_request_stream(struct audio_device *dev,
				gateway_stream_cb_t cb, void *user_data)
{
	struct gateway *gw = dev->gateway;
	GError *err = NULL;
	GIOChannel *io;

	if (!gw->rfcomm) {
		gw->sco_start_cb = cb;
		gw->sco_start_cb_data = user_data;
		get_records(dev);
	} else if (!gw->sco) {
		gw->sco_start_cb = cb;
		gw->sco_start_cb_data = user_data;
		io = bt_io_connect(BT_IO_SCO, sco_connect_cb, dev, NULL, &err,
				BT_IO_OPT_SOURCE_BDADDR, &dev->src,
				BT_IO_OPT_DEST_BDADDR, &dev->dst,
				BT_IO_OPT_INVALID);
		if (!io) {
			error("%s", err->message);
			g_error_free(err);
			return FALSE;
		}
	} else if (cb)
		cb(dev, err, user_data);

	return TRUE;
}
Exemplo n.º 3
0
/* These are functions to be called from unix.c for audio system
 * ifaces (alsa, gstreamer, etc.) */
unsigned int gateway_request_stream(struct audio_device *dev,
				gateway_stream_cb_t cb, void *user_data)
{
	struct gateway *gw = dev->gateway;
	GError *err = NULL;
	GIOChannel *io;

	if (!gw->rfcomm) {
		if (get_records(dev) < 0)
			return 0;
	} else if (!gw->sco) {
		io = bt_io_connect(sco_connect_cb, dev, NULL, &err,
				BT_IO_OPT_SOURCE_BDADDR, &dev->src,
				BT_IO_OPT_DEST_BDADDR, &dev->dst,
				BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
				BT_IO_OPT_INVALID);
		if (!io) {
			error("%s", err->message);
			g_error_free(err);
			return 0;
		}
	} else
		g_idle_add(request_stream_cb, dev);

	return connect_cb_new(gw, cb, user_data);
}
Exemplo n.º 4
0
int main(int argc, char *argv[])
{
    oct_init();

    set_records();
    get_records();

    printf("d2getset SUCESS!\n");
    return EXIT_SUCCESS;
}
Exemplo n.º 5
0
static void
a_moveitem(menu_t * pm)
{
    fileheader_t   *tmp;
    char            newnum[5];
    int             num, max, min;
    char            buf[PATHLEN];
    int             fail;

    snprintf(buf, sizeof(buf), "請輸入第 %d 選項的新次序:", pm->now + 1);
    if (!getdata(b_lines - 1, 1, buf, newnum, sizeof(newnum), DOECHO))
	return;
    num = (newnum[0] == '$') ? A_INVALID_PAGE : atoi(newnum) - 1;
    if (num >= pm->num)
	num = pm->num - 1;
    else if (num < 0)
	num = 0;
    setadir(buf, pm->path);
    min = num < pm->now ? num : pm->now;
    max = num > pm->now ? num : pm->now;
    tmp = (fileheader_t *) calloc(max + 1, FHSZ);

    fail = 0;
    if (get_records(buf, tmp, FHSZ, 1, min) != min)
	fail = 1;
    if (num > pm->now) {
	if (get_records(buf, &tmp[min], FHSZ, pm->now + 2, max - min) != max - min)
	    fail = 1;
	if (get_records(buf, &tmp[max], FHSZ, pm->now + 1, 1) != 1)
	    fail = 1;
    } else {
	if (get_records(buf, &tmp[min], FHSZ, pm->now + 1, 1) != 1)
	    fail = 1;
	if (get_records(buf, &tmp[min + 1], FHSZ, num + 1, max - min) != max - min)
	    fail = 1;
    }
    if (!fail)
	substitute_record(buf, tmp, FHSZ * (max + 1), 1);
    pm->now = num;
    free(tmp);
}
Exemplo n.º 6
0
// Loads PASSFILE into cache for all users.
// Returns 0 on success, -1 on error.
int load_ucache(void)
{
	int fd, iscreate = 0, passwdfd, i;

	// Lock cache.
	fd = ucache_lock();
	if (fd == -1) {
		return -1;
	}

	// Get shared memory.
	if (uidshm == NULL) {
		uidshm = attach_shm2("UCACHE_SHMKEY", 3696, sizeof(*uidshm),
				&iscreate);
		if(uidshm == NULL)
			exit(1);
	}
	log_usies("CACHE", "reload ucache", NULL);

	// Load PASSFILE.
	if ((passwdfd = open(PASSFILE, O_RDWR | O_CREAT, 0644)) == -1) {
		ucache_unlock(fd);
		exit(-1);
	}
	ftruncate(passwdfd, MAXUSERS * sizeof(struct userec));
	close(passwdfd);
	if (get_records(PASSFILE, uidshm->passwd, sizeof(struct userec), 1,
			MAXUSERS) != MAXUSERS) {
		ucache_unlock(fd);
		return -1;
	}

	// Initialize 'userid' and hash.
	memset(uidshm->userid, 0, sizeof(uidshm->userid));
	memset(uidshm->hash, 0, sizeof(uidshm->hash));
	memset(uidshm->next, 0, sizeof(uidshm->next));
	memset(uidshm->prev, 0, sizeof(uidshm->prev));

	// Fill cache.
	int last = 0;
	for (i = 0; i < MAXUSERS; i++) {
		if (fillucache(&(uidshm->passwd[i]), i))
			last = i;
	}
	uidshm->number = ++last;
	uidshm->uptime = time(NULL);

	// Unlock cache.
	ucache_unlock(fd);

	return 0;
}
Exemplo n.º 7
0
int gateway_config_stream(struct audio_device *dev, gateway_stream_cb_t sco_cb,
				void *user_data)
{
	struct gateway *gw = dev->gateway;

	if (!gw->rfcomm) {
		gw->sco_start_cb = sco_cb;
		gw->sco_start_cb_data = user_data;
		return get_records(dev);
	}

	if (sco_cb)
		sco_cb(dev, NULL, user_data);

	return 0;
}
Exemplo n.º 8
0
int show_gopher()
{
	extern int page, range;
	int     i;
	GOPHER *tmpnode;
	printgopher_title();
	move(3, 0);
	clrtobot();
	get_records(gophertmpfile, cur_page, sizeof(GOPHER), page + 1, 19);
	for (i = page; i < page + 19 && i < range; i++)
	{
		tmpnode = nth_item(i - page);
		move(i - page + 3, 0);
		prints(" %4d [%9s] %-65s\n", i + 1, ((tmpnode->title[0] == '0') ? "Á¬ÎÄ" : "Á¬Ä¿"), tmpnode->title + 1);
		refresh();
	}
}
Exemplo n.º 9
0
int main(void)
{
  char answer = 'n';
  PhoneRecord records[MAX_NUMBERS];                                                      // Array of phone records
//  Name aName;                                                                          // Stores a name
  size_t count = get_records(records, MAX_NUMBERS);                                      // Number of phone records

  printf_s("\nDo you want to search the phone records (y or n)? ");
  scanf_s(" %c" , &answer, sizeof(answer));
  if(tolower(answer) == 'y')
    search_records(records, count);

  printf_s("\nThe records we have are:\n");
  for(size_t i = 0 ; i < count ; ++i)
    show(records[i]);
  printf_s("\n");
  return 0;
}
Exemplo n.º 10
0
static DBusMessage *ag_connect(DBusConnection *conn, DBusMessage *msg,
				void *data)
{
	struct audio_device *au_dev = (struct audio_device *) data;
	struct gateway *gw = au_dev->gateway;
	int err;

	if (!gw->agent)
		return btd_error_agent_not_available(msg);

	err = get_records(au_dev);
	if (err < 0)
		return btd_error_failed(msg, strerror(-err));

	gw->msg = dbus_message_ref(msg);

	return NULL;
}
Exemplo n.º 11
0
/*
 * Loop until the auditpipe returns something, check if it is what
 * we want, else repeat the procedure until ppoll(2) times out.
 */
static void
check_auditpipe(struct pollfd fd[], const char *auditregex, FILE *pipestream)
{
	struct timespec currtime, endtime, timeout;

	/* Set the expire time for poll(2) while waiting for syscall audit */
	ATF_REQUIRE_EQ(0, clock_gettime(CLOCK_MONOTONIC, &endtime));
	endtime.tv_sec += 10;
	timeout.tv_nsec = endtime.tv_nsec;

	for (;;) {
		/* Update the time left for auditpipe to return any event */
		ATF_REQUIRE_EQ(0, clock_gettime(CLOCK_MONOTONIC, &currtime));
		timeout.tv_sec = endtime.tv_sec - currtime.tv_sec;

		switch (ppoll(fd, 1, &timeout, NULL)) {
		/* ppoll(2) returns, check if it's what we want */
		case 1:
			if (fd[0].revents & POLLIN) {
				if (get_records(auditregex, pipestream))
					return;
			} else {
				atf_tc_fail("Auditpipe returned an "
				"unknown event %#x", fd[0].revents);
			}
			break;

		/* poll(2) timed out */
		case 0:
			atf_tc_fail("%s not found in auditpipe within the "
					"time limit", auditregex);
			break;

		/* poll(2) standard error */
		case -1:
			atf_tc_fail("Poll: %s", strerror(errno));
			break;

		default:
			atf_tc_fail("Poll returned too many file descriptors");
		}
	}
}
Exemplo n.º 12
0
std::vector<std::string> Query::get_strings()
{
  std::vector<std::string> ret;

  auto const rr_set = get_records();

  for (auto rr : rr_set) {
    std::visit(
        [&ret, type = type_](auto const& r) {
          if (type == r.rr_type()) {
            auto const s = r.as_str();
            if (s)
              ret.push_back(*s);
          }
        },
        rr);
  }

  return ret;
}
Exemplo n.º 13
0
Arquivo: utmp.c Projeto: wyat/kbs
int getfriendstr(struct userec* user,struct user_info* puinfo,session_t * session)
{
    int nf;
    int i;
    struct friends *friendsdata;
    char buf[60];

    puinfo->friendsnum=0;
    if (session->topfriend != NULL) {
        free(session->topfriend);
        session->topfriend = NULL;
    }
    sethomefile(buf, user->userid, "friends");
    nf = get_num_records(buf, sizeof(struct friends));
    if (nf <= 0)
        return 0;
    if (nf>MAXFRIENDS)
        nf=MAXFRIENDS;
    friendsdata = (struct friends *) calloc(nf,sizeof(struct friends));
    get_records(buf, friendsdata, sizeof(struct friends), 1, nf);
    for (i = 0; i < nf; i++) {
        friendsdata[i].id[IDLEN] = 0;
        friendsdata[i].exp[LEN_FRIEND_EXP-1] = 0;
        if (id_invalid(friendsdata[i].id)||(searchuser(friendsdata[i].id)==0)) {
            memcpy(&friendsdata[i], &friendsdata[nf - 1], sizeof(struct friends));
            nf--;
        }
    }
    qsort(friendsdata, nf, sizeof(friendsdata[0]), cmpfuid);      /*For Bi_Search */
    session->topfriend = (struct friends_info *) calloc(nf,sizeof(struct friends_info));
    for (i = 0; i < nf; i++) {
        puinfo->friends_uid[i] = searchuser(friendsdata[i].id);
        strcpy(session->topfriend[i].exp, friendsdata[i].exp);
    }
    free(friendsdata);
    puinfo->friendsnum=nf;
    return 0;
}
Exemplo n.º 14
0
static DBusMessage *ag_connect(DBusConnection *conn, DBusMessage *msg,
				void *data)
{
	struct audio_device *au_dev = (struct audio_device *) data;
	struct gateway *gw = au_dev->gateway;
	int err;

	if (gw->state == GATEWAY_STATE_CONNECTING)
		return btd_error_in_progress(msg);
	else if (gw->state > GATEWAY_STATE_CONNECTING)
		return btd_error_already_connected(msg);

	if (!gw->agent)
		return btd_error_agent_not_available(msg);

	err = get_records(au_dev);
	if (err < 0)
		return btd_error_failed(msg, strerror(-err));

	gw->msg = dbus_message_ref(msg);

	return NULL;
}
Exemplo n.º 15
0
static int
a_loadname(menu_t * pm)
{
    char            buf[PATHLEN];
    int             len;

    if(p_lines != pm->header_size) {
	pm->header_size = p_lines;
	pm->header = (fileheader_t *) realloc(pm->header, pm->header_size*FHSZ);
	assert(pm->header);
    }

    setadir(buf, pm->path);
    len = get_records(buf, pm->header, FHSZ, pm->page + 1, pm->header_size); // XXX if get_records() return -1

    // if len < 0, the directory is not valid anymore.
    if (len < 0)
	return 0;

    if (len < pm->header_size)
	bzero(&pm->header[len], FHSZ * (pm->header_size - len));
    return 1;
}
Exemplo n.º 16
0
void do_domain(DNS::Resolver& res, char const* dom_cp)
{
  auto const dom{Domain{dom_cp}};

  auto cnames = res.get_strings(DNS::RR_type::CNAME, dom.ascii().c_str());
  if (!cnames.empty()) {
    // RFC 2181 section 10.1. CNAME resource records
    CHECK_EQ(cnames.size(), 1);
    std::cout << dom << " is an alias for " << cnames.front() << '\n';
  }

  auto as = res.get_strings(DNS::RR_type::A, dom.ascii().c_str());
  for (auto const& a : as) {
    do_addr(res, a.c_str());
  }

  auto aaaas = res.get_strings(DNS::RR_type::AAAA, dom.ascii().c_str());
  for (auto const& aaaa : aaaas) {
    do_addr(res, aaaa.c_str());
  }

  auto q{DNS::Query{res, DNS::RR_type::MX, dom.ascii()}};
  if (!q.has_record()) {
    std::cout << "no records\n";
    return;
  }

  TLD  tld_db;
  auto reg_dom{tld_db.get_registered_domain(dom.ascii())};
  if (dom != reg_dom) {
    std::cout << "registered domain is " << reg_dom << '\n';
  }

  check_uribls(res, dom.ascii().c_str());

  if (q.authentic_data()) {
    std::cout << "MX records authentic for domain " << dom << '\n';
  }

  auto mxs{q.get_records()};

  mxs.erase(std::remove_if(begin(mxs), end(mxs),
                           [](auto const& rr) {
                             return !std::holds_alternative<DNS::RR_MX>(rr);
                           }),
            end(mxs));

  if (!mxs.empty())
    std::cout << "mail for " << dom << " is handled by\n";

  std::sort(begin(mxs), end(mxs), [](auto const& a, auto const& b) {
    auto mxa = std::get<DNS::RR_MX>(a);
    auto mxb = std::get<DNS::RR_MX>(b);
    if (mxa.preference() == mxb.preference())
      return mxa.exchange() < mxb.exchange();
    return mxa.preference() < mxb.preference();
  });

  for (auto const& mx : mxs) {
    if (std::holds_alternative<DNS::RR_MX>(mx)) {
      auto x = std::get<DNS::RR_MX>(mx);
      std::cout << std::setfill(' ') << std::setw(3) << x.preference() << ' '
                << x.exchange() << '\n';
    }
  }
}
Exemplo n.º 17
0
int
get_record(const char *fpath, void *rptr, size_t size, int id)
{
    return get_records(fpath, rptr, size, id, 1);
}