Esempio n. 1
0
		extern int versioncheck_load(char const * filename)
		{
			std::FILE *	    fp;
			unsigned int    line;
			unsigned int    pos;
			char *	    buff;
			char *	    temp;
			char const *    eqn;
			char const *    mpqfile;
			char const *    archtag;
			char const *    clienttag;
			char const *    exeinfo;
			char const *    versionid;
			char const *    gameversion;
			char const *    checksum;
			char const *    versiontag;
			t_versioninfo * vi;

			if (!filename)
			{
				eventlog(eventlog_level_error, __FUNCTION__, "got NULL filename");
				return -1;
			}

			if (!(versioninfo_head = list_create()))
			{
				eventlog(eventlog_level_error, __FUNCTION__, "could create list");
				return -1;
			}
			if (!(fp = std::fopen(filename, "r")))
			{
				eventlog(eventlog_level_error, __FUNCTION__, "could not open file \"%s\" for reading (std::fopen: %s)", filename, std::strerror(errno));
				list_destroy(versioninfo_head);
				versioninfo_head = NULL;
				return -1;
			}

			line = 1;
			for (; (buff = file_get_line(fp)); line++)
			{
				for (pos = 0; buff[pos] == '\t' || buff[pos] == ' '; pos++);
				if (buff[pos] == '\0' || buff[pos] == '#')
				{
					continue;
				}
				if ((temp = std::strrchr(buff, '#')))
				{
					unsigned int len;
					unsigned int endpos;

					*temp = '\0';
					len = std::strlen(buff) + 1;
					for (endpos = len - 1; buff[endpos] == '\t' || buff[endpos] == ' '; endpos--);
					buff[endpos + 1] = '\0';
				}

				if (!(eqn = next_token(buff, &pos)))
				{
					eventlog(eventlog_level_error, __FUNCTION__, "missing eqn near line %u of file \"%s\"", line, filename);
					continue;
				}
				line++;
				if (!(mpqfile = next_token(buff, &pos)))
				{
					eventlog(eventlog_level_error, __FUNCTION__, "missing mpqfile near line %u of file \"%s\"", line, filename);
					continue;
				}
				line++;
				if (!(archtag = next_token(buff, &pos)))
				{
					eventlog(eventlog_level_error, __FUNCTION__, "missing archtag near line %u of file \"%s\"", line, filename);
					continue;
				}
				line++;
				if (!(clienttag = next_token(buff, &pos)))
				{
					eventlog(eventlog_level_error, __FUNCTION__, "missing clienttag near line %u of file \"%s\"", line, filename);
					continue;
				}
				line++;
				if (!(exeinfo = next_token(buff, &pos)))
				{
					eventlog(eventlog_level_error, __FUNCTION__, "missing exeinfo near line %u of file \"%s\"", line, filename);
					continue;
				}
				line++;
				if (!(versionid = next_token(buff, &pos)))
				{
					eventlog(eventlog_level_error, __FUNCTION__, "missing versionid near line %u of file \"%s\"", line, filename);
					continue;
				}
				line++;
				if (!(gameversion = next_token(buff, &pos)))
				{
					eventlog(eventlog_level_error, __FUNCTION__, "missing gameversion near line %u of file \"%s\"", line, filename);
					continue;
				}
				line++;
				if (!(checksum = next_token(buff, &pos)))
				{
					eventlog(eventlog_level_error, __FUNCTION__, "missing checksum near line %u of file \"%s\"", line, filename);
					continue;
				}
				line++;
				if (!(versiontag = next_token(buff, &pos)))
				{
					versiontag = NULL;
				}

				vi = (t_versioninfo*)xmalloc(sizeof(t_versioninfo));
				vi->eqn = xstrdup(eqn);
				vi->mpqfile = xstrdup(mpqfile);
				if (std::strlen(archtag) != 4)
				{
					eventlog(eventlog_level_error, __FUNCTION__, "invalid arch tag on line %u of file \"%s\"", line, filename);
					xfree((void *)vi->mpqfile); /* avoid warning */
					xfree((void *)vi->eqn); /* avoid warning */
					xfree(vi);
					continue;
				}
				if (!tag_check_arch((vi->archtag = tag_str_to_uint(archtag))))
				{
					eventlog(eventlog_level_error, __FUNCTION__, "got unknown archtag \"%s\"", archtag);
					xfree((void *)vi->mpqfile); /* avoid warning */
					xfree((void *)vi->eqn); /* avoid warning */
					xfree(vi);
					continue;
				}
				if (std::strlen(clienttag) != 4)
				{
					eventlog(eventlog_level_error, __FUNCTION__, "invalid client tag on line %u of file \"%s\"", line, filename);
					xfree((void *)vi->mpqfile); /* avoid warning */
					xfree((void *)vi->eqn); /* avoid warning */
					xfree(vi);
					continue;
				}
				if (!tag_check_client((vi->clienttag = tag_str_to_uint(clienttag))))
				{
					eventlog(eventlog_level_error, __FUNCTION__, "got unknown clienttag\"%s\"", clienttag);
					xfree((void *)vi->mpqfile); /* avoid warning */
					xfree((void *)vi->eqn); /* avoid warning */
					xfree(vi);
					continue;
				}
				if (std::strcmp(exeinfo, "NULL") == 0)
					vi->parsed_exeinfo = NULL;
				else
				{
					if (!(vi->parsed_exeinfo = parse_exeinfo(exeinfo)))
					{
						eventlog(eventlog_level_error, __FUNCTION__, "encountered an error while parsing exeinfo");
						xfree((void *)vi->mpqfile); /* avoid warning */
						xfree((void *)vi->eqn); /* avoid warning */
						xfree(vi);
						continue;
					}
				}

				vi->versionid = std::strtoul(versionid, NULL, 0);
				if (verstr_to_vernum(gameversion, &vi->gameversion) < 0)
				{
					eventlog(eventlog_level_error, __FUNCTION__, "malformed version on line %u of file \"%s\"", line, filename);
					xfree((void *)vi->parsed_exeinfo); /* avoid warning */
					xfree((void *)vi->mpqfile); /* avoid warning */
					xfree((void *)vi->eqn); /* avoid warning */
					xfree(vi);
					continue;
				}

				vi->checksum = std::strtoul(checksum, NULL, 0);
				if (versiontag)
					vi->versiontag = xstrdup(versiontag);
				else
					vi->versiontag = NULL;


				list_append_data(versioninfo_head, vi);
			}

			file_get_line(NULL); // clear file_get_line buffer
			if (std::fclose(fp) < 0)
				eventlog(eventlog_level_error, __FUNCTION__, "could not close versioncheck file \"%s\" after reading (std::fclose: %s)", filename, std::strerror(errno));

			return 0;
		}
