예제 #1
0
파일: tiny.c 프로젝트: 4179e1/misc
void serve_static (int fd, char *filename, int filesize)
{
	int srcfd;
	char *srcp, filetype[MAXLINE], buf[MAXLINE];

	get_filetype (filename, filetype);
	sprintf (buf, "HTTP/1.0 200 OK\r\n");
	sprintf (buf, "%sServer: Tiny Web Server\r\n", buf);
	sprintf (buf, "%sContent-length: %d\r\n", buf, filesize);
	sprintf (buf, "%sContent-type: %s\r\n\r\n", buf, filetype);
	wp_writen (fd, buf, strlen (buf));

	srcfd = wp_open (filename, O_RDONLY, 0);
	srcp = wp_mmap (0, filesize, PROT_READ, MAP_PRIVATE, srcfd, 0);
	wp_close (srcfd);
	wp_writen (fd, srcp, filesize);
	wp_munmap (srcp, filesize);
}
예제 #2
0
파일: wpconvert.c 프로젝트: ve7fet/fpac
int main(int ac, char **av)
{
	FILE *fptr;
	old_wp_t old_wp;
	wp_t new_wp;
	wp_header wph;
	char dnic[5];
	char *add, *call;
	char buf[20];

	if (ac < 2)
	{
		fprintf(stderr, "format : wpconv database\n");
		return 1;
	}
	
	fptr = fopen(av[1], "r");
	if (fptr == NULL)
	{
		fprintf(stderr, "Cannot open %s\n", av[1]);
		return 2;
	}

	if (fread(&wph, sizeof(wph), 1, fptr) == 0)
	{
		fclose(fptr);
		fprintf(stderr, "database %s is empty\n", av[1]);
		return 3;
	}

	/* Check the first record for compatibility */
	if (strcmp(wph.signature,OLD_FILE_SIGNATURE) != 0)
	{
		fprintf(stderr, "database %s is not compatible\n", av[1]);
		fclose(fptr);
		return 4;
	}

	printf("%u callsigns in database\n", wph.nb_record);

	if (wp_open("WPCNVT")) {
		perror("Cannot open WP service");
		exit(1);
	}
	
	while (fread(&old_wp, sizeof(old_wp_t), 1, fptr))
	{
			
		if (old_wp.date == 0)
			continue;
			
		add = rose_ntoa(&old_wp.address.srose_addr);
		call = ax25_ntoa(&old_wp.address.srose_call);

		if (wp_check_call(call) != 0)
			continue;

		strncpy(dnic, add, 4); dnic[4] = '\0';

		my_date(buf, old_wp.date),
		
		printf("%-9s %s => %s %-7s ", 
				call,
				buf,
				dnic, 
				add+4);
			
		if (old_wp.address.srose_ndigis)
			printf("%s ", ax25_ntoa(&old_wp.address.srose_digi));
						
		printf("%s %s\n", old_wp.name, old_wp.city);
		
		/* Add to the running database */
		
		memset(&new_wp, 0, sizeof(wp_t));
		
		new_wp.date = old_wp.date;
		new_wp.address.srose_addr     = old_wp.address.srose_addr;
		new_wp.address.srose_call     = old_wp.address.srose_call;
		new_wp.address.srose_digis[0] = old_wp.address.srose_digi;
		new_wp.address.srose_ndigis   = old_wp.address.srose_ndigis;

		wp_set(&new_wp);
	}

	wp_close();

	return(0);
}