解析CGI字符串:
NET=0&SSID=linux&KEY=&WIP1=192&WIP2=168&WIP3=144&WIP4=010&MASK1=255&MASK2=255&MASK3=255&MASK4=000&GW1=192&GW2=168&GW3=001&GW4=001&DNS1=202&DNS2=114&DNS3=134&DNS4=133&WMAC0=00&WMAC1=DF&WMAC2=24&WMAC3=6C&WMAC4=74&WMAC5=96&OK=%B1%A3%B4%E6
-
static int extract_uri_parameters(struct http_request *hs, char *params)
-
{
-
char *pair = NULL;
-
char *equals = NULL;
-
int loop;
-
-
/* If we have no parameters at all, return immediately. */
-
if(!params || (params[0] == '\0')) {
-
return(0);
-
}
-
-
if (hs->postfile) {
-
loop = 1;
-
hs->param_vals[0] = params;
-
}
-
else {
-
/* Get a pointer to our first parameter */
-
pair = params;
-
for(loop = 0; (loop < MAX_CGI_PARAMETERS) && pair; loop++) {
-
-
/* Save the name of the parameter */
-
hs->params[loop] = pair;
-
-
/* Remember the start of this name=value pair */
-
equals = pair;
-
-
pair = strchr(pair, '&');
-
if(pair) {
-
*pair = '\0';
-
pair++;
-
}
-
-
equals = strchr(equals, '=');
-
if(equals) {
-
*equals = '\0';
-
hs->param_vals[loop] = equals + 1;
-
} else {
-
hs->param_vals[loop] = NULL;
-
}
-
//DEBUGP("CGI para %d: %s = %s\n", loop, hs->params[loop], hs->param_vals[loop]);
-
}
-
}
-
-
return(loop);
-
}
t%20%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%0D%0At%20%3Croot%3E%0D%0At%20%3Cproject%20width%3D%22802%22%20height%3D%22629%22%20background%3D%221%22%2F%3E%0D%0At%20%3Citems%3E%0D%0At%20%3Citem%20itype%3D%22image%22%20device%3D%22undefined%22%20describe%3D%22undefined%22%3E%0D%0At%20%3Cimage%20x%3D%22189%22%20y%3D%22102%22%20width%3D%22100%22%20height%3D%22202%22%20href%3D%22icebox%22%2F%3E%0D%0At%20%3C%2Fitem%3E%0D%0At%20%3Citem%20itype%3D%22text%22%20device%3D%22undefined%22%20describe%3D%22undefined%22%3E%0D%0At%20%3Ctext%20%0D%0At%20textx%3D%22132%22%20texty%3D%22240%22%20text-anchor%3D%22left%22%20fontfamily%3D%22Arial%22%20%0D%0At%20fontsize%3D%2216%22%20fill%3D%22%23ffffff%22%20text%3D%22XXXXXX%22%20%2F%3E%0D%0At%20%3C%2Fitem%3E%0D%0At%20%3C%2Fitems%3E%0D%0At%20%3C%2Froot%3E%0D%0A.,
decode: len = 482, t
t
t
t -
t
t
t -
t
t textx="132" texty="240" text-anchor="left" fontfamily="Arial"
t fontsize="16" fill="#ffffff" text="XXXXXX" />
t
t
t
.
-
u16 URLDecode(char *str, u16 len)
-
{
-
char *dest = str;
-
char *data = str;
-
u16 value;
-
u16 c;
-
-
while (len--) {
-
if (*data == '+') {
-
*dest = ' ';
-
}
-
else
-
if (*data == '%' && len >= 2 && isxdigit((int) *(data + 1)) && isxdigit((int) *(data + 2))) {
-
c = ((unsigned char *)(data+1))[0];
-
if (isupper(c))
-
c = tolower(c);
-
value = (c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10) * 16;
-
c = ((unsigned char *)(data+1))[1];
-
if (isupper(c))
-
c = tolower(c);
-
value += c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10;
-
-
*dest = (char)value ;
-
data += 2;
-
len -= 2;
-
}
-
else {
-
*dest = *data;
-
}
-
data++;
-
dest++;
-
}
-
*dest = '\0';
-
-
return (dest - str);
-
}
3.
-
struct llhead {
-
struct llhead *prev;
-
struct llhead *next;
-
};
-
-
#define LL_INIT(N) ((N)->next = (N)->prev = (N))
-
-
#define LL_HEAD(H) struct llhead H = { &H, &H }
-
-
#define LL_ENTRY(P,T,N) ((T *)((char *)(P) - offsetof(T, N)))
-
-
#define LL_ADD(H, N) \\
-
do { \\
-
((H)->next)->prev = (N); \\
-
(N)->next = ((H)->next); \\
-
(N)->prev = (H); \\
-
(H)->next = (N); \\
-
} while (0)
-
-
#define LL_TAIL(H, N) \\
-
do { \\
-
((H)->prev)->next = (N); \\
-
(N)->prev = ((H)->prev); \\
-
(N)->next = (H); \\
-
(H)->prev = (N); \\
-
} while (0)
-
-
#define LL_DEL(N) \\
-
do { \\
-
((N)->next)->prev = ((N)->prev); \\
-
((N)->prev)->next = ((N)->next); \\
-
LL_INIT(N); \\
-
} while (0)
-
-
#define LL_EMPTY(N) ((N)->next == (N))
-
-
#define LL_FOREACH(H,N) for (N = (H)->next; N != (H); N = (N)->next)
-
-
#define LL_FOREACH_SAFE(H,N,T) \\
-
for (N = (H)->next, T = (N)->next; N != (H); \\
-
N = (T), T = (N)->next)
应用例程:
struct shttpd_ctx {
SSL_CTX *ssl_ctx; /* SSL context */
struct llhead registered_uris;/* User urls */
struct llhead error_handlers; /* Embedded error handlers */
struct llhead acl; /* Access control list */
struct llhead ssi_funcs; /* SSI callback functions */
struct llhead listeners; /* Listening sockets */
struct llhead workers; /* Worker workers */
FILE *access_log; /* Access log stream */
FILE *error_log; /* Error log stream */
char *options[NUM_OPTIONS]; /* Configurable options */
#if defined(__rtems__)
rtems_id mutex;
#endif /* _WIN32 */
};
struct shttpd_ctx *ctx;
LL_INIT(&ctx->registered_uris);
LL_INIT(&ctx->error_handlers);
4.
5.
阅读(1255) | 评论(0) | 转发(0) |