Esempio n. 1
0
RESPONSECODE IFDHICCPresence( DWORD Lun ) {

  /* This function returns the status of the card inserted in the 
     reader/slot specified by Lun.  It will return either:

     returns:
     IFD_ICC_PRESENT
     IFD_ICC_NOT_PRESENT
     IFD_COMMUNICATION_ERROR
  */
	if (proxy_init()!=0)
	{
		return IFD_COMMUNICATION_ERROR;
	}

	int bCardPresent = 0;
	bCardPresent = proxy_isCardPresent(Lun);
	if (proxy_getLastError() != 0) {
		return IFD_COMMUNICATION_ERROR;	
	}
	if (bCardPresent)
	{
		return 	IFD_ICC_PRESENT;
	}
	return IFD_ICC_NOT_PRESENT;
}
Esempio n. 2
0
File: main.c Progetto: Zabrane/shim
static void
start_listening(struct event_base *base, struct evdns_base *dns,
		const char *laddr, const char *lport)
{
	struct evutil_addrinfo hints;
	struct evutil_addrinfo *ai = NULL;
	int ret;

	if (!evutil_ascii_strcasecmp(laddr, "any"))
		laddr = NULL;

	memset(&hints, 0, sizeof(hints));
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;
	/* turn NULL hostname into INADDR_ANY, and skip looking up any address
	 * types we don't have an interface to connect to. */
	hints.ai_flags = EVUTIL_AI_PASSIVE|EVUTIL_AI_ADDRCONFIG;

	ret = evutil_getaddrinfo(laddr, lport, &hints, &ai);
	if (ret < 0) {
		log_error("shim: bad listen address: %s",
			  evutil_gai_strerror(ret));
		exit(1);
        }
	
	if (proxy_init(base, dns, ai->ai_addr, ai->ai_addrlen) < 0)
		exit(1);
}
Esempio n. 3
0
RESPONSECODE IFDHControl ( DWORD Lun, PUCHAR TxBuffer, 
			 DWORD TxLength, PUCHAR RxBuffer, 
			 PDWORD RxLength ) {

	LOGI("IFDHControl\n");

	if (proxy_init()!=0)
	{
		return IFD_COMMUNICATION_ERROR;
	}

	*RxLength = 0;
	return IFD_SUCCESS;

  /* This function performs a data exchange with the reader (not the card)
     specified by Lun.  Here XXXX will only be used.
     It is responsible for abstracting functionality such as PIN pads,
     biometrics, LCD panels, etc.  You should follow the MCT, CTBCS 
     specifications for a list of accepted commands to implement.

     TxBuffer - Transmit data
     TxLength - Length of this buffer.
     RxBuffer - Receive data
     RxLength - Length of the received data.  This function will be passed
     the length of the buffer RxBuffer and it must set this to the length
     of the received data.

     Notes:
     RxLength should be zero on error.
  */

}
Esempio n. 4
0
ape_proxy *proxy_init_by_host_port(char *host, char *port, acetables *g_ape)
{
	ape_proxy *proxy;
	apeconfig *conf = g_ape->srv;
	
	while (conf != NULL) {
		if (strcasecmp(conf->section, "Proxy") == 0) {
			char *h, *p, *id;
			
			h = ape_config_get_key(conf, "host");
			p = ape_config_get_key(conf, "port");
			id = ape_config_get_key(conf, "id");

			
			if (h != NULL && p != NULL && id != NULL && strcasecmp(host, h) == 0 && strcasecmp(port, p) == 0) {
				if ((proxy = proxy_init(id, host, atoi(port), g_ape)) != NULL) {

					return proxy;
				}
			}
					
		}
		conf = conf->next;
	}

	return NULL;
}
Esempio n. 5
0
RESPONSECODE IFDHSetCapabilities ( DWORD Lun, DWORD Tag, 
			       DWORD Length, PUCHAR Value ) {

	LOGI("IFDHSetCapabilities\n");
	
	if (proxy_init()!=0)
	{
		return IFD_COMMUNICATION_ERROR;
	}

	return IFD_ERROR_VALUE_READ_ONLY;

  /* This function should set the slot/card capabilities for a particular
     slot/card specified by Lun.  Again, if you have only 1 card slot and don't mind
     loading a new driver for each reader then ignore Lun.

     Tag - the tag for the information needing set

     Length - the length of the returned data
     Value  - the value of the data

     returns:
     
     IFD_SUCCESS
     IFD_ERROR_TAG
     IFD_ERROR_SET_FAILURE
     IFD_ERROR_VALUE_READ_ONLY
  */
  
	
}
Esempio n. 6
0
RESPONSECODE IFDHSetProtocolParameters ( DWORD Lun, DWORD Protocol, 
				   UCHAR Flags, UCHAR PTS1,
				   UCHAR PTS2, UCHAR PTS3) {

	LOGI("IFDHSetProtocolParameters\n");

	if (proxy_init()!=0)
	{
		LOGI("IFDHSetProtocolParameters - return IFD_SUCCESS");		
		return IFD_COMMUNICATION_ERROR;
	}
	
	LOGI("IFDHSetProtocolParameters - return IFD_SUCCESS");
	return IFD_SUCCESS;

  /* This function should set the PTS of a particular card/slot using
     the three PTS parameters sent

     Protocol  - 0 .... 14  T=0 .... T=14
     Flags     - Logical OR of possible values:
     IFD_NEGOTIATE_PTS1 IFD_NEGOTIATE_PTS2 IFD_NEGOTIATE_PTS3
     to determine which PTS values to negotiate.
     PTS1,PTS2,PTS3 - PTS Values.

     returns:

     IFD_SUCCESS
     IFD_ERROR_PTS_FAILURE
     IFD_COMMUNICATION_ERROR
     IFD_PROTOCOL_NOT_SUPPORTED
  */

}
Esempio n. 7
0
RESPONSECODE IFDHCloseChannel ( DWORD Lun ) {
	
	LOGI("IFDHCloseChannel Lun: %lu \n",Lun);
	if (proxy_init()!=0)
	{
		return IFD_COMMUNICATION_ERROR;
	}

	proxy_closeAllChannels(Lun);

	/*	
	if (proxy_getLastError() != 0) {
		return IFD_COMMUNICATION_ERROR;	
	}
	*/
	        
	return IFD_SUCCESS;

  
  /* This function should close the reader communication channel
     for the particular reader.  Prior to closing the communication channel
     the reader should make sure the card is powered down and the terminal
     is also powered down.

     returns:

     IFD_SUCCESS
     IFD_COMMUNICATION_ERROR     
  */
	
}
Esempio n. 8
0
int proxy_LTX_start(egg_module_t *modinfo)
{
	http_owner.module = socks5_owner.module = modinfo;
	modinfo->name = "proxy";
	modinfo->author = "eggdev";
	modinfo->version = "1.0.0";
	modinfo->description = "proxy support (http, socks4, socks5)";
	modinfo->close_func = proxy_close;

	proxy_init();
	return(0);
}
Esempio n. 9
0
int main(int argc, char **argv)
{
    if (argc < 3) {
        LOG("%s FRONT FEED...", argv[0]);
        exit(1);
    }

    char **opts = main_init(argc, argv);
    proxy_t proxy;
    proxy_init(&proxy);
    proxy_init_front(&proxy, *opts);

    void _run () { main_loop(&proxy, opts+1); }
Esempio n. 10
0
RESPONSECODE IFDHGetCapabilities ( DWORD Lun, DWORD Tag, 
				   PDWORD Length, PUCHAR Value ) {

	LOGI("IFDHGetCapabilities\n");
	if (proxy_init()!=0)
	{
		LOGI("IFDHGetCapabilities - return IFD_COMMUNICATION_ERROR");		
		return IFD_COMMUNICATION_ERROR;
	}

	RESPONSECODE ret = IFD_ERROR_TAG;

	switch(Tag) {

	case TAG_IFD_SLOTS_NUMBER:
		*Length = 1;
		*Value = 1;

		LOGI("IFDHGetCapabilities/TAG_IFD_SLOTS_NUMBER - return IFD_SUCCESS");		
		ret = IFD_SUCCESS;
		break;
	case TAG_IFD_SIMULTANEOUS_ACCESS:
		*Length = 1;
		*Value = 255;
		LOGI("IFDHGetCapabilities/TAG_IFD_SIMULTANEOUS_ACCESS - return IFD_SUCCESS");	
		ret = IFD_SUCCESS;
		break;
	default:
		break;
	}
	LOGI("IFDHGetCapabilities - return IFD_ERROR_TAG");
	return ret;
  
  /* This function should get the slot/card capabilities for a particular
     slot/card specified by Lun.  Again, if you have only 1 card slot and don't mind
     loading a new driver for each reader then ignore Lun.

     Tag - the tag for the information requested
         example: TAG_IFD_ATR - return the Atr and it's size (required).
         these tags are defined in ifdhandler.h

     Length - the length of the returned data
     Value  - the value of the data

     returns:
     
     IFD_SUCCESS
     IFD_ERROR_TAG
  */

}
Esempio n. 11
0
RESPONSECODE IFDHCreateChannel ( DWORD Lun, DWORD Channel ) {

	LOGI("IFDHCreateChannel Lun: %lu  Channel: %lu  \n",Lun,Channel);
	if (proxy_init()!=0)
   	{
		return IFD_COMMUNICATION_ERROR;
   	}

   	proxy_readerlist_addchannel(Lun, Channel);
   	return IFD_SUCCESS;

  /* Lun - Logical Unit Number, use this for multiple card slots 
     or multiple readers. 0xXXXXYYYY -  XXXX multiple readers,
     YYYY multiple slots. The resource manager will set these 
     automatically.  By default the resource manager loads a new
     instance of the driver so if your reader does not have more than
     one smartcard slot then ignore the Lun in all the functions.
     Future versions of PC/SC might support loading multiple readers
     through one instance of the driver in which XXXX would be important
     to implement if you want this.
  */
  
  /* Channel - Channel ID.  This is denoted by the following:
     0x000001 - /dev/pcsc/1
     0x000002 - /dev/pcsc/2
     0x000003 - /dev/pcsc/3
     
     USB readers may choose to ignore this parameter and query 
     the bus for the particular reader.
  */

  /* This function is required to open a communications channel to the 
     port listed by Channel.  For example, the first serial reader on COM1 would
     link to /dev/pcsc/1 which would be a sym link to /dev/ttyS0 on some machines
     This is used to help with intermachine independance.
     
     Once the channel is opened the reader must be in a state in which it is possible
     to query IFDHICCPresence() for card status.
 
     returns:

     IFD_SUCCESS
     IFD_COMMUNICATION_ERROR
  */
  
	
}
Esempio n. 12
0
int main(int ac, char *av[])
{
    int c;

    while ((c = getopt(ac, av, "a:b:hRs:v")) != -1)
    {
        switch (c)
        {
        case 'b':
            if (sscanf(optarg, "%zu", &g_ctx.block_sz) != 1)
                usage(av[0]);
            break;
        case 'v':
            g_ctx.verbose = true;
            break;
        case 's':
            if (sscanf(optarg, "%lld", (long long *)&g_ctx.sep.tv_sec) != 1)
                usage(av[0]);
            break;
        case 'a':
            if (parse_addr(optarg, g_ctx.addr, sizeof g_ctx.addr,
                           &g_ctx.port))
                usage(av[0]);
            break;
        case 'h':
        default:
            usage(av[0]);
        }
    }

    /* Initialize libevent and evcoap machinery. */
    con_err_ifm (proxy_init(), "evcoap initialization failed");

    /* Bind configured addresses. */
    con_err_ifm (proxy_bind(), "proxy socket setup failed");

    con_err_ifm (ec_register_fb(g_ctx.coap, proxy_req, NULL),
                 "error registering proxy_req");

    con_err_ifm (proxy_run(), "proxy failed");

    proxy_term();
    return EXIT_SUCCESS;
err:
    proxy_term();
    return EXIT_FAILURE;
}
Esempio n. 13
0
RESPONSECODE IFDHTransmitToICC ( DWORD Lun, SCARD_IO_HEADER SendPci, 
				 PUCHAR TxBuffer, DWORD TxLength, 
				 PUCHAR RxBuffer, PDWORD RxLength, 
				 PSCARD_IO_HEADER RecvPci ) {

	LOGI("IFDHTransmitToICC\n");

	if (proxy_init()!=0)
	{
		return IFD_COMMUNICATION_ERROR;
	}

	int bSuccess = 0;
	bSuccess = proxy_transmit(Lun, TxBuffer, TxLength, RxBuffer, RxLength, RecvPci );
	proxy_getLastError();
	return (bSuccess ? IFD_SUCCESS : IFD_COMMUNICATION_ERROR);
}
Esempio n. 14
0
int main(int argc,char* argv[]){
	int serverfd;
	int sockfd;
	struct sockaddr_in serv;
	struct sockaddr_in server_addr;
    socklen_t length_ptr;
	pthread_t th;
	Signal(SIGPIPE,	SIG_IGN);
    proxy_init();

	sockfd=socket(AF_INET,SOCK_STREAM,0);
	bzero(&serv,sizeof(serv));

	/*set the structure and port defined as argv[1]*/
	serv.sin_family=AF_INET;
	serv.sin_port=htons(atoi(argv[1]));
    serv.sin_addr.s_addr = INADDR_ANY;
//	inet_pton(AF_INET,"",&serv.sin_addr);

	bind(sockfd,(struct sockaddr*)&serv,sizeof(serv));
	if(listen(sockfd,1000)<0){
		perror("listen");
		exit(-1);
	}

	/*continously get the request from the browser 
	 * and build the thread to run each request*/
	while(1){
		serverfd=accept(sockfd,(struct sockaddr*)&server_addr,&length_ptr);
		if(serverfd<=0){
            perror("Error accept");
			break;
        }
		printf("serverfd:%d\n",serverfd);
        int *valp = (int*)malloc(sizeof(int));
        *valp = serverfd;
		pthread_create(&th,NULL,request,valp);
	}
	printf("serverfd :%d\n",serverfd);
	fflush(stdout);
	close(sockfd);
	return 0;
}
Esempio n. 15
0
void proxy_init_from_conf(acetables *g_ape)
{
	apeconfig *conf = g_ape->srv;
	
	while (conf != NULL) {
		if (strcasecmp(conf->section, "Proxy") == 0) {
			char *host, *port, *readonly, *id;
			int iPort;

			host = ape_config_get_key(conf, "host");
			port = ape_config_get_key(conf, "port");
			readonly = ape_config_get_key(conf, "readonly");
			id = ape_config_get_key(conf, "id");
			
			if (host != NULL && port != NULL && readonly != NULL && id != NULL) {
				struct hostent *h;
				
				iPort = atoi(port);
				if ((h = gethostbyname(host)) != NULL) {
					printf("Cache : (%s) : %s\n", host, inet_ntoa(*((struct in_addr *)h->h_addr)));
					proxy_cache_addip(host, inet_ntoa(*((struct in_addr *)h->h_addr)), g_ape);
					
					if (strcasecmp(readonly, "true") == 0) {
						proxy_init(id, host, iPort, g_ape);
					} else {
						;//
					}
				} else {
					printf("[Warn] Unable to resolve : %s\n", host);
				}
			} else {
				printf("[Warn] Proxy : Configuration error\n");
			}
			
		}
		conf = conf->next;
	}
}
Esempio n. 16
0
static void *
stormfs_init(struct fuse_conn_info *conn)
{
  if(conn->capable & FUSE_CAP_ATOMIC_O_TRUNC)
    conn->want |= FUSE_CAP_ATOMIC_O_TRUNC;

  if(conn->capable & FUSE_CAP_BIG_WRITES)
    conn->want |= FUSE_CAP_BIG_WRITES;

  cache_mime_types();
  show_debug_header();

  if(proxy_init(&stormfs) != 0) {
    fprintf(stderr, "%s: unable to initialize service\n", stormfs.progname);
    exit(EXIT_FAILURE);
  }

  if(cache_init() != 0) {
    fprintf(stderr, "%s: unable to initialize cache\n", stormfs.progname);
    exit(EXIT_FAILURE);
  }

  return NULL;
}
Esempio n. 17
0
RESPONSECODE IFDHPowerICC ( DWORD Lun, DWORD Action, 
			    PUCHAR Atr, PDWORD AtrLength ) {

	LOGI("IFDHPowerICC\n");

	if (proxy_init()!=0)
	{
		return IFD_COMMUNICATION_ERROR;
	}

	//check if card present
	int bCardPresent = proxy_isCardPresent(Lun);

	if (proxy_getLastError() != 0) {
		return IFD_COMMUNICATION_ERROR;	
	}			
	
	if (!bCardPresent)
	{
		LOGI("card not present");
		return IFD_COMMUNICATION_ERROR;
 	}
		
	RESPONSECODE ret = IFD_NOT_SUPPORTED;
	char *res;
	int len;

	switch(Action) {

	case IFD_POWER_UP:
		ret = IFD_COMMUNICATION_ERROR;


		*AtrLength = 5;
			memcpy(Atr, "\x3B\x80\x80\x01\x01", 5);
		

		ret = IFD_SUCCESS;
		break;

	default:
		break;
	}
	return ret;



  /* This function controls the power and reset signals of the smartcard reader
     at the particular reader/slot specified by Lun.

     Action - Action to be taken on the card.

     IFD_POWER_UP - Power and reset the card if not done so 
     (store the ATR and return it and it's length).
 
     IFD_POWER_DOWN - Power down the card if not done already 
     (Atr/AtrLength should
     be zero'd)
 
    IFD_RESET - Perform a quick reset on the card.  If the card is not powered
     power up the card.  (Store and return the Atr/Length)

     Atr - Answer to Reset of the card.  The driver is responsible for caching
     this value in case IFDHGetCapabilities is called requesting the ATR and it's
     length.  This should not exceed MAX_ATR_SIZE.

     AtrLength - Length of the Atr.  This should not exceed MAX_ATR_SIZE.

     Notes:

     Memory cards without an ATR should return IFD_SUCCESS on reset
     but the Atr should be zero'd and the length should be zero

     Reset errors should return zero for the AtrLength and return 
     IFD_ERROR_POWER_ACTION.

     returns:

     IFD_SUCCESS
     IFD_ERROR_POWER_ACTION
     IFD_COMMUNICATION_ERROR
     IFD_NOT_SUPPORTED
  */

}
Esempio n. 18
0
static struct context *
core_ctx_create(struct instance *nci)
{
    rstatus_t status;
    struct context *ctx;
    int64_t now;
    uint32_t npool;

    ctx = nc_alloc(sizeof(*ctx));
    if (ctx == NULL) {
        return NULL;
    }

    now = nc_msec_now();
    if (now < 0) {
        nc_free(ctx);
        return NULL;
    }

    ctx->id = ++ctx_id;
    ctx->cf = NULL;
    ctx->stats = NULL;
    ctx->evb = NULL;
    array_null(&ctx->pool);
    ctx->max_timeout = nci->stats_interval;
    ctx->timeout = ctx->max_timeout;
    ctx->next_tick = now + NC_TICK_INTERVAL;

    /* parse and create configuration */
    ctx->cf = conf_create(nci->conf_filename);
    if (ctx->cf == NULL) {
        nc_free(ctx);
        return NULL;
    }

    npool = array_n(&ctx->cf->pool);
    
    /* initialize server pool from configuration */
    if (npool != 0) {
        status = server_pool_init(&ctx->pool, &ctx->cf->pool, ctx);
        if (status != NC_OK) {
            conf_destroy(ctx->cf);
            nc_free(ctx);
            return NULL;
        }
    }

    /* create stats per server pool */
    if (npool != 0) {
        ctx->stats = stats_create(nci->stats_port, nci->stats_addr, nci->stats_interval,
                                  nci->hostname, &ctx->pool);
        if (ctx->stats == NULL) {
            server_pool_deinit(&ctx->pool);
            conf_destroy(ctx->cf);
            nc_free(ctx);
            return NULL;
        }
    }

    /* initialize event handling for client, proxy and server */
    ctx->evb = evbase_create(NC_EVENT_SIZE, &core_core);
    if (ctx->evb == NULL) {
        stats_destroy(ctx->stats);
        server_pool_deinit(&ctx->pool);
        conf_destroy(ctx->cf);
        nc_free(ctx);
        return NULL;
    }

    /* preconnect? servers in server pool */
    if (npool != 0) {
        status = server_pool_preconnect(ctx);
        if (status != NC_OK) {
            server_pool_disconnect(ctx);
            evbase_destroy(ctx->evb);
            stats_destroy(ctx->stats);
            server_pool_deinit(&ctx->pool);
            conf_destroy(ctx->cf);
            nc_free(ctx);
            return NULL;
        }
    }

    /* initialize proxy per server pool */
    if (npool != 0) {
        status = proxy_init(ctx);
        if (status != NC_OK) {
            server_pool_disconnect(ctx);
            evbase_destroy(ctx->evb);
            stats_destroy(ctx->stats);
            server_pool_deinit(&ctx->pool);
            conf_destroy(ctx->cf);
            nc_free(ctx);
            return NULL;
        }
    }

    log_debug(LOG_VVERB, "created ctx %p id %"PRIu32"", ctx, ctx->id);

    return ctx;
}
Esempio n. 19
0
int config_load_servers(char *filename, master_server *master_srv) {
	/* load servers from config file */
	config *conf = NULL;
	
	FILE *file = NULL;
	char line[4048];
	int len, i;
 	
	if ((file = fopen(filename, "r")) == NULL) {
		perror ("ERROR opening config file");
		return -1;
	}
     
     	int is_key, is_value, next;
     	
     	char key[128];
     	char value[2048];
     	
     	int key_len = 0;
     	int value_len = 0;
     	
     	int out_of_scope = 1;
 	int count = 0;
     	
     	char *scope = "none";
     	
	while (fgets(line, sizeof(line), file) != NULL) {  
		if ((len = strlen(line)) > 1) {
			is_key = 1;
			is_value = 0;
			next = 0;
			
			key_len = 0;
			value_len = 0;
			
			for (i = 0; i < len; ++i) {
				switch (line[i]) {
					case '#':
						/* comment */
						next = 1;	
					break;	
					
					case '=':
						if (is_key) {
							key[key_len] = '\0';
							is_key = 0;
							is_value = 1;
						}
					break;
					
					case '\t':
					case '\r':
					case '\n':
					break;
					
					case '{':
						if (key_len == 6) {
							if (strcmp(key, "server") == 0) {
								out_of_scope = 0;
								next = 1;
								
								/* create a new server */
								master_srv->servers[count] = malloc(sizeof(server));
								server *srv = master_srv->servers[count];
		
								/* copy global config */
								srv->config = config_init();
								config_copy (srv->config, master_srv->config);
								
								conf = srv->config;
								++count;
								
								scope = "server";
							}
						}
						else if (key_len == 5) {
							if (strcmp(key, "proxy") == 0) {
								out_of_scope = 0;
								next = 1;
								
								/* create a new proxy */
								conf->proxies[conf->proxy_count] = proxy_init();
								conf->proxy_count++;
								
								scope = "proxy";
							}
						}
					break;
					
					case '}':
						if (!out_of_scope) {
							out_of_scope = 1;
							scope = "none";
						}
					break;
					
					default:
						if (is_key) {
							if (line[i] != ' ') {
								key[key_len] = line[i];
								++key_len;
							}
						}
						else if (is_value) {
							if (line[i] != ' ' || value_len != 0) {
								value[value_len] = line[i];
								++value_len;
							}
						}
					break;
				}
				
				if (next) {
					break;
				}
			}
			
			if (!out_of_scope) {
				value[value_len] = '\0';
			
				if (key_len > 0 && value_len > 0) {
					if (conf != NULL) {
						/* save the value */
						config_save_value (key, value, conf, scope);
				
						if (strcmp(key, "default") == 0) {
							/* found default server */
							if (atoi(value) == 1) {
								master_srv->server_default = count-1;
							}
						}
					}
				}
			}
		}
	}

	fclose (file);

	/* validate */
	if (conf->cache_turn_off_limit == 0 || conf->cache_turn_off_limit > conf->cache_memory_size) {
		/* invalid cache turn-off limit */
		conf->cache_turn_off_limit = conf->cache_memory_size * 0.90;
	}

	master_srv->server_count = count;

	return 0;
}
Esempio n. 20
0
static struct context *
core_ctx_create(struct instance *nci)
{
    rstatus_t status;
    struct context *ctx;

    ctx = nc_alloc(sizeof(*ctx));
    if (ctx == NULL) {
        return NULL;
    }
    ctx->id = ++ctx_id;
    ctx->cf = NULL;
    ctx->stats = NULL;
    ctx->evb = NULL;
    array_null(&ctx->pool);
    ctx->max_timeout = nci->stats_interval;
    ctx->timeout = ctx->max_timeout;
    ctx->max_nfd = 0;
    ctx->max_ncconn = 0;
    ctx->max_nsconn = 0;

    /* parse and create configuration */
    ctx->cf = conf_create(nci->conf_filename);
    if (ctx->cf == NULL) {
        nc_free(ctx);
        return NULL;
    }

    /* initialize server pool from configuration */
    status = server_pool_init(&ctx->pool, &ctx->cf->pool, ctx);
    if (status != NC_OK) {
        conf_destroy(ctx->cf);
        nc_free(ctx);
        return NULL;
    }

    /*
     * Get rlimit and calculate max client connections after we have
     * calculated max server connections
     */
    status = core_calc_connections(ctx);
    if (status != NC_OK) {
        server_pool_deinit(&ctx->pool);
        conf_destroy(ctx->cf);
        nc_free(ctx);
        return NULL;
    }

    /* create stats per server pool */
    ctx->stats = stats_create(nci->stats_port, nci->stats_addr, nci->stats_interval,
                              nci->hostname, &ctx->pool);
    if (ctx->stats == NULL) {
        server_pool_deinit(&ctx->pool);
        conf_destroy(ctx->cf);
        nc_free(ctx);
        return NULL;
    }

    /* initialize event handling for client, proxy and server */
    ctx->evb = event_base_create(EVENT_SIZE, &core_core);
    if (ctx->evb == NULL) {
        stats_destroy(ctx->stats);
        server_pool_deinit(&ctx->pool);
        conf_destroy(ctx->cf);
        nc_free(ctx);
        return NULL;
    }

    /* preconnect? servers in server pool */
    status = server_pool_preconnect(ctx);
    if (status != NC_OK) {
        server_pool_disconnect(ctx);
        event_base_destroy(ctx->evb);
        stats_destroy(ctx->stats);
        server_pool_deinit(&ctx->pool);
        conf_destroy(ctx->cf);
        nc_free(ctx);
        return NULL;
    }

    /* initialize proxy per server pool */
    status = proxy_init(ctx);
    if (status != NC_OK) {
        server_pool_disconnect(ctx);
        event_base_destroy(ctx->evb);
        stats_destroy(ctx->stats);
        server_pool_deinit(&ctx->pool);
        conf_destroy(ctx->cf);
        nc_free(ctx);
        return NULL;
    }

    log_debug(LOG_VVERB, "created ctx %p id %"PRIu32"", ctx, ctx->id);

    return ctx;
}
int main(int argc, char **argv) {
    // Initialize syslog
    setup_syslog();

    // Parse the command line
    char *config_file = NULL;
    int parse_res = parse_cmd_line_args(argc, argv, &config_file);
    if (parse_res) return 1;

    // Parse the config file
    statsite_proxy_config *config = calloc(1, sizeof(statsite_proxy_config));
    int config_res = config_from_filename(config_file, config);
    if (config_res != 0) {
        syslog(LOG_ERR, "Failed to read the configuration file!");
        return 1;
    }

    // Validate the config file
    int validate_res = validate_config(config);
    if (validate_res != 0) {
        syslog(LOG_ERR, "Invalid configuration!");
        return 1;
    }

    // Set the syslog mask
    setlogmask(config->syslog_log_level);

    // Daemonize
    if (config->daemonize) {
        pid_t pid, sid;
        syslog(LOG_INFO, "Daemonizing.");
        pid = fork();

        // Exit if we failed to fork
        if (pid < 0) {
            syslog(LOG_ERR, "Failed to fork() daemon!");
            return 1;
        }

        // Parent process returns
        if (pid) return 0;

        // Create a new session
        sid = setsid();
        if (sid < 0) {
            syslog(LOG_ERR, "Failed to set daemon SID!");
            return 1;
        }

        int write_pidfile_res = write_pidfile(config->pid_file, sid);
        if (write_pidfile_res) {
            syslog(LOG_ERR, "Failed to write pidfile. Terminating.");
            return 1;
        }

        close(STDIN_FILENO);
        close(STDOUT_FILENO);
        close(STDERR_FILENO);
    }

    // Log that we are starting up
    syslog(LOG_INFO, "Starting statsite-proxy.");
    syslog(LOG_INFO, "Loaded Servers config: %s", config->servers);

    // Initialize proxy
    proxy *proxy = NULL;
    int proxy_res = proxy_init(&proxy, config->servers);

    if (proxy_res != 0) {
    	syslog(LOG_ERR, "Failed to initialize proxy!");
    	return 1;
    }

    // Initialize the networking
    statsite_proxy_networking *netconf = NULL;
    int net_res = init_networking(config, &netconf, proxy);
    if (net_res != 0) {
        syslog(LOG_ERR, "Failed to initialize networking!");
        return 1;
    }

    // Start the network workers
    pthread_t thread;
    pthread_create(&thread, NULL, (void*(*)(void*))start_networking_worker, netconf);

    /**
     * Loop forever, until we get a signal that
     * indicates we should shutdown.
     */

    signal(SIGPIPE, SIG_IGN);       // Ignore SIG_IGN
    signal(SIGHUP, SIG_IGN);        // Ignore SIG_IGN
    signal(SIGINT, signal_handler);
    signal(SIGTERM, signal_handler);
    while (SHOULD_RUN) {
        sleep(1);
    }

    // Begin the shutdown/cleanup
    shutdown_networking(netconf);

    // If daemonized, remove the pid file

    if (config->daemonize && unlink(config->pid_file)) {
        syslog(LOG_ERR, "Failed to delete pid file!");
    }

    // Free our memory
    proxy_destroy(proxy);
    free(config);



    // Done
    return 0;
}
Esempio n. 22
0
int win32_net_http_open(char* url, struct httpdata *hd)
{
	mpg123_string purl, host, port, path;
	mpg123_string request, response, request_url;
	mpg123_string httpauth1;
	ws.local_socket = SOCKET_ERROR;
	int oom  = 0;
	int relocate, numrelocs = 0;
	int got_location = FALSE;
	/*
		workaround for http://www.global24music.com/rautemusik/files/extreme/isdn.pls
		this site's apache gives me a relocation to the same place when I give the port in Host request field
		for the record: Apache/2.0.51 (Fedora)
	*/
	int try_without_port = 0;
	mpg123_init_string(&purl);
	mpg123_init_string(&host);
	mpg123_init_string(&port);
	mpg123_init_string(&path);
	mpg123_init_string(&request);
	mpg123_init_string(&response);
	mpg123_init_string(&request_url);
	mpg123_init_string(&httpauth1);

	/* Get initial info for proxy server. Once. */
	if(hd->proxystate == PROXY_UNKNOWN && !proxy_init(hd)) goto exit;

	if(!translate_url(url, &purl)){ oom=1; goto exit; }

	/* Don't confuse the different auth strings... */
	if(!split_url(&purl, &httpauth1, NULL, NULL, NULL) ){ oom=1; goto exit; }

	/* "GET http://"		11
	 * " HTTP/1.0\r\nUser-Agent: <PACKAGE_NAME>/<PACKAGE_VERSION>\r\n"
	 * 				26 + PACKAGE_NAME + PACKAGE_VERSION
	 * accept header            + accept_length()
	 * "Authorization: Basic \r\n"	23
	 * "\r\n"			 2
	 * ... plus the other predefined header lines
	 */
	/* Just use this estimate as first guess to reduce malloc calls in string library. */
	{
		size_t length_estimate = 62 + strlen(PACKAGE_NAME) + strlen(PACKAGE_VERSION) 
		                       + accept_length() + strlen(CONN_HEAD) + strlen(icy_yes) + purl.fill;
		if(    !mpg123_grow_string(&request, length_estimate)
		    || !mpg123_grow_string(&response,4096) )
		{
			oom=1; goto exit;
		}
	}

	do
	{
		/* Storing the request url, with http:// prepended if needed. */
		/* used to be url here... seemed wrong to me (when loop advanced...) */
		if(strncasecmp(purl.p, "http://", 7) != 0) mpg123_set_string(&request_url, "http://");
		else mpg123_set_string(&request_url, "");

		mpg123_add_string(&request_url, purl.p);

		if (hd->proxystate >= PROXY_HOST)
		{
			/* We will connect to proxy, full URL goes into the request. */
			if(    !mpg123_copy_string(&hd->proxyhost, &host)
			    || !mpg123_copy_string(&hd->proxyport, &port)
			    || !mpg123_set_string(&request, "GET ")
			    || !mpg123_add_string(&request, request_url.p) )
			{
				oom=1; goto exit;
			}
		}
		else
		{
			/* We will connect to the host from the URL and only the path goes into the request. */
			if(!split_url(&purl, NULL, &host, &port, &path)){ oom=1; goto exit; }
			if(    !mpg123_set_string(&request, "GET ")
			    || !mpg123_add_string(&request, path.p) )
			{
				oom=1; goto exit;
			}
		}

		if(!fill_request(&request, &host, &port, &httpauth1, &try_without_port)){ oom=1; goto exit; }

		httpauth1.fill = 0; /* We use the auth data from the URL only once. */
		debug2("attempting to open_connection to %s:%s", host.p, port.p);
		win32_net_open_connection(&host, &port);
		if(ws.local_socket == SOCKET_ERROR)
		{
			error1("Unable to establish connection to %s", host.fill ? host.p : "");
			goto exit;
		}
		debug("win32_net_open_connection succeed");
#define http_failure win32_net_close(ws.local_socket); ws.local_socket=SOCKET_ERROR; goto exit;
		
		if(param.verbose > 2) fprintf(stderr, "HTTP request:\n%s\n",request.p);
		if(!win32_net_writestring(ws.local_socket, &request)){ http_failure; }
		debug("Skipping fdopen for WSA sockets");
		relocate = FALSE;
		/* Arbitrary length limit here... */
#define safe_readstring \
		win32_net_readstring(&response, SIZE_MAX/16, NULL); \
		if(response.fill > SIZE_MAX/16) /* > because of appended zero. */ \
		{ \
			error("HTTP response line exceeds max. length"); \
			http_failure; \
		} \
		else if(response.fill == 0) \
		{ \
			error("readstring failed"); \
			http_failure; \
		} \
		if(param.verbose > 2) fprintf(stderr, "HTTP in: %s", response.p);
		safe_readstring;

		{
			char *sptr;
			if((sptr = strchr(response.p, ' ')))
			{
				if(response.fill > sptr-response.p+2)
				switch (sptr[1])
				{
					case '3':
						relocate = TRUE;
					case '2':
						break;
					default:
						fprintf (stderr, "HTTP request failed: %s", sptr+1); /* '\n' is included */
						http_failure;
				}
				else{ error("Too short response,"); http_failure; }
			}
		}

		/* If we are relocated, we need to look out for a Location header. */
		got_location = FALSE;

		do
		{
			safe_readstring; /* Think about that: Should we really error out when we get nothing? Could be that the server forgot the trailing empty line... */
			if (!strncasecmp(response.p, "Location: ", 10))
			{ /* It is a redirection! */
				if(!win32_net_resolve_redirect(&response, &request_url, &purl)){ oom=1, http_failure; }

				if(!strcmp(purl.p, request_url.p))
				{
					warning("relocated to very same place! trying request again without host port");
					try_without_port = 1;
				}
				got_location = TRUE;
			}
			else
			{ /* We got a header line (or the closing empty line). */
				char *tmp;
				debug1("searching for header values... %s", response.p);
				/* Not sure if I want to bail out on error here. */
				/* Also: What text encoding are these strings in? Doesn't need to be plain ASCII... */
				get_header_string(&response, "content-type", &hd->content_type);
				get_header_string(&response, "icy-name",     &hd->icy_name);
				get_header_string(&response, "icy-url",      &hd->icy_url);

				/* watch out for icy-metaint */
				if((tmp = get_header_val("icy-metaint", &response)))
				{
					hd->icy_interval = (off_t) atol(tmp); /* atoll ? */
					debug1("got icy-metaint %li", (long int)hd->icy_interval);
				}
			}
		} while(response.p[0] != '\r' && response.p[0] != '\n');
	} while(relocate && got_location && purl.fill && numrelocs++ < HTTP_MAX_RELOCATIONS);
	if(relocate)
	{
		if(!got_location)
		error("Server meant to redirect but failed to provide a location!");
		else
		error1("Too many HTTP relocations (%i).", numrelocs);

		http_failure;
	}

exit: /* The end as well as the exception handling point... */
	if(oom) error("Apparently, I ran out of memory or had some bad input data...");

	mpg123_free_string(&purl);
	mpg123_free_string(&host);
	mpg123_free_string(&port);
	mpg123_free_string(&path);
	mpg123_free_string(&request);
	mpg123_free_string(&response);
	mpg123_free_string(&request_url);
	mpg123_free_string(&httpauth1);
	if (ws.local_socket == SOCKET_ERROR || oom)
	return -1;
	else
	return 1;
}
Esempio n. 23
0
static struct context *
core_ctx_create(struct instance *nci)
{
    rstatus_t status;
    struct context *ctx;
    struct conn *sentinel_conn;

    ctx = nc_alloc(sizeof(*ctx));
    if (ctx == NULL) {
        return NULL;
    }
    ctx->id = ++ctx_id;
    ctx->cf = NULL;
    ctx->stats = NULL;
    array_null(&ctx->pool);
    ctx->ep = -1;
    ctx->nevent = EVENT_SIZE_HINT;
    ctx->max_timeout = nci->stats_interval;
    ctx->timeout = ctx->max_timeout;
    ctx->event = NULL;
    ctx->server_reconnect_interval = nci->server_reconnect_interval;
    ctx->whitelist = nci->whitelist;

    /* parse and create configuration */
    ctx->cf = conf_create(nci->conf_filename);
    if (ctx->cf == NULL) {
        nc_free(ctx);
        return NULL;
    }

    /* initialize server pool from configuration */
    status = server_pool_init(&ctx->pool, &ctx->cf->pool, ctx);
    if (status != NC_OK) {
        conf_destroy(ctx->cf);
        nc_free(ctx);
        return NULL;
    }

    /* initialize sentinel server */
    ctx->sentinel = sentinel_init(nci->sentinel_port, nci->sentinel_addr);
    if (ctx->sentinel == NULL) {
        server_pool_deinit(&ctx->pool);
        conf_destroy(ctx->cf);
        nc_free(ctx);
        return NULL;
    }

    /* create stats per server pool */
    ctx->stats = stats_create(nci->stats_port, nci->stats_addr, nci->stats_interval,
                              nci->hostname, &ctx->pool);
    if (ctx->stats == NULL) {
        sentinel_deinit(ctx->sentinel);
        server_pool_deinit(&ctx->pool);
        conf_destroy(ctx->cf);
        nc_free(ctx);
        return NULL;
    }

    /* initialize event handling for client, proxy and server */
    status = event_init(ctx, EVENT_SIZE_HINT);
    if (status != NC_OK) {
        stats_destroy(ctx->stats);
        sentinel_deinit(ctx->sentinel);
        server_pool_deinit(&ctx->pool);
        conf_destroy(ctx->cf);
        nc_free(ctx);
        return NULL;
    }

    /* preconnect? servers in server pool */
    status = server_pool_preconnect(ctx);
    if (status != NC_OK) {
        server_pool_disconnect(ctx);
        event_deinit(ctx);
        stats_destroy(ctx->stats);
        sentinel_deinit(ctx->sentinel);
        server_pool_deinit(&ctx->pool);
        conf_destroy(ctx->cf);
        nc_free(ctx);
        return NULL;
    }

    /* initialize sentinel server conn */
    sentinel_conn = sentinel_connect(ctx);
    if (sentinel_conn == NULL) {
        server_pool_disconnect(ctx);
        event_deinit(ctx);
        stats_destroy(ctx->stats);
        sentinel_deinit(ctx->sentinel);
        server_pool_deinit(&ctx->pool);
        conf_destroy(ctx->cf);
        nc_free(ctx);
    }

    /* initialize proxy per server pool */
    status = proxy_init(ctx);
    if (status != NC_OK) {
        sentinel_conn->close(ctx, sentinel_conn);
        server_pool_disconnect(ctx);
        event_deinit(ctx);
        stats_destroy(ctx->stats);
        sentinel_deinit(ctx->sentinel);
        server_pool_deinit(&ctx->pool);
        conf_destroy(ctx->cf);
        nc_free(ctx);
        return NULL;
    }

    log_debug(LOG_VVERB, "created ctx %p id %"PRIu32"", ctx, ctx->id);

    return ctx;
}
Esempio n. 24
0
static struct context *
core_ctx_create(struct instance *nci)
{
	rstatus_t status;
	struct context *ctx;

	srand((unsigned) time(NULL));

	ctx = dn_alloc(sizeof(*ctx));
	if (ctx == NULL) {
		return NULL;
	}
	ctx->id = ++ctx_id;
	ctx->cf = NULL;
	ctx->stats = NULL;
	ctx->evb = NULL;
	array_null(&ctx->pool);
	ctx->max_timeout = nci->stats_interval;
	ctx->timeout = ctx->max_timeout;
	ctx->dyn_state = INIT;

	/* parse and create configuration */
	ctx->cf = conf_create(nci->conf_filename);
	if (ctx->cf == NULL) {
		loga("Failed to create context!!!");
		dn_free(ctx);
		return NULL;
	}

	/* initialize server pool from configuration */
	status = server_pool_init(&ctx->pool, &ctx->cf->pool, ctx);
	if (status != DN_OK) {
		loga("Failed to initialize server pool!!!");
		conf_destroy(ctx->cf);
		dn_free(ctx);
		return NULL;
	}


	/* crypto init */
    status = crypto_init(ctx);
    if (status != DN_OK) {
   	loga("Failed to initialize crypto!!!");
    	dn_free(ctx);
    	return NULL;
    }


	/* create stats per server pool */
	ctx->stats = stats_create(nci->stats_port, nci->stats_addr, nci->stats_interval,
			                  nci->hostname, &ctx->pool, ctx);
	if (ctx->stats == NULL) {
		loga("Failed to create stats!!!");
		crypto_deinit();
		server_pool_deinit(&ctx->pool);
		conf_destroy(ctx->cf);
		dn_free(ctx);
		return NULL;
	}

	/* initialize event handling for client, proxy and server */
	ctx->evb = event_base_create(EVENT_SIZE, &core_core);
	if (ctx->evb == NULL) {
		loga("Failed to create socket event handling!!!");
		crypto_deinit();
		stats_destroy(ctx->stats);
		server_pool_deinit(&ctx->pool);
		conf_destroy(ctx->cf);
		dn_free(ctx);
		return NULL;
	}

	/* preconnect? servers in server pool */
	status = server_pool_preconnect(ctx);
	if (status != DN_OK) {
		loga("Failed to preconnect for server pool!!!");
		crypto_deinit();
		server_pool_disconnect(ctx);
		event_base_destroy(ctx->evb);
		stats_destroy(ctx->stats);
		server_pool_deinit(&ctx->pool);
		conf_destroy(ctx->cf);
		dn_free(ctx);
		return NULL;
	}

	/* initialize proxy per server pool */
	status = proxy_init(ctx);
	if (status != DN_OK) {
		loga("Failed to initialize proxy!!!");
		crypto_deinit();
		server_pool_disconnect(ctx);
		event_base_destroy(ctx->evb);
		stats_destroy(ctx->stats);
		server_pool_deinit(&ctx->pool);
		conf_destroy(ctx->cf);
		dn_free(ctx);
		return NULL;
	}

	/* initialize dnode listener per server pool */
	status = dnode_init(ctx);
	if (status != DN_OK) {
		loga("Failed to initialize dnode!!!");
		crypto_deinit();
		server_pool_disconnect(ctx);
		event_base_destroy(ctx->evb);
		stats_destroy(ctx->stats);
		server_pool_deinit(&ctx->pool);
		conf_destroy(ctx->cf);
		dn_free(ctx);
		return NULL;
	}

	ctx->dyn_state = JOINING;  //TODOS: change this to JOINING

	/* initialize peers */
	status = dnode_peer_init(&ctx->pool, ctx);
	if (status != DN_OK) {
		loga("Failed to initialize dnode peers!!!");
		crypto_deinit();
		dnode_deinit(ctx);
		server_pool_disconnect(ctx);
		event_base_destroy(ctx->evb);
		stats_destroy(ctx->stats);
		server_pool_deinit(&ctx->pool);
		conf_destroy(ctx->cf);
		dn_free(ctx);
		return NULL;
	}

	core_debug(ctx);

	/* preconntect peers - probably start gossip here */
	status = dnode_peer_pool_preconnect(ctx);
	if (status != DN_OK) {
		loga("Failed to preconnect dnode peers!!!");
		crypto_deinit();
		dnode_peer_deinit(&ctx->pool);
		dnode_deinit(ctx);
		server_pool_disconnect(ctx);
		event_base_destroy(ctx->evb);
		stats_destroy(ctx->stats);
		server_pool_deinit(&ctx->pool);
		conf_destroy(ctx->cf);
		dn_free(ctx);
		return NULL;
	}

	//init ring msg queue
	CBUF_Init(C2G_InQ);
	CBUF_Init(C2G_OutQ);

	//init stats msg queue
	CBUF_Init(C2S_InQ);
	CBUF_Init(C2S_OutQ);

	gossip_pool_init(ctx);

	log_debug(LOG_VVERB, "created ctx %p id %"PRIu32"", ctx, ctx->id);

	return ctx;
}
Esempio n. 25
0
void VBoxNetLwipNAT::onLwipTcpIpInit(void* arg)
{
    AssertPtrReturnVoid(arg);
    VBoxNetLwipNAT *pNat = static_cast<VBoxNetLwipNAT *>(arg);

    HRESULT hrc = com::Initialize();
    Assert(!FAILED(hrc));

    proxy_arp_hook = pxremap_proxy_arp;
    proxy_ip4_divert_hook = pxremap_ip4_divert;

    proxy_na_hook = pxremap_proxy_na;
    proxy_ip6_divert_hook = pxremap_ip6_divert;

    /* lwip thread */
    RTNETADDRIPV4 network;
    RTNETADDRIPV4 address = g_pLwipNat->getIpv4Address();
    RTNETADDRIPV4 netmask = g_pLwipNat->getIpv4Netmask();
    network.u = address.u & netmask.u;

    ip_addr LwipIpAddr, LwipIpNetMask, LwipIpNetwork;

    memcpy(&LwipIpAddr, &address, sizeof(ip_addr));
    memcpy(&LwipIpNetMask, &netmask, sizeof(ip_addr));
    memcpy(&LwipIpNetwork, &network, sizeof(ip_addr));

    netif *pNetif = netif_add(&g_pLwipNat->m_LwipNetIf /* Lwip Interface */,
                              &LwipIpAddr /* IP address*/,
                              &LwipIpNetMask /* Network mask */,
                              &LwipIpAddr /* gateway address, @todo: is self IP acceptable? */,
                              g_pLwipNat /* state */,
                              VBoxNetLwipNAT::netifInit /* netif_init_fn */,
                              tcpip_input /* netif_input_fn */);

    AssertPtrReturnVoid(pNetif);

    LogRel(("netif %c%c%d: mac %RTmac\n",
            pNetif->name[0], pNetif->name[1], pNetif->num,
            pNetif->hwaddr));
    LogRel(("netif %c%c%d: inet %RTnaipv4 netmask %RTnaipv4\n",
            pNetif->name[0], pNetif->name[1], pNetif->num,
            pNetif->ip_addr, pNetif->netmask));
    for (int i = 0; i < LWIP_IPV6_NUM_ADDRESSES; ++i) {
        if (!ip6_addr_isinvalid(netif_ip6_addr_state(pNetif, i))) {
            LogRel(("netif %c%c%d: inet6 %RTnaipv6\n",
                    pNetif->name[0], pNetif->name[1], pNetif->num,
                    netif_ip6_addr(pNetif, i)));
        }
    }

    netif_set_up(pNetif);
    netif_set_link_up(pNetif);

    if (pNat->m_ProxyOptions.ipv6_enabled) {
        /*
         * XXX: lwIP currently only ever calls mld6_joingroup() in
         * nd6_tmr() for fresh tentative addresses, which is a wrong place
         * to do it - but I'm not keen on fixing this properly for now
         * (with correct handling of interface up and down transitions,
         * etc).  So stick it here as a kludge.
         */
        for (int i = 0; i <= 1; ++i) {
            ip6_addr_t *paddr = netif_ip6_addr(pNetif, i);

            ip6_addr_t solicited_node_multicast_address;
            ip6_addr_set_solicitednode(&solicited_node_multicast_address,
                                       paddr->addr[3]);
            mld6_joingroup(paddr, &solicited_node_multicast_address);
        }

        /*
         * XXX: We must join the solicited-node multicast for the
         * addresses we do IPv6 NA-proxy for.  We map IPv6 loopback to
         * proxy address + 1.  We only need the low 24 bits, and those are
         * fixed.
         */
        {
            ip6_addr_t solicited_node_multicast_address;

            ip6_addr_set_solicitednode(&solicited_node_multicast_address,
                                       /* last 24 bits of the address */
                                       PP_HTONL(0x00000002));
            mld6_netif_joingroup(pNetif,  &solicited_node_multicast_address);
        }
    }

    proxy_init(&g_pLwipNat->m_LwipNetIf, &g_pLwipNat->m_ProxyOptions);

    natServiceProcessRegisteredPf(g_pLwipNat->m_vecPortForwardRule4);
    natServiceProcessRegisteredPf(g_pLwipNat->m_vecPortForwardRule6);
}
Esempio n. 26
0
/********************************************************
 *   'Here be Dragons'...art, beauty, fun, & magic.     *
 ********************************************************/
gboolean program_init(int argc, char **argv){
	if((ipc_init_check(argc, argv))){
		g_fprintf(stdout, "%s is already running.  Be sure to check your desktop's notification tray for %s's icon.\n", GETTEXT_PACKAGE, GETTEXT_PACKAGE);
		ipc_deinit();
		return FALSE;
	}
	
	datetime_locale_init();
	
	GOptionContext *option_context=g_option_context_new(GETTEXT_PACKAGE);
	GOptionEntry option_entries[]={
					{
						G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY,
						&remaining_argv,
						"Special option that collects any remaining arguments for us"
					},
					{ NULL }
	};
	
	g_option_context_add_main_entries(option_context, option_entries, NULL);
	
	program=gnome_program_init(
					GETTEXT_PACKAGE, PACKAGE_RELEASE_VERSION,
					LIBGNOME_MODULE,
					argc, argv,
					GNOME_PARAM_GOPTION_CONTEXT, option_context,
					GNOME_PARAM_NONE
	);
	
	if(remaining_argv)
		remaining_argc=g_strv_length(remaining_argv)-1;
	
	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
	textdomain(GETTEXT_PACKAGE);
	
	g_set_application_name(GETTEXT_PACKAGE);
	gtk_window_set_default_icon_name(GETTEXT_PACKAGE);
	
	if(!g_thread_supported()) g_thread_init(NULL);
	
	gtk_init(&argc, &argv);
	
	cache_init();
	
	debug_init();
	
	gconfig_start();
	
	notifing=notify_init(GETTEXT_PACKAGE);
	
	proxy_init();
	online_services_init();
	
	www_init();
	images_init();
	groups_init();
	
	main_window_create();
	
	return TRUE;
}/*program_init();*/