Beispiel #1
0
/**
 * Parse the file at filename, and populate the array at n.
 * Return the number of nodes parsed on success, or -1 and set errno on
 * failure.
 */
static int parse_graph_file(char *filename, node_t *n) {

  FILE *f;
  char buf[MAX_LENGTH];
  int errno_copy;
  int id = 0;

  if ((f = fopen(filename,"r")) == NULL) {
    return -1;
  }

  while (fgets(buf, MAX_LENGTH, f) != NULL) {

    /* fgets retained the trailing newline; get rid of it */
    strtok(buf, "\n");

    if (parse_input_line(buf, id, n) == 0) {
      n++;
      id++;
    }
    else {
      return -1;
    }
  }

  /*
   * Make sure that we actually reached the end of the file, and close it.  The
   * error-handling seems a bit odd here, but it's just because we want to
   * retain any errno value that occurred during fgets rather than stomping on
   * it with a possible fclose errno value.
   */
  if (ferror(f)) {
    errno_copy = errno;
    fclose(f);  /* Ignore error; it's not what we want to report */
    errno = errno_copy;
    return -1;
  }
  if (fclose(f) == EOF) {
    return -1;
  }
  
  /* Otherwise return the number of nodes parsed */
  // printf ("the number of nodes=%d\n", id);
  return id;
  
}
Beispiel #2
0
int read_file(FILE * file, node_t * array[], int max_nodes) {
	char line[max_nodes];
	int count = 0;
    
	while (fgets(line, MAX_LENGTH, file)) {
        node_t * node = (node_t*)malloc(sizeof(node_t));
        //parse node and check that it was properly created
        if(parse_input_line(line, count, node) == 1){
            array[count] = node;
			count++;
        } else {
            perror("Could not produce node from line");
            return -1;
        }
	}
	link_nodes(array, count);
	return count;
}
Beispiel #3
0
    void process_input_line (
        CNGSObject <ngs::ReferenceSequence, ncbi::String>& ref_obj,
        char const* line, size_t line_size )
    {
        char const* key, *ref_name, *allele;
        size_t key_len, ref_name_len, allele_len, ref_pos, del_len;

        if ( parse_input_line ( line, line_size,
            & key, & key_len,
            & ref_name, & ref_name_len,
            & allele, & allele_len,
            & ref_pos, & del_len ) )
        {
            expand_variation ( ref_obj, key, key_len,
                ref_name, ref_name_len,
                ref_pos, del_len,
                allele, allele_len );
        }
    }
