//kagecgi.c\r
//\r
\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <png.h>\r
-#include <glib.h>\r
#include "kage.h"\r
#include "kagecgi.h"\r
+#include "sysdep.h"\r
\r
int main(int argc, char *argv[]){\r
GString *tmp1, *tmp2, *test1, *test2, *filename;\r
- FILE *err, *fp;\r
+ FILE *err;\r
char errbuf[errorFileSize];\r
char *pos, *cur;\r
int dummy;\r
- int i;\r
+ int type;\r
\r
dummy = initDB();\r
\r
kResultText = g_string_new("");\r
kMode = 0;\r
\r
- //set some param by request\r
-// tmp1 = g_string_new((gchar *)argv[1]);\r
- tmp1 = g_string_new((gchar *)getenv("QUERY_STRING"));\r
+ //confirm request\r
+ type = 0;\r
+ //GET request\r
+ if(type == 0){\r
+ tmp1 = g_string_new((gchar *)getenv("QUERY_STRING"));\r
+ if(tmp1->len != 0) type = 2;\r
+ }\r
+ //argv(detect after GET request)\r
+ if(type == 0){
+ tmp1 = g_string_new((gchar *)argv[1]);\r
+ if(tmp1->len != 0) type = 1;
+ }
+ //redirect\r
+ if(type == 0){\r
+ tmp1 = g_string_new((gchar *)getenv("REDIRECT_URL"));\r
+ if(tmp1->len != 0) type = 3;\r
+ }\r
+ //error\r
+ if(type == 0){\r
+ fprintf(stderr, "Request Error.\n");\r
+ return 0;\r
+ }\r
pos = tmp1->str;\r
\r
//separate token\r
- if(tmp1->len != 0){\r
+ if(type == 1 || type == 2){ //argv or GET request\r
while(1){\r
cur = strchr(pos, '&');\r
tmp2 = g_string_new(pos);\r
if(cur != NULL) g_string_set_size(tmp2, cur - pos);\r
//got request string\r
-// if(strncmp(tmp2->str, "design=jp", 9) == 0) kDesign = 0;\r
-// else if(strncmp(tmp2->str, "design=cs", 9) == 0) kDesign = 10;\r
-// else if(strncmp(tmp2->str, "design=ct", 9) == 0) kDesign = 11;\r
-// else if(strncmp(tmp2->str, "design=kr", 9) == 0) kDesign = 20;\r
-// else if(strncmp(tmp2->str, "design=vn", 9) == 0) kDesign = 30;\r
-// else if(strncmp(tmp2->str, "design=un", 9) == 0) kDesign = 40;\r
-// else if(strncmp(tmp2->str, "shotai=mincho", 13) == 0) kShotai = kMincho;\r
if(strncmp(tmp2->str, "shotai=mincho", 13) == 0) kShotai = kMincho;\r
else if(strncmp(tmp2->str, "shotai=gothic", 13) == 0) kShotai = kGothic;\r
else if(strncmp(tmp2->str, "shotai=skeleton", 15) == 0) kShotai = kGothic;\r
}\r
else{ // redirected request\r
kInput = 0;\r
- tmp1 = g_string_new((gchar *)getenv("REDIRECT_URL"));\r
- pos = tmp1->str;\r
while(1){\r
cur = strchr(pos, '/');\r
tmp2 = g_string_new(pos);\r
if(cur != NULL) g_string_set_size(tmp2, cur - pos);\r
//got request string\r
-// if(strncmp(tmp2->str, "jp", 2) == 0) kDesign = 0;\r
-// else if(strncmp(tmp2->str, "cs", 2) == 0) kDesign = 10;\r
-// else if(strncmp(tmp2->str, "ct", 2) == 0) kDesign = 11;\r
-// else if(strncmp(tmp2->str, "kr", 2) == 0) kDesign = 20;\r
-// else if(strncmp(tmp2->str, "vn", 2) == 0) kDesign = 30;\r
-// else if(strncmp(tmp2->str, "un", 2) == 0) kDesign = 40;\r
-// else if(strncmp(tmp2->str, "mincho", 6) == 0) kShotai = kMincho;\r
if(strncmp(tmp2->str, "mincho", 6) == 0) kShotai = kMincho;\r
else if(strncmp(tmp2->str, "gothic", 6) == 0) kShotai = kGothic;\r
else if(strncmp(tmp2->str, "skeleton", 8) == 0) kShotai = kGothic;\r
drawGlyph(test2, 0);\r
//output to file\r
filename = g_string_new(pngFilePath);\r
-// if(kDesign == 0) g_string_append(filename, "jp/");\r
-// else if(kDesign == 10) g_string_append(filename, "cs/");\r
-// else if(kDesign == 11) g_string_append(filename, "ct/");\r
-// else if(kDesign == 20) g_string_append(filename, "kr/");\r
-// else if(kDesign == 30) g_string_append(filename, "vn/");\r
-// else if(kDesign == 40) g_string_append(filename, "un/");\r
if(kShotai == kMincho) g_string_append(filename, "mincho/");\r
else if(kShotai == kGothic) g_string_append(filename, "gothic/");//skeleton??\r
g_string_append(filename, test1->str);\r
// writePng(pngWidth, pngHeight, kageCanvas, fp);\r
// fclose(fp);\r
//output to stdout\r
- fprintf(stdout, "Content-type: image/png\n\n");\r
+ if(type != 1) fprintf(stdout, "Content-type: image/png\n\n");\r
writePng(pngWidth, pngHeight, kageCanvas, stdout);\r
//done\r
closePng(pngWidth, pngHeight, kageCanvas);\r
}\r
else{\r
- err = fopen("error.png", "r");\r
+ err = fopen(errorFileName, "r");\r
fread(errbuf, sizeof(char), errorFileSize, err);\r
// printf("An error occurred.\r\n");\r
- fprintf(stdout, "Content-type: image/png\n\n");\r
+ if(type != 1) fprintf(stdout, "Content-type: image/png\n\n");\r
fwrite(errbuf, sizeof(char), errorFileSize, stdout);\r
fclose(err);\r
}\r
kMode = 1;\r
drawGlyph(test2, 0);\r
g_string_append(kResultText, "</svg>\n");\r
- fprintf(stdout, "Content-type: image/svg-xml\n\n");\r
+ if(type != 1) fprintf(stdout, "Content-type: image/svg-xml\n\n");\r
fprintf(stdout, "%s", kResultText->str);\r
}\r
else{\r
- fprintf(stdout, "Content-type: text/plain\n\n");\r
+ if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n");\r
fprintf(stdout, "An error occurred.");\r
}\r
}\r
drawGlyph(test2, 0);\r
g_string_append(kResultText, "fill\n");\r
g_string_append(kResultText, "%%EOF\n");\r
- fprintf(stdout, "Content-type: application/postscript\n\n");\r
+ if(type != 1) fprintf(stdout, "Content-type: application/postscript\n\n");\r
fprintf(stdout, "%s", kResultText->str);\r
}\r
else{\r
- fprintf(stdout, "Content-type: text/plain\n\n");\r
+ if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n");\r
fprintf(stdout, "An error occurred.");\r
}\r
}\r
else{ //raw(text)\r
+\r
if(test2->len != 0){\r
- fprintf(stdout, "Content-type: text/plain\n\n");\r
+ test2 = CalcSizes(test2, 1);\r
+ if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n");\r
fprintf(stdout, "result=%s", test2->str);\r
}\r
else{\r
- fprintf(stdout, "Content-type: text/plain\n\n");\r
+ if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n");\r
fprintf(stdout, "result=nodata");\r
}\r
}\r