int GPIORelaisController::openMap()
{
	int res = 1;
	info_printf("GPIORelaisController::openMap\n");

	gpioregs = (char *) mmap_device_memory( 0, gpioPortLen, PROT_READ|PROT_WRITE|PROT_NOCACHE, 0, gpioPortBase );
	if ( gpioregs == MAP_FAILED ) {
		info_printf( "mmap_device_memory for physical address %X  and length %X failed\n", gpioPortBase, gpioPortLen );
		res = 0;
	}
		
/*	memfd = open("/dev/mem", O_RDWR|O_SYNC);
	if( memfd == NULL ) {
		info_printf("Error while opening the mem file.\n");
		gpioregs = MAP_FAILED;
		res = 0;
	}
	if (res  == 0 ) { 
		gpioregs = (char *)mmap(0, mapLen, PROT_READ|PROT_WRITE, MAP_SHARED, memfd, mapBase);
		if (gpioregs == MAP_FAILED)  {
			info_printf("Error while mmap.\n");
			res = 0;
		}
//		info_printf("gpioregs mapped\n");
	}
//	usleep(500000);

 */
	return res;
}
Exemple #2
0
int main(int argc, const char * const *argv)
{
	// if VALGRIND testing is enabled, we have to call ourselves with valgrind checking
	const char *valgrind = getenv("VALGRIND_TESTS");

	if (!valgrind || !*valgrind || !strcmp(valgrind, "0")) {
		// fallthrough
	}
	else if (!strcmp(valgrind, "1")) {
		char cmd[strlen(argv[0]) + 256];

		snprintf(cmd, sizeof(cmd), "VALGRIND_TESTS=\"\" valgrind --error-exitcode=301 --leak-check=yes --show-reachable=yes --track-origins=yes %s", argv[0]);
		return system(cmd) != 0;
	} else {
		char cmd[strlen(valgrind) + strlen(argv[0]) + 32];

		snprintf(cmd, sizeof(cmd), "VALGRIND_TESTS="" %s %s", valgrind, argv[0]);
		return system(cmd) != 0;
	}

	init(argc, argv); // allows us to test with options (e.g. with --debug)

	srand((unsigned int) time(NULL));

	// testing basic library functionality
	test_buffer();
	test_buffer_printf();
	test_utils();
	test_strcasecmp_ascii();
	test_vector();
	test_stringmap();

	if (failed) {
		info_printf("ERROR: %d out of %d basic tests failed\n", failed, ok + failed);
		info_printf("This may completely break Mget functionality !!!\n");
		return 1;
	}

	test_iri_parse();
	test_iri_relative_to_absolute();
	test_iri_compare();
	test_parser();

	test_cookies();
	test_hsts();
	test_parse_challenge();

	selftest_options() ? failed++ : ok++;

	deinit(); // free resources allocated by init()

	if (failed) {
		info_printf("Summary: %d out of %d tests failed\n", failed, ok + failed);
		return 1;
	}

	info_printf("Summary: All %d tests passed\n", ok + failed);
	return 0;
}
Exemple #3
0
static void _test_buffer(mget_buffer_t *buf, const char *name)
{
	char test[256];
	int it;

	for (it = 0; it < (int)sizeof(test)-1; it++) {
		test[it] = 'a' + it % 26;
		test[it + 1] = 0;

		mget_buffer_strcpy(buf, test);
		mget_buffer_strcat(buf, test);

		if (!strncmp(buf->data, test, it + 1) && !strncmp(buf->data + it + 1, test, it + 1)) {
			ok++;
		} else {
			failed++;
			info_printf("test_buffer.1 '%s': [%d] got %s (expected %s%s)\n", name, it, buf->data, test, test);
		}

		mget_buffer_memcpy(buf, test, it + 1);
		mget_buffer_memcat(buf, test, it + 1);

		if (!strncmp(buf->data, test, it + 1) && !strncmp(buf->data + it + 1, test, it + 1)) {
			ok++;
		} else {
			failed++;
			info_printf("test_buffer.2 '%s': [%d] got %s (expected %s%s)\n", name, it, buf->data, test, test);
		}

		mget_buffer_printf(buf, "%s%s", test, test);

		if (!strncmp(buf->data, test, it + 1) && !strncmp(buf->data + it + 1, test, it + 1)) {
			ok++;
		} else {
			failed++;
			info_printf("test_buffer.3 '%s': [%d] got %s (expected %s%s)\n", name, it, buf->data, test, test);
		}

		mget_buffer_printf(buf, "%s", test);
		mget_buffer_printf_append(buf, "%s", test);

		if (!strncmp(buf->data, test, it + 1) && !strncmp(buf->data + it + 1, test, it + 1)) {
			ok++;
		} else {
			failed++;
			info_printf("test_buffer.4 '%s': [%d] got %s (expected %s%s)\n", name, it, buf->data, test, test);
		}
	}
}
Exemple #4
0
// Callback function, called from CSS parser for each @charset found.
static void css_parse_encoding(void *context, const char *encoding, size_t len)
{
    struct css_context *ctx = context;

    // take only the first @charset rule
    if (!ctx->encoding_allocated && mget_strncasecmp(ctx->encoding, encoding, len)) {
        if (ctx->encoding)
            info_printf("Encoding changed from '%s' to '%.*s'\n", ctx->encoding, (int)len, encoding);
        else
            info_printf("Encoding set to '%.*s'\n", (int)len, encoding);

        ctx->encoding = strndup(encoding, len);
        ctx->encoding_allocated = 1;
    }
}
Exemple #5
0
NonPosixTimer::NonPosixTimer()
{
	info_printf("NonPosixTimer creator\n");
	stopCond = 0;
	step = 0;
	memset(timerCnt,0,sizeof(timerCnt));
}
Exemple #6
0
void AppInit_TCPIP (void)
{
	#if EMAC_CFG_MAC_ADDR_SEL == EMAC_MAC_ADDR_SEL_CFG
	NetIF_MAC_Addr[0] = 0x00;
	NetIF_MAC_Addr[1] = 0x50;
	NetIF_MAC_Addr[2] = 0xC2;
	NetIF_MAC_Addr[3] = 0x25;
	NetIF_MAC_Addr[4] = 0x60;
	NetIF_MAC_Addr[5] = 0x01;
	#endif

	#if uC_TTCP_MODULE > 0
	BSP_USART_Init(TTCP_COMM_SEL, 38400);                           
	#endif

	err = Net_Init();                                                  

	ip      = NetASCII_Str_to_IP((CPU_CHAR *) ownIPAddress,  &err);
	msk     = NetASCII_Str_to_IP((CPU_CHAR *)"255.255.255.0", &err);
	gateway = NetASCII_Str_to_IP((CPU_CHAR *)"192.168.1.1",   &err);

	err     = NetIP_CfgAddrThisHost(ip, msk);
	err     = NetIP_CfgAddrDfltGateway(gateway);

	#if uC_TTCP_MODULE > 0
	TTCP_Init();                                               
	#endif
	info_printf("tcp/ip network initialized ...\n");
}
Exemple #7
0
int  main (void)
{
#if (OS_TASK_NAME_SIZE > 7) && (OS_TASK_STAT_EN > 0)
    CPU_INT08U  err;
#endif


    CPU_IntDis();                                                       /* Disable all interrupts until we are ready to accept them */
    OSInit();  	
	BSP_Init();          
	
	init_err_printf();                                           

    OSTaskCreateExt(AppTaskStart,                                      
                    (void *)0,
                    (OS_STK *)&AppTaskStartStk[APP_TASK_START_STK_SIZE - 1],
                    APP_TASK_START_PRIO,
                    APP_TASK_START_PRIO,
                    (OS_STK *)&AppTaskStartStk[0],
                    APP_TASK_START_STK_SIZE,
                    (void *)0,
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

#if (OS_TASK_NAME_SIZE > 7) && (OS_TASK_STAT_EN > 0)
    OSTaskNameSet(APP_TASK_START_PRIO, (CPU_CHAR *)"Startup", &err);
#endif

    OSStart();     
	                                                   
	info_printf("EVK1100_Interface to cyclone-III rustlight fpga starting\n");

    return (0);                                                        
}
Exemple #8
0
static void test_hsts(void)
{
	static const struct hsts_db_data {
		const char *
			host;
		int
			port;
		const char *
			hsts_params;
	} hsts_db_data[] = {
		{ "www.example.com", 443, "max-age=14400; includeSubDomains" },
		{ "www.example2.com", 443, "max-age=14400" },
		{ "www.example2.com", 443, "max-age=0" }, // this removes the previous entry
	};
	static const struct hsts_data {
		const char *
			host;
		int
			port;
		int
			result;
	} hsts_data[] = {
		{ "www.example.com", 443, 1 }, // exact match
		{ "ftp.example.com", 443, 0 },
		{ "example.com", 443, 0 },
		{ "sub.www.example.com", 443, 1 }, // subdomain
		{ "sub1.sub2.www.example.com", 443, 1 }, // subdomain
		{ "www.example2.com", 443, 0 }, // entry should have been removed due to maxage=0
		{ "www.example.com", 80, 1 }, // default port
		{ "www.example.com", 8080, 0 }, // wrong port
	};
	wget_hsts_db_t *hsts_db = wget_hsts_db_init(NULL);
	time_t maxage;
	char include_subdomains;
	int n;

	// fill HSTS database with values
	for (unsigned it = 0; it < countof(hsts_db_data); it++) {
		const struct hsts_db_data *t = &hsts_db_data[it];
		wget_http_parse_strict_transport_security(t->hsts_params, &maxage, &include_subdomains);
		wget_hsts_db_add(hsts_db, wget_hsts_new(t->host, t->port, maxage, include_subdomains));
	}

	// check HSTS database with values
	for (unsigned it = 0; it < countof(hsts_data); it++) {
		const struct hsts_data *t = &hsts_data[it];

		n = wget_hsts_host_match(hsts_db, t->host, t->port);

		if (n == t->result)
			ok++;
		else {
			failed++;
			info_printf("Failed [%u]: wget_hsts_host_match(%s,%d) -> %d (expected %d)\n", it, t->host, t->port, n, t->result);
		}
	}

	wget_hsts_db_free(&hsts_db);
}
GPIORelaisController::GPIORelaisController()
{
	info_printf("constructur GPIORelaisController\n");
	allRelaisBits = allRelaisValue();
	if (openMap()) {
		setOffAllRelais();
	}
}
Exemple #10
0
void infohelper_print_progress(char *msg, float cval, float maxval)
{
    unsigned int cur, cnt;

    if(cval == 0)
    {
        beat = 0;
    }
    
    cur = (35 / maxval) * cval;

    cnt = 35-cur;
    
    if(msg)
    {
        info_printf(1, "%s: [", msg);
    }
    else
    {
        info_printf(1, "[");
    }

    while(cur--)
    {
        info_printf(101, "*");
    }

    if(cnt)
    {
        if(cval)
        {
            info_printf(101, "%c",heartbeat[beat]);
        }
        else
        {
            info_printf(101, " ");
        }
    }
    else
    {
        info_printf(101, "*");
    }

    while(cnt--)
    {
        info_printf(101, " ");
    }

    info_printf(101, "\b]\r");
    fflush(stdout);
    
    beat++;
    beat &= 0x07;
}
Exemple #11
0
// convert the pointed string to a right ascension value; if a conversion cannot be done,
// the value is unchanged and -1 is returned
int scan_ra(double *d, char *val)
{
	int ret;
	double v;
	ret = dms_to_degrees(val, &v);
	if (!ret) {
		return -1;
	}
	if (v < 0) {
		info_printf("RA value is negative, ignoring sign\n");
		v = -v;
	} 
	if (v > 24.0) {
		info_printf("RA value is too large, ignoring\n");
		return -1;
	}
	*d = v; 
	return 0;
} 
int GPIORelaisController::closeMap()
{
	int res = 0;
	info_printf("GPIORelaisController::closeMap()\n");

//	if (munmap_device_memory( gpioPortBase, gpioPortLen ) == -1 )  {  ???
	if (munmap_device_memory( gpioregs, gpioPortLen ) == -1 )  {
		info_printf("GPIORelaisController::closeMap:   munmap_device_memory failed \n");
	}

/*	if ( munmap(gpioregs, mapLen) < 0) {
		printf("munmap() error");
		res = 1;
	}
//	printf("gioregs unmapped\n");
	close(memfd);
	*/

	return res;
}
Exemple #13
0
void NonPosixTimer::stop()
{
	//	DWORD tmOut;
		info_printf("\nstop NonPosixTimer\n");
		
		setStopCond();

		/*
		tmOut = 
		*/

		pthread_join(nptThread,NULL);    // pn 22. sept 12,
											// timeout would be desirable, but not possible via join (timedjoin), seems not be supported 
											// in the library, according to pthread.h. Could be implemented by slowly polling for 
											// a thread-terminated-variable with max counter condition. Or with a call to 
											// pthread_cond_timedwait when waiting for a thread terminated condition
											// currently left this point open for later implementation
		
		info_printf("NonPosixTimer threadMethod stopped\n");
}
Exemple #14
0
static void test_iri_compare(void)
{
	static const struct iri_test_data {
		const char
			*url1,
			*url2;
		int
			result;
	} test_data[] = {
		{ "http://abc.com", "http://abc.com/", -1}, // different, some web servers redirect ... to .../ due to normalization issues
		{ "http://abc.com", "http://abc.com:", 0},
		{ "http://abc.com", "http://abc.com:/", -1},
		{ "http://abc.com", "http://abc.com:80/", -1},
		{ "http://abc.com", "http://abc.com:80//", -1},
		// { "http://äöü.com", "http://ÄÖÜ.com:80//", 0},
		{ "http://abc.com:80/~smith/home.html", "http://abc.com/~smith/home.html", 0},
		{ "http://abc.com:80/~smith/home.html", "http://ABC.com/~smith/home.html", 0},
		{ "http://abc.com:80/~smith/home.html", "http://ABC.com/%7Esmith/home.html", 0},
		{ "http://abc.com:80/~smith/home.html", "http://ABC.com/%7esmith/home.html", 0},
		{ "http://ABC.com/%7esmith/home.html", "http://ABC.com/%7Esmith/home.html", 0},
		{ "http://ABC.com/%7esmith/home.html", "http://ACB.com/%7Esmith/home.html", -1}
	};
	unsigned it;
	int n;

	for (it = 0; it < countof(test_data); it++) {
		const struct iri_test_data *t = &test_data[it];
		mget_iri_t *iri1 = mget_iri_parse(t->url1, "utf-8");
		mget_iri_t *iri2 = mget_iri_parse(t->url2, "utf-8");

		n = mget_iri_compare(iri1, iri2);
		if (n < -1) n = -1;
		else if (n > 1) n = 1;

		if (n == t->result)
			ok++;
		else {
			failed++;
			info_printf("Failed [%u]: compare(%s,%s) -> %d (expected %d)\n", it, t->url1, t->url2, n, t->result);
			printf("  display %s / %s\n", iri1->display, iri2->display);
			printf("  scheme %s / %s\n", iri1->scheme, iri2->scheme);
			printf("  user %s / %s\n", iri1->userinfo, iri2->userinfo);
			printf("  host %s / %s\n", iri1->host, iri2->host);
			printf("  port %s / %s\n", iri1->port, iri2->port);
			printf("  path %s / %s\n", iri1->path, iri2->path);
			printf("  query %s / %s\n", iri1->query, iri2->query);
			printf("  fragment %s / %s\n", iri1->fragment, iri2->fragment);
			printf("\n");
		}

		mget_iri_free(&iri2);
		mget_iri_free(&iri1);
	}
}
void GPIORelaisController::testMethod()
{	int cnt1;
	info_printf("GPIORelaisController::testMethod()\n");
	
	for (cnt1 = 0; cnt1 < 100; ++ cnt1) {
//		printf("step %i\n",cnt1);
		setMultipleRelaisOn(5);
		sleep(4);
		setMultipleRelaisOn(0);
		sleep(1);
		
		setMultipleRelaisOn(5);
		sleep(1);
		setMultipleRelaisOn(0);
		sleep(1);		
		
		setMultipleRelaisOn(4);
		sleep(1);
		setMultipleRelaisOn(0);
		sleep(1);	

		setMultipleRelaisOn(3);
		sleep(1);
		setMultipleRelaisOn(0);
		sleep(1);		
		
		setMultipleRelaisOn(2);
		sleep(1);
		setMultipleRelaisOn(0);
		sleep(1);		
		
		setMultipleRelaisOn(1);
		sleep(1);
		setMultipleRelaisOn(0);
		sleep(1);		
		
		setMultipleRelaisOn(0);
		sleep(3);	
	}
	info_printf("END GPIORelaisController::testMethod()\n");
}
Exemple #16
0
int mget_cookie_db_save(mget_cookie_db_t *cookie_db, const char *fname, int keep_session_cookies)
{
	FILE *fp;
	int it, ret = -1;
	time_t now = time(NULL);

	if (!cookie_db || !fname)
		return -1;

	info_printf(_("saving cookies to '%s'\n"), fname);

	if ((fp = fopen(fname, "w"))) {
		fputs("# HTTP cookie file\n", fp);
		fputs("#Generated by Mget " PACKAGE_VERSION ". Edit at your own risk.\n\n", fp);

		mget_thread_mutex_lock(&cookie_db->mutex);

		for (it = 0; it < mget_vector_size(cookie_db->cookies) && !ferror(fp); it++) {
			mget_cookie_t *cookie = mget_vector_get(cookie_db->cookies, it);

			if (cookie->persistent) {
				if (cookie->expires < now)
					continue;
			} else if (!keep_session_cookies)
				continue;

			fprintf(fp, "%s%s%s\t%s\t%s\t%s\t%"PRId64"\t%s\t%s\n",
				cookie->http_only ? "#HttpOnly_" : "",
				cookie->domain_dot ? "." : "", // compatibility, irrelevant since RFC 6562
				cookie->domain,
				cookie->host_only ? "FALSE" : "TRUE",
				cookie->path, cookie->secure_only ? "TRUE" : "FALSE",
				(int64_t)cookie->expires,
				cookie->name, cookie->value);
		}

		mget_thread_mutex_unlock(&cookie_db->mutex);

		if (!ferror(fp))
			ret = 0;

		if (fclose(fp))
			ret = -1;

		if (ret)
			error_printf(_("Failed to write to cookie file '%s' (%d)\n"), fname, errno);

	} else
		error_printf(_("Failed to open cookie file '%s' (%d)\n"), fname, errno);

	return ret;
}
Exemple #17
0
static void test_hashing(void)
{
	static const struct test_data {
		const char *
			text;
		const char *
			result;
		int
			algo;
	} test_data[] = {
		{ "moin", "06a998cdd13c50b7875775d4e7e9fa74", WGET_DIGTYPE_MD5 },
		{ "moin", "ba3cffcc93a92e08f82c33c55d887666fdf364ae", WGET_DIGTYPE_SHA1 },
		{ "moin", "2500d0ed4d0ea1b3ea9f7f57a5f16c2fba8ad15d05d3c057d42f9796f1250169", WGET_DIGTYPE_SHA256 },
		{ "moin", "e3ab1c142d6136fd938c810d13deaf47ccdb176687fab916611302ceb6a89787f45fdda2df544fec4f5a9a2a40916f316fcdf57bc27b5b757b7598da24c7c4c4", WGET_DIGTYPE_SHA512 },
	};
	unsigned char digest[64];
	char digest_hex[sizeof(digest) * 2 + 1];
	int rc;

	for (unsigned it = 0; it < countof(test_data); it++) {
		const struct test_data *t = &test_data[it];

		if ((rc = wget_hash_fast(t->algo, t->text, strlen(t->text), digest)) == 0) {
			int len = wget_hash_get_len(t->algo);

			wget_memtohex(digest, len, digest_hex, len * 2 + 1);

			if (!strcmp(digest_hex, t->result))
				ok++;
			else {
				failed++;
				info_printf("Failed [%u]: wget_hash_fast(%s,%d) -> %s (expected %s)\n", it, t->text, t->algo, digest_hex, t->result);
			}
		} else {
			failed++;
			info_printf("Failed [%u]: wget_hash_fast(%s,%d) failed with %d\n", it, t->text, t->algo, rc);
		}
	}
}
Exemple #18
0
	/**
	 * It should take care of destroying the thread, the session or
	 * leave it to the shutdown thread.
	 */
	void Server::end_session(uint64_t session_id, int code)
	{
		if (shutting_down)
			return;
		Mutex::Locker l(open_sessions_mutex);
		if (shutting_down)
			return;

		shared_ptr<Session> session = open_sessions[session_id];
		pthread_detach(session->get_thread());
		open_sessions.erase(session_id);
		info_printf(err_cons, "Session %d ended with code %d (%s), working sessions left: %d", (int)session_id, (int)code, SBQLstrerror(code).c_str(), (int)get_sessions_count());
	}
Exemple #19
0
void * NonPosixTimer::nonPosixTimerThreadMethod(void * parm)
{
	int cnt;

	NonPosixTimer* lpTimer = (NonPosixTimer*) parm;
	lpTimer->step = 0;
	
    info_printf("\nNonPosixTimer::nonPosixTimerThreadMethod Started\n");
    
    while (!lpTimer->isStopCondSet()) {
		++ lpTimer->step;
		for (cnt = 0; cnt < maxTimers; ++ cnt){
			if (lpTimer->isTimerTodo(cnt)){
				lpTimer->onTimer(cnt);
			}
		}
		sleep(1);
	}
	info_printf("\nNonPosixTimer::nonPosixTimerThreadMethod Returning\n");
	
	return 0;
}
Exemple #20
0
static void test_parser(void)
{
	DIR *dirp;
	struct dirent *dp;
	const char *ext;
	char fname[128];
	int xml = 0, html = 0, css = 0;

	// test the XML / HTML parser, you should start the test with valgrind
	// to detect memory faults
	if ((dirp = opendir(SRCDIR "/files")) != NULL) {
		while ((dp = readdir(dirp)) != NULL) {
			if (*dp->d_name == '.') continue;
			if ((ext = strrchr(dp->d_name, '.'))) {
				snprintf(fname, sizeof(fname), SRCDIR "/files/%s", dp->d_name);
				if (!mget_strcasecmp_ascii(ext, ".xml")) {
					info_printf("parsing %s\n", fname);
					mget_xml_parse_file(fname, NULL, NULL, 0);
					xml++;
				}
/*				else if (!mget_strcasecmp_ascii(ext, ".html")) {
					info_printf("parsing %s\n", fname);
					mget_html_parse_file(fname, NULL, NULL, 0);
					html++;
				}
				else if (!mget_strcasecmp_ascii(ext, ".css")) {
					info_printf("parsing %s\n", fname);
					mget_css_parse_file(fname, _css_dump_uri, _css_dump_charset, NULL);
					css++;
				} */
			}
		}
		closedir(dirp);
	}

	info_printf("%d XML, %d HTML and %d CSS files parsed\n", xml, html, css);
}
Exemple #21
0
	void Server::main_loop()
	{
		sigset_t sigset_tmpl, sigset;
		pthread_sigmask(0, NULL, &sigset_tmpl);
		sigaddset(&sigset_tmpl, SIGUSR1);
		sigset = sigset_tmpl;
		auto_ptr<DataStream> stream;
		try{
			info_printf(err_cons, "Waiting for connections.");
			while (!shutting_down){
				auto_ptr<DataStream> stream = server.accept(sigset, shutting_down);
				Mutex::Locker l(open_sessions_mutex);
				if (!shutting_down && get_sessions_count() < get_config_max_sessions()){
					try{
						auto_ptr<PackageStream> pstream(new PackageCodec(stream, get_config_max_package_size()));
						shared_ptr<Session> new_session(new Session(*this, pstream));
						open_sessions[new_session->get_id()] = new_session;
						new_session->launch();
					} catch (LoximException &ex) {
						warning_print(err_cons, "Caught exception while creating new session:");
						warning_print(err_cons, ex.to_string());
					} catch (...) {
						warning_print(err_cons, "Caught unknown exception while creating new session");
					}
				}
			}
		} catch (OperationCancelled &ex) {
			//this is a normal way of exiting the server
		} catch (LoximException &ex){
			info_print(err_cons, "Caught exception in server loop, shutting down");
			debug_print(err_cons, ex.to_string());
		} catch (...) {
			info_print(err_cons, "Caught unknown exception in server loop, shutting down");
		}
		{
			Mutex::Locker l(open_sessions_mutex);
			shutting_down = 1;
			info_print(err_cons, "Quitting, telling sessions to shut down");
			for (set<pair<const uint64_t, shared_ptr<Session> > >::iterator i = open_sessions.begin(); i != open_sessions.end(); i++){
				i->second->shutdown(0);
			}
		}
		info_print(err_cons, "Joining threads");
		for (set<pair<const uint64_t, shared_ptr<Session> > >::iterator i = open_sessions.begin(); i != open_sessions.end(); i++){
			pthread_join(i->second->get_thread(), NULL);
		}
		open_sessions.clear();
		info_print(err_cons, "Threads joined");
	}
Exemple #22
0
// convert the pointed string to a declination value; if a conversion cannot be done,
// the value is unchanged and -1 is returned
int scan_dec(double *d, char *val)
{
	int ret;
	double v;
	ret = dms_to_degrees(val, &v);
	if (!ret) {
		return -1;
	}
	if (v > 90.0 || v < -90.0) {
		info_printf("DEC value is too large, ignoring\n");
		return -1;
	}
	*d = v; 
	return 0;
} 
static int info_draw(ToolWin *tw) {
	toolwin_backing(tw);
	/* info */
	cairo_set_source_rgba(tw->ctx,0,0,0,1.0);
	cairo_set_font_face(tw->ctx, conf.bfont);
	cairo_move_to(tw->ctx, 0, 8);
	info_printf(tw, A_CENTER, "%.3lf sec, %.2lf KHz",
			spect->fft->time[mx],spect->fft->freq[my]);
	cairo_rel_move_to(tw->ctx,0,12);
	info_split_printf(tw, "Threshold:", "%.2lf", -1.0 * conf.thresh);
	info_split_printf(tw, "Spectrogram Floor:", "%.2lf",
			-1.0 * conf.spect_floor);
	info_split_printf(tw, "Path Length:","%.2lf", spect->pex);
	info_split_printf(tw, "Path Duration:","%.3lf", spect->tex);
	info_split_printf(tw, "Frequency Excursion:","%.3lf", spect->fex);
	cairo_move_to(tw->ctx, 0, 145);
	/* modes */
	info_split_printf(tw, "Modes:","");
	cairo_set_font_face(tw->ctx, conf.bfont);
		/* erase */
	set_color(tw->ctx,RGBA_ERASE1)
	if (mode & MODE_ERASE) set_color(tw->ctx,RGBA_ERASE1)
	else cairo_set_source_rgba(tw->ctx,0.8,0.8,0.8,1.0);
	cairo_rectangle(tw->ctx, 10, 170, tw->w / 2.0 - 15, 20);
	cairo_fill_preserve(tw->ctx);
	cairo_set_source_rgba(tw->ctx,0,0,0,1.0);
	cairo_stroke(tw->ctx);
	cairo_text_extents(tw->ctx,"Erase",&ext);
	cairo_move_to(tw->ctx, tw->w / 4.0 - ext.width / 2.0, 185);
	cairo_set_source_rgba(tw->ctx,0,0,0,1.0);
	cairo_show_text(tw->ctx,"Erase");
		/* crop */
	if (mode & MODE_CROP) set_color(tw->ctx, RGBA_CROP)
	else cairo_set_source_rgba(tw->ctx,0.8,0.8,0.8,1.0);
	cairo_rectangle(tw->ctx, 5 + tw->w / 2.0, 170, tw->w / 2.0 - 15, 20);
	cairo_fill_preserve(tw->ctx);
	cairo_set_source_rgba(tw->ctx,0.0,0.0,0.0,1.0);
	cairo_stroke(tw->ctx);
	cairo_text_extents(tw->ctx,"Crop",&ext);
	cairo_move_to(tw->ctx, tw->w * 0.75 - ext.width / 2.0, 185);
	cairo_set_source_rgba(tw->ctx,0,0,0,1.0);
	cairo_show_text(tw->ctx,"Crop");
	/* draw */
	toolwin_draw(tw);
	return 0;
}
Exemple #24
0
static void test_striconv(void)
{
	const char *utf8 = "abcßüäö";
	char *utf16be = NULL, *utf16le = NULL, *result = NULL;
	size_t n;

	// convert utf-8 to utf-16be
	if (wget_memiconv("utf-8", utf8, strlen(utf8), "UTF-16BE", &utf16be, &n) ||
		wget_memiconv("UTF-16BE", utf16be, n, "UTF-16LE", &utf16le, &n) ||
		wget_memiconv("UTF-16LE", utf16le, n, "UTF-8", &result, &n) ||
		strcmp(utf8, result))
	{
		info_printf("Character conversion of '%s' failed (got '%s')\n", utf8, result);
		failed++;
	} else {
		ok++;
	}

	xfree(result);
	xfree(utf16le);
	xfree(utf16be);
}
Exemple #25
0
void startTcpipThread()
{
	INT8U retVal = 0;
	retVal = OSTaskCreateExt(tcp_ip_Thread_Method,
					(void *)0,
					(OS_STK *)&tcp_ip_Thread_MethodStk[tcp_ip_Thread_Method_STK_SIZE - 1],
					tcp_ip_Thread_TASK_PRIO,
					tcp_ip_Thread_TASK_PRIO,
					(OS_STK *)&tcp_ip_Thread_MethodStk[0],
					tcp_ip_Thread_Method_STK_SIZE,
					(void *)0,
					OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
	
	if (retVal !=  OS_NO_ERR  ) {
		err_printf("error create sec100 tcp_ip Thread\n");
	}  else {
		info_printf("tcp/ip started as %s:%d\n",ownIPAddress,UDP_SERVER_PORT);
	}

	#if (OS_TASK_NAME_SIZE > 10)
	OSTaskNameSet(tcp_ip_Thread_TASK_PRIO, (CPU_CHAR *)"tcp_ip", &err);
	#endif
}
Exemple #26
0
static  void  AppTaskStart (void *p_arg)
{
    CPU_INT08U  i;


    (void)p_arg;
                                                        

#if OS_TASK_STAT_EN > 0
    OSStatInit();                                                       /* Determine CPU capacity                                  */
#endif

#if uC_TCPIP_MODULE > 0
//	AppInit_TCPIP();                                               
#endif

//	initIfDipatcher();
	
//    AppTaskCreate();                                                


	INT32U   loopCnt = 0;
    while (1) {          
		loopCnt ++;
        for (i = 1; i <= 6; i++) {
            LED_On(i);
            OSTimeDlyHMSM(0, 0, 1, 0);
            LED_Off(i);
        }
        for (i = 4; i <= 7; i++) {
            LED_On(9 - i);
            OSTimeDlyHMSM(0, 0, 1, 0);
            LED_Off(9 - i);
        }
		info_printf("AppTaskStart loopCnt: %u \n",loopCnt);
    }
}
Exemple #27
0
static void test_utils(void)
{
	int it;
	unsigned char src[1];
	char dst1[3], dst2[3];

	for (int ndst = 1; ndst <= 3; ndst++) {
		for (it = 0; it <= 255; it++) {
			src[0] = (unsigned char) it;
			mget_memtohex(src, 1, dst1, ndst);
			snprintf(dst2, ndst, "%02x", src[0]);
			if (strcmp(dst1, dst2)) {
				info_printf("buffer_to_hex failed: '%s' instead of '%s' (ndst=%d)\n", dst1, dst2, ndst);
				failed++;
				break;
			}
		}

		if (it >= 256)
			ok++;
		else
			failed++;
	}
}
Exemple #28
0
int main(int argc, char **argv)
{
    std::string header = "*** BRONCO v0.1 ***";

    /* Read arguments */
    if (argc != 2) {
        printf("Announce: %s --announce <path-to-file> bronco://<host>[:<port>]\n", argv[0]);
        printf("    Join: %s bronco://<host>[:<port>]/<content_id>\n", argv[0]);
        cleanup_and_exit(EXIT_FAILURE);
    }

    /* Set signal handlers */
    signal(SIGINT, signal_close);
    signal(SIGTERM, signal_close);
    signal(SIGHUP, signal_close);
    
    /* Initialize ncurses */
    initscr();

    /* Get screen dimensions */
    uint32_t maxy = 0;
    uint32_t maxx = 0;
    getmaxyx(stdscr, maxy, maxx);

    /* Create windows */
    header_win = newwin(HEADER_HEIGHT, maxx, 0, 0);
    file_win = newwin(FILE_HEIGHT, maxx, HEADER_HEIGHT, 0);
    info_win = newwin(maxy-HEADER_HEIGHT-FILE_HEIGHT, maxx, HEADER_HEIGHT+FILE_HEIGHT, 0);

    /* Set ncurses options */
    noecho();
    curs_set(0);
    halfdelay(5);
    keypad(stdscr, TRUE);
    scrollok(info_win, TRUE);

    /* Create peer manager */
    struct bronco::peermanager::peer_config c = {10, 10, 5, "localhost", bronco::peermanager::select_port()};
    struct bronco::peermanager::nc_parameters p = {"bin/bronco-nc", 512, 400};

    manager_ptr = new bronco::peermanager(argv[1], &c, &p, &info_printf);

    /* Screen update loop */
    while (1) {
        /* Write content */
        wclear(header_win);
        wclear(file_win);
        mvwprintw(header_win, 0, (maxx - header.size())/2, header.c_str());
        mvwprintw(file_win, 0, 0, " Anders_Bech_-_Store_patter_betyder_undskyld.mp3\n [#####      ]");

        /* Resize and refresh windows */
        update_windows(&maxy, &maxx);

        /* Wait for keypress or timeout */
        int key = wgetch(info_win);
        if (key != ERR)
            info_printf("Key pressed!\n");
    }
    
    /* Finalize */
    cleanup_and_exit(EXIT_SUCCESS);



    return 0;
}
Exemple #29
0
static void test_buffer(void)
{
	char sbuf[16];
	mget_buffer_t buf, *bufp;

	// testing buffer on stack, using initial stack memory
	// without resizing

	mget_buffer_init(&buf, sbuf, sizeof(sbuf));
	mget_buffer_deinit(&buf);

	// testing buffer on stack, using initial stack memory
	// with resizing

	mget_buffer_init(&buf, sbuf, sizeof(sbuf));
	_test_buffer(&buf, "Test 1");
	mget_buffer_deinit(&buf);

	// testing buffer on stack, using initial heap memory
	// without resizing

	mget_buffer_init(&buf, NULL, 16);
	mget_buffer_deinit(&buf);

	// testing buffer on stack, using initial heap memory
	// with resizing

	mget_buffer_init(&buf, NULL, 16);
	_test_buffer(&buf, "Test 2");
	mget_buffer_deinit(&buf);

	// testing buffer on heap, using initial stack memory
	// without resizing

	bufp = mget_buffer_init(NULL, sbuf, sizeof(sbuf));
	mget_buffer_deinit(bufp);

	bufp = mget_buffer_init(NULL, sbuf, sizeof(sbuf));
	mget_buffer_free(&bufp);

	// testing buffer on heap, using initial stack memory
	// with resizing

	bufp = mget_buffer_init(NULL, sbuf, sizeof(sbuf));
	_test_buffer(bufp, "Test 3");
	mget_buffer_deinit(bufp);

	bufp = mget_buffer_init(NULL, sbuf, sizeof(sbuf));
	_test_buffer(bufp, "Test 4");
	mget_buffer_free(&bufp);

	// testing buffer on heap, using initial heap memory
	// without resizing

	bufp = mget_buffer_alloc(16);
	mget_buffer_free(&bufp);

	// testing buffer on heap, using initial heap memory
	// with resizing

	bufp = mget_buffer_alloc(16);
	_test_buffer(bufp, "Test 5");
	mget_buffer_free(&bufp);

	// check that appending works

	mget_buffer_init(&buf, sbuf, sizeof(sbuf));
	mget_buffer_strcpy(&buf, "A");
	mget_buffer_strcat(&buf, "B");
	mget_buffer_memcat(&buf, "C", 1);
	mget_buffer_memset_append(&buf, 'D', 1);
	mget_buffer_printf_append2(&buf, "%s", "E");
	if (!strcmp(buf.data, "ABCDE"))
		ok++;
	else {
		failed++;
		info_printf("test_buffer.append: got %s (expected %s)\n", buf.data, "ABCDE");
	}
	mget_buffer_deinit(&buf);

	// test mget_buffer_trim()

	mget_buffer_init(&buf, sbuf, sizeof(sbuf));
	for (int mid_ws = 0; mid_ws <= 2; mid_ws++) {
		char expected[16];
		snprintf(expected, sizeof(expected), "x%.*sy", mid_ws, "  ");

		for (int lead_ws = 0; lead_ws <= 2; lead_ws++) {
			for (int trail_ws = 0; trail_ws <= 2; trail_ws++) {
				mget_buffer_printf2(&buf, "%.*sx%.*sy%.*s", lead_ws, "  ", mid_ws, "  ", trail_ws, "  ");
				mget_buffer_trim(&buf);
				if (!strcmp(buf.data, expected))
					ok++;
				else {
					failed++;
					info_printf("test_buffer_trim: got '%s' (expected '%s') (%d, %d, %d)\n", buf.data, expected, lead_ws, mid_ws, trail_ws);
				}
			}
		}
	}
	mget_buffer_deinit(&buf);
}
Exemple #30
0
static void test_cookies(void)
{
	static const struct test_data {
		const char
			*uri,
			*set_cookie,
			*name, *value, *domain, *path, *expires;
		unsigned int
			domain_dot : 1, // for compatibility with Netscape cookie format
			normalized : 1,
			persistent : 1,
			host_only : 1,
			secure_only : 1, // cookie should be used over secure connections only (TLS/HTTPS)
			http_only : 1; // just use the cookie via HTTP/HTTPS protocol
		int
			result,
			psl_result;
	} test_data[] = {
		{	// allowed cookie
			"www.example.com",
			"ID=65=abcd; expires=Tuesday, 07-May-2013 07:48:53 GMT; path=/; domain=.example.com; HttpOnly",
			"ID", "65=abcd", "example.com", "/", "Tue, 07 May 2013 07:48:53 GMT",
			1, 1, 1, 0, 0, 1,
			0, 0
		},
		{	// allowed cookie ANSI C's asctime format
			"www.example.com",
			"ID=65=abcd; expires=Tue May 07 07:48:53 2013; path=/; domain=.example.com",
			"ID", "65=abcd", "example.com", "/", "Tue, 07 May 2013 07:48:53 GMT",
			1, 1, 1, 0, 0, 0,
			0, 0
		},
		{	// allowed cookie without path
			"www.example.com",
			"ID=65=abcd; expires=Tue, 07-May-2013 07:48:53 GMT; domain=.example.com",
			"ID", "65=abcd", "example.com", "/", "Tue, 07 May 2013 07:48:53 GMT",
			1, 1, 1, 0, 0, 0,
			0, 0
		},
		{	// allowed cookie without domain
			"www.example.com",
			"ID=65=abcd; expires=Tue, 07-May-2013 07:48:53 GMT; path=/",
			"ID", "65=abcd", "www.example.com", "/", "Tue, 07 May 2013 07:48:53 GMT",
			0, 1, 1, 1, 0, 0,
			0, 0
		},
		{	// allowed cookie without domain, path and expires
			"www.example.com",
			"ID=65=abcd",
			"ID", "65=abcd", "www.example.com", "/", "Tue, 07 May 2013 07:48:53 GMT",
			0, 1, 0, 1, 0, 0,
			0, 0
		},
		{	// illegal cookie
			"www.example.com",
			"ID=65=abcd; expires=Tue, 07-May-2013 07:48:53 GMT; path=/; domain=.example.org",
			"ID", "65=abcd", "example.org", "/", "Tue, 07 May 2013 07:48:53 GMT",
			1, 0, 1, 0, 0, 0,
			-1, 0
		},
#ifdef WITH_LIBPSL
		{	// supercookie, accepted by normalization (rule 'com') but not by mget_cookie_check_psl())
			"www.example.com",
			"ID=65=abcd; expires=Mon, 29-Feb-2016 07:48:54 GMT; path=/; domain=.com; HttpOnly; Secure",
			"ID", "65=abcd", "com", "/", "Mon, 29 Feb 2016 07:48:54 GMT",
			1, 0, 1, 0, 1, 1,
			0, -1
		},
		{	// supercookie, accepted by normalization  (rule '*.ar') but not by mget_cookie_check_psl())
			"www.sa.gov.au",
			"ID=65=abcd; expires=Tue, 29-Feb-2000 07:48:55 GMT; path=/; domain=.sa.gov.au",
			"ID", "65=abcd", "sa.gov.au", "/", "Tue, 29 Feb 2000 07:48:55 GMT",
			1, 0, 1, 0, 0, 0,
			0, -1
		},
#endif
		{	// exception rule '!educ.ar', accepted by normalization
			"www.educ.ar",
			"ID=65=abcd; path=/; domain=.educ.ar",
			"ID", "65=abcd", "educ.ar", "/", NULL,
			1, 1, 0, 0, 0, 0,
			0, 0
		},
	};
	mget_cookie_t cookie;
	mget_cookie_db_t *cookies;
	mget_iri_t *iri;
	unsigned it;
	int result, result_psl;

	cookies = mget_cookie_db_init(NULL);
	mget_cookie_db_load_psl(cookies, DATADIR "/effective_tld_names.dat");

	for (it = 0; it < countof(test_data); it++) {
		const struct test_data *t = &test_data[it];
		char thedate[32], *header;

		iri = mget_iri_parse(t->uri, "utf-8");
		mget_http_parse_setcookie(t->set_cookie, &cookie);
		if ((result = mget_cookie_normalize(iri, &cookie)) != t->result) {
			failed++;
			info_printf("Failed [%u]: normalize_cookie(%s) -> %d (expected %d)\n", it, t->set_cookie, result, t->result);
			mget_cookie_deinit(&cookie);
			goto next;
		} else {
			if ((result_psl = mget_cookie_check_psl(cookies, &cookie)) != t->psl_result) {
				failed++;
				info_printf("Failed [%u]: PSL check(%s) -> %d (expected %d)\n", it, t->set_cookie, result_psl, t->psl_result);
			}
			mget_cookie_deinit(&cookie);
			goto next;
		}

		if (cookie.expires) {
			mget_http_print_date(cookie.expires, thedate, sizeof(thedate));
			if (strcmp(thedate, t->expires)) {
				failed++;
				info_printf("Failed [%u]: expires mismatch: '%s' != '%s' (time_t %lld)\n", it, thedate, t->expires, (long long)cookie.expires);
				mget_cookie_deinit(&cookie);
				goto next;
			}
		}

		if (strcmp(cookie.name, t->name) ||
			strcmp(cookie.value, t->value) ||
			strcmp(cookie.domain, t->domain) ||
			strcmp(cookie.path, t->path) ||
			cookie.domain_dot != t->domain_dot ||
			cookie.normalized != t->normalized ||
			cookie.persistent != t->persistent ||
			cookie.host_only != t->host_only ||
			cookie.secure_only != t->secure_only ||
			cookie.http_only != t->http_only)
		{
			failed++;

			info_printf("Failed [%u]: cookie (%s) differs:\n", it, t->set_cookie);
			if (strcmp(cookie.name, t->name))
				info_printf("  name %s (expected %s)\n", cookie.name, t->name);
			if (strcmp(cookie.value, t->value))
				info_printf("  value %s (expected %s)\n", cookie.value, t->value);
			if (strcmp(cookie.domain, t->domain))
				info_printf("  domain %s (expected %s)\n", cookie.domain, t->domain);
			if (strcmp(cookie.path, t->path))
				info_printf("  path %s (expected %s)\n", cookie.path, t->path);
			if (cookie.domain_dot != t->domain_dot)
				info_printf("  domain_dot %d (expected %d)\n", cookie.domain_dot, t->domain_dot);
			if (cookie.normalized != t->normalized)
				info_printf("  normalized %d (expected %d)\n", cookie.normalized, t->normalized);
			if (cookie.persistent != t->persistent)
				info_printf("  persistent %d (expected %d)\n", cookie.persistent, t->persistent);
			if (cookie.host_only != t->host_only)
				info_printf("  host_only %d (expected %d)\n", cookie.host_only, t->host_only);
			if (cookie.secure_only != t->secure_only)
				info_printf("  secure_only %d (expected %d)\n", cookie.secure_only, t->secure_only);
			if (cookie.http_only != t->http_only)
				info_printf("  http_only %d (expected %d)\n", cookie.http_only, t->http_only);

			mget_cookie_deinit(&cookie);
			goto next;
		}

		mget_cookie_store_cookie(cookies, &cookie);

		info_printf("%s\n", header = mget_cookie_create_request_header(cookies, iri));
		xfree(header);

		ok++;

next:
		mget_iri_free(&iri);
	}

	mget_cookie_db_free(&cookies);
}