Example #1
0
int main(int argc, char** argv){

    if(argc < 3)
        exit(EXIT_FAILURE);

    // file di input
    char* train = argv[1];
    char* test = argv[2];
    std::ifstream trainfile(train);
    std::ifstream validfile(test);

    // HMM
    int n_stati = 5, n_simboli = 14 ,span = 1;
    HMM hmm(n_stati, n_simboli, span);

    // dataset di train e validation
    std::vector< std::vector<int> > trainset;
    std::vector< std::vector<int> > validset;

    // stringhe per acquisizione temporanea dati
    std::string train_input, valid_input;

    // conta il n° di gesture processate
    int count = 0;

    // acquisizione training set
    while(!trainfile.eof()){

        // acquisisce la prima parola FORMATTATA
        trainfile >> train_input;

        // inizio di una gesture
        if(train_input == "<gesture>"){

            // crea una nuova gesture nel dataset
            trainset.push_back(std::vector<int>());

            // incrementa il n° di gesture processate
            count++;

        }
        // fase acquisizione dati della gesture
        else if(train_input != "<gesture>" && train_input != "</gesture>"){

            // converte la parola acquisita in mumero
            std::istringstream num(train_input);
            double value;
            num >> value;

            // inserisce il valore nella gesture corrente
            trainset.at(count-1).push_back(value);

        }
        // fine di una gesture
        else if(train_input == "</gesture>"){
Example #2
0
static char*
fswalk1(Fid *fid, char *name, Qid *qid)
{
	FInfo fi;
	int rc, n, i;
	Aux *a = fid->aux;
	static char e[ERRMAX];
	char *p, *npath, *winpath;

	*e = 0;
	npath = newpath(a->path, name);
	if(strcmp(npath, "/") == 0){			/* root dir */
		*qid = mkqid("/", 1, 1, Proot, 0);
		free(a->path);
		a->path = npath;
		fid->qid = *qid;
		return nil;
	}

	if(strrchr(npath, '/') == npath){		/* top level dir */
		if((n = walkinfo(name)) != -1){		/* info file */
			*qid = mkqid(npath, 0, 1, Pinfo, n);
		}
		else {					/* volume name */
			for(i = 0; i < Nshares; i++){
				n = strlen(Shares[i].name);
				if(cistrncmp(npath+1, Shares[i].name, n) != 0)
					continue;
				if(Checkcase && strncmp(npath+1, Shares[i].name, n) != 0)
					continue;
				if(npath[n+1] != 0 && npath[n+1] != '/')
					continue;
				break;
			}
			if(i >= Nshares){
				free(npath);
				return "not found";
			}
			a->sp = Shares+i;
			*qid = mkqid(npath, 1, 1, Pshare, i);
		}
		free(a->path);
		a->path = npath;
		fid->qid = *qid;
		return nil;
	}

	/* must be a vanilla file or directory */
again:
	if(mapshare(npath, &a->sp) == -1){
		rerrstr(e, sizeof(e));
		free(npath);
		return e;
	}

	winpath = mapfile(npath);
	memset(&fi, 0, sizeof fi);
	if(Sess->caps & CAP_NT_SMBS)
		rc = T2queryall(Sess, a->sp, winpath, &fi);
	else
		rc = T2querystandard(Sess, a->sp, winpath, &fi);

	if(rc == -1){
		rerrstr(e, sizeof(e));
		free(npath);
		return e;
	}

	if((a->sp->options & SMB_SHARE_IS_IN_DFS) != 0 &&
	    (fi.attribs & ATTR_REPARSE) != 0){
		if(redirect(Sess, a->sp, npath) != -1)
			goto again;
	}

	if((p = strrchr(fi.name, '/')) == nil && (p = strrchr(fi.name, '\\')) == nil)
		p = fi.name;
	else
		p++;

	if(! validfile(p, name, winpath, a->sp)){
		free(npath);
		return "not found";

	}
	*qid = mkqid(npath, fi.attribs & ATTR_DIRECTORY, fi.changed, 0, 0);

	free(a->path);
	a->path = npath;
	fid->qid = *qid;
	return nil;
}
Example #3
0
int 
handleclient(int conn) 
{
	char *basedir;
	char *clientdir;
	mp3entry *mp3buf;
	FILE *stream;

	if ((stream = fdopen(conn, "r+")) == NULL || !readrequest(stream)) {
		debug(1, "error while reading client request");
		fclose(stream);
		return(EXIT_FAILURE);
	}
	
	debug(1, "requested path %s", conf.path);

	GETCWD(basedir);
	if(chdir(conf.path))
		die("incorrect dir");
	GETCWD(clientdir);
	
	debug(1, "doing security checks");
	if(strncmp(basedir, clientdir, strlen(basedir) - 1)) {
		fclose(stream);
		debug(1, "basedir %s, clientdir %s", basedir, clientdir);
		die("client tried to break out of base directory");
	}
	
	debug(1, "looking for mp3 files in subdirectory %s", conf.path);
	if(!MODE_ISSET(MODE_SINGLE)) {
		getfiles(".");
	} else if(validfile(conf.filename, clientdir, &mp3buf)) { 
		addentry(&root, mp3buf);
	}
	
	if(!root)
		die("no files");
	else
		debug(1, "%d MP3 file(s) found", countentries(root));

	if(!MODE_ISSET(MODE_INDEX) && !conf.order) {
		debug(1, "shuffling mp3 files");
		shuffleentries();
	}

	if(conf.debuglevel > 2) {
		debug(1, "listing mp3 files");
		dumpentries();
	}
	
	if(MODE_ISSET(MODE_INDEX)) {
		debug(1, "entering HTTP mode");
		fprintf(stream, HTTPSERVMSG, AMPLE_VERSION);
		fflush(stream);
		createhtml(stream,(clientdir + strlen(basedir)),(strlen(clientdir) + 1));
	} else if(MODE_ISSET(MODE_SINGLE)) {
		debug(1, "entering MP3-Single mode");
		fprintf(stream, SINGLESERVMSG, AMPLE_VERSION, root->filesize);
		fflush(stream);
		playfile(stream, root);
	} else if (MODE_ISSET(MODE_METADATA)) {
		debug(1, "entering MP3-Metadata mode");
		fprintf(stream, SHOUTSERVMSG, AMPLE_VERSION, conf.servername, BYTESBETWEENMETA);
		fflush(stream);
		playlist(stream);
	} else {
		debug(1, "entering MP3-Basic mode");
		fprintf(stream, BASICSERVMSG, AMPLE_VERSION);
		fflush(stream);
		playlist(stream);
	}

	fclose(stream);
	clearlist(root);
	return(EXIT_SUCCESS);
}