Esempio n. 2
0
extern int autoupdate_load(char const * filename)
{
    unsigned int   line;
    unsigned int   pos;
    char *         buff;
    char *         temp;
    char const *   archtag;
    char const *   clienttag;
    char const *   mpqfile;
    char const *   versiontag;
    t_autoupdate * entry;
    
    if (!filename) {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL filename");
	return -1;
    }
    
    if (!(fp = fopen(filename,"r"))) {
	eventlog(eventlog_level_error,__FUNCTION__,"could not open file \"%s\" for reading (fopen: %s)",filename,pstrerror(errno));
	return -1;
    }

    autoupdate_head = list_create();
    
    for (line=1; (buff = file_get_line(fp)); line++) {
	for (pos=0; buff[pos]=='\t' || buff[pos]==' '; pos++);
	
	if (buff[pos]=='\0' || buff[pos]=='#') {
	    continue;
	}
	
	if ((temp = strrchr(buff,'#'))) {
	    unsigned int len;
	    unsigned int endpos;
	    
	    *temp = '\0';
	    len = strlen(buff)+1;
	    for (endpos=len-1;  buff[endpos]=='\t' || buff[endpos]==' '; endpos--);
	    buff[endpos+1] = '\0';
	}
	
	/* FIXME: use next_token instead of strtok */
	if (!(archtag = strtok(buff, " \t"))) { /* strtok modifies the string it is passed */
	    eventlog(eventlog_level_error,__FUNCTION__,"missing archtag on line %u of file \"%s\"",line,filename);
	    continue;
	}
	if (!(clienttag = strtok(NULL," \t"))) {
	    eventlog(eventlog_level_error,__FUNCTION__,"missing clienttag on line %u of file \"%s\"",line,filename);
	    continue;
	}
        if (!(versiontag = strtok(NULL, " \t"))) {
	    eventlog(eventlog_level_error,__FUNCTION__,"missing versiontag on line %u of file \"%s\"",line,filename);
	    continue;
	}
	if (!(mpqfile = strtok(NULL," \t"))) {
	    eventlog(eventlog_level_error,__FUNCTION__,"missing mpqfile on line %u of file \"%s\"",line,filename);
	    continue;
	}

	entry = (t_autoupdate*)xmalloc(sizeof(t_autoupdate));
	
	if (!tag_check_arch((entry->archtag = tag_str_to_uint(archtag)))) {
	    eventlog(eventlog_level_error,__FUNCTION__,"got unknown archtag");
	    xfree(entry);
	    continue;
	}
	if (!tag_check_client((entry->clienttag = tag_str_to_uint(clienttag)))) {
	    eventlog(eventlog_level_error,__FUNCTION__,"got unknown clienttag");
	    xfree(entry);
	    continue;
	}
	entry->versiontag = xstrdup(versiontag);
	entry->mpqfile = xstrdup(mpqfile);

	eventlog(eventlog_level_debug,__FUNCTION__,"update '%s' version '%s' with file %s",clienttag,versiontag,mpqfile);
	
	list_append_data(autoupdate_head,entry);
    }
    file_get_line(NULL); // clear file_get_line buffer
    fclose(fp);
    return 0;
}