|
@@ -33,6 +33,53 @@ static void growRoutes(void);
|
|
static int lookupRoute(cchar *uri);
|
|
static int lookupRoute(cchar *uri);
|
|
static bool redirectHandler(Webs *wp);
|
|
static bool redirectHandler(Webs *wp);
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+typedef struct PERSON
|
|
|
|
+{
|
|
|
|
+ char *name;
|
|
|
|
+ int age;
|
|
|
|
+ char *gender;
|
|
|
|
+}Person;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+void personInfoAction(Webs *wp)
|
|
|
|
+{
|
|
|
|
+ logmsg(2, "-----------------------111----------------------");
|
|
|
|
+ int i;
|
|
|
|
+ Person person[2];
|
|
|
|
+ person[0].name = "kangkang";
|
|
|
|
+ person[0].age = 12;
|
|
|
|
+ person[0].gender = "male";
|
|
|
|
+ person[1].name = "Jane";
|
|
|
|
+ person[1].age = 14;
|
|
|
|
+ person[1].gender = "female";
|
|
|
|
+
|
|
|
|
+ websSetStatus(wp, 200);
|
|
|
|
+ websWriteHeaders(wp, -1, 0);
|
|
|
|
+ websWriteEndHeaders(wp);
|
|
|
|
+
|
|
|
|
+ websWrite(wp, "[");
|
|
|
|
+ for (i = 0;i < 2; i++)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ websWrite(wp, " {\"name\":\"%s\",\"age\":\"%d\",\"gender\":\"%s\"}",
|
|
|
|
+ person[i].name, person[i].age, person[i].gender);
|
|
|
|
+ if (i != 1)
|
|
|
|
+ {
|
|
|
|
+ websWrite(wp, ",");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ websWrite(wp, "]");
|
|
|
|
+ websDone(wp);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
/************************************ Code ************************************/
|
|
/************************************ Code ************************************/
|
|
/*
|
|
/*
|
|
Route the request. If wp->route is already set, test routes after that route
|
|
Route the request. If wp->route is already set, test routes after that route
|
|
@@ -40,6 +87,9 @@ static bool redirectHandler(Webs *wp);
|
|
|
|
|
|
PUBLIC void websRouteRequest(Webs *wp)
|
|
PUBLIC void websRouteRequest(Webs *wp)
|
|
{
|
|
{
|
|
|
|
+
|
|
|
|
+ // logmsg(2,"——————————————————————0————————————");
|
|
|
|
+ logmsg(2, "-----------------------222----------------------");
|
|
WebsRoute *route;
|
|
WebsRoute *route;
|
|
WebsHandler *handler;
|
|
WebsHandler *handler;
|
|
ssize plen, len;
|
|
ssize plen, len;
|
|
@@ -53,7 +103,7 @@ PUBLIC void websRouteRequest(Webs *wp)
|
|
|
|
|
|
safeMethod = smatch(wp->method, "POST") || smatch(wp->method, "GET") || smatch(wp->method, "HEAD");
|
|
safeMethod = smatch(wp->method, "POST") || smatch(wp->method, "GET") || smatch(wp->method, "HEAD");
|
|
plen = slen(wp->path);
|
|
plen = slen(wp->path);
|
|
-
|
|
|
|
|
|
+ logmsg(2, "-----------------------0.1----------------------");
|
|
/*
|
|
/*
|
|
Resume routine from last matched route. This permits the legacy service() callbacks to return false
|
|
Resume routine from last matched route. This permits the legacy service() callbacks to return false
|
|
and continue routing.
|
|
and continue routing.
|
|
@@ -71,10 +121,12 @@ PUBLIC void websRouteRequest(Webs *wp)
|
|
} else {
|
|
} else {
|
|
i = 0;
|
|
i = 0;
|
|
}
|
|
}
|
|
|
|
+ // logmsg(2, "-----------------------0.11----------------------");
|
|
wp->route = 0;
|
|
wp->route = 0;
|
|
|
|
|
|
for (; i < routeCount; i++) {
|
|
for (; i < routeCount; i++) {
|
|
route = routes[i];
|
|
route = routes[i];
|
|
|
|
+ logmsg(2, "-----------------------0.2----------------------%s", route->prefix);
|
|
assert(route->prefix && route->prefixLen > 0);
|
|
assert(route->prefix && route->prefixLen > 0);
|
|
|
|
|
|
if (plen < route->prefixLen) continue;
|
|
if (plen < route->prefixLen) continue;
|
|
@@ -84,6 +136,7 @@ PUBLIC void websRouteRequest(Webs *wp)
|
|
Match route
|
|
Match route
|
|
*/
|
|
*/
|
|
if (strncmp(wp->path, route->prefix, len) != 0) {
|
|
if (strncmp(wp->path, route->prefix, len) != 0) {
|
|
|
|
+ // logmsg(2,"——————————————————————————————%s", route->prefix);
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
if (route->protocol && !smatch(route->protocol, wp->protocol)) {
|
|
if (route->protocol && !smatch(route->protocol, wp->protocol)) {
|
|
@@ -100,15 +153,21 @@ PUBLIC void websRouteRequest(Webs *wp)
|
|
}
|
|
}
|
|
if (route->extensions >= 0 && (wp->ext == 0 || !hashLookup(route->extensions, &wp->ext[1]))) {
|
|
if (route->extensions >= 0 && (wp->ext == 0 || !hashLookup(route->extensions, &wp->ext[1]))) {
|
|
trace(5, "Route %s doesn match extension %s", route->prefix, wp->ext ? wp->ext : "");
|
|
trace(5, "Route %s doesn match extension %s", route->prefix, wp->ext ? wp->ext : "");
|
|
|
|
+
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
wp->route = route;
|
|
wp->route = route;
|
|
|
|
+ logmsg(2,"-----------------------11-----------------------");
|
|
#if ME_GOAHEAD_AUTH
|
|
#if ME_GOAHEAD_AUTH
|
|
|
|
+ logmsg(2,"-----------------------22-----------------------%s", route->authType);
|
|
if (route->authType && !websAuthenticate(wp)) {
|
|
if (route->authType && !websAuthenticate(wp)) {
|
|
|
|
+ personInfoAction(wp);//
|
|
|
|
+ logmsg(2,"-----------------------33-----------------------");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
if (route->abilities >= 0 && !websCan(wp, route->abilities)) {
|
|
if (route->abilities >= 0 && !websCan(wp, route->abilities)) {
|
|
|
|
+ logmsg(2,"-----------------------44-----------------------");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|