Ejemplo n.º 1
0
OpenConnectionTask *TestingTaskFactory::createOpenConnectionTask(Model *model)
{
    if (fakeOpenConnectionTask) {
        return new Fake_OpenConnectionTask(model, newParser(model));
    } else {
        return TaskFactory::createOpenConnectionTask(model);
    }
}
Ejemplo n.º 2
0
void Console::evaluateFragment(const QString& fragment)
{
	try
	{
		parser->parseFragment(fragment);
	}
	catch (Xtreeme::ParseError* e)
	{
		std::cerr << ":: " << (const char*) QString(*e).toUtf8() << '\n';

		delete parser;
		parser = newParser();
	}
}
Ejemplo n.º 3
0
void *doSmall(void *arg) {
    bool runFlag=true;
//    char *queueName ;
    mqd_t mq;
    struct mq_attr attr;
    ssize_t len;
    struct cmdMessage buffer;
    //    char *res;

    struct linuxParser *p;

    bool ff;
    struct Small *myTable=arg;

    // This lock is held by this threads parent.
    // Once the parent has completed its setup it will release the lock, and
    // then we can continue.
    //
    pthread_mutex_lock(&lock);
    fprintf(stderr,"Started\n");

    queueName = dbLookup(myTable,"QNAME");
    if(!queueName) {
        ff=addRecord(myTable,"QNAME","/atlast");
        if(ff) {
            fprintf(stderr,"db install faulure, fatal error\n");
            exit(1);
        }
        queueName = dbLookup(myTable,"QNAME");
    }

    attr.mq_flags = 0;
    attr.mq_maxmsg = 10;
    printf("size %d\n", sizeof(struct cmdMessage));
    attr.mq_msgsize = sizeof(struct cmdMessage);
    attr.mq_curmsgs = 0;

    mq = mq_open(queueName, O_CREAT | O_RDONLY, 0644, &attr);
    if( (mqd_t)-1 == mq) {
        perror("mq_open");
        if(errno == ENOSYS) {
            fprintf(stderr,"Fatal ERROR\n");
            exit(1);
        }
    }

    mq_setattr(mq, &attr,NULL);

    p=newParser(myTable);

    setIam(p,queueName);

    while(runFlag) {
        len = mq_receive(mq, &buffer, sizeof(buffer), NULL);
        if( len < 0) {
            perror("mq_receive");
        } else {
            ff=cmdParse(p,&buffer,NULL);
        }
    }

}
Ejemplo n.º 4
0
Console::Console(Xtreeme::Database* d)
	: db(d)
	, parser(newParser())
{}
Ejemplo n.º 5
0
int main(int argc, char **argv)
{
	int compile = 0;
	
	if(argc >= 3) {
		int i;
		for(i = 2; i < argc; i++) {
			if(strcmp(argv[i-1], "-c") == 0) {
				compile = 1;
			}
		}
	}else if(argc == 2) {
		compile = 0;
	}else {
		print_help();
		return 0;
	}
	
	Parser *p = newParser(argv[argc-1]);
	TokenList *list = p->Parse(p);
	
	if(compile == 1) {
		compile_list(list);
		return 0;
	}
	
	uint16_t acc = 0;
	int memoffs = 0;
	int memsize = 0x10000;
	uint16_t *mem = malloc(sizeof(uint16_t) * memsize);
	if(!mem) {
		printf("Failed to allocate program memory! Retrying with a lower value!\n");
		
		memsize = 0x8000;
		mem = malloc(0x8000);
		if(!mem) {
			printf("Failed to allocate program memory! Bye!\n");
			return -1;
		}
	}
	
	int i;
	for(i = 0; i < memsize; i++) {
		mem[i] = 0;
	}
	
	int loopstart = 0;
	Stack *loopstack = stack_new(0x200);
	
	char input_buffer[10];
	int val;
	int ret;
	
	for(i = 0; i < list->size; i++) {
		switch(list->tokens[i]) {
			case TOKEN_PLUS:
				acc++;
				break;
			case TOKEN_MINUS:
				acc--;
				break;
			case TOKEN_RIGHT:
				if(memoffs < memsize) memoffs++;
				break;
			case TOKEN_LEFT:
				if(memoffs > 0) memoffs--;
				break;
			case TOKEN_INPUT:
				ret = scanf("%d", &val);
				
				if(ret == EOF || ret == 0) {
					printf("Invalid input!\n");
					exit(EXIT_FAILURE);
				}
				
				acc = val;
				
				break;
			case TOKEN_OUTPUT:
				printf("%d", acc);
				break;
			case TOKEN_ZERO:
				acc = 0;
				break;
			case TOKEN_WRITE:
				mem[memoffs] = acc;
				break;
			case TOKEN_READ:
				acc = mem[memoffs];
				break;
			case TOKEN_READ_ADD:
				acc += mem[memoffs];
				break;
			case TOKEN_READ_SUB:
				acc -= mem[memoffs];
				break;
			case TOKEN_LOOP_START:
				stack_push(loopstack, i);
				//find_loop(list, loopstart, &loopend);
				break;
			case TOKEN_LOOP_END:
				if(mem[memoffs] != 0) {
					i = stack_peek(loopstack);
				}
				break;
			case TOKEN_LOAD:
				memoffs = acc;
				break;
			case TOKEN_SAVE:
				acc = memoffs;
				break;
			case TOKEN_INPUT_CHAR:
				//printf(": ");
				//fgets(input_buffer, 10, stdin);
				//acc = input_buffer[0];
				acc = getchar();
				break;
			case TOKEN_OUTPUT_CHAR:
				printf("%c", acc);
				break;
		}
	}
	
	printf("\nFinished!\n");
	
	return 0;
}
Ejemplo n.º 6
0
cryptoHolder_t *
clparser(int argc, char ** argv){
	cryptoHolder_t * ans;

	if((ans = calloc(sizeof(cryptoHolder_t), 1)) == NULL)
		return NULL;

	parserADT parser = newParser(argc, argv);

	char * aOpt[4] = {"aes128", "aes192", "aes256", "des"};
	char * mOpt[4] = {"ecb", "cfb", "ofb", "cbc"};

	setArg(parser, 1, "-in", 0, 1, ARG_TYPE1, 0, NULL);
	setArg(parser, 2, "-out", 0, 1, ARG_TYPE1, 0, NULL);
	setArg(parser, 3, "-e", 0, 1, ARG_TYPE0, 0, NULL);
	setArg(parser, 4, "-d", 0, 1, ARG_TYPE0, 0, NULL);
	setArg(parser, 5, "-pass", 0, 1, ARG_TYPE1, 0, NULL);
	setArg(parser, 6, "-K", 0, 1, ARG_TYPE1, 0, NULL);
	setArg(parser, 7, "-iv", 0, 1, ARG_TYPE1, 0, NULL);
	setArg(parser, 8, "-a", 0, 1, ARG_TYPE1, 4, aOpt);
	setArg(parser, 9, "-m", 0, 1, ARG_TYPE1, 4, mOpt);
	setArg(parser, 10, "-h", 0, 1, ARG_TYPE0, 0, NULL); //help

	encryption_t encriptation = newEncryptation();

	int error = 0;
	keyIv_t keyIv = {NULL, NULL};
	passOrKey_t passOrKey = -1;
	while(!noMoreArgs(parser) && !error){
		switch (getArg(parser)) {
			case 1:
				LOG("reading source file\n");
				printf("Source file: %s\n", getValue(parser));

				if(ans->sourceFile != NULL){
					WARN("sourceFile already set\n");
					error = 1;
					break;
				}

				if((ans->sourceFile = malloc(sizeof(char) * (strlen(getValue(parser)) + 1))) == NULL) {
					ERROR("mem alloc failed\n");
					error = 1;
					break;
				}

				strcpy(ans->sourceFile, getValue(parser));
				LOG("finish reading source file\n");
				break;
			case 2:
				LOG("reading target  file\n");
				printf("Target file: %s\n", getValue(parser));

				if(ans->targetFile != NULL){
					WARN("targetFile already set\n");
					error = 1;
					break;
				}

				if((ans->targetFile = malloc(sizeof(char) * (strlen(getValue(parser)) + 1))) == NULL) {
					ERROR("mem alloc failed\n");
					error = 1;
					break;
				}
				strcpy(ans->targetFile, getValue(parser));
				LOG("finish reading target file\n");
				break;

			case 3:
				printf("Encription\n");
				if(isSetCryptoEncryptOrDecrypt(encriptation))
					error = 1;
				else
					setCryptoEncryptOrDecrypt(&encriptation, encrypOrDecrypt_encrypt);
				break;

			case 4:
				printf("Desencription\n");
				if(isSetCryptoEncryptOrDecrypt(encriptation))
					error = 1;
				else
					setCryptoEncryptOrDecrypt(&encriptation, encrypOrDecrypt_decrypt);
				break;

			case 5:
				printf("Pass: %s\n", getValue(parser));
				if(isSetCryptoPassKeyIv(encriptation) || isSetCryptoPassOrKey(encriptation)){
					error = 1;
					break;
				}

				// create the pass and set the encriptation
				passKeyIv_t passKeyIv;
				if((passKeyIv.password = malloc(sizeof(char) * (strlen(getValue(parser)) + 1))) == NULL){
					ERROR("memory alloc failed\n");
					error = 1;
					break;
				}

				passOrKey = passOrKey_pass;
				setCryptoPassOrKey(&encriptation, passOrKey);
				strcpy((char*)passKeyIv.password, getValue(parser));
				setCryptoPassKeyIv(&encriptation, passKeyIv);
				break;

			case 6:
				printf("Key: %s\n", getValue(parser));
				if(keyIv.key != NULL){
					error = 1;
					break;
				}

				if((keyIv.key = malloc(sizeof(char) * strlen(getValue(parser)) + 1)) == NULL){
					error = 1;
					break;
				}

				strcpy((char*)keyIv.key, getValue(parser));

				if(keyIv.iv != NULL){
					passKeyIv_t passKeyIv;
					passKeyIv.keyIv = keyIv;
					setCryptoPassKeyIv(&encriptation, passKeyIv);
				}
				passOrKey = passOrKey_key;
				setCryptoPassOrKey(&encriptation, passOrKey);
				break;

			case 7:
				printf("IV: %s\n", getValue(parser));
				if(keyIv.iv != NULL){
					error = 1;
					break;
				}

				if((keyIv.iv = malloc(sizeof(char) * strlen(getValue(parser)) + 1)) == NULL){
					error = 1;
					break;
				}

				strcpy((char*)keyIv.iv, getValue(parser));

				if(keyIv.key != NULL){
					passKeyIv_t passKeyIv;
					passKeyIv.keyIv = keyIv;
					setCryptoPassKeyIv(&encriptation, passKeyIv);
				}
				break;
				passOrKey = passOrKey_key;
				setCryptoPassOrKey(&encriptation, passOrKey);
			case 8:
				printf("Encription algorithm: %s\n", getValue(parser));
				if(isSetCryptoAlgorithm(encriptation))
					error = 1;
				else{
					algorithm_t alg;
					if(strcmp(getValue(parser), "aes128") == 0)
						alg = algorithm_aes128;
					else if(strcmp(getValue(parser), "aes192") == 0)
						alg = algorithm_aes192;
					else if(strcmp(getValue(parser), "aes256") == 0)
						alg = algorithm_aes256;
					else if(strcmp(getValue(parser), "des") == 0)
						alg = algorithm_des;
					else{
						error = 1;
						break;
					}
					setCryptoAlgorithm(&encriptation, alg);
				}
				break;

			case 9:
				printf("Block method: %s\n", getValue(parser));
				if(isSetCryptoCiphermode(encriptation))
					error = 1;
				else{
					ciphermode_t cipher;
					if(strcmp(getValue(parser), "ecb") == 0) {
						LOG("ciphermode is ecb\n");
						cipher = ciphermode_ecb;
					} else if(strcmp(getValue(parser), "cfb") == 0) {
						cipher = ciphermode_cfb;
						LOG("ciphermode is cfb\n");
					}else if(strcmp(getValue(parser), "ofb") == 0) {
						cipher = ciphermode_ofb;
						LOG("ciphermode is ofb\n");
					}else if(strcmp(getValue(parser), "cbc") == 0) {
						cipher = ciphermode_cbc;
						LOG("ciphermode is cbc\n");
					}else{
						error = 1;
						break;
					}
					setCryptoCiphermode(&encriptation, cipher);
				}
				break;

			case 10:
				showHelp();
				return NULL;
				break;

			default:
				error = 1;
				break;
		}
	}


	if(error){
		printf("ERROR: Argument not understood %s\n", getValue(parser));
		return NULL;
	}

	freeParser(parser);

	ans->encription = encriptation;

	return ans;
}
Ejemplo n.º 7
0
configuration_t *clparser(int argc, char ** argv) {
	configuration_t *conf;
	char *aOpt[] = {"aes128", "aes192", "aes256", "des"};
	char *mOpt[] = {"ecb", "cfb", "ofb", "cbc"};
	char *stegOpt[] = {"LSB1", "LSB4", "LSBE", "WANTED"};


	if((conf = calloc(sizeof(configuration_t),1)) == NULL){
		return NULL;
	}

	parserADT parser = newParser(argc, argv);

	setArg(parser, arg_in, "-in", 0, 1, ARG_TYPE1, 0, NULL);
	setArg(parser, arg_out, "-out", 0, 1, ARG_TYPE1, 0, NULL);
	setArg(parser, arg_porter, "-p", 0, 1, ARG_TYPE1, 0, NULL);
	setArg(parser, arg_embed, "-embed", 1, 1, ARG_TYPE0, 0, NULL);
	setArg(parser, arg_extract, "-extract", 1, 1, ARG_TYPE0, 0, NULL);
	setArg(parser, arg_pass, "-pass", 1, 1, ARG_TYPE1, 0, NULL);
	setArg(parser, arg_algorithm, "-a", 1, 1, ARG_TYPE1, SIZE_OF_ARRAY(aOpt), aOpt);
	setArg(parser, arg_ciphermode, "-m", 1, 1, ARG_TYPE1, SIZE_OF_ARRAY(mOpt) , mOpt);
	setArg(parser, arg_steg, "-steg", 1, 1, ARG_TYPE1, SIZE_OF_ARRAY(stegOpt), stegOpt);
	setArg(parser, arg_help, "-h", 1, 1, ARG_TYPE0, 0, NULL); //help

	int error = 0;
	while(!noMoreArgs(parser) && !error){
		switch(getArg(parser)){
		case arg_out:
			error = !processArg(&conf->targetFile, getValue(parser), "target file");
			break;
		case arg_in:
			error = !processArg(&conf->sourceFile, getValue(parser), "source file");
			break;
		case arg_porter:
			error = !processArg(&conf->carrierFile, getValue(parser), "carrier file");
			break;
		case arg_embed:
			if(conf->embed == steg_notSet){
				LOG("embed/extract is embed\n");
				conf->embed = steg_embed;

				if(conf->encriptation != NULL) {
					conf->encriptation->encrypOrDecrypt = encrypOrDecrypt_encrypt;
				}

			}
			else {
				printf("embed/extract already set\n");
				error = 1;
			}
			break;
		case arg_extract:
			if(conf->embed == steg_notSet){
				LOG("embed/extract is extract\n");
				conf->embed = steg_extract;

				if(conf->encriptation != NULL) {
					conf->encriptation->encrypOrDecrypt = encrypOrDecrypt_decrypt;
				}


			} else {
				printf("embed/extract already set\n");
				error = 1;
			}
			break;
		case arg_pass:
			if(!initEncrypt(conf)){
				error = 1;
			} else {
			error = !processArg((char**)&conf->encriptation->passKeyIv.password, getValue(parser), "password");
			}
			break;
		case arg_algorithm:
			if(!initEncrypt(conf)){
				error = 1;
			} else {
				algorithm_t alg = getCryptoAlgorithm(getValue(parser));
				if(alg != algorithm_none){
					setCryptoAlgorithm(conf->encriptation, alg);
				} else {
					printf("encryptation algorithm not reconized: %s\n", getValue(parser));
					error = 1;
				}
			}
			break;
		case arg_ciphermode:
			if(!initEncrypt(conf)){
				error = 1;
			} else {
				ciphermode_t cipherm = getCipherMode(getValue(parser));
				if(cipherm != ciphermode_none){
					setCryptoCiphermode(conf->encriptation, cipherm);
				} else {
					printf("ciphermode not reconized: %s\n", getValue(parser));
					error = 1;
				}
			}
			break;
		case arg_steg:
			if(conf->stegMode != stegMode_none){
				printf("steg already set\n");
				error = 1;
			} else {
				stegMode_t mode = getStegMode(getValue(parser));
				if(mode == stegMode_none){
					printf("steg mode not reconized: %s\n", getValue(parser));
					error = 1;
				} else {
					conf->stegMode = mode;
				}
			}
			break;
		case arg_help:
			showHelp();
			return NULL;
			break;
		default:
			error = 1;
			break;
		}

	}

	return conf;

}