コード例 #1
0
/* Do UPnP interface initialization */
int
upnp_ifattach(UPNP_CONTEXT *context, char *ifname, UPNP_DEVICE *device)
{
	UPNP_INTERFACE	*ifp;

	/* Allocate interface space */
	ifp = (UPNP_INTERFACE *)malloc(sizeof(*ifp));
	if (ifp == 0)
		return 0;

	memset(ifp, 0, sizeof(*ifp));

	/* Setup context */
	strncpy(ifp->ifname, ifname, sizeof(ifp->ifname));
	ifp->ifname[sizeof(ifp->ifname)-1] = '\0';
	ifp->http_sock = -1;

	if (get_if_ipaddr(ifp) != 0) {
		free(ifp);
		return 0;
	}

	/* Do prepend */
	ifp->next = context->iflist;
	context->iflist = ifp;

	/* Attache device */
	if (context->ssdp_sock == -1) {
		if (ssdp_init(context) != 0) {
			free(ifp);
			return -1;
		}
	}

	context->focus_ifp = ifp;

	/* Perform per interface protocol initialization */
	if (upnp_http_init(context) != 0) {
		upnp_syslog(LOG_ERR, "upnp_http_init::%s init error!", ifp->ifname);
		return -1;
	}

	if (ssdp_add_multi(context) == -1) {
		upnp_syslog(LOG_ERR, "ssdp_add_multi::%s error!", ifp->ifname);
		return -1;
	}

	/*
	 * Hook device table to each interface.
	 * The init function of each device
	 * intialize the event variables, and send SSDP ALIVE to each
	 * interface
	 */
	if (upnp_device_attach(context, device) == -1) {
		upnp_syslog(LOG_ERR, "upnp_device_attach::%s(%s) error!",
			device->root_device_xml, ifp->ifname);
		return -1;
	}
	return 0;
}
コード例 #2
0
ファイル: main.c プロジェクト: lundman/llink
int main( int argc, char **argv )
{

	// Read any command line arguments from our friend the user.
	arguments(argc, argv);

	// Catch some signals so can exit cleanly

	signal(SIGINT, exit_interrupt);
#ifndef WIN32
	signal(SIGHUP,  exit_interrupt);
	signal(SIGTERM, exit_interrupt);
	signal(SIGPIPE, SIG_IGN);
    if (debug_on)
        setvbuf(stdout, NULL, _IONBF, 0);
#endif

	printf("%s - Jorgen Lundman v%s %s %s\n\n",
		argv ? argv[0] : "llink",
		   VERSION,
		   VERSION_STRING,
#if WITH_DVDREAD
		   "(libdvdread)"
#else

#if HAVE_CLINKC
		   "(libdvdnav, ClinkC)"
#else
		   "(libdvdnav)"
#endif
#endif
		   );


	lion_buffersize(conf_buffersize);
	//lion_buffersize(2352);

	if (lion_init()) {
		printf("Failed to initialize lion/networking\n");
		exit(-1);
	}

	debugf("\n");

	// Read configuration file, if any
	// Warning, calls lion_poll until done.
	conf_init();

	debugf("[main] initialising...\n");

	// Warning, calls lion_poll until done.
	mime_init();

	// Warning, calls lion_poll until done.
	skin_init();

	ssdp_init();

	httpd_init();

	request_init();

	root_init();

	llrar_init();

	visited_init();

	cgicmd_init();

#ifdef EXTERNAL
	external_init();
#endif

	printf("[main] ready!\n");

	// Background?
#ifndef WIN32
	if (!foreground) {
		if (fork()) exit(0);
		setsid();

        if (conf_pidfile) {
            FILE *fd;
            if ((fd = fopen(conf_pidfile, "w"))) {
                fprintf(fd, "%u\r\n", getpid());
                fclose(fd);
            }
        }
	}
#endif

    cupnp_init();


	// Scan for media
	if (conf_xmlscan) {
		signal(SIGINT, SIG_DFL);
		xmlscan_run();
		do_exit = 1;
	}


	query_init();

#ifdef WIN32
	SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);
#endif

	// The main loop
	while ( !do_exit ) {

        // Was 250,0 - we should probably let users control this in
        // conf settings.
		if (lion_poll(0, 1)<0) do_exit=1;

		request_events();

#ifdef EXTERNAL
		external_resume();
#endif

	}

	printf("\n[main] releasing resources...\n");

	query_free();

    cupnp_free();

#ifdef EXTERNAL
	external_free();
#endif

	root_free();

	cgicmd_free();

	visited_free();

	llrar_free();

	request_free();

	httpd_free();

	ssdp_free();

	skin_free();

	mime_free();

	conf_free();

#ifndef WIN32  // Crashed when releasing spawned processes, until i can fix:
	lion_free();
#endif

	debugf("[main] done.\n");

	return 0;

}
コード例 #3
0
/* UPnP module initialization */
int
upnp_init(UPNP_CONTEXT *context)
{
	UPNP_INTERFACE	*ifp = 0;
	UPNP_DEVICE		*device;
	int	i;

	char ifname_list[256];
	
	
	char *name, *p, *next;

	sprintf(xml_InternetGatewayDevice_real,xml_InternetGatewayDevice,nvram_safe_get("DD_BOARD"),nvram_safe_get("router_name"),nvram_safe_get("DD_BOARD"));
	/* Clear flag */
	upnp_flag = 0;

	/* Clean up */
	memset(context, 0, sizeof(*context));

	upnp_osl_read_config(&context->config);
	oslib_ifname_list(ifname_list);

	/* Do context common initialization */
	context->adv_seconds = time(0);
	context->gena_last_check = time(0);
	context->ssdp_sock = -1;

	for (i = 0; (device = upnp_device_table[i]) != 0; i++) {
		(*device->common_init)(context);

		/*
		 * Give a unique uuid to this router,
		 * create same uuid when restart
		 */
		upnp_device_renew_uuid(context, device);
	}

	/* Create the mutlicast receive socket for all interfaces */
	if (ssdp_init(context) != 0)
		goto error_out;

	for (name = ifname_list, p = name;
	     name && name[0];
	     name = next, p = 0) {
		strtok_r(p, " ", &next);

		ifp = upnp_ifinit(context, name);
		if (ifp == 0)
			continue;

		context->focus_ifp = ifp;

		/* Perform per interface protocol initialization */
		if (upnp_http_init(context) != 0) {
			upnp_syslog(LOG_ERR, "upnp_http_init::%s init error!", ifp->ifname);
			goto error_out;
		}

		if (ssdp_add_multi(context) == -1) {
			upnp_syslog(LOG_ERR, "ssdp_init::%s error!", ifp->ifname);
			goto error_out;
		}

		if (upnp_request_init(context) != 0) {
			upnp_syslog(LOG_ERR, "upnp_request_init::init error!");
			goto error_out;
		}

		/*
		 * Hook device table to each interface.
		 * The init function of each device
		 * intialize the event variables, and send SSDP ALIVE to each
		 * interface
		 */
		for (i = 0; (device = upnp_device_table[i]) != 0; i++) {
			if (device->attach_mode == DEVICE_ATTACH_ALWAYS)
				upnp_device_attach(context, device);
		}
	}

	/* No interface found, return directly */
	if (context->iflist == 0) {
		upnp_syslog(LOG_ERR, "No UPnP interface specified, bye!");
		goto error_out;
	}

	upnp_syslog(LOG_INFO, "UPnP daemon is ready to run");
	return 0;

error_out:
	upnp_flag = UPNP_FLAG_SHUTDOWN;
	return -1;
}