Ejemplo n.º 1
0
/* ------------------------------------------------------------- **
**  Sets up the control connection to the server and initialises
**  session info.
** ------------------------------------------------------------- */
void init_session(int fd, struct sockaddr_in source)
{
	info = init_info(fd, source);

	write_log(INFO, "Connect from %s",
		  sstr_buf(addr2name(info->client_control.address.sin_addr)));

	/*FIXME have a login function which deals with ntp and cache */
	ccp_changedest();
	ntp_changedest();
	info->final_server_address = info->server_control.address;

	write_log(INFO, "... to %s(%s)",
		  inet_ntoa(info->final_server_address.sin_addr),
		  sstr_buf(info->server_name));

#ifdef ENABLE_CHANGEPROC
	set_proc_title("frox: %s <-> %s",
		       inet_ntoa(info->client_control.address.sin_addr),
		       inet_ntoa(info->final_server_address.sin_addr));
#endif
	connect_to_server();

	ntp_senduser();

	run_proxy();
}
Ejemplo n.º 2
0
/* thread handler: do proxy*/
void *proxy_thread(void *argp)
{
    int connfd = *((int *)argp);
    Pthread_detach(pthread_self());
    Free(argp);
    //connfd = pop_fd_q();
    //printf("### proxy_thread: %d, tid: %d\n", connfd, gettid());
    run_proxy(connfd);

    return NULL;
}
Ejemplo n.º 3
0
int cpl_run_script( struct cpl_interpreter *intr )
{
	char *new_ip;

	do {
		check_overflow_by_offset( SIMPLE_NODE_SIZE(intr->ip), intr, error);
		switch ( NODE_TYPE(intr->ip) ) {
			case CPL_NODE:
				LM_DBG("processing CPL node \n");
				new_ip = run_cpl_node( intr ); /*UPDATED&TESTED*/
				break;
			case ADDRESS_SWITCH_NODE:
				LM_DBG("processing address-switch node\n");
				new_ip = run_address_switch( intr ); /*UPDATED&TESTED*/
				break;
			case STRING_SWITCH_NODE:
				LM_DBG("processing string-switch node\n");
				new_ip = run_string_switch( intr ); /*UPDATED&TESTED*/
				break;
			case PRIORITY_SWITCH_NODE:
				LM_DBG("processing priority-switch node\n");
				new_ip = run_priority_switch( intr ); /*UPDATED&TESTED*/
				break;
			case TIME_SWITCH_NODE:
				LM_DBG("processing time-switch node\n");
				new_ip = run_time_switch( intr ); /*UPDATED&TESTED*/
				break;
			case LANGUAGE_SWITCH_NODE:
				LM_DBG("processing language-switch node\n");
				new_ip = run_language_switch( intr ); /*UPDATED&TESTED*/
				break;
			case LOOKUP_NODE:
				LM_DBG("processing lookup node\n");
				new_ip = run_lookup( intr ); /*UPDATED&TESTED*/
				break;
			case LOCATION_NODE:
				LM_DBG("processing location node\n");
				new_ip = run_location( intr ); /*UPDATED&TESTED*/
				break;
			case REMOVE_LOCATION_NODE:
				LM_DBG("processing remove_location node\n");
				new_ip = run_remove_location( intr ); /*UPDATED&TESTED*/
				break;
			case PROXY_NODE:
				LM_DBG("processing proxy node\n");
				new_ip = run_proxy( intr );/*UPDATED&TESTED*/
				break;
			case REJECT_NODE:
				LM_DBG("processing reject node\n");
				new_ip = run_reject( intr ); /*UPDATED&TESTED*/
				break;
			case REDIRECT_NODE:
				LM_DBG("processing redirect node\n");
				new_ip = run_redirect( intr ); /*UPDATED&TESTED*/
				break;
			case LOG_NODE:
				LM_DBG("processing log node\n");
				new_ip = run_log( intr ); /*UPDATED&TESTED*/
				break;
			case MAIL_NODE:
				LM_DBG("processing mail node\n");
				new_ip = run_mail( intr ); /*UPDATED&TESTED*/
				break;
			case SUB_NODE:
				LM_DBG("processing sub node\n");
				new_ip = run_sub( intr ); /*UPDATED&TESTED*/
				break;
			default:
				LM_ERR("unknown type node (%d)\n",
					NODE_TYPE(intr->ip));
				goto error;
		}

		if (new_ip==CPL_RUNTIME_ERROR) {
			LM_ERR("runtime error\n");
			return SCRIPT_RUN_ERROR;
		} else if (new_ip==CPL_SCRIPT_ERROR) {
			LM_ERR("script error\n");
			return SCRIPT_FORMAT_ERROR;
		} else if (new_ip==DEFAULT_ACTION) {
			LM_DBG("running default action\n");
			return run_default(intr);
		} else if (new_ip==EO_SCRIPT) {
			LM_DBG("script interpretation done!\n");
			return SCRIPT_END;
		} else if (new_ip==CPL_TO_CONTINUE) {
			LM_DBG("done for the moment; waiting after signaling!\n");
			return SCRIPT_TO_BE_CONTINUED;
		}
		/* move to the new instruction */
		intr->ip = new_ip;
	}while(1);

error:
	return SCRIPT_FORMAT_ERROR;
}
Ejemplo n.º 4
0
int
main (int argc, char **argv)
{
  struct option long_options[] =
    {
      { "help",     no_argument,       0,            'h' },
      { "verbose",  no_argument,       &opt.verbose, 1   },
      { "protocol", required_argument, 0,            'p' },
      { "server",   required_argument, 0,            's' },
      { "listen",   required_argument, 0,            'l' },
      { 0, 0, 0, 0 }
    };
  int ret;
  int err;
  int c;

  while (1)
    {
      int opt_idx = 0;
      c = getopt_long (argc, argv, "hvp:s:l:",
		       long_options, &opt_idx);

      if (c == -1)
	break;

      switch (c)
	{
	case 0:
	  if (long_options[opt_idx].flag)
	    break;
	  printf ("option %s", long_options[opt_idx].name);
	  if (optarg)
	    printf (" with arg %s", optarg);
	  printf ("\n");
	  break;

	case 'p':
	  opt.protocol_file = optarg;
	  break;

	case 's':
	  opt.server_spec = optarg;
	  break;

	case 'l':
	  opt.listen_spec = optarg;
	  break;

	case 'v':
	  opt.verbose = 1;
	  break;

	case 'h':
	  print_help (EXIT_SUCCESS);
	  break;

	default:
	  abort ();
	}
    }

  if (opt.verbose)
    {
      printf ("server: %s\n", opt.server_spec ? opt.server_spec : "");
      printf ("listen: %s\n", opt.listen_spec ? opt.listen_spec : "");
      printf ("protocol: %s\n", opt.protocol_file ? opt.protocol_file : "");
    }

  if (! (opt.server_spec && opt.listen_spec))
    print_help (EXIT_FAILURE);

  err = run_proxy ();
  if (err)
    {
      fprintf (stderr, "run_proxy() failed: %s\n", strerror (err));
      ret = EXIT_FAILURE;
    }
  else
    /* ? */
    ret = EXIT_SUCCESS;

  return ret;
}
Ejemplo n.º 5
0
int main(int argc, char *argv[])
{
	struct sigaction sa;
	GIOChannel *dev_io;
	char *device = NULL, *snoop = NULL;
	bdaddr_t bdaddr;
	int fd, dd, opt, detach = 1, dev = -1;

	bacpy(&bdaddr, BDADDR_ANY);

	while ((opt=getopt_long(argc, argv, "d:b:s:nh", main_options, NULL)) != EOF) {
		switch(opt) {
		case 'd':
			device = strdup(optarg);
			break;

		case 'b':
			str2ba(optarg, &bdaddr);
			break;

		case 's':
			snoop = strdup(optarg);
			break;

		case 'n':
			detach = 0;
			break;

		case 'h':
		default:
			usage();
			exit(0);
		}
	}

	argc -= optind;
	argv += optind;
	optind = 0;

	if (argc < 1) {
		usage();
		exit(1);
	}

	if (strlen(argv[0]) > 3 && !strncasecmp(argv[0], "hci", 3)) {
		dev = hci_devid(argv[0]);
		if (dev < 0) {
			perror("Invalid device");
			exit(1);
		}
	} else {
		if (getbdaddrbyname(argv[0], &vdev.bdaddr) < 0)
			exit(1);
	}

	if (detach) {
		if (daemon(0, 0)) {
			perror("Can't start daemon");
			exit(1);
		}
	}

	/* Start logging to syslog and stderr */
	openlog("hciemu", LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_DAEMON);
	syslog(LOG_INFO, "HCI emulation daemon ver %s started", VERSION);

	memset(&sa, 0, sizeof(sa));
	sa.sa_flags   = SA_NOCLDSTOP;
	sa.sa_handler = SIG_IGN;
	sigaction(SIGCHLD, &sa, NULL);
	sigaction(SIGPIPE, &sa, NULL);

	sa.sa_handler = sig_term;
	sigaction(SIGTERM, &sa, NULL);
	sigaction(SIGINT,  &sa, NULL);

	io_init();

	if (!device && dev >= 0)
		device = strdup(GHCI_DEV);

	/* Open and create virtual HCI device */
	if (device) {
		fd = open(device, O_RDWR);
		if (fd < 0) {
			syslog(LOG_ERR, "Can't open device %s: %s (%d)",
						device, strerror(errno), errno);
			free(device);
			exit(1);
		}
		free(device);
	} else {
		fd = open(VHCI_DEV, O_RDWR);
		if (fd < 0) {
			fd = open(VHCI_UDEV, O_RDWR);
			if (fd < 0) {
				syslog(LOG_ERR, "Can't open device %s: %s (%d)",
						VHCI_DEV, strerror(errno), errno);
				exit(1);
			}
		}
	}

	/* Create snoop file */
	if (snoop) {
		dd = create_snoop(snoop);
		if (dd < 0)
			syslog(LOG_ERR, "Can't create snoop file %s: %s (%d)",
						snoop, strerror(errno), errno);
		free(snoop);
	} else
		dd = -1;

	/* Create event loop */
	event_loop = g_main_loop_new(NULL, FALSE);

	if (dev >= 0)
		return run_proxy(fd, dev, &bdaddr);

	/* Device settings */
	vdev.features[0] = 0xff;
	vdev.features[1] = 0xff;
	vdev.features[2] = 0x8f;
	vdev.features[3] = 0xfe;
	vdev.features[4] = 0x9b;
	vdev.features[5] = 0xf9;
	vdev.features[6] = 0x01;
	vdev.features[7] = 0x80;

	memset(vdev.name, 0, sizeof(vdev.name));
	strncpy((char *) vdev.name, "BlueZ (Virtual HCI)",
							sizeof(vdev.name) - 1);

	vdev.dev_class[0] = 0x00;
	vdev.dev_class[1] = 0x00;
	vdev.dev_class[2] = 0x00;

	vdev.inq_mode = 0x00;
	vdev.eir_fec = 0x00;
	memset(vdev.eir_data, 0, sizeof(vdev.eir_data));

	vdev.fd = fd;
	vdev.dd = dd;

	dev_io = g_io_channel_unix_new(fd);
	g_io_add_watch(dev_io, G_IO_IN, io_hci_data, NULL);

	setpriority(PRIO_PROCESS, 0, -19);

	/* Start event processor */
	g_main_loop_run(event_loop);

	close(fd);

	if (dd >= 0)
		close(dd);

	syslog(LOG_INFO, "Exit");

	return 0;
}