Exemple #1
0
char* irc_get_mask(char *buf, char *raw) {
    char *data;
    char *seperateFrmSp;
    char *mask;
    
    if(buf == NULL)
        return buf;
    
    data = (char*)callocm(MAX_LEN, sizeof(char));
    if(data == NULL)
        return NULL;
    
    xstrcpy(data, raw, MAX_LEN);
    
    seperateFrmSp = xstrtok(data, " ", NULL);
    if(seperateFrmSp == NULL) {
        freem(data);
        return NULL;
    }
    
    xstrcpy(data, seperateFrmSp, MAX_LEN);
    mask = xstrtok(data, ":", NULL);
    if(mask == NULL) {
        freem(data);
        return NULL;
    }
    
    strcpy(buf, mask);
    
    freem(data);
    return buf;
}
Exemple #2
0
char* irc_get_nick(char *buf, char *raw) {
    char *data;
    char *seperateFrmCol;
    char *nick;
    
    if(buf == NULL)
        return buf;
    
    data = (char*)callocm(MAX_LEN, sizeof(char));
    if(data == NULL)
        return NULL;
    
    xstrcpy(data, raw, MAX_LEN);
    
    seperateFrmCol = xstrtok(data, ":", NULL);
    if(seperateFrmCol == NULL) {
        freem(data);
        return NULL;
    }
    
    strcpy(data, seperateFrmCol);
    if(strchr(data, '!') == NULL)
        nick = xstrtok(data, " ", NULL);
    else
        nick = xstrtok(data, "!", NULL);
    if(nick == NULL) {
        freem(data);
        return NULL;
    }
    
    xstrcpy(buf, nick, MAX_NICKLEN);
    
    freem(data);
    return buf;
}
Exemple #3
0
char* irc_get_cmdtype(char *buf, char *raw) {
    char *data;
    char *type;
    int pos = 0;
    
    if(buf == NULL)
        return buf;
    
    data = (char*)callocm(MAX_LEN, sizeof(char));
    if(data == NULL)
        return NULL;
    
    xstrcpy(data, raw, MAX_LEN);
    xstrtok(data, " ", &pos);
    type = xstrtok(data, " ", &pos);
    if(type == NULL) {
        freem(data);
        return NULL;
    }
    
    strcpy(buf, type);
    
    freem(data);
    return buf;
}
Exemple #4
0
char* irc_get_target(char *buf, char *raw) {  
    char *data;
    char *target;
    int pos = 0;
    
    if(buf == NULL)
        return buf;
    
    data = (char*)callocm(MAX_LEN, sizeof(char));
    if(data == NULL)
        return NULL;
    
    xstrcpy(data, raw, MAX_LEN);
    
    xstrtok(data, " ", &pos);
    xstrtok(data, " ", &pos);
    target = xstrtok(data, " ", &pos);
    if(target == NULL) {
        freem(data);
        return NULL;
    }
    
    if(*target == ':')
        target++;
    strcpy(buf, target);
    
    freem(data);
    return buf;
}
Exemple #5
0
static inline int analysisDuoWanCfg(struct redirect_conf* pstRedirectConf)
{
	srand((int)(time(0)));
	pstRedirectConf->other = (void*)malloc(sizeof(struct duowanData));
	struct duowanData* other = (struct duowanData*)pstRedirectConf->other;
	char* str =xstrtok(NULL, " \t\r\n");
	if(NULL == str)
	{
		fprintf(g_fpLog,"no verify\n");
		return -1;
	}
	char* str2;
	if(NULL==(str2 = strchr(str,'%')))
	{
		fprintf(g_fpLog,"error configure entry for duowan\n");
		return -1;
	}

	/*
	 * char* percentWord = (char*)malloc(str2-str+1);

	strncpy(percentWord,str,str2-str);
	percentWord[str2-str+1] = 0;
	
	char percentValue = atoi(percentWord);

	if(str2<=str)
	{
		fprintf(g_fpLog,"error percentValue,reconfigure the line please\n");
		return -1;
	}
	*/

	//printf("the percentValue of atoi is: \n");
	int percentValue = atoi(str);
	//printf("the percentValue of atoi is: %d\n",percentValue);
	if(percentValue > 100 || percentValue< 0)
	{
		fprintf(g_fpLog,"error percentValue,reconfigure the line please\n");
		return -1;
	}

	other->percentValue = percentValue;
	str =xstrtok(NULL, "\t\r\n");
	if(NULL == str)
	{
		fprintf(g_fpLog, "no replace URL\n");
		return -1;
	}


	other->replaceUrl = str;

	other = NULL;


//		fprintf(g_fpLog,".....................leaving analysisDuoWanCfg\n");
	return 0;

}
Exemple #6
0
/*
 * Initialize translation tables from config option "AreasXlate"
 */
static void areas_init_xlate(void)
{
    char *cf;
    unsigned char *x_a, *x_g, *p, *q;
    
    for ( cf = cf_get_string("AreasXlate", TRUE);
	  cf && *cf;
	  cf = cf_get_string("AreasXlate", FALSE) )
    {
	debug(8, "config: AreasXlate %s", cf);
	
	/* Chars in area name */
	x_a = (unsigned char *)xstrtok(cf  , " \t");
	/* Chars in newsgroup name */
	x_g = (unsigned char *)xstrtok(NULL, " \t");
	if(!x_a || !x_g)
	    return;

	/* Fill table */
	p = x_a;
	q = x_g;
	while(*p || *q)
	{
	    if(*p)
		areas_x_a[*p] = *q;
	    if(*q)
		areas_x_g[*q] = *p;
	    if(*p)
		p++;
	    if(*q)
		q++;
	}
    }
}
Exemple #7
0
static
void parseIinstr(char* commandLine, dictionary *D)
{
	Iinstr cmd;
	cmd.cmd = getCmdEnum(xstrtok(commandLine, cmd_delim));
	char * token = xstrtok(NULL, cmd_delim);
	if(token == NULL)
	{
	    fprintf(stderr, "%s: ", commandLine);
		error(E_CMD_INVALID, ACTION_PRINTMSG);
		return;
	}
	cmd.dstReg = strToRRegNum(token);
	token = xstrtok(NULL, cmd_delim);
	if(token == NULL)
	{
	    fprintf(stderr, "%s: ", commandLine);
		error(E_CMD_INVALID, ACTION_PRINTMSG);
		return;
	}
	cmd.srcReg = strToRRegNum(token);
    if(cmd.srcReg == -1 || cmd.dstReg == -1)
	{
	    fprintf(stderr, "%s: ", commandLine);
     	error(E_CMD_REG_INV, ACTION_PRINTMSG);
     	return;
	}
	token = xstrtok(NULL, cmd_delim);
	if(token == NULL)
	{
	    fprintf(stderr, "%s: ", commandLine);
		error(E_CMD_INVALID, ACTION_PRINTMSG);
		return;
	}
	cmd.immediate = atoi(token);
	if(cmd.immediate == 0)
	{
	    fprintf(stderr, "%s: ", commandLine);
	    fprintf(stderr, "Cannot parse the given string to int value\n");
	    return;
	}
    ASMinstr a;
	a.type = ITYPE;
	a.isBreakpoint = false;
	a.instr.i = cmd;
	add_node_parser(L1, a, D);
    fprintf(stdout, "I-type command: %-6.6s %6d %6d %6d\n", getCmdStr(cmd.cmd), cmd.dstReg, cmd.srcReg, cmd.immediate);

}
Exemple #8
0
static inline int analysisReplaceRegex(struct redirect_conf* pstRedirectConf)
{
	char* str =xstrtok(NULL, " \t\r\n");
	if(NULL == str)
	{
		fprintf(g_fpLog, "no match string\n");
		return -1;
	}
	char* str2 =xstrtok(NULL, " \t\r\n");
	if(NULL == str)
	{
		fprintf(g_fpLog, "no replace string\n");
		return -1;
	}
	char* str3 =xstrtok(NULL, " \t\r\n");
	pstRedirectConf->regex_incase = 0;
	if((NULL!=str3) && ('i'==*str3))
	{
		pstRedirectConf->regex_incase = 1;
	}

	struct replace_regex* replace = (struct replace_regex*)calloc(1, sizeof(struct replace_regex));
	int number = analysisRegexMatch(str, pstRedirectConf->regex_incase, replace);
	if(number < 0)
	{
		fprintf(g_fpLog, "match string error\n");
		free(replace);
		return -1;
	}
	int number2 = analysisRegexReplace(str2, replace);
	if(number2 < 0)
	{
		fprintf(g_fpLog, "replace string error\n");
		free(replace);
		return -1;
	}
	if(number2 > number)
	{
		fprintf(g_fpLog, "replace string number is too large\n");
		free(replace);
		return -1;
	}

	pstRedirectConf->other = replace;
	return 0;
}
Exemple #9
0
static
void parseRRinstr(char* commandLine, dictionary *D)
{
	Rinstr cmd;
	cmd.cmd = getCmdEnum(xstrtok(commandLine, cmd_delim));
	char * token = xstrtok(NULL, cmd_delim);
	if(token == NULL)
	{
	    fprintf(stderr, "%s: ", commandLine);
		error(E_CMD_INVALID, ACTION_PRINTMSG);
		return;
	}
	cmd.dstReg = strToRRegNum(token);
	token = xstrtok(NULL, cmd_delim);
	if(token == NULL)
	{
	    fprintf(stderr, "%s: ", commandLine);
		error(E_CMD_INVALID, ACTION_PRINTMSG);
		return;
	}
	cmd.src1Reg = strToRRegNum(token);
	token = xstrtok(NULL, cmd_delim);
	if(token == NULL)
	{
	    fprintf(stderr, "%s: ", commandLine);
		error(E_CMD_INVALID, ACTION_PRINTMSG);
		return;
	}
	cmd.src2Reg = strToRRegNum(token);
	if(cmd.src1Reg == -1 || cmd.src2Reg == -1 || cmd.dstReg == -1)
	{
	    fprintf(stderr, "%s: ", commandLine);
		fprintf(stderr, "Register invalid, not included in the FPR\n");
	}
	else
	{
		//TODO Put cmd in list
		ASMinstr a;
		a.type = RTYPE;
		a.isBreakpoint = false;
		a.instr.r = cmd;
		add_node_parser(L1, a, D);
		fprintf(stdout, "R-type command: %-6.6s %6d %6d %6d\n", getCmdStr(cmd.cmd), cmd.dstReg, cmd.src1Reg, cmd.src2Reg);
	}
}
Exemple #10
0
/*
 * Read list of aliases from LIBDIR/ALIASES file.
 *
 * Format:
 *     ALIAS	NODE	"FULL NAME"
 */