Beispiel #4
0
int parse_cmd_lines(_MIPD_ int argc, char* argv[], char *globalptr) {
	int len;
	u32 secret_p[17], secret_q[17];
	char public_key[0x81];
	char secret_key[0x81];

	u8   userhex[0x1000];
	char str_skypename[0x1000];
	char user_cred[0x101];

	char str_remote_skype[1024];
	char tmpdestip[1024];
	char tmpdestport[1024];

	char line1[0x1000];
	char line2[0x1000];
	
	int retcode;
	
	int fd;

	struct global_s *global;
	global=(struct global_s *)globalptr;

	memset(public_key,0,sizeof(public_key));
	memset(secret_key,0,sizeof(secret_key));



	if (argc!=2){
		printf("usege: skydirect <our public ip>\n");
		return -1;
	};

	strncpy(global->our_public_ip,argv[1],0x100);

	fd=open("a_cred.txt",O_RDONLY);
	len=read(fd,&line1,0x1000);
	close(fd);
	if (len<=0){
		if(DEBUG_LEVEL>=100) printf("file open error\n");
		return -1;
	};
	if (len>=0x1000){
		if(DEBUG_LEVEL>=100) printf("file too big\n");
		return -1;
	};
	line1[len]=0;

	parse_input_line(line1, secret_p, secret_q, (char*)&str_skypename, (char*)&user_cred);


	if(DEBUG_LEVEL>=100) printf("skypename=%s\n",str_skypename);

	show_memory(user_cred,0x100,"cred:");

	memcpy(global->CREDENTIALS,"\x00\x00\x00\x01",4);
	memcpy(global->CREDENTIALS+4,user_cred,0x100);
	global->CREDENTIALS_LEN=0x104;


	//
	fd=open("a_sendto.txt",O_RDONLY);
	len=read(fd,&line2,0x1000);
	close(fd);
	if (len<=0){
		if(DEBUG_LEVEL>=100) printf("file open error\n");
		return -1;
	};
	if (len>=0x1000){
		if(DEBUG_LEVEL>=100) printf("file too big\n");
		return -1;
	};
	line2[len]=0;

	retcode=parse_input_line2(line2, (u8 *)&userhex, (char *)&str_remote_skype, (char *)&tmpdestip, (char *)&tmpdestport);

	if(DEBUG_LEVEL>=100) show_memory(userhex,0x08,"userhex id:");

	memcpy(global->USERHEX,userhex,0x08);

	if (retcode==-1){
		printf("load parsing, at sendto file parsing error\n");
		return -1;
	};
	


	if(DEBUG_LEVEL>=100) printf("remote_skypename=%s\n",str_remote_skype);
	if(DEBUG_LEVEL>=100) printf("destip=%s\n",tmpdestip);
	if(DEBUG_LEVEL>=100) printf("destport=%s\n",tmpdestport);

	strncpy(global->user_snodeip,tmpdestip,1024);
	global->user_snodeport=atoi(tmpdestport);


	restore_user_keypair(_MIPP_ secret_p, secret_q, public_key, secret_key);


	memcpy(global->xoteg_pub,public_key,0x80);
	memcpy(global->xoteg_sec,secret_key,0x80);

	show_memory(global->xoteg_pub,0x80,"xoteg_pubkey:");
	show_memory(global->xoteg_sec,0x80,"xoteg_seckey:");

	show_memory(global->CREDENTIALS,0x104,"CREDENTIALS:");


	strcpy(global->REMOTE_NAME,str_remote_skype);

	strcat(global->CHAT_STRING,"#");
	strcat(global->CHAT_STRING,str_skypename);
	strcat(global->CHAT_STRING,"/$");
	strcat(global->CHAT_STRING,global->REMOTE_NAME);
	strcat(global->CHAT_STRING,";");
	strcat(global->CHAT_STRING,global->CHAT_RND_ID);

	strcat(global->CHAT_PEERS,global->REMOTE_NAME);
	strcat(global->CHAT_PEERS," ");
	strcat(global->CHAT_PEERS,str_skypename);


	if(DEBUG_LEVEL>=100) printf("CHAT_STRING: %s\n",global->CHAT_STRING);
    if(DEBUG_LEVEL>=100) printf("REMOTE_NAME: %s\n",global->REMOTE_NAME);
    if(DEBUG_LEVEL>=100) printf("CHAT_PEERS: %s\n",global->CHAT_PEERS);


	fd=open("a_msg.txt",O_RDONLY);
	len=read(fd,&global->MSG_TEXT,0x1000);
	close(fd);
    
	if (len<=0){
		if(DEBUG_LEVEL>=100) printf("file open error\n");
		return -1;
	};
	if (len>=0x1000){
		if(DEBUG_LEVEL>=100) printf("file too big\n");
		return -1;
	};

	global->MSG_TEXT[len]=0;

 	if(DEBUG_LEVEL>=100) printf("\nMSG_TEXT: %s\n",global->MSG_TEXT);


	return 1;
}
Beispiel #5
0
int
do_test(char *input_buf)
{
	int argc, seal_argc;
	char **argv, **argv_array;
	char *cmd;
	int i, bufsize = 512;
	char str_buf[512];
	utf8string str;
	uid_t uid;
	gid_t gid;
	int stat;

	argv = 0;

	if (parse_input_line(input_buf, &argc, &argv) == 0) {
		printf(gettext("\n"));
		return (1);
	}

	/*
	 * remember argv_array address, which is memory calloc'd by
	 * parse_input_line, so it can be free'd at the end of the loop.
	 */
	argv_array = argv;

	if (argc < 1) {
		usage();
		free(argv_array);
		return (0);
	}

	cmd = argv[0];

	if (strcmp(cmd, "str2uid") == 0) {
		if (argc < 2) {
			usage();
			free(argv_array);
			return (0);
		}
		str.utf8string_val = argv[1];
		str.utf8string_len = strlen(argv[1]);
		stat = nfs_idmap_str_uid(&str, &uid);
		printf(gettext("%d stat=%s \n"), uid, mapstat(stat));

	} else if (strcmp(cmd, "str2gid") == 0) {
		if (argc < 2) {
			usage();
			free(argv_array);
			return (0);
		}
		str.utf8string_val = argv[1];
		str.utf8string_len = strlen(argv[1]);
		stat = nfs_idmap_str_gid(&str, &gid);
		printf(gettext("%d stat=%s \n"), gid, mapstat(stat));

	} else if (strcmp(cmd, "uid2str") == 0) {
		if (argc < 2) {
			usage();
			free(argv_array);
			return (0);
		}
		uid = atoi(argv[1]);
		bzero(str_buf, bufsize);
		str.utf8string_val = str_buf;
		stat = nfs_idmap_uid_str(uid, &str);
		printf(gettext("%s stat=%s\n"), str.utf8string_val,
					mapstat(stat));

	} else if (strcmp(cmd, "gid2str") == 0) {
		if (argc < 2) {
			usage();
			free(argv_array);
			return (0);
		}
		gid = atoi(argv[1]);
		bzero(str_buf, bufsize);
		str.utf8string_val = str_buf;
		stat = nfs_idmap_gid_str(gid, &str);
		printf(gettext("%s stat=%s\n"), str.utf8string_val,
					mapstat(stat));

	} else if (strcmp(cmd, "echo") == 0) {
		for (i = 1; i < argc; i++)
			printf("%s ", argv[i]);
		printf("\n");
	} else if (strcmp(cmd, "exit") == 0 ||
		    strcmp(cmd, "quit") == 0) {
		printf(gettext("\n"));
		free(argv_array);
		return (1);

	} else
		usage();

	/* free argv array */
	free(argv_array);
	return (0);
}
Beispiel #6
0
int parse_cmd_lines(_MIPD_ int argc, char* argv[], char *globalptr) {
	int len;
	u32 secret_p[17], secret_q[17];
	char public_key[0x81];
	char secret_key[0x81];

	char str_skypename[0x1000];
	char user_cred[0x101];

	char str_remote_skype[1024];
	char tmpdestip[1024];
	char tmpdestport[1024];

	char line1[0x1000];
	char line2[0x1000];

	int fd;

	struct global_s *global;
	global=(struct global_s *)globalptr;

	memset(public_key,0,sizeof(public_key));
	memset(secret_key,0,sizeof(secret_key));


	fd=open("a_cred.txt",O_RDONLY);
	len=read(fd,&line1,0x1000);
	close(fd);
	if (len<=0){
		if(DEBUG_LEVEL>=100) printf("file open error\n");
		return -1;
	};
	if (len>=0x1000){
		if(DEBUG_LEVEL>=100) printf("file too big\n");
		return -1;
	};

	line1[len]=0;
	while(len>0){
		if (line1[len]==0x0D){
			line1[len]=0;
		};
		if (line1[len]==0x0A){
			line1[len]=0;
		};
		len--;
	}

	len=strlen(line1);

	//printf("%c %c\n",line1[len-2], line1[len-1] );

	if ( (line1[len-2]==':') && (line1[len-1]=='2') ){

		if (DEBUG_LEVEL>=100) printf("format version 2\n");

		parse_input_line_type2(line1, (char*)&public_key, (char*)&secret_key, (char*)&str_skypename, (char*)&user_cred);

		memcpy(global->xoteg_pub,public_key,0x80);
		memcpy(global->xoteg_sec,secret_key,0x80);

		show_memory(global->xoteg_pub,0x80,"xoteg_pubkey:");
		show_memory(global->xoteg_sec,0x80,"xoteg_seckey:");

	}else{

		if (DEBUG_LEVEL>=100) printf("format version 1\n");

		parse_input_line(line1, secret_p, secret_q, (char*)&str_skypename, (char*)&user_cred);

		restore_user_keypair(_MIPP_ secret_p, secret_q, public_key, secret_key);

		memcpy(global->xoteg_pub,public_key,0x80);
		memcpy(global->xoteg_sec,secret_key,0x80);

		show_memory(global->xoteg_pub,0x80,"xoteg_pubkey:");
		show_memory(global->xoteg_sec,0x80,"xoteg_seckey:");
	};




	if(DEBUG_LEVEL>=100) printf("skypename=%s\n",str_skypename);

	show_memory(user_cred,0x100,"cred:");

	memcpy(global->CREDENTIALS,"\x00\x00\x00\x01",4);
	memcpy(global->CREDENTIALS+4,user_cred,0x100);
	global->CREDENTIALS_LEN=0x104;


	//
	fd=open("a_sendto.txt",O_RDONLY);
	len=read(fd,&line2,0x1000);
	close(fd);
	if (len<=0){
		if(DEBUG_LEVEL>=100) printf("file open error\n");
		return -1;
	};
	if (len>=0x1000){
		if(DEBUG_LEVEL>=100) printf("file too big\n");
		return -1;
	};
	line2[len]=0;

	parse_input_line2(line2, (char *)&str_remote_skype, (char *)&tmpdestip, (char *)&tmpdestport);

	if(DEBUG_LEVEL>=100) printf("remote_skypename=%s\n",str_remote_skype);
	if(DEBUG_LEVEL>=100) printf("destip=%s\n",tmpdestip);
	if(DEBUG_LEVEL>=100) printf("destport=%s\n",tmpdestport);

	strncpy(global->remoteip,tmpdestip,1024);
	global->remoteport=atoi(tmpdestport);



	show_memory(global->CREDENTIALS,0x104,"CREDENTIALS:");


	strcpy(global->REMOTE_NAME,str_remote_skype);

	strcat(global->CHAT_STRING,"#");
	strcat(global->CHAT_STRING,str_skypename);
	strcat(global->CHAT_STRING,"/$");
	strcat(global->CHAT_STRING,global->REMOTE_NAME);
	strcat(global->CHAT_STRING,";");
	strcat(global->CHAT_STRING,global->CHAT_RND_ID);

	strcat(global->CHAT_PEERS,global->REMOTE_NAME);
	strcat(global->CHAT_PEERS," ");
	strcat(global->CHAT_PEERS,str_skypename);


	if(DEBUG_LEVEL>=100) printf("CHAT_STRING: %s\n",global->CHAT_STRING);
    if(DEBUG_LEVEL>=100) printf("REMOTE_NAME: %s\n",global->REMOTE_NAME);
    if(DEBUG_LEVEL>=100) printf("CHAT_PEERS: %s\n",global->CHAT_PEERS);


	fd=open("a_msg.txt",O_RDONLY);
	len=read(fd,&global->MSG_TEXT,0x1000);
	close(fd);
    
	if (len<=0){
		if(DEBUG_LEVEL>=100) printf("file open error\n");
		return -1;
	};
	if (len>=0x1000){
		if(DEBUG_LEVEL>=100) printf("file too big\n");
		return -1;
	};

	global->MSG_TEXT[len]=0;

 	if(DEBUG_LEVEL>=100) printf("\nMSG_TEXT: %s\n",global->MSG_TEXT);


	return 0;
}