예제 #1
0
파일: conf.c 프로젝트: JeffHemmen/thesmurFS
void loadconf(int argc, char** argv, struct confStruct* conf) {
    char* confFile;
    char* fuse_args;
    char line[LINEBUFFER_LENGTH];
    
    conf->argv = calloc(34, sizeof(char*));     //max number of possible options
    conf->argv[0] = argv[0];
    
    if(argc == 2)
        confFile = argv[1];
    else
        confFile = CONF_FILE_DEFAULT_PATH;
    
    printf("Loading conf file \"%s\"\n", confFile);
    
    FILE *fp = fopen(confFile, "r");
    if(fp == 0) {
        fprintf(stderr, "Could not open configuration file \"%s\".\nExiting.", confFile);
        fprintf(stdout, "Could not open configuration file \"%s\".\nExiting.", confFile);
        exit(1);
    }
    
    while(fgets(line, LINEBUFFER_LENGTH, fp)) { 

        if(line == 0 || line[0] == EOF)
            break;
        if(line[0] == '#')
            continue;   //comment
        if(line[0] == 0)
            break;      //eof
        if(line[0] == 'r') {    //root dir
            conf_read_string(line+1, &(conf->rootdir));
            conf->rootdirlen = strlen(conf->rootdir);
        }
        if(line[0] == 'm') {    //mount point
            conf_read_string(line+1, &(conf->mountdir));
        }
        if(line[0] == 'x') {    //xattr namespace
            int l;
            conf_read_string(line+1, &(conf->xattr_namespace));
            l = strlen(conf->xattr_namespace);
            conf->xattr_name = calloc(l+5, sizeof(char));
            memcpy(conf->xattr_name, conf->xattr_namespace, l);
            memcpy(conf->xattr_name+l, ".hash", 5);
            conf->xattr_name[l+5] = 0;   //calloc takes care of this but better be safe
        }
        if(line[0] == 'l') {
            conf_read_string(line+1, &(conf->logpath));
        }
        if(line[0] == 'f') {
            conf_read_string(line+1, &fuse_args);
        }
    }
    
    tokenise_fuse_args(conf, fuse_args);       //needs fuse_args AND conf->mountdir to be set!
    
    
    //testing...
    /*conf->mountdir = "/home/jeff/thesmurFS";
    conf->mountdir_mod = S_IRWXU;
        
    conf->rootdir  = "/home/jeff/.thesmurFS/data";
    conf->rootdirlen = 26;
    
    conf->argc = 3;
    conf->argv = (char**) calloc(conf->argc*sizeof(char*), 1);
    conf->argv[0] = argv[0];
    conf->argv[1] = "-d";
    conf->argv[2] = conf->mountdir;
    
    conf->xattr_namespace = "user.lu.citrusfruit.thesmurFS";
    conf->xattr_name = "user.lu.citrusfruit.thesmurFS.hash";
    
    conf->logpath = "/home/jeff/.thesmurFS/log";
    */
    fprintf(stdout, "Configuration file loaded...!\n");
    dump_conf(conf);
    printf("%s|\n", fuse_args);
}
예제 #2
0
void parse(int fd, wchar_t* buf, char* dir)
{
    /* word word */

    CorpusInfo *corpus = NULL;
    wchar_t *ptr;
    int direction = 0;
    nat_boolean_t exact_match = FALSE;
    nat_boolean_t both = FALSE;
    wchar_t words[50][150];
    int i = 0; 
    wchar_t *token = NULL;
    char tmp[150];
		
    chomp(buf);

    for (i=0;i<50;i++)
        wcscpy(words[i], L"");
    i = 0;

    if (wcscmp(buf, L"") == 0) return;

#if DEBUG
    LOG("Request was [%s]", buf);
#endif

    token = wcstok(buf, L" ", &ptr);
    while(token) {
    	wcscpy(words[i], token);
    	i++;
    	token = wcstok(NULL, L" ", &ptr);
    }

    if (wcsncmp(words[0], L"LIST", 4) == 0) {
    	dump_corpora_list(fd, LAST_CORPORA, CORPORA);
    	return;
    } else if (wcsncmp(words[0], L"??", 2) == 0) {
        dump_all_conf(get_corpus(atoi((char*)words[1])), fd);
        return;
    } else if (wcsncmp(words[0], L"?", 1) == 0) {
        sprintf(tmp, "%ls", words[2]);
    	dump_conf(get_corpus(atoi((char*)words[1])), fd, tmp);
    	return;
    } else if (wcsncmp(words[0], L"~>", 2) == 0) {
    	corpus = get_corpus(atoi((char*)words[1]));
    	dump_dict_w(fd, words[2], 1, corpus);
    	return;
    } else if (wcsncmp(words[0], L"~#>", 3) == 0) {
    	corpus = get_corpus(atoi((char*)words[1]));
    	dump_dict_n(fd, words[2], 1, corpus);
    	return;
    } else if (wcsncmp(words[0], L"<~", 2) == 0) {
    	corpus = get_corpus(atoi((char*)words[1]));
    	dump_dict_w(fd, words[2], -1, corpus);
    	return;
    } else if (wcsncmp(words[0], L"<#~", 3) == 0) {
    	corpus = get_corpus(atoi((char*)words[1]));
    	dump_dict_n(fd, words[2], -1, corpus);
    	return;
    } else if (wcsncmp(words[0], L"<->", 3) == 0) {
    	direction = 1;
    	both = TRUE;
    	exact_match = FALSE;

    	corpus = get_corpus(atoi((char*)words[1]));
    	dump_conc(fd, corpus, direction, both, exact_match, words, i);
    } else if (wcsncmp(words[0], L"<=>", 3) == 0) {
    	direction = 1;
    	both = TRUE;
    	exact_match = TRUE;

    	corpus = get_corpus(atoi((char*)words[1]));
    	dump_conc(fd, corpus, direction, both, exact_match, words, i);
    } else if (wcsncmp(words[0], L"<-", 2) == 0) {
    	direction = -1;
    	both = FALSE;
    	exact_match = FALSE;

    	corpus = get_corpus(atoi((char*)words[1]));
    	dump_conc(fd, corpus, direction, both, exact_match, words, i);
    } else if (wcsncmp(words[0], L"->", 2) == 0) {
    	direction = 1;
    	both = FALSE;
    	exact_match = FALSE;

    	corpus = get_corpus(atoi((char*)words[1]));
    	dump_conc(fd, corpus, direction, both, exact_match, words, i);
    } else if (wcsncmp(words[0], L"<=", 2) == 0) {
    	direction = -1;
    	both = FALSE;
    	exact_match = TRUE;

    	corpus = get_corpus(atoi((char*)words[1]));
    	dump_conc(fd, corpus, direction, both, exact_match, words, i);
    } else if (wcsncmp(words[0], L"=>", 2) == 0) {
    	direction = 1;
    	both = FALSE;
    	exact_match = TRUE;

    	corpus = get_corpus(atoi((char*)words[1]));
    	dump_conc(fd, corpus, direction, both, exact_match, words, i);
    } else if (wcsncmp(words[0], L":>", 2) == 0) {
        direction = 1;
        corpus = get_corpus(atoi((char*)words[1]));
        dump_ngrams(fd, corpus, direction, words, i );

    } else if (wcsncmp(words[0], L"<:", 2) == 0) {
        direction = -1;
        corpus = get_corpus(atoi((char*)words[1]));
        dump_ngrams(fd, corpus, direction, words, i );

    } else if (wcsncmp(words[0], L"GET", 3) == 0) {
    	LOG("Playing http server");
    	play(fd);
    	return;
    } else {
    	ERROR(fd);
    }

}