static Alias *alias_parse_line(char *buf)
{
    Alias *p;
    char *u, *n, *f;
    Node node;
    char *un, *ud;
    
    u = xstrtok(buf,  " \t");	/* User name */
    n = xstrtok(NULL, " \t");	/* FTN node */
    f = xstrtok(NULL, " \t");	/* Full name */
    if(u==NULL || n==NULL)
	return NULL;
    if(strieq(u, "include")) 
    {
	alias_do_file(n);
	return NULL;
    }
    if(f==NULL)
	return NULL;
    
    if( asc_to_node(n, &node, FALSE) == ERROR )
    {
	logit("hosts: illegal FTN address %s", n);
	return NULL;
    }
    
    p = (Alias *)xmalloc(sizeof(Alias));
    p->next     = NULL;
    p->node     = node;
    un = xstrtok(u,  "@");	/* User name */
    ud = xstrtok(NULL, " \t");	/* User domain */
    p->username = strsave(un);
    p->userdom  = ud ? strsave(ud) : NULL;
    p->fullname = strsave(f);
    
    if(p->userdom)
	debug(15, "aliases: %s@%s %s %s", p->username, p->userdom,
	      znfp1(&p->node), p->fullname);
    else
	debug(15, "aliases: %s %s %s", p->username, 
	      znfp1(&p->node), p->fullname);

    return p;
}
Exemple #11
0
static const char *
munge_menu_line(const char *buf, cachemgr_request * req)
{
    char *x;
    const char *a;
    const char *d;
    const char *p;
    char *a_url;
    char *buf_copy;
    static char html[2 * 1024];
    if (strlen(buf) < 1)
	return buf;
    if (*buf != ' ')
	return buf;
    buf_copy = x = xstrdup(buf);
    a = xstrtok(&x, '\t');
    d = xstrtok(&x, '\t');
    p = xstrtok(&x, '\t');
    a_url = xstrdup(menu_url(req, a));
    /* no reason to give a url for a disabled action */
    if (!strcmp(p, "disabled"))
	snprintf(html, sizeof(html), "<LI type=\"circle\">%s (disabled)<A HREF=\"%s\">.</A>\n", d, a_url);
    else
	/* disable a hidden action (requires a password, but password is not in squid.conf) */
    if (!strcmp(p, "hidden"))
	snprintf(html, sizeof(html), "<LI type=\"circle\">%s (hidden)<A HREF=\"%s\">.</A>\n", d, a_url);
    else
	/* disable link if authentication is required and we have no password */
    if (!strcmp(p, "protected") && !req->passwd)
	snprintf(html, sizeof(html), "<LI type=\"circle\">%s (requires <a href=\"%s\">authentication</a>)<A HREF=\"%s\">.</A>\n",
	    d, menu_url(req, "authenticate"), a_url);
    else
	/* highlight protected but probably available entries */
    if (!strcmp(p, "protected"))
	snprintf(html, sizeof(html), "<LI type=\"square\"><A HREF=\"%s\"><font color=\"#FF0000\">%s</font></A>\n",
	    a_url, d);
    /* public entry or unknown type of protection */
    else
	snprintf(html, sizeof(html), "<LI type=\"disk\"><A HREF=\"%s\">%s</A>\n", a_url, d);
    xfree(a_url);
    xfree(buf_copy);
    return html;
}
Exemple #12
0
char* config_line(char *buf, unsigned long line) {
    char *fbuf, *l;
    FILE *fptr;
    unsigned long fsize, i;
    int pos = 0;
    
    #if defined(PLATFORM_WINDOWS)
    fptr = fopen(bot.config, "r+t");
    #else
    fptr = fopen(bot.config, "r+");
    #endif
    if(!fptr) {
        make_error("Couldn't open config file.");
        return NULL;
    }
    
    fseek(fptr, 0, SEEK_END);
    fsize = ftell(fptr);
    if((fbuf = (char*)callocm((fsize+1), sizeof(char))) == NULL) {
        return NULL;
    }
    rewind(fptr);
    fread(fbuf, sizeof(char), fsize, fptr);
    fclose(fptr);
    
    if(line == 0) line++;
    
    if((l = xstrtok(fbuf, "\n", &pos)) == NULL) {
        freem(fbuf);
        return NULL;
    }
    for(i = 1;l != NULL;i++) {
        if(i == line) {
            xstrcpy(buf, l, CONF_MAX_ITEMLEN);
            freem(fbuf);
            return buf;
        }
        l = xstrtok(fbuf, "\n", &pos);
    }
    
    freem(fbuf);
    return NULL;
}
Exemple #13
0
static const char *
munge_action_line(const char *_buf, cachemgr_request * req)
{
    static char html[2 * 1024];
    char *buf = xstrdup(_buf);
    char *x = buf;
    const char *action, *description;
    char *p;

    if ((p = strchr(x, '\n')))
	*p = '\0';
    action = xstrtok(&x, '\t');
    description = xstrtok(&x, '\t');
    if (!description)
	description = action;
    if (!action)
	return "";
    snprintf(html, sizeof(html), " <a href=\"%s\">%s</a>", menu_url(req, action), description);
    return html;
}
Exemple #14
0
static const char *
munge_other_line(const char *buf, cachemgr_request * req)
{
    static const char *ttags[] =
    {"td", "th"};
    static char html[4096];
    static int table_line_num = 0;
    static int next_is_header = 0;
    int is_header = 0;
    const char *ttag;
    char *buf_copy;
    char *x, *p;
    int l = 0;
    /* does it look like a table? */
    if (!strchr(buf, '\t') || *buf == '\t') {
	/* nope, just text */
	snprintf(html, sizeof(html), "%s%s",
	    table_line_num ? "</table>\n<pre>" : "", buf);
	table_line_num = 0;
	return html;
    }
    /* start html table */
    if (!table_line_num) {
	l += snprintf(html + l, sizeof(html) - l, "</pre><table border=1 cellpadding=2 cellspacing=1>\n");
	next_is_header = 0;
    }
    /* remove '\n' */
    is_header = (!table_line_num || next_is_header) && !strchr(buf, ':') && !is_number(buf);
    ttag = ttags[is_header];
    /* record starts */
    l += snprintf(html + l, sizeof(html) - l, "<tr>");
    /* substitute '\t' */
    buf_copy = x = xstrdup(buf);
    if ((p = strchr(x, '\n')))
	*p = '\0';
    while (x && strlen(x)) {
	int column_span = 1;
	const char *cell = xstrtok(&x, '\t');
	while (x && *x == '\t') {
	    column_span++;
	    x++;
	}
	l += snprintf(html + l, sizeof(html) - l, "<%s colspan=%d align=\"%s\">%s</%s>",
	    ttag, column_span,
	    is_header ? "center" : is_number(cell) ? "right" : "left",
	    cell, ttag);
    }
    xfree(buf_copy);
    /* record ends */
    l += snprintf(html + l, sizeof(html) - l, "</tr>\n");
    next_is_header = is_header && strstr(buf, "\t\t");
    table_line_num++;
    return html;
}
Exemple #15
0
char* get_itemtok(char *buf, char* item, unsigned int tok) {
    char *retval;
    char *temp = (char*)callocm(CONF_MAX_ITEMLEN, sizeof(char));
    char *temp2 = (char*)callocm(CONF_MAX_ITEMLEN, sizeof(char));
    unsigned int i = 0, x = 0;
    int pos = 0;
    
    xstrcpy(temp, item, (CONF_MAX_ITEMLEN-1));
    strcat(temp, ":");
    
    for(i = 0;i < strlen(temp);i++) {
        if(temp[i] == ':') {
            x++;
            if(x == 2) {
                sprintf(temp2,":;%s",temp+i);
                memmove(temp+(i-1),temp2,strlen(temp2));
                x = 0;
            }
        }
        else {
            x = 0;
        }
    }
    
    if(tok == 0) tok++;
    
    retval = xstrtok(temp, ":", &pos);
    for(i = 1;retval != NULL;i++) {
        if(i == tok) {
            xstrcpy(buf, retval, CONF_MAX_ITEMLEN);
            freem(temp);
            freem(temp2);
            return buf;
        }
        retval = xstrtok(temp, ":", &pos);
    }
    
    freem(temp);
    freem(temp2);
    return NULL;
}
Exemple #16
0
char* irc_get_host(char *buf, char *raw) {
    char *data;
    char *seperateFrmSp;
    char *host;
    int pos = 0;
    
    if(buf == NULL)
        return buf;
    
    data = (char*)callocm(MAX_LEN, sizeof(char));
    if(data == NULL)
        return NULL;
    
    xstrcpy(data, raw, MAX_LEN);
    
    xstrtok(data, " ", &pos);
    seperateFrmSp = xstrtok(data, " ", &pos);
    if(seperateFrmSp == NULL) {
        freem(data);
        return NULL;
    }
    
    xstrcpy(data, seperateFrmSp, MAX_LEN);
    pos = 0;
    xstrtok(data, "@", &pos);
    host = xstrtok(data, "@", &pos);
    if(host == NULL) {
        freem(data);
        return NULL;
    }
    
    strcpy(buf, host);
    
    freem(data);
    return buf;
}
Exemple #17
0
static
void parseBinstr(char* commandLine, dictionary *D)
{
	Binstr cmd;
	cmd.cmd = getCmdEnum(xstrtok(commandLine, cmd_delim));
	char * token = xstrtok(NULL, cmd_delim);
	if(token == NULL)
	{
	    fprintf(stderr, "%s: ", commandLine);
		error(E_CMD_INVALID, ACTION_PRINTMSG);
		return;
	}
	cmd.dstReg = strToRRegNum(token);
	token = xstrtok(NULL, cmd_delim);
	if(token == NULL)
	{
	    fprintf(stderr, "%s: ", commandLine);
		error(E_CMD_INVALID, ACTION_PRINTMSG);
		return;
	}
	//cmd.br.label = malloc(sizeof(uint64_t));
	cmd.br.label = hash(strcat(token, ":"));
	//xstrcpy(cmd.br.label, token);
	//for(uint_fast16_t i=0; i<strlen(token); i++)
    //    cmd.br.label[i] = token[i];
	//strncpy(cmd.br.label, token, strlen(token));
    //TODO Put cmd in list
    ASMinstr a;
	a.type = BTYPE;
	a.isBreakpoint = false;
	a.instr.b = cmd;
	add_node_parser(L1, a, D);
    fprintf(stdout, "B-type command: %-6.6s %6d %lu\n", getCmdStr(cmd.cmd), cmd.dstReg, cmd.br.label);

    add_node(L2, a); // also adding to the list of the 2nd pass
}
Exemple #18
0
char* irc_get_servname(char *buf, char *raw) {
    char *servname;
    
    if(buf == NULL)
        return buf;
    
    if(blankstr(raw))
        return NULL;
    
    servname = (char*)callocm(256, sizeof(char));
    xstrcpy(servname, raw+1, 256);
    strcpy(buf, xstrtok(servname, " ", NULL));
    
    freem(servname);
    return buf;
}
Exemple #19
0
char* irc_get_netname(char *buf, char *raw) {
    char *netname, *str;
    
    if(buf == NULL)
        return buf;
    
    if(strstr(raw, "NETWORK=") == NULL) return NULL;
    
    netname = (char*)callocm(33, sizeof(char));
    str = strstr(raw, "NETWORK=");
    if(blankstr(str)) {
        *buf = 0;
        return buf;
    }
    xstrcpy(netname, str+8, 32);
    strcpy(buf, xstrtok(netname, " ", NULL));
    
    freem(netname);
    return buf;
}
Exemple #20
0
static inline int analysisOneConf(const char* line, struct redirect_conf* pstRedirectConf)
{
	char buffer[BUFSIZ];
	memset(buffer, '\0', BUFSIZ);
	strcpy(buffer, line);
	int rtn_code = 0;
	//get domain
	char* str = xstrtok(buffer, " \t");
	if(NULL == str)
	{
		fprintf(g_fpLog, "get domain failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
		return -1;
	}
	if(0 == strcasecmp(str, "null"))
	{
		pstRedirectConf->domain = NULL;
	}
	else
	{
		pstRedirectConf->domain = malloc(strlen(str)+1);
		strcpy(pstRedirectConf->domain, str);
	}
	//get cust
	str = xstrtok(NULL, " \t");
	if(NULL == str)
	{
		fprintf(g_fpLog, "get cult failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
		return -1;
	}
	if(0 == strcasecmp(str, "null"))
	{
		pstRedirectConf->cust = NULL;
		pstRedirectConf->cust_size = 0;
	}
	else if(0 == strcasecmp(str, "none"))
	{
		pstRedirectConf->cust = NULL;
		pstRedirectConf->cust_size = -1;
	}
	else
	{
		pstRedirectConf->cust_size = strlen(str);
		pstRedirectConf->cust = malloc(pstRedirectConf->cust_size+1);
		strcpy(pstRedirectConf->cust, str);		
	}
	//get operate
	str = xstrtok(NULL, " \t\r\n");
	if(NULL == str)
	{
		fprintf(g_fpLog, "get operate failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
		return -1;
	}
	char *ptr = strchr(str,':');
	if(ptr != NULL)
	{
		*ptr = 0;
		rtn_code = atoi(ptr+1);
		if( rtn_code >200 && rtn_code < 600 )
		{
			pstRedirectConf->return_code = atoi(ptr+1);
			log_output(1,"get return code in conf [%d]\n",pstRedirectConf->return_code);
		}
		else
		{
			fprintf(g_fpLog,"error:get no code or out of range[<200 >600][%d]\n",pstRedirectConf->return_code);
			pstRedirectConf->return_code = 0;       
		}
	}

#ifdef OUPENG
    if (0 == strcasecmp(str, OUPENG_FILTER_CHAR))
    {
        pstRedirectConf->operate = OUPENG_FILTER;    
    }
#endif

	if(0 == strcasecmp(str, IP_FILTER_CHAR))
	{
		pstRedirectConf->operate = IP_FILTER;
	}
	else if(0 == strcasecmp(str, IP_ABORT_FILTER_CHAR))
	{
		pstRedirectConf->operate = IP_ABORT_FILTER;
	}
	else if(0 == strcasecmp(str, TIME_FILTER_CHAR))
	{
		pstRedirectConf->operate = TIME_FILTER;
	}
	else if(0 == strcasecmp(str, TIME1_FILTER_CHAR))
	{
		pstRedirectConf->operate = TIME1_FILTER;
	}
	else if(0 == strcasecmp(str, TIME2_FILTER_CHAR))
	{
		pstRedirectConf->operate = TIME2_FILTER;
	}
	else if(0 == strcasecmp(str, IP_TIME_FILTER_CHAR))
	{
		pstRedirectConf->operate = IP_TIME_FILTER;
	}
	else if(0 == strcasecmp(str, IP_TIME_ABORT_FILTER_CHAR))
	{
		pstRedirectConf->operate = IP_TIME_ABORT_FILTER;
	}
	else if(0 == strcasecmp(str, KEY_FILTER_CHAR))
	{
	    pstRedirectConf->operate = KEY_FILTER; 
	}
	else if(0 == strcasecmp(str, REPLACE_HOST_FILTER_CHAR))
	{
		pstRedirectConf->operate = REPLACE_HOST_FILTER;
	}
	else if(0 == strcasecmp(str, DENY_FILTER_CHAR))
	{
		pstRedirectConf->operate = DENY_FILTER;
	}
	else if(0 == strcasecmp(str, BYPASS_FILTER_CHAR))
	{
		pstRedirectConf->operate = BYPASS_FILTER;
//		return 0;
	}
	else if(0 == strcasecmp(str, RID_QUESTION_FILTER_CHAR))
	{
		pstRedirectConf->operate = RID_QUESTION_FILTER;
		return 0;
	}
	else if(0 == strcasecmp(str, REPLACE_HOST_ALL_FILTER_CHAR))
	{
		pstRedirectConf->operate = REPLACE_HOST_ALL_FILTER;
	}
	else if(0 == strcasecmp(str, REPLACE_REGEX_FILTER_CHAR))
	{
		pstRedirectConf->operate = REPLACE_REGEX_FILTER;
		return analysisReplaceRegex(pstRedirectConf);
	}
#ifdef QQ_MUSIC
	/* add by xt for 64bit complie */
	else if(0 == strcasecmp(str, QQ_MUSIC_FILTER_CHAR))
	{
		pstRedirectConf->operate = QQ_MUSIC_FILTER;
		return analysisQQMusic(pstRedirectConf);
	}
#endif
#ifdef NNPAN
    /* add by chenqi for 99pan.com */
    else if (0 == strcasecmp(str, NINETY_NINE_CHAR))
    {
        pstRedirectConf->operate = NINETY_NINE_FILTER;
        return analysisNinetyNineCfg(pstRedirectConf);
    }
#endif
#ifdef NOKIA
    else if (0 == strcasecmp(str, NOKIA_FILTER_CHAR))
    {
        pstRedirectConf->operate = NOKIA_FILTER;
        return analysisNokiaCfg(pstRedirectConf); 
    }
#endif
	else if(0 == strcasecmp(str, MYSPACE_FILTER_CHAR)) {	
		pstRedirectConf->operate = MYSPACE_FILTER;
	}
	else if(0 == strcasecmp(str, SINA_FILTER_CHAR)) {
		/* add by xt for sina */
		pstRedirectConf->operate = SINA_FILTER;
	}
	else if(0 == strcasecmp(str, COOKIE_MD5_FILTER_CHAR)) {
		pstRedirectConf->operate = COOKIE_MD5_FILTER;
		return analyseCookieMd5Cfg(pstRedirectConf);
	}
	else if(0 == strcasecmp(str, QQ_TOPSTREAM_FILTER_CHAR)){
		pstRedirectConf->operate = QQ_TOPSTREAM_FILTER;
		return analyseQQTopStreamCfg(pstRedirectConf);
	}
    else if(0 == strcasecmp(str, TUDOU_FILTER_CHAR)){
        pstRedirectConf->operate = TUDOU_FILTER;
        return analyseTudouCfg(pstRedirectConf);
    }

#ifdef OUPENG
    else if (0 == strcasecmp(str, OUPENG_FILTER_CHAR))
    {
		pstRedirectConf->operate = OUPENG_FILTER;
		return analysisOupengCfg(pstRedirectConf);
    }
#endif
    else if (0 == strcasecmp(str, LONGYUAN_FILTER_CHAR))
    {
        pstRedirectConf->operate = LONGYUAN_FILTER;
        return analysisLongyuanCfg(pstRedirectConf);
    }
#ifdef DUOWAN
	/* add by Jiangbo.tian xt for 64bit complie */
	else if(0 == strcasecmp(str, DUOWAN_FILTER_CHAR))
	{
		pstRedirectConf->operate = DUOWAN_FILTER;
		return analysisDuoWanCfg(pstRedirectConf);
	}
#endif
#ifdef QQ_GREEN_MP3
	else if(0 == strcasecmp(str,QQ_GREEN_HIGH_PERFORM_CHAR))
	{
		pstRedirectConf->operate = QQ_GREEN_HIGH_PERFORM_FILTER;           
		fprintf(g_fpLog,"befor analysisQQGreenHighPerformCfg\n");
		return analysisQQGreenMP3Cfg(pstRedirectConf);
	}
#endif
#ifdef PPTV
    else if(0 == strcasecmp(str,PPTV_ANTIHIJACK_CHAR))
    {   
        pstRedirectConf->operate = PPTV_ANTIHIJACK_FILTER;    
        fprintf(g_fpLog,"befor analysisPPVodCfg\n");
        return analysisPPTVCfg(pstRedirectConf);
    }   
#endif
#ifdef SDO
	else if(0 == strcasecmp(str,SDO_CHAR))
	{
		pstRedirectConf->operate = SDO_FILTER;           
		fprintf(g_fpLog,"befor analysisSDOCfg\n");
		return analysisSDOCfg(pstRedirectConf);
	}
#endif

#ifdef OOYALA
	else if(0 == strcasecmp(str,OOYALA_FILTER_CHAR))
	{
		pstRedirectConf->operate = OOYALA_FILTER;
		fprintf(g_fpLog,"befor analysisOoyalaCfg\n");
		return analysisOoyalaCfg(pstRedirectConf);
	}
#endif

    // added for microsoft by chenqi
    else if (0 == strcasecmp(str,MICROSOFT_FILTER_CHAR))
    {    
        pstRedirectConf->operate = MICROSOFT_FILTER;
        fprintf(g_fpLog, "befor analysisMicrosoftCfg\n");
        return analysisMicrosoftCfg(pstRedirectConf);
    }    
    else if (0 == strcasecmp(str,MICROSOFT_MD5_FILTER_CHAR))
    {    
        pstRedirectConf->operate = MICROSOFT_MD5_FILTER;
        fprintf(g_fpLog, "befor analysisMicrosoftCfg_MD5\n");
        return analysisMicrosoftCfg_MD5(pstRedirectConf);
    }    
    // add end
#ifdef IQILU
    else if(0 == strcasecmp(str,IQILU_CHAR))	
        {
                pstRedirectConf->operate = IQILU_FILTER;
                fprintf(g_fpLog,"befor analysisIQILUCfg\n");
                return analysisIQILUCfg(pstRedirectConf);
        }
#endif
	else if(0 == strcasecmp(str,ICONV_FILTER_CHAR))
	{
		pstRedirectConf->operate = DECODE_FILTER;           
	}
	else if(0 == strcasecmp(str,LIGHTTPD_SECDOWNLOAD_FILTER_CHAR))
	{
        pstRedirectConf->operate = LIGHTTPD_SECDOWNLOAD_FILTER;           
    }
    else if(0 == strcasecmp(str,MFW_MUSIC_FILTER_CHAR))
    {   
        pstRedirectConf->operate = MFW_MUSIC_FILTER;    
        return analysisMFWMusicCfg(pstRedirectConf);
    }  
	else if(0 == strcasecmp(str, BOKECC_FILTER_CHAR))
	{
		pstRedirectConf->operate = BOKECC_FILTER;
		return analysisBokeccCfg(pstRedirectConf);
	}

    else if(0 == strcasecmp(str, MSN_FILTER_CHAR))
    {    
        pstRedirectConf->operate = MSN_DOWNLOAD_FILTER;
        return analysisMSNCfg(pstRedirectConf);
    }
    else if(0 == strcasecmp(str,MUSIC163_FILTER_CHAR))
    {
        pstRedirectConf->operate = MUSIC163_FILTER;           
        return analysis163MusicCfg(pstRedirectConf); 
    }
	else if(0 == strcasecmp(str, WANGLONG_FILTER_CHAR))
	{
		pstRedirectConf->operate = WANGLONG_FILTER;           
		return analysisWanglongCfg(pstRedirectConf);
		
	}
	else if (0 == strcasecmp(str, CWG_FILTER_CHAR))
	{
		pstRedirectConf->operate = CWG_FILTER;
		return analysisCWGCfg(pstRedirectConf);
	}
#ifdef BAID
    else if(0 == strcasecmp(str,BAIDU_XCODE_CHAR))
    {
        pstRedirectConf->operate = BAIDU_XCODE_FILTER;
        fprintf(g_fpLog,"befor analysisBaiduXcodeCfg\n");
        return analysisBaiduXcodeCfg(pstRedirectConf);
    }
#endif


	else
	{
		fprintf(g_fpLog, "operator error in conf=[%.*s]\n", (int)strlen(line)-1, line);;
		return -1;
	}
	//get key
	str = xstrtok(NULL, " \t");
	if(NULL == str)
	{
		fprintf(g_fpLog, "get key failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
		return -1;
	}
	if(0 == strcasecmp(str, "null"))
	{
		pstRedirectConf->key = NULL;
	}
	else
	{
		pstRedirectConf->key = malloc(strlen(str)+1);
		strcpy(pstRedirectConf->key, str);
	}
	//get key2
	str = xstrtok(NULL, " \t");
	if(NULL == str)
	{
		fprintf(g_fpLog, "get key2 failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
		return -1;
	}
	if(0 == strcasecmp(str, "null"))
	{
		pstRedirectConf->key2 = NULL;
	}
	else
	{
		pstRedirectConf->key2 = malloc(strlen(str)+1);
		strcpy(pstRedirectConf->key2, str);
	}
	//get md5_start
	str = xstrtok(NULL, " \t");
	if(NULL == str)
	{
		fprintf(g_fpLog, "get md5 start failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
		return -1;
	}
	pstRedirectConf->md5_start = atoi(str);
	//get md5_length
	str = xstrtok(NULL, " \t");
	if(NULL == str)
	{
		fprintf(g_fpLog, "get md5 length failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
		return -1;
	}
	pstRedirectConf->md5_length = atoi(str);
	//get decode
	str = xstrtok(NULL, " \t");
	if(NULL == str)
	{
		fprintf(g_fpLog, "get decode failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
		return -1;
	}
	pstRedirectConf->decode = atoi(str);
	log_output(3,"get decode = %d\n",pstRedirectConf->decode);
	//get replace_host
	str = xstrtok(NULL, " \t");
	if(NULL == str)
	{
		fprintf(g_fpLog, "get replace host failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
		return -1;
	}
	if(0 == strcasecmp(str, "null"))
	{
		pstRedirectConf->replace_host = NULL;
	}
	else
	{
		pstRedirectConf->replace_host = malloc(strlen(str)+1);
		strcpy(pstRedirectConf->replace_host, str);
		fprintf(g_fpLog, "get replace host %s\n", pstRedirectConf->replace_host);
	}
	//get replace_dir
	str = xstrtok(NULL, " \t");
	if(NULL == str)
	{
		fprintf(g_fpLog, "get replace dir failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
		return -1;
	}
	if(0 == strcasecmp(str, "null"))
	{
		pstRedirectConf->replace_dir = NULL;
	}
	else
	{
		pstRedirectConf->replace_dir = malloc(strlen(str)+1);
		strcpy(pstRedirectConf->replace_dir, str);
	}
	//get fail_dst
	str = xstrtok(NULL, " \t\r\n");
	if(NULL == str)
	{
		fprintf(g_fpLog, "get fail dst failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
		return -1;
	}
	if(0 == strcasecmp(str, "null"))
	{
		pstRedirectConf->fail_dst = NULL;
	}
	else
	{
		/* Fixed start: xin.yao, add code[401/403] for check failed */
		size_t n;
		int code = atoi(str);

		if (401 == code || 403 == code)
		{
			n = 3;
			pstRedirectConf->fail_dst_type = FAIL_DST_TYPE_CODE;
		}
		else
		{
			n = strlen(str);
			pstRedirectConf->fail_dst_type = FAIL_DST_TYPE_URL;
		}
		pstRedirectConf->fail_dst = malloc(n + 1);
		strncpy(pstRedirectConf->fail_dst, str, n);
		pstRedirectConf->fail_dst[n] = '\0';
		/* Fixed end: xin.yao */
	}
	/* get valid interval */
	if((TIME_FILTER==pstRedirectConf->operate) || 
		(TIME1_FILTER==pstRedirectConf->operate) ||	
		(TIME2_FILTER==pstRedirectConf->operate) ||	
		(IP_TIME_FILTER==pstRedirectConf->operate) || 
		(IP_TIME_ABORT_FILTER==pstRedirectConf->operate) ||
		(SINA_FILTER == pstRedirectConf->operate)||
		(LIGHTTPD_SECDOWNLOAD_FILTER ==  pstRedirectConf->operate))
	{
		pstRedirectConf->other = malloc(sizeof(struct valid_period));
		if(NULL == pstRedirectConf->other)
		{
			fprintf(g_fpLog, "cannot malloc\n");
			return -1;
		}
		struct valid_period* pstValidPeriod = (struct valid_period*)pstRedirectConf->other;
		//get seconds_before
		str = xstrtok(NULL, " \t");
		if(NULL == str)
		{
			fprintf(g_fpLog, "get seconds_before failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
			return -1;
		}
		if(0 == strcasecmp(str, "null"))
		{
			pstValidPeriod->seconds_before = 360*60;
		}
		else
		{
			pstValidPeriod->seconds_before = atoi(str)*60;
		}
		//get seconds_after
		str = xstrtok(NULL, " \t\r\n");
		if(NULL == str)
		{
			fprintf(g_fpLog, "get seconds_after failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
			return -1;
		}
		if(0 == strcasecmp(str, "null"))
		{
			pstValidPeriod->seconds_after = 360*60;
		}
		else
		{
			pstValidPeriod->seconds_after = atoi(str)*60;
		}
		log_output(3,"pstValidPeriod->seconds_before = %d\n",pstValidPeriod->seconds_before/60);
		log_output(3,"pstValidPeriod->seconds_after = %d\n",pstValidPeriod->seconds_after/60);

		/* add by xt for ip filter range */
		goto range_flag;
		/* end */
	}
	/* add by xt for ip filter range */
	/* get Flag */
	str = xstrtok(NULL, " \t\r\n");
	str = xstrtok(NULL, " \t\r\n");
range_flag:
	if((str = xstrtok(NULL, " \t\r\n"))) {
		if(1 == atoi(str)) 
			pstRedirectConf->range_flag = 1;
	}
	/* get cookie flag */
	if((str = xstrtok(NULL, " \t\r\n"))) 
		if(1 == atoi(str)) 
			pstRedirectConf->cookie_flag = 1;
	
	/* get cookie pass */
	if((str = xstrtok(NULL, " \t\r\n"))) 
		pstRedirectConf->cookie_pass = strtol(str, NULL, 16);
	/* end */
	return 0;
}
Exemple #21
0
int	ModuleCmd_Update(	Tcl_Interp	*interp,
                        int		 count,
                        char		*module_list[])
{
#ifdef  BEGINENV
    char	 *buf,			/** Read buffer			     **/
             *var_ptr,		/** Pointer to a variables name	     **/
             *val_ptr,		/** Pointer to a variables value     **/
             **load_list,		/** List of loaded modules	     **/
             *tmpload,		/** LOADEDMODULES contents	     **/
             *loaded,		/** Buffer for tokenization	     **/
             *filename;		/** The name of the file, where the  **/
    /** beginning environment resides    **/
    FILE	 *file;			/** Handle to read in a file	     **/
    int		  list_count = 0,
              maxlist = 16,		/** Max. number of list entries	     **/
              buffer_size = UPD_BUFSIZE;
    /** Current size of the input buffer **/
    char	 *ptr, c;		/** Read pointers and char buffer    **/

#  if BEGINENV == 99
    if (!EMGetEnv( interp,"MODULESBEGINENV")) {
        ErrorLogger( ERR_BEGINENVX, LOC, NULL);
        return( TCL_ERROR);	/** -------- EXIT (FAILURE) -------> **/
    }
#  endif
    /**
     **  Nothing loaded so far - we're ready!
     **/

    if(!(tmpload = (char *) getenv("LOADEDMODULES"))) {
        if( OK != ErrorLogger( ERR_MODULE_PATH, LOC, NULL))
            goto unwind0;
        else
            goto success0;
    }

    /**
     **  First I'll update the environment with whatever in _MODULESBEGINENV_
     **/
    filename = EMGetEnv( interp,"_MODULESBEGINENV_");
    if(filename && *filename) {

        /**
         **  Read the begining environment
         **/
        if((file = fopen( filename, "r"))) {

            if(!(buf = stringer(NULL, buffer_size, NULL )))
                if( OK != ErrorLogger( ERR_STRING, LOC, NULL))
                    goto unwind0;

            while( !feof( file)) {

                /**
                 **  Trigger on entries of the type
                 **    <variable> = <value>
                 **/
                ptr = buf;
                while( !feof( file)) {
                    if((ptr-buf) >= buffer_size-10) {	/** 10 bytes safety  **/
                        null_free((void *) &buf);
                        if(!(buf = stringer(NULL,
                                            buffer_size += UPD_BUFSIZE, NULL )))
                            if( OK != ErrorLogger( ERR_STRING, LOC, NULL))
                                goto unwind0;
                    }
                    /**
                     **  Read a character and put it into the read buffer. Check
                     **  for the lines (CR) or a terminator character ...
                     **/
                    if( '\n' == (*ptr++ = c = fgetc( file))) {
                        *ptr++ = c = '\0';
                        break;
                    }

                    if( !c)
                        break;

                } /** while **/

                /**
                 **  If there hasn't been a terminator so far, put it at the
                 **  end of the line. Therefor we've left a safety space at the
                 **  buffers end ;-)
                 **/
                if( c)
                    *ptr++ = '\0';

                /**
                 **  Now let's evaluate the read line
                 **/
                if( (var_ptr = strchr( buf, '=')) ) {
                    *var_ptr = '\0';
                    val_ptr = var_ptr+1;
                    var_ptr = buf;

                    /**
                     **  Reset the environment to the values derivered from the
                     **  _MODULESBEGINENV_.
                     **  Do not change the LOADEDMODULES variable ;-)
                     **  Do not change the TCL_LIBRARY and TK_LIBRARY also.
                     **/
                    if( strncmp( var_ptr, "LOADEDMODULES", 12) &&
                            strncmp( var_ptr, "TCL_LIBRARY", 10 ) &&
                            strncmp( var_ptr, "TK_LIBRARY", 9 )) {
                        if( !strncmp( var_ptr, "MODULEPATH", 10))
                            moduleSetenv( interp, var_ptr, val_ptr, 1);
                        else
                            EMSetEnv( interp, var_ptr, val_ptr);
                    }
                } /** if( var_ptr) **/
            } /** while **/

            /**
             **  Close the _MODULESBEGINENV_ file anf free up the read buffer.
             **/
            null_free((void *) &buf);

            if( EOF == fclose( file))
                if( OK != ErrorLogger( ERR_CLOSE, LOC, filename, NULL))
                    goto unwind0;

        } else { /** if( fopen) **/

            if( OK != ErrorLogger( ERR_OPEN, LOC, filename,_(em_reading),NULL))
                goto unwind0;

        } /** if( fopen) **/
    } /** if( filename) **/
    null_free((void *) &filename);

    /**
     **  Allocate memory for a buffer to tokenize the list of loaded modules
     **  and a list buffer
     **/
    if(!(load_list = (char**) module_malloc( maxlist*sizeof(char**))))
        if( OK != ErrorLogger( ERR_ALLOC, LOC, NULL))
            goto unwind0;

    if(!(loaded = stringer(NULL, 0, tmpload, NULL)))
        if( OK != ErrorLogger( ERR_STRING, LOC, NULL))
            goto unwind1;

    /**
     **  Tokenize and build the list
     **/
    if( *loaded) {

        for( load_list[ list_count++] = xstrtok( loaded, ":");
                load_list[ list_count-1];
                load_list[ list_count++] = xstrtok( NULL, ":") ) {

            /**
             **  Conditionally we have to double the space, we've allocated for
             **  the list
             **/

            if( list_count >= maxlist) {
                maxlist = maxlist<<1;

                if(!(load_list = (char**) module_realloc(
                                     (char *) load_list, maxlist*sizeof(char**))))
                    if( OK != ErrorLogger( ERR_ALLOC, LOC, NULL))
                        goto unwind1;

            } /** if( maxlist) **/
        } /** for **/

        /**
         **  Load all the modules in the list
         **/
        ModuleCmd_Load( interp, 1, list_count, load_list);
    }

    /**
     **  Free up what has been allocated and return on success
     **/
    null_free((void *) &loaded);
    null_free((void *) &load_list);

success0:
    return( TCL_OK);			/** -------- EXIT (SUCCESS) -------> **/

unwind1:
    null_free((void *) &load_list);
unwind0:
    null_free((void *) &filename);
#else	/* BEGINENV */
    ErrorLogger( ERR_BEGINENV, LOC, NULL);
#endif	/* !BEGINENV */
    return( TCL_ERROR);			/** -------- EXIT (FAILURE) -------> **/

} /** End of 'ModuleCmd_Update' **/
Exemple #22
0
static
void splitCommandLine(char* commandLine, int currentLine, dictionary *D)
{
	//ASMinstr cmd;
	static consecutive_labels = 0;

	char * token = xstrtok(commandLine, cmd_delim);
	//if (strIncludedInArray(token, RtypeCommands))
	if (!strcmp(token, "breakpoint"))
	{
        ASMinstr a;
        a.type = BREAKPOINT;
        a.isBreakpoint = true;
        add_node(L1, a);
                    /* ?!?!?! MAYBE add_node(L1, a); is better
                       than add_node_parser(L1, a, D) for breakpoints; */
        //add_node_parser(L1, a, D);
        fprintf(stderr, "Found breakpoint: %s\n", commandLine);
        //When there is a breakpoint in a line, anything following will be considered as comment
        return;
        //token = xstrtok(NULL, cmd_delim);
        //if (!xstrcmp(token, "arloumpes"))
        //    return;
	}
	if (isRFinstr(token))
	{
		//cmd.type = RTYPE;
		//cmd.instr.r = parseRinstr(commandLine);
		parseRinstr(commandLine, D);
	}
	//else if (strIncludedInArray(token, ItypeCommands))
	else if (isIinstr(token))
	{
		//cmd.type = ITYPE;
		//cmd.instr.i = parseIinstr(commandLine);
		parseIinstr(commandLine, D);
	}
	else if (isBinstr(token))
	{
	    parseBinstr(commandLine, D);
	}
	else if (isSDinstr(token))
        parseSDinstr(commandLine, D);
    else if (isLDinstr(token))
        parseLDinstr(commandLine, D);
    else if (isRRinstr(token))
        parseRRinstr(commandLine, D);
	else
	{
		if(token[strlen(token)-1] == ':')
		{
		    //token = strncpy(token, token, strlen(token)-2);
		    //token[strlen(token)+1] = '\0';
			fprintf(stdout, "New Label: %s\n", token); //TODO Put label in dict

            /*
            if (previouslabel != NULL) //|| isFirstLabel
            {
                //isFirstLabel = false;
                add_to_dict(D, hash(token), node_mod);
                consecutive_labels++;
            }
            else
                while(consecutive_labels > 0)
                {
                    D->e[D->entries-consecutive_labels].goto_node = D->e[D->entries].goto_node;
                    consecutive_labels--;
                }
            */

			previouslabel = (char *)malloc(sizeof(char *));
			strcpy(previouslabel, token);
			token = xstrtok(commandLine, cmd_delim);
			char lampel[MAX_LABEL_LEN];
			strcpy(lampel, token);
            if(token[0] == '0' && token[1] == 'x')
            {
                long hexLabel = 0;
                hexLabel = strtol(lampel, NULL, 16);
                if(hexLabel > 0 && hexLabel < 65535)
                    fprintf(stderr, "The label is in hexadecimal format and within the byte addressing range.\n");
            }
            strcpy(lampel, token);
		}
		else
		{
		    fprintf(stderr, "%s: ", commandLine);
			error(E_CMD_INVALID, ACTION_PRINTMSG);
		}
	}

}
int ModuleCmd_Apropos(	Tcl_Interp	*interp,
			int		 argc,
			char		*argv[])
{
    struct stat	 stats;
    char	*dirname;
    char	*modpath;		/** Buffer for the contents of the   **/
					/** environment variable MODULEPATH  **/
    int		 i, done = 0;
    char	*c;
    char	*cache_file;		/** Name of the cache file	     **/
    FILE	*cachefp = (FILE *) NULL;	/** Cache file pointer	     **/

#if WITH_DEBUGGING_MODULECMD
    ErrorLogger( NO_ERR_START, LOC, _proc_ModuleCmd_Apropos, NULL);
#endif

    /**
     **	 Ignore case ... convert all arguments to lower case
     **/
    if( sw_icase)
	for( i=0; i<argc; i++)
	    for( c=argv[ i]; c && *c; c++)
		*c = tolower( *c);

    /**
     **	 If there's no MODULEPATH defined, we cannot output anything
     **/
    if((char *) NULL == (modpath =  xgetenv( "MODULEPATH")))
	if( OK != ErrorLogger( ERR_MODULE_PATH, LOC, NULL))
	    goto unwind0;

    /**
     **	 Check whether	there's a cache file. If it is, grep for the tokens
     **	 in this file. Otherwise read all module files ...
     **/
    cache_file = apropos_cache();
    if( !sw_create && cache_file && !stat( cache_file, &stats)) {

	/**
	 **  Open the cache file
	 **/
	if((FILE *) NULL == (cachefp = fopen( cache_file, "r"))) {
	    if( OK != ErrorLogger( ERR_OPEN, LOC, cache_file, NULL))
		goto unwind1;
	
	} else {
		
	    /**
	     **	 Read the cache and close the file
	     **/
	    read_cache( argc, argv, cachefp, WHATIS_SOME);

	    if( EOF == fclose( cachefp))
		if( OK != ErrorLogger( ERR_CLOSE, LOC, cache_file, NULL))
		    goto unwind1;

	    done = 1;
	}
    }

    /**
     **	 If we're not done now, we have to scan the files
     **/
    if( !done) {

	/**
	 **  Open the cache file if neccessary
	 **/
	if( sw_create && cache_file)
	    if((FILE *) NULL == (cachefp = fopen( cache_file, "w")))
		if( OK != ErrorLogger( ERR_OPEN, LOC, cache_file, NULL))
		    goto unwind1;

	/**
	 **  Tokenize the module path string and check all dirs
	 **/
	for( dirname = xstrtok( modpath, ":");
	     dirname;
	     dirname = xstrtok( NULL, ":") ) {
	
	    if( !check_dir( dirname))
		continue;
	
	    whatis_dir( dirname, argc, argv, cachefp, WHATIS_SOME);

	} /** for **/

	/**
	 **  Close the cache file
	 **/
	if( cachefp)
	    if( EOF == fclose( cachefp))
		if( OK != ErrorLogger( ERR_CLOSE, LOC, cache_file, NULL))
		    goto unwind1;
    }

    /**
     **	 Free up what has been allocated and exit from this procedure
     **/
    null_free((void *) &modpath);

#if WITH_DEBUGGING_MODULECMD
    ErrorLogger( NO_ERR_END, LOC, _proc_ModuleCmd_Apropos, NULL);
#endif

    return( TCL_OK);

unwind1:
    null_free((void *) &modpath);
unwind0:
    return( TCL_ERROR);				/** ---- EXIT (FAILURE) ---> **/

} /** End of 'ModuleCmd_Apropos' **/
Exemple #24
0
int
main(int argc, char **argv) {
#else
int
xpath_locator(int argc, char **argv) {
#endif

    if (argc < 2) {
        fprintf(stderr, "Need to specify an input filename.\n"
            "Usage: xpath_locator file.xml xpath1 xpath2 ...\n");
        exit(1);
    }
    char *xml_filename = argv[1];

    num_xpaths = argc - 2;

    xpath_finders = (XPathFinder *) mmalloc(num_xpaths * sizeof(XPathFinder));

    for (int xpath_num = 0; xpath_num < num_xpaths; ++xpath_num) {
        xmlChar *xpath_expr = (xmlChar *) argv[xpath_num + 2];
        XPathFinder *xpath_finder = &xpath_finders[xpath_num];
        xpath_finder->original = new_string(xpath_expr);
        xpath_finder->current_level = 0;
        xpath_finder->line_number = 0;
        xpath_finder->column_number = 0;


        escape_uri_slashes(xpath_expr, TRUE);
        int num_segs = xpath_finder->num_segs = count_chars(xpath_expr, '/');

        XPathSegFinder *seg_finders = 
            (XPathSegFinder *) mmalloc(num_segs * sizeof(XPathSegFinder));
        xpath_finder->seg_finders = seg_finders;

        /* Extract each XPath segment */
        xmlChar *seg = xstrtok(xpath_expr, "/");
        int seg_num = 0;
        while (seg != NULL) {
            XPathSegFinder *seg_finder = &seg_finders[seg_num];
            seg_finder->count = 0;

            escape_uri_slashes(seg, FALSE);
            seg_finder->original = new_string(seg);

            // Get the element local name
            xmlChar *lns = starts_with(seg, (const xmlChar *) "*:") ? seg + 2 : seg;
            const xmlChar *bracket = xstrchr(seg, '[');
            if (!bracket) 
                xpath_error(xpath_num, xpath_finder, seg_num, "No bracket found");
            int local_name_len = bracket - lns;
            xmlChar *local_name = seg_finder->local_name = 
                new_string_n(lns, local_name_len);

            if (starts_with(bracket + 1, (const xmlChar *) "namespace-uri()=")) {
                const xmlChar *ns_start = bracket + 18;
                const xmlChar *ns_end = xstrchr(ns_start, '\'');
                if (!ns_end) 
                    xpath_error(xpath_num, xpath_finder, seg_num, 
                        "No end to the namespace URI");
                seg_finder->namespace_uri = new_string_n(ns_start, ns_end - ns_start);
                bracket = xstrchr(ns_end, '[');
                if (!bracket) 
                    xpath_error(xpath_num, xpath_finder, seg_num, "No position found");
            }
            else {
                seg_finder->namespace_uri = NULL;
            }

            const xmlChar *pos_start = bracket + 1;
            const xmlChar *pos_end = xstrchr(pos_start, ']');
            if (!pos_end) 
                xpath_error(xpath_num, xpath_finder, seg_num, "No closing bracket found");
            size_t pos_str_len = pos_end - pos_start;
            char pos_str[10];
            strncpy(pos_str, (const char *) pos_start, pos_str_len);
            pos_str[pos_str_len] = 0;
            seg_finder->position = strtol(pos_str, NULL, 10);
            if (seg_finder->position <= 0) 
                xpath_error(xpath_num, xpath_finder, seg_num, "Bad position argument");

            seg = xstrtok(NULL, "/");
            seg_num++;
        }
    }


    // Initialize default handler structure for SAX 2
    xmlSAXVersion(handlers, 2);
    handlers->startElementNs = my_startElementNs;
    handlers->endElementNs = my_endElementNs;

    parser_level = 0;  // [c] parser_level is safe
    int res = xmlSAXUserParseFile(handlers, NULL, xml_filename);

    // Output the results
    for (int xpath_num = 0; xpath_num < num_xpaths; ++xpath_num) {
        XPathFinder *xpath_finder = &xpath_finders[xpath_num];
        printf("%d:%d\n", xpath_finder->line_number, xpath_finder->column_number);
    }    


    for (int xpath_num = 0; xpath_num < num_xpaths; ++xpath_num) {
        XPathFinder *xpath_finder = &xpath_finders[xpath_num];
        int num_segs = xpath_finder->num_segs;
        XPathSegFinder *seg_finders = xpath_finder->seg_finders;
        for (int seg_num = 0; seg_num < num_segs; ++seg_num) {
            XPathSegFinder *seg_finder = &seg_finders[seg_num];
            ffree(seg_finder->original);
            ffree(seg_finder->local_name);
            ffree(seg_finder->namespace_uri);
        }

        ffree(xpath_finder->seg_finders);
        ffree(xpath_finder->original);
    }
    ffree(xpath_finders);

    return 0;
}
int ModuleCmd_Whatis(	Tcl_Interp	*interp,
			int		 argc,
			char		*argv[])
{
    struct stat	 stats;
    Tcl_Interp	*whatis_interp;
    Tcl_DString	 cmdbuf;
    int		 i, result = TCL_OK, done = 0;
    char	 modulefile[ MOD_BUFSIZE],
		 modulename[ MOD_BUFSIZE],
		*modpath = (char *)NULL,/** Buffer for the contents of the   **/
					/** environment variable MODULEPATH  **/
		**wptr,
		*dirname = (char *)NULL,
		*cache_file = (char *) NULL;	/** Name of the cache file   **/
    FILE	*cachefp = (FILE *) NULL;	/** Cache file pointer	     **/

#if WITH_DEBUGGING_MODULECMD
    ErrorLogger( NO_ERR_START, LOC, _proc_ModuleCmd_Whatis, NULL);
#endif

    /**
     **	 Initialize the command buffer and set up the modules flag to
     **	 'whatisonly'
     **/
    Tcl_DStringInit( &cmdbuf);
    g_flags |= M_WHATIS;

    /**
     **	 Handle each passed module file. Create a Tcl interpreter for each
     **	 module file to be handled and initialize it with custom module commands
     **/

    if ( argc) {
    /**
     **	 User provided a list of modules for ``whatis'' info
     **/
	for(i=0; i<argc && argv[i]; i++) {

	    whatis_interp = EM_CreateInterp();
	    if( TCL_OK != (result = InitializeModuleCommands( whatis_interp))) {
		EM_DeleteInterp( whatis_interp);
		result = TCL_ERROR;
		break;
	    }

	    /**
	     **	 locate the filename related to the passed module
	     **/
	    if( TCL_ERROR ==
		Locate_ModuleFile(whatis_interp,argv[i],modulename,modulefile)){
		EM_DeleteInterp( whatis_interp);
		if( OK != ErrorLogger( ERR_LOCATE, LOC, argv[i], NULL))
		    break;
		else
		    continue;
	    }

	    /**
	     **	 Print out everything that would happen if the module file were
	     **	 executed ...
	     **/
	    g_current_module = modulename;

	    cmdModuleWhatisInit();
	    result = CallModuleProcedure( whatis_interp, &cmdbuf, modulefile,
		"ModulesWhatis", 0);

	    /**
	     **	 Print the result ...
	     **/
	    if( whatis) {
		wptr = whatis;
		while( *wptr)
		    fprintf( stderr, "%-21s: %s\n", argv[i], *wptr++);
	    }

	    /**
	     **	 Remove the Tcl interpreter that has been used for printing ...
	     **/
	    EM_DeleteInterp( whatis_interp);
	    cmdModuleWhatisShut();

	} /** for **/
    } else {
       /**
	**  User wants all module ``whatis'' info
	**/

	/**
	 **  If no MODULEPATH defined, we can not output anything
	 **/
	if( !(modpath = (char *) xgetenv( "MODULEPATH")))
	    if( OK != ErrorLogger( ERR_MODULE_PATH, LOC, NULL))
		goto unwind0;

	/**
	 **  Check whether a cache file exists then list all the ``whatis'' info
	 **  Otherwise read all module files ...
	 **/
	cache_file = apropos_cache();
	if( !sw_create && cache_file && !stat( cache_file, &stats)) {

	    /**
	     **	 Open the cache file
	     **/
	    if((FILE *) NULL == (cachefp = fopen( cache_file, "r"))) {
		if( OK != ErrorLogger( ERR_OPEN, LOC, cache_file, NULL))
		    goto unwind1;
	
	    } else {
		
		/**
		 **  Read the cache and close the file
		 **/
		result = read_cache( argc, argv, cachefp, WHATIS_ALL);

		if( EOF == fclose( cachefp))
		    if( OK != ErrorLogger( ERR_CLOSE, LOC, cache_file, NULL))
			goto unwind1;

		done = 1;
	    }
	}

	/**
	 **  If we're not done now, we have to scan the files
	 **/
	 if( !done) {

	     /**
	      **  Open the cache file if neccessary
	      **/
	     if( sw_create && cache_file)
		 if((FILE *) NULL == (cachefp = fopen( cache_file, "w")))
		     if( OK != ErrorLogger( ERR_OPEN, LOC, cache_file, NULL))
			 goto unwind1;
		
	     /**
	      **  Tokenize the module path string and check all dirs
	      **/
	     for( dirname = xstrtok( modpath, ":");
		  dirname;
		  dirname = xstrtok( NULL, ":") ) {
	
		 if( !check_dir( dirname))
		     continue;
	
		 whatis_dir( dirname, argc, argv, cachefp, WHATIS_ALL);

	     } /** for **/

	     /**
	      **  Close the cache file
	      **/
	     if( cachefp)
		 if( EOF == fclose( cachefp))
		     if( OK != ErrorLogger( ERR_CLOSE, LOC, cache_file, NULL))
			 goto unwind1;
	 }
    }

    /**
     **	 Leave the 'whatis only mode', free up what has been used and return
     **/
    g_flags &= ~M_WHATIS;
    fprintf( stderr, "\n");

    Tcl_DStringFree( &cmdbuf);

    /**
     **	 Free up allocated resources
     **/
    null_free((void *) &cache_file);
    null_free((void *) &modpath);

    /**
     **	 Return on success
     **/

#if WITH_DEBUGGING_MODULECMD
    ErrorLogger( NO_ERR_END, LOC, _proc_ModuleCmd_Whatis, NULL);
#endif

    return( result);			/** --- EXIT PROCEDURE (result)  --> **/

unwind1:
    null_free((void *) &cache_file);
    null_free((void *) &modpath);
unwind0:
    return( TCL_ERROR);			/** --- EXIT PROCEDURE (FAILURE) --> **/

} /** End of 'ModuleCmd_Whatis' **/
int	ModuleCmd_List(	Tcl_Interp	*interp,
			int		 argc,
                   	char		*argv[])
{
    /**
     **  Get the list of loaded modules at first
     **/

    char	*loaded, *lmfiles;
    int		 i, count1, count2;
    char	*list[ MOD_BUFSIZE];
    char	*files[ MOD_BUFSIZE];
    char	*tmplist[ MOD_BUFSIZE], *s;
    int	  	 len;

#if WITH_DEBUGGING_MODULECMD
    ErrorLogger( NO_ERR_START, LOC, _proc_ModuleCmd_List, NULL);
#endif

    lmfiles = getLMFILES( interp);
    loaded = getenv( "LOADEDMODULES");
    
    if( !loaded || !*loaded) {
	if( sw_format & (SW_TERSE | SW_LONG | SW_HUMAN) )
	    fprintf(stderr, "No Modulefiles Currently Loaded.\n");
    } else {

	/**
	 **  Now tokenize it, form a list and print it out.
	 **/

	if( sw_format & SW_LONG ) {
	    fprintf( stderr, long_header);
	}
	if( sw_format & (SW_TERSE | SW_LONG | SW_HUMAN) )
	    fprintf( stderr, "Currently Loaded Modulefiles:\n");

	/**
	 **  LOADEDMODULES and _LMFILES_ should provide a list of loaded
	 **  modules and assigned files in the SAME ORDER
	 ** but double check, because if they aren't you will get a crash.
	 **/

	count1 = 1;
        for( list[ 0] = xstrtok( loaded, ":");
	     list[ count1] = xstrtok( NULL, ":");
	     count1++ );

	count2 = 1;
        for( files[ 0] = xstrtok( lmfiles, ":");
	     files[ count2] = xstrtok( NULL, ":");
	     count2++ );
	if (count1 != count2) {
	  ErrorLogger( ERR_ENVVAR, LOC, NULL);
	}
	  

	/**
	 **  We have to build a single list of files for each loaded entry
	 **  in order to be able to figure out the length of the directory
	 **  part
	 **/

	for( i=0; i<count1; i++) {

	    len = strlen( files[i]) - strlen( list[i]);
	    tmplist[i] = files[i];

	    /**
	     **  We have to source all relevant .modulerc and .version files
	     **  on the path
	     **/

	    s = files[i] + len;
	    while( s) {
		if( s = strchr( s, '/'))
		    *s = '\0';

		SourceRC( interp, files[i], modulerc_file);
		SourceVers( interp, files[i], list[i]);

		if( s)
		    *s++ = '/';
	    }

	    /** 
	     **  Print this guy
	     **/
	}
	print_aligned_files( interp, NULL, NULL, tmplist, count1, 1);
    }

    /**
     **  Return on success
     **/

#if WITH_DEBUGGING_MODULECMD
    ErrorLogger( NO_ERR_END, LOC, _proc_ModuleCmd_List, NULL);
#endif

    return( TCL_OK);

} /** End of 'ModuleCmd_List' **/
Exemple #27
0
// Importación de CSV a SC
int import_csv(char * fname, char d) {

    register FILE * f;
    //int pid = 0;
    //int rfd = STDOUT_FILENO;
    int r = 0, c = 0;
    char line_in[FBUFLEN];
    char line_interp[FBUFLEN] = "";    

    char * token;

    int quote = 0; // if value has '"'. ex: 12,"1234,450.00",56
    char delim[2] = ""; //strtok receives a char *, not a char
    add_char(delim, d, 0);

    //if ((f = openfile(fname, & pid, & rfd)) == NULL) {
    if ((f = fopen(fname , "r")) == NULL) {
        error("Can't read file \"%s\"", fname);
        return -1;
    }

    // recorro archivo csv
    while ( ! feof(f) && (fgets(line_in, sizeof(line_in), f) != NULL) ) {        
        // this hack is for importing file that have DOS eol
        int l = strlen(line_in);
        while (l--)
            if (line_in[l] == 0x0d) {
                line_in[l] = '\0';
                break;
            }

        // rompo la cadena por delimitador
        token = xstrtok(line_in, delim);
        c = 0;

        while( token != NULL ) {
            clean_carrier(token);
            if ( (token[0] == '\"' || quote) && (token[strlen(token)-1] != '\"' || strlen(token) == 1) ) {
                quote = 1;
                sprintf(token + strlen(token), "%s", xstrtok(NULL, ","));
                continue;
            }
            if (quote) { // elimino comillas si vengo de quote
                del_char(token, 0);
                del_char(token, strlen(token)-1);
            }
            if (isnumeric(token)) {
                sprintf(line_interp, "let %s%d=%s", coltoa(c), r, token);
            //} else if (token[0] == '"') {
            //    sprintf(line_interp, "label %s%d=\"%s\"", coltoa(c), r, token);
            } else {
                sprintf(line_interp, "label %s%d=\"%s\"", coltoa(c), r, token);
                //info("label %s%d=\"%s\"", coltoa(c), r, token);
                //get_key();
            }
            send_to_interp(line_interp);
            c++;
            quote = 0;
            token = xstrtok(NULL, ",");            
        }     
        
        r++;
    }
    
    maxrow = r-1;
    maxcol = c-1;

    auto_justify(0, maxcol, DEFWIDTH);

    //closefile(f, pid, rfd);
    fclose(f);

    EvalAll();

    return 0;
}
Exemple #28
0
/*
 * Function test
 */
int main(int argc, char *argv[])
{
    char *d, *p;
    char *last;
    int i;


    BUF_COPY(buffer, "Dies ist ein Test fuer die strtok-Funktionen\n");
    d = DELIM_WS;
    printf("String = %s", buffer);
    for(i = 0, p = strtok_r_ext(buffer, d, &last, FALSE);
	p;
	i++,   p = strtok_r_ext(NULL, d, &last, FALSE))
        printf("    %02d = [%s]\n", i, p);


    BUF_COPY(buffer, "Dies ist \"ein Test\" \"fuer die\" strtok-Funktionen\n");
    d = DELIM_WS;
    printf("String = %s", buffer);
    for(i = 0, p = strtok_r_ext(buffer, d, &last, FALSE);
	p;
	i++,   p = strtok_r_ext(NULL, d, &last, FALSE))
        printf("    %02d = [%s]\n", i, p);


    BUF_COPY(buffer, "Dies ist \"ein Test\" \"fuer die\" strtok-Funktionen\n");
    d = DELIM_WS;
    printf("String = %s", buffer);
    for(i = 0, p = strtok_r_ext(buffer, d, &last, TRUE);
	p;
	i++,   p = strtok_r_ext(NULL, d, &last, TRUE))
        printf("    %02d = [%s]\n", i, p);


    BUF_COPY(buffer, "Dies ist \"ein Test\\\" \\\"fuer die\" strtok-Funktionen\n");
    d = DELIM_WS;
    printf("String = %s", buffer);
    for(i = 0, p = strtok_r_ext(buffer, d, &last, DQUOTE);
	p;
	i++,   p = strtok_r_ext(NULL, d, &last, DQUOTE))
        printf("    %02d = [%s]\n", i, p);


    BUF_COPY(buffer, "Dies\\s ist \"ein\\1 Test\\\" \\\"fuer \\2die\" strtok-Funktionen\\n\n");
    d = DELIM_WS;
    printf("String = %s", buffer);
    for(i = 0, p = strtok_r_ext(buffer, d, &last, DQUOTE);
	p;
	i++,   p = strtok_r_ext(NULL, d, &last, DQUOTE))
        printf("    %02d = [%s]\n", i, p);


    BUF_COPY(buffer, "Dies 'ist ein Test' 'fuer die' strtok-Funktionen\n");
    d = DELIM_WS;
    printf("String = %s", buffer);
    for(i = 0, p = strtok_r_ext(buffer, d, &last, SQUOTE);
	p;
	i++,   p = strtok_r_ext(NULL, d, &last, SQUOTE))
        printf("    %02d = [%s]\n", i, p);


    BUF_COPY(buffer, "fido.de,de.answers,comp.misc.misc,alt.x.xx.xxx.xxxx");
    d = ",";
    printf("String = %s\n", buffer);
    for(i = 0, p = strtok_r_ext(buffer, d, &last, FALSE);
	p;
	i++,   p = strtok_r_ext(NULL, d, &last, FALSE))
        printf("    %02d = [%s]\n", i, p);


    BUF_COPY(buffer, "\"12,5\",\"0,9\",\"13,75\",\"0,99\",\"1,23\"");
    d = ",";
    printf("String = %s\n", buffer);
    for(i = 0, p = strtok_r_ext(buffer, d, &last, QUOTE);
	p;
	i++,   p = strtok_r_ext(NULL, d, &last, QUOTE))
        printf("    %02d = [%s]\n", i, p);


    BUF_COPY(buffer, "Dies ist \"ein Test\" \"fuer die\" strtok()-Funktion\n");
    d = DELIM_WS;
    printf("String = %s", buffer);
    for(i = 0, p = strtok(buffer, d);
	p;
	i++,   p = strtok(NULL, d))
        printf("    %02d = [%s]\n", i, p);


    BUF_COPY(buffer, "Dies ist \"ein Test\" \"fuer die\" xstrtok()-Funktion\n");
    d = DELIM_WS;
    printf("String = %s", buffer);
    for(i = 0, p = xstrtok(buffer, d);
	p;
	i++,   p = xstrtok(NULL, d))
        printf("    %02d = [%s]\n", i, p);


    BUF_COPY(buffer, "Origin\t\tDies ist ein Test\n");
    printf("String = %s", buffer);
    for(i = 0, p = xstrtok(buffer, DELIM_WS);
	p;
	i++,   p = xstrtok(NULL, DELIM_EOL))
        printf("    %02d = [%s]\n", i, p);


    BUF_COPY(buffer, "Origin\t\t\"Dies ist ein Test\"\n");
    printf("String = %s", buffer);
    for(i = 0, p = xstrtok(buffer, DELIM_WS);
	p;
	i++,   p = xstrtok(NULL, DELIM_EOL))
        printf("    %02d = [%s]\n", i, p);


    exit(0);
}
Exemple #29
0
NmeaGga::NmeaGga(string raw): NmeaBase(raw) {
//    long time_str;
    char str[100], *ptr;
    int index = 0;
    
    float lat_deg, lon_deg;
    char lat_dir, lon_dir;
    
    strncpy(str, _raw.c_str(), 100);
    
    ptr = xstrtok(str, ",");
    while (ptr != NULL) {
        switch (index++) {
            case 0:     // Type
            case 10:    // Above sea units
            case 12:    // Geo ID height unit
            case 15:    // Checksum
                break;
            case 1:     // Time
                sscanf(ptr, "%2f%2f%f", &_time[0], &_time[1], &_time[2]);
                break;
            case 2:     // Lat. degrees
                lat_deg = strtof(ptr, NULL);
                break;
            case 3:     // Lat. direction
                lat_dir = *ptr;
                break;
            case 4:     // Lon. degrees
                lon_deg = strtof(ptr, NULL);
                break;
            case 5:     // Lon. direction
                lon_dir = *ptr;
                break;
            case 6:     // Quality
                _qual = (unsigned short) strtoul(ptr, NULL, 0);
                break;
            case 7:     // Number of tracking satellites
                _num_tracking = (unsigned short) strtoul(ptr, NULL, 0);
                break;
            case 8:     // Dilution of precision
                _dilution = strtof(ptr, NULL);
                break;
            case 9:     // Height above sea-level
                _above_sea = strtof(ptr, NULL);
                break;
            case 11:    // Height of geo ID
                _geo_id_height = strtof(ptr, NULL);
                break;
            case 13:    // seconds since DGPS update
                _dgps_age = (unsigned int) strtoul(ptr, NULL, 0);
                break;
            case 14:    // DGPS station
                _dgps_id = (unsigned int) strtoul(ptr, NULL, 0);
                break;
            default:    // Only here in error
                std::cerr << "Could not parse: '" << _raw << "'" << std::endl;
                assert(0);
//                throw out_of_range("Could not parse");
                break;
        }
        ptr = xstrtok(NULL, ",");
    }
    
    _lat = degToDec(lat_deg, lat_dir);
    _lon = degToDec(lon_deg, lon_dir);
}
Exemple #30
0
static inline int analysisQQMusic(struct redirect_conf* pstRedirectConf)
{
	char* str =xstrtok(NULL, " \t\r\n");
	if(NULL == str)
	{
		fprintf(g_fpLog, "no verify\n");
		return -1;
	}
	if(0 == strcmp(str, "off"))
	{
		pstRedirectConf->md5_start = 0;
	}
	else
	{
		pstRedirectConf->md5_start = 1;
	}

	str =xstrtok(NULL, " \t\r\n");
	if(NULL == str)
	{
		fprintf(g_fpLog, "no fail_dst\n");
		return -1;
	}
	if(0 == strcasecmp(str, "null"))
	{
		pstRedirectConf->fail_dst = NULL;
	}
	else
	{
		pstRedirectConf->fail_dst = malloc(strlen(str)+1);
		strcpy(pstRedirectConf->fail_dst, str);
	}

	pstRedirectConf->decode = 0;
	pstRedirectConf->other = 0;
	str =xstrtok(NULL, " \t\r\n");
	if(NULL == str)
	{
		return 0;
	}
	if(0 != strncasecmp(str, "Referer:", 8))		//rid_question
	{
		pstRedirectConf->decode = atoi(str);
		str =xstrtok(NULL, " \t\r\n");
		if(NULL == str)
		{
			return 0;
		}
		if(0 != strncasecmp(str, "Referer:", 8))		//Referer
		{
			fprintf(g_fpLog, "no Referer\n");
			return -1;
		}
	}
	str += 8;
	if(getRefererValue(str, &pstRedirectConf->other) <= 0)
	{
		fprintf(g_fpLog, "no Referer value\n");
		return -1;
	}
	
	return 0;
}