Ejemplo n.º 1
0
int CFRtpSenderExit(CFRtpSender* rs)
{
    int i;
    
    CFPipeExit(&rs->fullBufs);

    CFPipeExit(&rs->emptyBufs);
    for (i=0; i<CF_ARRAY_SIZE(rs->cacheBufs); i++) {
        CFBufferExit(&rs->cacheBufs[i].buf);
    }
    
    free(rs->rtpBuf);
    
    if (rs->wrtEvtInited) {
        CFFdeventExit(&rs->wrtEvt);
        rs->wrtEvtInited = FALSE;
    }
    
    if (rs->sock > 0) {
        close(rs->sock);
        rs->sock = -1;
    }

    return 0;
}
Ejemplo n.º 2
0
void cf_reset_to_default(void) {
	int i,j;
	CONF_ITEM *cf;
	for (i = 0; i < 128; i++) {
		for (j = 0; j < cf_hash[i].nb_item; j++) {
			cf = cf_hash[i].conf[j];
			if (cf && !cf->modified && !(cf->flags & CF_SETBYCMD)) {
				switch (cf->type) {
					case CFT_INT:
						CF_VAL(cf) = cf->data.dt_int.default_val;
						break;
					case CFT_BOOLEAN:
						CF_BOOL(cf) = cf->data.dt_bool.default_bool;
						break;
					case CFT_STRING:
						CF_STR(cf)=rstrcpy(CF_STR(cf), cf->data.dt_str.default_str, 254);
						break;
					case CFT_ARRAY:
						memcpy(cf->data.dt_array.array, cf->data.dt_array.default_array,
								CF_ARRAY_SIZE(cf) * sizeof (int));
						//read_array(CF_ARRAY(cf), val, CF_ARRAY_SIZE(cf));
						break;
					default:
						break;
				}
			}
		}
	}
}
Ejemplo n.º 3
0
char* cf_parse_cmd_line(int argc, char *argv[]) {
	int c;
	CONF_ITEM *cf;


	option_index = optind = 0;
#ifdef WII
	return NULL;
#endif
	while ((c = getopt_long(argc, argv, shortopt, longopt, &option_index)) != EOF) {
		//if (c != 0) {
//			printf("c=%d\n",c);
			cf = cf_get_item_by_val(c&0xFFF);
			if (cf) {
				cf->flags |= CF_SETBYCMD;
//				printf("flags %s set on cmd line\n", cf->name);
				switch (cf->type) {

					case CFT_INT:
						CF_VAL(cf) = atoi(optarg);
						break;
					case CFT_BOOLEAN:
					if (c & 0x1000)
						CF_BOOL(cf) = 0;
					else
						CF_BOOL(cf) = 1;
						break;
					case CFT_STRING:
						strcpy(CF_STR(cf), optarg);
						//printf("conf %s %s\n",CF_STR(cf),optarg);
						break;
					case CFT_ARRAY:
						read_array(CF_ARRAY(cf), optarg, CF_ARRAY_SIZE(cf));
						break;
					case CFT_ACTION_ARG:
						strcpy(CF_STR(cf), optarg);
						if (cf->action) {
							exit(cf->action(cf));
						}
						break;
					case CFT_ACTION:
						if (cf->action) {
							exit(cf->action(cf));
						}
						break;
					case CFT_STR_ARRAY:
						/* TODO */
						break;
				}
			//}
		}
	}
	cf_cache_conf();
	if (optind >= argc)
		return NULL;

	return strdup(argv[optind]);
}
Ejemplo n.º 4
0
bool cf_open_file(char *filename) 
{
	/* if filename==NULL, we use the default one: $HOME/.gngeo/gngeorc */
	FILE *f;
	int i = 0;
	char *buf=NULL;
	char *name=NULL, *ptr;
	CONF_ITEM *cf;

	f = fopen(filename, "rb");
	if (! f)
	{
		printf("ERROR: Unable to open %s\n",filename);
		return false;
	}

	buf=calloc(8192,sizeof(char));
	while (!feof(f)) {
		i = 0;
		my_fgets(buf, 8190, f);
		if (discard_line(buf))
			continue;
	
		ptr=get_token(buf, " =", &name);

		cf = cf_get_item_by_name(name);
		if (cf && !(cf->flags & CF_SETBYCMD) && (!cf->modified)) {
			switch (cf->type) {
				case CFT_INT:
					CF_VAL(cf) = atoi(ptr);
					break;
				case CFT_BOOLEAN:
					CF_BOOL(cf) = (strcasecmp(ptr, "true") == 0 ? true : false);
					break;
				case CFT_STRING:
					printf("ST: %s\n",ptr);
					CF_STR(cf)=rstrcpy(CF_STR(cf), ptr, 8190);
					break;
				case CFT_ARRAY:
					read_array(CF_ARRAY(cf), ptr, CF_ARRAY_SIZE(cf));
					break;
				case CFT_ACTION:
				case CFT_ACTION_ARG:
					/* action are not available in the conf file */
					break;
				case CFT_STR_ARRAY:
					CF_STR_ARRAY(cf) = read_str_array(ptr, &CF_STR_ARRAY_SIZE(cf));
					break;
			}
		} else {
			/*printf("Unknow option %s\n",name);*/
			/* unknow option...*/
		}
	}

	if (name) free(name);
	if (buf) free(buf);

	cf_cache_conf();
	return true;
}
Ejemplo n.º 5
0
bool cf_save_file(char *filename, int flags) {
	char *conf_file = NULL;
	char *conf_file_dst;
	FILE *f;
	FILE *f_dst;
	int i = 0, j, a;
	char buf[512];
	char *name=NULL, *ptr;
	CONF_ITEM *cf;

	if (! sstrlen(filename)) conf_file=cf_default_path(conf_file, "gngeorc", "");
	else conf_file=rstrcpy(conf_file, filename, 1024);

	conf_file_dst = alloca(strlen(conf_file) + 4);
	sprintf(conf_file_dst, "%s.t", conf_file);

	if ((f_dst = fopen(conf_file_dst, "w")) == 0) {
		//printf("Unable to open %s\n",conf_file);
		if (conf_file) free(conf_file);
		return false;
	}

	if ((f = fopen(conf_file, "rb"))) {

		//printf("Loading current .cf\n");

		while (!feof(f)) {
			i = 0;
			my_fgets(buf, 510, f);
			if (discard_line(buf)) {
				fprintf(f_dst, "%s\n", buf);
				continue;
			}

			//this is an odd approach, seeks to replace existing config
			//items in the order they exist in config file?
			ptr=get_token(buf, " ", &name);

			cf = cf_get_item_by_name(name);
			if (cf) {
				if (cf->modified) {
					cf->modified = 0;
					switch (cf->type) {
						case CFT_INT:
							fprintf(f_dst, "%s %d\n", cf->name, CF_VAL(cf));
							break;
						case CFT_BOOLEAN:
							if (CF_BOOL(cf))
								fprintf(f_dst, "%s true\n", cf->name);
							else
								fprintf(f_dst, "%s false\n", cf->name);
							break;
						case CFT_STRING:
							fprintf(f_dst, "%s %s\n", cf->name, CF_STR(cf));
							break;
						case CFT_ARRAY:
							fprintf(f_dst, "%s ", cf->name);
							for (a = 0; a < CF_ARRAY_SIZE(cf) - 1; a++)
								fprintf(f_dst, "%d,", CF_ARRAY(cf)[a]);
							fprintf(f_dst, "%d\n", CF_ARRAY(cf)[a]);
							break;
						case CFT_ACTION:
						case CFT_ACTION_ARG:
							break;
						case CFT_STR_ARRAY:
							printf("TODO: Save CFT_STR_ARRAY\n");
							break;
					}
				} else
					fprintf(f_dst, "%s\n", buf);
			}
		}
		fclose(f);

	}
	/* Now save options that were not in the previous file */
	for (i = 0; i < 128; i++) {
		for (j = 0; j < cf_hash[i].nb_item; j++) {
			cf = cf_hash[i].conf[j];
			//printf("Option %s %d\n",cf->name,cf->modified);
			if (cf->modified!=0) {
				cf->modified=0;
				switch (cf->type) {
					case CFT_INT:
						fprintf(f_dst, "%s %d\n", cf->name, CF_VAL(cf));
						break;
					case CFT_BOOLEAN:
						if (CF_BOOL(cf))
							fprintf(f_dst, "%s true\n", cf->name);
						else
							fprintf(f_dst, "%s false\n", cf->name);
						break;
					case CFT_STRING:
						fprintf(f_dst, "%s %s\n", cf->name, CF_STR(cf));
						break;
					case CFT_ARRAY:
						fprintf(f_dst, "%s ", cf->name);
						for (a = 0; a < CF_ARRAY_SIZE(cf) - 1; a++)
							fprintf(f_dst, "%d,", CF_ARRAY(cf)[a]);
						fprintf(f_dst, "%d\n", CF_ARRAY(cf)[a]);
						break;
					case CFT_ACTION:
					case CFT_ACTION_ARG:
						/* action are not available in the conf file */
						break;
					case CFT_STR_ARRAY:
						printf("TODO: Save CFT_STR_ARRAY\n");
						break;
				}
			}
		}
	}
	fclose(f_dst);

	remove(conf_file);
	rename(conf_file_dst, conf_file);

	if (name) free(name);
	if (conf_file) free(conf_file);

	return true;
}
Ejemplo n.º 6
0
int CFRtpSenderInit(CFRtpSender* rs, int mups, 
        uint8_t pt, CFRtpPayload payload, uint32_t ssrc, 
        CFFdevents* evts)
{
    LCF_DBG("\n");
    int initedBufCount;
    int i;
    
    LCF_DBG("\n");
    memset(rs, 0, sizeof(CFRtpSender));

    if (rs->mups < 0) {
        rs->mups = CF_DEFAULT_MUPS;
    } else {
        rs->mups = mups;
    }
    LCF_DBG("\n");
    
    rs->rtpBuf = (uint8_t*)malloc(rs->mups);
    if (!rs->rtpBuf) {
        LCF_ERR_OUT(ERR_OUT, "malloc() failed\n");
    }
    
    if (!evts) {
        LCF_ERR_OUT(ERR_FREE_UDP_BUF, "No imp\n");
    }
    rs->evts = evts;
    
    
    for (initedBufCount=0; initedBufCount<CF_ARRAY_SIZE(rs->cacheBufs); initedBufCount++) {
        if (CFBufferInit(&rs->cacheBufs[initedBufCount].buf, rs->mups<<2, 1024)) {
            break;
        }
    }
    if (initedBufCount != CF_ARRAY_SIZE(rs->cacheBufs)) {
        LCF_ERR_OUT(ERR_EXIT_CACHE_BUFS, "\n");
    }
    
    if (CFPipeInit(&rs->emptyBufs, CF_ARRAY_SIZE(rs->cacheBufs))) {
        LCF_ERR_OUT(ERR_EXIT_CACHE_BUFS, "\n");
    }
    if (CFPipeInit(&rs->fullBufs, CF_ARRAY_SIZE(rs->cacheBufs))) {
        LCF_ERR_OUT(ERR_EXIT_EMPTY_BUFS, "\n");
    }
    for (i=0; i<CF_ARRAY_SIZE(rs->cacheBufs); i++) {
        if (CFPipePush(&rs->emptyBufs, &rs->cacheBufs[i])) {
            LCF_ERR_OUT(ERR_EXIT_FULL_BUFS, "\n");
        }
    }
    
    rs->payload = payload;
    rs->rtpHdr.v = 2;
    rs->rtpHdr.p = 0;
    rs->rtpHdr.x = 0;
    rs->rtpHdr.cc = 0;
    rs->rtpHdr.m = 0;
    rs->rtpHdr.pt = pt;
    rs->rtpHdr.sn = 0;
    rs->rtpHdr.ts = 0;
    rs->rtpHdr.ssrc = ssrc;
    rs->rtpHdr.csrc = NULL;
    rs->rtpHdr.csrcLen = 0;
    /* prepare RTP header */
    rs->rtpBuf[0] = rs->rtpHdr.v<<6 | rs->rtpHdr.p<<5 | rs->rtpHdr.x<<4 | rs->rtpHdr.cc<<0;
    rs->rtpBuf[1] = rs->rtpHdr.m<<7 | rs->rtpHdr.pt;
    (*((uint16_t*)(rs->rtpBuf+2))) = htons(rs->rtpHdr.sn);
    (*((uint32_t*)(rs->rtpBuf+4))) = htonl(rs->rtpHdr.ts);
    (*((uint32_t*)(rs->rtpBuf+8))) = htonl(rs->rtpHdr.ssrc);
    return 0;
    
ERR_EXIT_FULL_BUFS:
    if (evts) {
        CFPipeExit(&rs->fullBufs);
    }
ERR_EXIT_EMPTY_BUFS:
    if (evts) {
        CFPipeExit(&rs->emptyBufs);
    }
ERR_EXIT_CACHE_BUFS:
    if (evts) {
        for (i=0; i< initedBufCount; i++) {
            CFBufferExit(&rs->cacheBufs[i].buf);
        }
    }
ERR_FREE_UDP_BUF:
    free(rs->rtpBuf);
ERR_OUT:
    return -1;
}
Ejemplo n.º 7
0
bool cf_open_file(char *filename) {
	/* if filename==NULL, we use the default one: $HOME/Documents/gngeorc */
	char *conf_file = filename;
	FILE *f;
	int i = 0;
	char buf[512];
	char name[32];
	char val[255];
	CONF_ITEM *cf;

	if (!conf_file) {
#ifdef EMBEDDED_FS
		int len = strlen("gngeorc") + strlen(ROOTPATH"conf/") + 1;
		conf_file = (char *) alloca(len * sizeof (char));
		sprintf(conf_file, ROOTPATH"conf/gngeorc");
#elif __AMIGA__
		int len = strlen("gngeorc") + strlen("/PROGDIR/data/") + 1;
		conf_file = (char *) alloca(len * sizeof (char));
		sprintf(conf_file, "/PROGDIR/data/gngeorc");
#else
		int len = strlen("gngeorc") + strlen(getenv("HOME")) + strlen("/Documents/") + 1;
		conf_file = (char *) alloca(len * sizeof (char));
		sprintf(conf_file, "%s/Documents/gngeorc", getenv("HOME"));
#endif
	}
	if ((f = fopen(conf_file, "rb")) == 0) {
		//printf("Unable to open %s\n",conf_file);
		return false;
	}

	while (!feof(f)) {
		i = 0;
		my_fgets(buf, 510, f);
		if (discard_line(buf))
			continue;
	
		/* TODO: Verify this on Win32 */
		sscanf(buf, "%s %s", name, val);

		//sscanf(buf, "%s ", name);
		//strncpy(val,buf+strlen(name)+1,254);

//		printf("%s|%s|\n",name,val);
		cf = cf_get_item_by_name(name);
		if (cf && !(cf->flags & CF_SETBYCMD) && (!cf->modified)) {
//			printf("Option %s\n",cf->name);
			switch (cf->type) {
				case CFT_INT:
					CF_VAL(cf) = atoi(val);
//                    printf("got val: %d\n",CF_VAL(cf));
					break;
				case CFT_BOOLEAN:
					CF_BOOL(cf) = (strcasecmp(val, "true") == 0 ? true : false);
					break;
				case CFT_STRING:
					strncpy(CF_STR(cf), val, 254);
					break;
				case CFT_ARRAY:
					read_array(CF_ARRAY(cf), val, CF_ARRAY_SIZE(cf));
					break;
				case CFT_ACTION:
				case CFT_ACTION_ARG:
					/* action are not available in the conf file */
					break;
				case CFT_STR_ARRAY:
					CF_STR_ARRAY(cf) = read_str_array(val, &CF_STR_ARRAY_SIZE(cf));
					break;
			}
		} else {
			/*printf("Unknow option %s\n",name);*/
			/* unknow option...*/
		}
	}

	cf_cache_conf();
	return true;
}
Ejemplo n.º 8
0
bool cf_save_file(char *filename, int flags) {
	char *conf_file = filename;
	char *conf_file_dst;
	FILE *f;
	FILE *f_dst;
	int i = 0, j, a;
	char buf[512];
	char name[32];
	char val[255];
	CONF_ITEM *cf;

	if (!conf_file) {
#ifdef EMBEDDED_FS
		int len = strlen("gngeorc") + strlen(ROOTPATH"conf/") + 1;
		conf_file = (char *) alloca(len * sizeof (char));
		sprintf(conf_file, ROOTPATH"conf/gngeorc");
#elif __AMIGA__
		int len = strlen("gngeorc") + strlen("/PROGDIR/data/") + 1;
		conf_file = (char *) alloca(len * sizeof (char));
		sprintf(conf_file, "/PROGDIR/data/gngeorc");
#else /* POSIX */
		int len = strlen("gngeorc") + strlen(getenv("HOME")) + strlen("/Documents/") + 1;
		conf_file = (char *) alloca(len * sizeof (char));
		sprintf(conf_file, "%s/Documents/gngeorc", getenv("HOME"));
#endif
	}
	conf_file_dst = alloca(strlen(conf_file) + 4);
	sprintf(conf_file_dst, "%s.t", conf_file);

	if ((f_dst = fopen(conf_file_dst, "w")) == 0) {
		//printf("Unable to open %s\n",conf_file);
		return false;
	}

	if ((f = fopen(conf_file, "rb"))) {

		//printf("Loading current .cf\n");

		while (!feof(f)) {
			i = 0;
			my_fgets(buf, 510, f);
			if (discard_line(buf)) {
				fprintf(f_dst, "%s\n", buf);
				continue;
			}

			//sscanf(buf, "%s %s", name, val);
			sscanf(buf, "%s ", name);
			strncpy(val, buf + strlen(name) + 1, 254);

			cf = cf_get_item_by_name(name);
			if (cf) {
				if (cf->modified) {
					cf->modified = 0;
					switch (cf->type) {
						case CFT_INT:
							fprintf(f_dst, "%s %d\n", cf->name, CF_VAL(cf));
							break;
						case CFT_BOOLEAN:
							if (CF_BOOL(cf))
								fprintf(f_dst, "%s true\n", cf->name);
							else
								fprintf(f_dst, "%s false\n", cf->name);
							break;
						case CFT_STRING:
							fprintf(f_dst, "%s %s\n", cf->name, CF_STR(cf));
							break;
						case CFT_ARRAY:
							fprintf(f_dst, "%s ", cf->name);
							for (a = 0; a < CF_ARRAY_SIZE(cf) - 1; a++)
								fprintf(f_dst, "%d,", CF_ARRAY(cf)[a]);
							fprintf(f_dst, "%d\n", CF_ARRAY(cf)[a]);
							break;
						case CFT_ACTION:
						case CFT_ACTION_ARG:
							break;
						case CFT_STR_ARRAY:
							printf("TODO: Save CFT_STR_ARRAY\n");
							break;
					}
				} else
					fprintf(f_dst, "%s\n", buf);
			}
		}
		fclose(f);

	}
	/* Now save options that were not in the previous file */
	for (i = 0; i < 128; i++) {
		for (j = 0; j < cf_hash[i].nb_item; j++) {
			cf = cf_hash[i].conf[j];
			//printf("Option %s %d\n",cf->name,cf->modified);
			if (cf->modified!=0) {
				cf->modified=0;
				switch (cf->type) {
					case CFT_INT:
						fprintf(f_dst, "%s %d\n", cf->name, CF_VAL(cf));
						break;
					case CFT_BOOLEAN:
						if (CF_BOOL(cf))
							fprintf(f_dst, "%s true\n", cf->name);
						else
							fprintf(f_dst, "%s false\n", cf->name);
						break;
					case CFT_STRING:
						fprintf(f_dst, "%s %s\n", cf->name, CF_STR(cf));
						break;
					case CFT_ARRAY:
						fprintf(f_dst, "%s ", cf->name);
						for (a = 0; a < CF_ARRAY_SIZE(cf) - 1; a++)
							fprintf(f_dst, "%d,", CF_ARRAY(cf)[a]);
						fprintf(f_dst, "%d\n", CF_ARRAY(cf)[a]);
						break;
					case CFT_ACTION:
					case CFT_ACTION_ARG:
						/* action are not available in the conf file */
						break;
					case CFT_STR_ARRAY:
						printf("TODO: Save CFT_STR_ARRAY\n");
						break;
				}
			}
		}
	}
	fclose(f_dst);

	remove(conf_file);
	rename(conf_file_dst, conf_file);

	return true;
}