CGI 에 관한 여러가지 사항을 예제로 표현해봤습니다. (첨부파일)
pipe 관련한 예제는 다음의 링크를 참고하세요.
https://bbs.minzkn.com/viewtopic.php?t=68&highlight=pipe
관련글 : http://joinc.co.kr/modules.php?op=modload&name=Forum&file=viewtopic&topic=31315&forum=1
pipe 관련한 예제는 다음의 링크를 참고하세요.
https://bbs.minzkn.com/viewtopic.php?t=68&highlight=pipe
| 코드: |
| /* Copyright (C) Information Equipment co.,LTD All rights reserved. Code by JaeHyuk Cho <mailto:minzkn@infoeq.com> CVSTAG="$Header$" */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> static int g_argc; static char **g_argv; static char **g_env; static int (cgi_system)(int s_print, const char *s_command) { FILE *s_pipe; unsigned char s_buffer[ 4 << 10 ]; size_t s_read_bytes; if((s_pipe = popen(s_command, "r")) == ((FILE *)0))return(-1); while(feof(s_pipe) == 0) { s_read_bytes = fread((void *)(&s_buffer[0]), (size_t)1, (size_t)sizeof(s_buffer), s_pipe); if(s_read_bytes <= ((size_t)0))break; if((s_print != 0) && (fwrite((void *)(&s_buffer[0]), (size_t)1, s_read_bytes, stdout) != ((ssize_t)s_read_bytes)))break; } return(pclose(s_pipe)); } static void (html_init)(void) { (void)fputs("Content-Type: text/html\n\n", stdout); } static void (html_head)(void) { (void)fputs("<html><head><title>cgi test</title></head><body>\n", stdout); } static void (html_tail)(void) { (void)fputs(" </body>\n</html>\n", stdout); } static void (html_body)(void) { int s_index; (void)fputs("<p>MINZKN's CGI TEST</p><hr /><pre>\n", stdout); for(s_index = 0;s_index < g_argc;s_index++)(void)fprintf(stdout, "argv[%d] = \"%s\"\n", s_index, g_argv[s_index]); (void)fputs("</pre><hr />\n", stdout); (void)fputs("<pre>\n", stdout); for(s_index = 0;g_env[s_index] != ((char *)0);s_index++)(void)fprintf(stdout, "env[%d] = \"%s\"\n", s_index, g_env[s_index]); (void)fputs("</pre><hr />\n", stdout); (void)fputs("<pre>WHOAMI : ", stdout); (void)cgi_system(1, "whoami"); (void)fprintf(stdout, "UID : %u</pre><hr />\n", (unsigned int)getuid()); (void)fputs("<pre>", stdout); (void)cgi_system(1, "/bin/ls -al /tmp"); (void)fputs("</pre><hr />\n", stdout); } static void (html_flush)(void) { (void)fflush(stdout); } int (main)(int s_argc, char **s_argv, char **s_env) { g_argc = s_argc, g_argv = s_argv, g_env = s_env; html_init(); html_head(); html_body(); html_tail(); html_flush(); return(0); } /* vim: set expandtab: */ /* End of source */ |
관련글 : http://joinc.co.kr/modules.php?op=modload&name=Forum&file=viewtopic&topic=31315&forum=1


mzcgi.tar.bz2

댓글을 달아 주세요