|
@@ -38,10 +38,94 @@ static LRESULT CALLBACK websWindProc(HWND hwnd, UINT msg, UINT wp, LPARAM lp);
|
|
|
static void sigHandler(int signo);
|
|
|
#endif
|
|
|
|
|
|
+static void buy(Webs *wp);
|
|
|
+static void actionTest(Webs *wp);
|
|
|
+static void personInfoAction(Webs *wp);
|
|
|
+
|
|
|
+
|
|
|
+typedef struct PERSON
|
|
|
+{
|
|
|
+ char *name;
|
|
|
+ int age;
|
|
|
+ char *gender;
|
|
|
+}Person;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+static 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);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+static void buy(Webs *wp)
|
|
|
+{
|
|
|
+ char *name, *age;
|
|
|
+ name = websGetVar(wp, "name", NULL);
|
|
|
+ age = websGetVar(wp, "age", NULL);
|
|
|
+ logmsg(2, "---------------------------------------------");
|
|
|
+ logmsg(2, "name value is : %s", name );
|
|
|
+ logmsg(2, "age value is : %s", age );
|
|
|
+ websSetStatus(wp, 200);
|
|
|
+ websWriteHeaders(wp, 0, 0);
|
|
|
+ websWriteEndHeaders(wp);
|
|
|
+ websWrite(wp, "Name %s", name);
|
|
|
+ websWrite(wp, "Age %s", age);
|
|
|
+ websFlush(wp, 0);
|
|
|
+ websDone(wp);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+ Implement /action/actionTest. Parse the form variables: name, address and echo back.
|
|
|
+ */
|
|
|
+static void actionTest(Webs *wp)
|
|
|
+{
|
|
|
+ cchar *name, *address;
|
|
|
+
|
|
|
+ name = websGetVar(wp, "name", NULL);
|
|
|
+ address = websGetVar(wp, "address", NULL);
|
|
|
+ websSetStatus(wp, 200);
|
|
|
+ websWriteHeaders(wp, -1, 0);
|
|
|
+ websWriteEndHeaders(wp);
|
|
|
+ websWrite(wp, "<html><body><h2>name: %s, address: %s</h2></body></html>\n", name, address);
|
|
|
+ websFlush(wp, 0);
|
|
|
+ websDone(wp);
|
|
|
+}
|
|
|
+
|
|
|
/*********************************** Code *************************************/
|
|
|
|
|
|
MAIN(goahead, int argc, char **argv, char **envp)
|
|
|
{
|
|
|
+
|
|
|
char *argp, *home, *documents, *endpoints, *endpoint, *route, *auth, *tok, *lspec;
|
|
|
int argind;
|
|
|
logmsg(2, "---> log1\n");
|
|
@@ -151,6 +235,13 @@ MAIN(goahead, int argc, char **argv, char **envp)
|
|
|
*/
|
|
|
websAddRoute("/", "file", 0);
|
|
|
#endif
|
|
|
+
|
|
|
+//add by lusa start
|
|
|
+ websDefineAction("buy", buy);
|
|
|
+ websDefineAction("test", actionTest);
|
|
|
+ websDefineAction("person", personInfoAction);
|
|
|
+
|
|
|
+// add by lusa end
|
|
|
#ifdef GOAHEAD_INIT
|
|
|
/*
|
|
|
Define your init function in main.me goahead.init, or
|