static void
UdpHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
{
ushort proto;
char line[MAX_LINE];
char section[MAX_SECTION] = "";
char prev_name[MAX_NAME] = "";
char *start;
char *end;
char *name;
char *value;
int i, linelen;
int newline = 1;
int lineno = 0;
int error = 0;
int flag = 1;
char *udpkt;
char *udppkt;
udpkt=(char *)malloc(1000*sizeof(char));
udppkt = strcpy(udpkt,(char *)pkt);
printf("receive udp packet\n");
while(flag){
end = memchr(udppkt, '\n', (size_t)len);
if( *end != '\n')
end = memchr(udppkt, '\r', (size_t)len);
if (end == NULL) {
if (len == 0)
return;
end = udppkt + len;
newline = 0;
}
linelen = min((end - udppkt) + newline, MAX_LINE);
memcpy(line, udppkt, linelen);
if (linelen < MAX_LINE)
line[linelen] = '\0';
/* prepare the mem vars for the next call */
len -= (end - udppkt) + newline;
udppkt += (end - udppkt) + newline;
lineno++;
start = lskip(rstrip(line));
loop:
if (*start && *start != ':' && *start != '[' && *start != '#') {
/* Not a comment, must be a name[=:]value pair */
end = find_char_or_comment(start, '=');
if (*end != '=')
end = find_char_or_comment(start, ':');
if (*end == '=' || *end == ':') {
*end = '\0';
name = rstrip(start);
value = lskip(end + 1);
end = find_char_or_comment(value, ';');
if(*end == ';'){ //batch cmd
*end = '\0';
end = find_char_or_comment(value, '\0');
rstrip(value);
/* Strip double-quotes */
if (value[0] == '"' &&
value[strlen(value)-1] == '"') {
value[strlen(value)-1] = '\0';
value += 1;
}
/*
* Valid name[=:]value pair found, call handler
*/
strncpy0(prev_name, name, sizeof(prev_name));
printf("start %d line:%s %s\n",lineno, name, value);
if (inifile_handler(section, section, name, value) &&
!error){
start = ++end;
goto loop;
}
else
error = lineno;
}
else{
end = find_char_or_comment(value, '\0');
rstrip(value);
/* Strip double-quotes */
if (value[0] == '"' &&
value[strlen(value)-1] == '"') {
value[strlen(value)-1] = '\0';
value += 1;
}
/*
* Valid name[=:]value pair found, call handler
*/
strncpy0(prev_name, name, sizeof(prev_name));
printf("start %d line:%s\n",lineno, value);
if (!inifile_handler(section, section, name, value) &&
!error)
error = lineno;
}
}
else if (!error){
/* No '=' or ':' found on name[=:]value line */
error = lineno;
}
}
else if ((*start == ':' && start[1] == ':') || *start == '#') {
/*
* Per Python ConfigParser, allow '#' comments at start
* of line
*/
}
#if CONFIG_INI_ALLOW_MULTILINE
else if (*prev_name && *start && start > line) {
/*
* Non-blank line with leading whitespace, treat as
* continuation of previous name's value (as per Python
* ConfigParser).
*/
if (!inifile_handler(section, section, prev_name, start) && !error)
error = lineno;
}
#endif
else if (*start == '[') {
/* A "[section]" line */
end = find_char_or_comment(start + 1, ']');
if (*end == ']') {
*end = '\0';
strncpy0(section, start + 1, sizeof(section));
*prev_name = '\0';
} else if (!error) {
/* No ']' found on section line */
error = lineno;
}
}
if(error){
printf("error= %d\n", error);
break;
}
printf("%d line done\n", lineno);
}
free(udpkt);
udpkt = NULL;
if ( error ){
Upgrade_flag = UPGRADE_FAILED;
TftpNetReStartCount = 10;
}
else{
Upgrade_flag = UPGRADE_SUCCESS;
TftpNetReStartCount = 11;
}
}
|