📄 inet_msg_util.c
字号:
{
src++; /* skip over single quote, copy next always */
}
*dst++ = *src++; /* copy character */
}
}
*dst = '\0'; /* tie off string */
}
return ret; /* return our string */
}
/*****************************************************************************
* FUNCTION
* inet_msg_mime_skipws
* DESCRIPTION
* This function is called to skip white spaces in a given string
* PARAMETERS
* s [IN/OUT] Double pointer to the string in which
* RETURNS
* void
*****************************************************************************/
void inet_msg_mime_skipws(kal_char **s)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
while (1)
{
if (**s == ' ' || **s == '\t')
{
++ * s; /* skip space */
}
else if ((**s != '(') || !inet_msg_mime_skip_comment(s, (kal_int32) NULL))
{
return;
}
}
}
/*****************************************************************************
* FUNCTION
* inet_msg_skipcfws
* DESCRIPTION
* This function skips CFWS, ie, space, tab, \r\n and comments.
* PARAMETERS
* s [IN]
* a(?) [IN] S
* RETURNS
* void
*****************************************************************************/
void inet_msg_skipcfws(kal_char **s)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
while (1)
{
if (**s == ' ' || **s == '\r' || **s == '\n' || **s == '\t')
{
++ * s; /* skip space & \r\n */
}
else if (**s == '(')
{
inet_msg_mime_skip_comment(s, (kal_int32) NULL);
}
else
{
/* neither space, \r\n, and comment, leave this loop */
return;
}
}
} /* end of email_skipcfws */
/*****************************************************************************
* FUNCTION
* inet_msg_skipcfws2
* DESCRIPTION
*
* PARAMETERS
* s [IN]
* RETURNS
* void
*****************************************************************************/
void inet_msg_skipcfws2(kal_char **s) /* kevin */
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
int len;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (!s || !(*s))
{
return;
}
while (1)
{
if (**s == ' ' || **s == '\r' || **s == '\n' || **s == '\t')
{
++ * s; /* skip space & \r\n */
}
else if (**s == '(')
{
inet_msg_mime_skip_comment(s, (kal_int32) NULL);
}
else
{
/* neither space, \r\n, and comment, leave this loop */
break;
}
}
if (!s || !(*s))
{
return;
}
len = strlen(*s);
if (len > 0)
{
while (*(*s + len - 1) == ' ' ||
*(*s + len - 1) == '\t' || *(*s + len - 1) == '\r' || *(*s + len - 1) == '\n' || len <= 0)
{
*(*s + len - 1) = 0x00;
len--;
}
}
} /* end of inet_msg_skipcfws2 */
/*****************************************************************************
* FUNCTION
* inet_msg_skipfws2
* DESCRIPTION
*
* PARAMETERS
* s [IN]
* RETURNS
* void
*****************************************************************************/
void inet_msg_skipfws2(kal_char **s) /* kevin */
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
int len;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (!s || !(*s))
{
return;
}
while (1)
{
if (**s == ' ' || **s == '\r' || **s == '\n' || **s == '\t')
{
++ * s; /* skip space & \r\n */
}
else
{
/* neither space, \r\n, leave this loop */
break;
}
}
if (!s || !(*s))
{
return;
}
len = strlen(*s);
if (len > 0)
{
while (*(*s + len - 1) == ' ' ||
*(*s + len - 1) == '\t' || *(*s + len - 1) == '\r' || *(*s + len - 1) == '\n' || len <= 0)
{
*(*s + len - 1) = 0x00;
len--;
}
}
} /* end of inet_msg_skipfws2 */
/*****************************************************************************
* FUNCTION
* inet_msg_mime_skip_comment
* DESCRIPTION
* This function is called to Skip some special characters
* PARAMETERS
* s [IN/OUT]
* trim [IN]
* trin(?) [IN]
* RETURNS
* void
*****************************************************************************/
kal_char *inet_msg_mime_skip_comment(kal_char **s, kal_int32 trim)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_char *ret;
kal_char *s1 = *s;
kal_char *t = NULL;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
/* skip past whitespace */
for (ret = ++s1; *ret == ' '; ret++);
do
switch (*s1)
{ /* get character of comment */
case '(': /* nested comment? */
if (!inet_msg_mime_skip_comment(&s1, (kal_int32) NULL))
{
return NULL;
}
t = --s1; /* last significant kal_uint8 at end of comment */
break;
case ')': /* end of comment? */
*s = ++s1; /* skip past end of comment */
if (trim)
{ /* if level 0, must trim */
if (t)
{
t[1] = '\0'; /* tie off comment string */
}
else
{
*ret = '\0'; /* empty comment */
}
}
return ret;
case '\\': /* quote next character? */
if (*++s1)
{ /* next character non-null? */
t = s1; /* update last significant character pointer */
break; /* all OK */
}
case '\0': /* end of string */
/* _snprintf (tmp,100,"Unterminated comment: %.80s",*s); */
INET_MSG_LOG("Unterminated comment");
**s = '\0'; /* nuke duplicate messages in case reparse */
return NULL; /* this is wierd if it happens */
case ' ': /* whitespace isn't significant */
break;
default: /* random character */
t = s1; /* update last significant character pointer */
break;
} while (s1++);
return NULL; /* impossible, but pacify lint et al */
}
/*****************************************************************************
* FUNCTION
* inet_msg_trimcfws
* DESCRIPTION
* //"abc\t" --> "abc\0".
* PARAMETERS
* s [IN] String pointer
* RETURNS
* void
*****************************************************************************/
void inet_msg_trimcfws(kal_char *s)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
while (1)
{
if (*s == ' ' || *s == '\r' || *s == '\n' || *s == '\t')
{
*s = '\0';
return;
}
else if (*s == '\0')
{
/* neither space, \r\n, and comment, leave this loop */
return;
}
else
{
s++;
}
} /* while */
} /* end of trimcfws */
/*****************************************************************************
* FUNCTION
* inet_msg_strdup
* DESCRIPTION
* This function duplicates a string.
* PARAMETERS
* mem_func [?]
* s [IN] String pointer
* RETURNS
* new string pointer
*****************************************************************************/
kal_char *inet_msg_strdup(inet_mem_func_struct *mem_func, const kal_char *s)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_char *p;
kal_uint16 l;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (!mem_func || !s || !*s)
{
return 0;
}
l = strlen(s) + 1;
p = (kal_char*) inet_malloc(mem_func, l);
if (!p)
{
return NULL;
}
kal_mem_cpy(p, s, l);
return (p);
}
/*****************************************************************************
* FUNCTION
* inet_msg_struct_2_string
* DESCRIPTION
* This function is used to convert inet struct to string.
* PARAMETERS
* app_type [IN] Caller Module Id
* mem_func [?]
* header_id [IN]
* arg [?]
* uri(?) [IN] Inet_uri_struct pointer
* MEM_func(?) [IN] Memory functions
* RETURNS
* new string pointer
*****************************************************************************/
kal_char *inet_msg_struct_2_string(
kal_uint8 app_type,
inet_mem_func_struct *mem_func,
inet_header_field_enum header_id,
void *arg)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_char *buf;
kal_int32 buf_size = 0;
kal_int32 r_size = 0;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (arg == NULL || mem_func == NULL || header_id > INET_HDR_NUM)
{
return NULL;
}
if (inet_msg_get_header_pack_size(app_type, mem_func, header_id, arg, &buf_size) != INET_RESULT_OK)
{
return NULL;
}
buf_size++;
buf = (kal_char*) INET_MEM_ALLOC(buf_size);
if (inet_msg_header_pack_fn(header_id) (app_type, (void*)arg, buf, buf_size, &r_size) != INET_RESULT_OK)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -