Ejemplo n.º 1
0
void bronco::serverconnection::handle_read(const boost::system::error_code &error, size_t type)
{
    /* Check if read operation resulted in error */
    if (!error) {
        /* Read OK */
        process_type(type);
    } else {
        handle_error(error);
    }
}
Ejemplo n.º 2
0
My402TransData * parse_file(char * str)
{
	// Data structure to store one line of file
	My402TransData * data;

	if(str[MAX_LINE_LENGTH] != '\0')
		print_error("one line in the file is too long");
	else
	{
		char type, timestamp[MAX_TIMESTAMP_LENGTH + 1];
		int amount;
		// status indicate which kind data currently read, 0:type; 1:timestamp; 2:amount; 3:description
		int i = 0;
		enum readStatus status = 0;

		while(str[i] != '\0')
		{
			switch(status)
			{
				case Type: // read type
					data = (My402TransData *)malloc(sizeof(My402TransData));
					if(!data)
						print_error("malloc space failed");
					i = process_type(str, i, &type);
					status++;
					data -> type = type;
					break;
				case Timestamp: // read timestamp
					i = process_timestamp(str, i, timestamp);
					status++;
					unsigned int time_value = atoi(timestamp);
					check_time(time_value);
					data -> timestamp = time_value;
					break;
				case Amount: // read amount
					i = process_amount(str, i, &amount);
					status++;
					data -> amount = amount;
					break;
				case Description: // read description
					i = process_description(str, i, data -> description);
					status++;
					break;
				default:
					print_error("parse file error");
					break;
			}
		}
	}
	return data;
}
Ejemplo n.º 3
0
int main(
    int argc,
    char **argv)
{
    char **skis;
    char inbuf[128];
    int numskis = 0;
    if (argc < 2)
        fatal("Usage: name of constraints file");
    FILE *str = fopen(argv[1], "r");
    if (!str)
        fatal("Can't open %s", argv[1]);
    FILE *tmpstr;
    char *f = "xproof.tmp";
    int i = 0;
    struct keyring keyring = { NULL, NULL, NULL };

    OPEN_LOG("proofreader", LOG_USER);

    if (!my_config_load())
    {
        LOG(LOG_ERR, "can't load configuration");
        exit(EXIT_FAILURE);
    }

    if (!(tmpstr = fopen(f, "w+")))
        fatal("Can't open %s", f);

    if (parse_SKI_blocks(&keyring, str, argv[1], inbuf, sizeof(inbuf), &i) < 0)
        fatal("Invalid line: %s", errbuf);
    fseek(str, (long)0, 0);
    *inbuf = 0;
    while (1)
    {
        if (!fgets(inbuf, sizeof(inbuf), str))
            abort();
        if (!strncmp(inbuf, "SKI ", 4))
            break;
        fputs(inbuf, tmpstr);
    }
    char *c;
    do                          // starting with first SKI line
    {
        for (c = &inbuf[4]; *c && ((*c >= '0' && *c <= '9') || *c == ':' ||
                                   (*c >= 'A' && *c <= 'F') || (*c >= 'a'
                                                                && *c <= 'f'));
             c++);
        if (c != &inbuf[63])
            fatal("Invalid line: %s", inbuf);
        while (*c == ' ' || *c == '\t')
            c++;
        if (*c != '\n')
            fatal("Invalid line: %s", inbuf);
        if (numskis)
        {
            int num;
            for (num = 0; num < numskis && strcmp(inbuf, skis[num]); num++);
            if (num < numskis)
                fatal("Duplicate SKI: %s ", &inbuf[4]);
        }
        if (!numskis)
            skis = (char **)calloc(2, sizeof(char *));
        else
            skis = (char **)realloc(skis, (sizeof(char *) * (numskis + 2)));
        skis[numskis] = calloc(1, strlen(inbuf) + 2);
        strcpy(skis[numskis], inbuf);
        numskis++;
        fputs(inbuf, tmpstr);
        // get IPv4 start
        if (!fgets(inbuf, sizeof(inbuf), str))
            fatal("Premature end of file");
        if (strcmp(inbuf, "IPv4\n"))
            fatal("Missing IPv4 line");
        fputs(inbuf, tmpstr);   // print v4 hdr
        // get first v4 line, if any
        if (!fgets(inbuf, sizeof(inbuf), str))
            fatal("Premature end of file");
        // process v4 entries, if any
        process_type(str, tmpstr, 4, inbuf, "IPv6\n");
        fputs(inbuf, tmpstr);   // print v6 hdr
        // get first v6 line, if any
        if (!fgets(inbuf, sizeof(inbuf), str))
            fatal("Premature end of file");
        process_type(str, tmpstr, 6, inbuf, "AS#\n");
        fputs(inbuf, tmpstr);   // print as# hdr
        // get first AS#, if any
        if (!(c = fgets(inbuf, sizeof(inbuf), str)))
            break;
        process_type(str, tmpstr, 8, inbuf, "SKI ");
    }
    while (*inbuf);
    if (warnings == 0)
    {
        LOG(LOG_INFO, "Finished %s OK", argv[1]);
    }
    else
    {
        LOG(LOG_ERR, "Had %d warnings. New file NOT created", warnings);
    }
    config_unload();
    CLOSE_LOG();
    return 0;
}