// stdafx.cpp : source file that includes just the standard includes
// TestWeb.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include <io.h>
#include <fcntl.h>
#include <iostream>
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
#define NO_UNISTD 1
#if CGICDEBUG
#define CGICDEBUGSTART \
{ \
FILE *dout; \
dout = fopen("/home/boutell/public_html/debug", "a"); \
#define CGICDEBUGEND \
fclose(dout); \
}
#else /* CGICDEBUG */
#define CGICDEBUGSTART
#define CGICDEBUGEND
#endif /* CGICDEBUG */
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#ifndef NO_UNISTD
#include <unistd.h>
#endif /* NO_UNISTD */
#include "cgic.h"
#define cgiStrEq(a, b) (!strcmp((a), (b)))
char *cgiServerSoftware;
char *cgiServerName;
char *cgiGatewayInterface;
char *cgiServerProtocol;
char *cgiServerPort;
char *cgiRequestMethod;
char *cgiPathInfo;
char *cgiPathTranslated;
char *cgiScriptName;
char *cgiQueryString;
char *cgiRemoteHost;
char *cgiRemoteAddr;
char *cgiAuthType;
char *cgiRemoteUser;
char *cgiRemoteIdent;
char *cgiContentType;
int cgiContentLength;
char *cgiAccept;
char *cgiUserAgent;
char *cgiReferrer;
char *cgiCookie;
FILE *cgiIn;
FILE *cgiOut;
/* One form entry, consisting of an attribute-value pair. */
typedef struct cgiFormEntryStruct {
char *attr;
char *value;
struct cgiFormEntryStruct *next;
} cgiFormEntry;
/* The first form entry. */
static cgiFormEntry *cgiFormEntryFirst;
/* True if CGI environment was restored from a file. */
static int cgiRestored = 0;
static void cgiGetenv(char **s, char *var);
typedef enum {
cgiParseSuccess,
cgiParseMemory,
cgiParseIO
} cgiParseResultType;
static cgiParseResultType cgiParseGetFormInput();
static cgiParseResultType cgiParsePostFormInput();
static cgiParseResultType cgiParseFormInput(char *data, int length);
static void cgiSetupConstants();
static void cgiFreeResources();
static int cgiStrEqNc(char *s1, char *s2);
int main(int argc, char *argv[]) {
int result;
char *cgiContentLengthString;
cgiSetupConstants();
cgiGetenv(&cgiServerSoftware, "SERVER_SOFTWARE");
cgiGetenv(&cgiServerName, "SERVER_NAME");
cgiGetenv(&cgiGatewayInterface, "GATEWAY_INTERFACE");
cgiGetenv(&cgiServerProtocol, "SERVER_PROTOCOL");
cgiGetenv(&cgiServerPort, "SERVER_PORT");
cgiGetenv(&cgiRequestMethod, "REQUEST_METHOD");
cgiGetenv(&cgiPathInfo, "PATH_INFO");
cgiGetenv(&cgiPathTranslated, "PATH_TRANSLATED");
cgiGetenv(&cgiScriptName, "SCRIPT_NAME");
cgiGetenv(&cgiQueryString, "QUERY_STRING");
cgiGetenv(&cgiRemoteHost, "REMOTE_HOST");
cgiGetenv(&cgiRemoteAddr, "REMOTE_ADDR");
cgiGetenv(&cgiAuthType, "AUTH_TYPE");
cgiGetenv(&cgiRemoteUser, "REMOTE_USER");
cgiGetenv(&cgiRemoteIdent, "REMOTE_IDENT");
cgiGetenv(&cgiContentType, "CONTENT_TYPE");
cgiGetenv(&cgiContentLengthString, "CONTENT_LENGTH");
cgiContentLength = atoi(cgiContentLengthString);
cgiGetenv(&cgiAccept, "HTTP_ACCEPT");
cgiGetenv(&cgiUserAgent, "HTTP_USER_AGENT");
cgiGetenv(&cgiReferrer, "HTTP_REFERER");
cgiGetenv(&cgiCookie, "HTTP_COOKIE");
#ifdef CGICDEBUG
CGICDEBUGSTART
fprintf(dout, "%d\n", cgiContentLength);
fprintf(dout, "%s\n", cgiRequestMethod);
fprintf(dout, "%s\n", cgiContentType);
CGICDEBUGEND
#endif /* CGICDEBUG */
#ifdef WIN32
/* 1.07: Must set stdin and stdout to binary mode */
_setmode( _fileno( stdin ), _O_BINARY );
_setmode( _fileno( stdout ), _O_BINARY );
#endif /* WIN32 */
cgiFormEntryFirst = 0;
cgiIn = stdin;
cgiOut = stdout;
cgiRestored = 0;
/* These five lines keep compilers from
producing warnings that argc and argv
are unused. They have no actual function. */
if (argc) {
if (argv[0]) {
cgiRestored = 0;
}
}
if (cgiStrEqNc(cgiRequestMethod, "post")) {
#ifdef CGICDEBUG
CGICDEBUGSTART
fprintf(dout, "POST recognized\n");
CGICDEBUGEND
#endif /* CGICDEBUG */
if (cgiStrEqNc(cgiContentType, "application/x-www-form-urlencoded")) {
#ifdef CGICDEBUG
CGICDEBUGSTART
fprintf(dout, "Calling PostFormInput\n");
CGICDEBUGEND
#endif /* CGICDEBUG */
if (cgiParsePostFormInput() != cgiParseSuccess) {
#ifdef CGICDEBUG
CGICDEBUGSTART
fprintf(dout, "PostFormInput failed\n");
CGICDEBUGEND
#endif /* CGICDEBUG */
cgiFreeResources();
return -1;
}
#ifdef CGICDEBUG
CGICDEBUGSTART
fprintf(dout, "PostFormInput succeeded\n");
CGICDEBUGEND
#endif /* CGICDEBUG */
}
} else if (cgiStrEqNc(cgiRequestMethod, "get")) {
/* The spec says this should be taken care of by
the server, but... it isn't */
cgiContentLength = strlen(cgiQueryString);
if (cgiParseGetFormInput() != cgiParseSuccess) {
#ifdef CGICDEBUG
CGICDEBUGSTART
fprintf(dout, "GetFormInput failed\n");
CGICDEBUGEND
#endif /* CGICDEBUG */
cgiFreeResources();
return -1;
} else {
#ifdef CGICDEBUG
CGICDEBUGSTART
fprintf(dout, "GetFormInput succeeded\n");
CGICDEBUGEND
#endif /* CGICDEBUG */
}
}
result = cgiMain();
cgiFreeResources();
return result;
}
static void cgiGetenv(char **s, char *var){
*s = getenv(var);
if (!(*s)) {
*s = "";
}
}
static cgiParseResultType cgiParsePostFormInput() {
char *input;
cgiParseResultType result;
if (!cgiContentLength) {
return cgiParseSuccess;
}
input = (char *) malloc(cgiContentLength);
if (!input) {
return cgiParseMemory;
}
if (fread(input, 1, cgiContentLength, cgiIn) != cgiContentLength) {
return cgiParseIO;
}
result = cgiParseFormInput(input, cgiContentLength);
free(input);
return result;
}
static cgiParseResultType cgiParseGetFormInput() {
return cgiParseFormInput(cgiQueryString, cgiContentLength);
}
typedef enum {
cgiEscapeRest,
cgiEscapeFirst,
cgiEscapeSecond
} cgiEscapeState;
typedef enum {
cgiUnescapeSuccess,
cgiUnescapeMemory
} cgiUnescapeResultType;
static cgiUnescapeResultType cgiUnescapeChars(char **sp, char *cp, int len);
static cgiParseResultType cgiParseFormInput(char *data, int length) {
/* Scan for pairs, unescaping and storing them as they are found. */
int pos = 0;
cgiFormEntry *n;
cgiFormEntry *l = 0;
while (pos != length) {
int foundEq = 0;
int foundAmp = 0;
int start = pos;
int len = 0;
char *attr;
char *value;
while (pos != length) {
if (data[pos] == '=') {
foundEq = 1;
pos++;
break;
}
pos++;
len++;
}
if (!foundEq) {
break;
}
if (cgiUnescapeChars(&attr, data+start, len)
!= cgiUnescapeSuccess) {
return cgiParseMemory;
}
start = pos;
len = 0;
while (pos != length) {
if (data[pos] == '&') {
foundAmp = 1;
pos++;
break;
}
pos++;
len++;
}
/* The last pair probably won't be followed by a &, but
that's fine, so check for that after accepting it */
if (cgiUnescapeChars(&value, data+start, len)
!= cgiUnescapeSuccess) {
return cgiParseMemory;
}
/* OK, we have a new pair, add it to the list. */
n = (cgiFormEntry *) malloc(sizeof(cgiFormEntry));
if (!n) {
return cgiParseMemory;
}
n->attr = attr;
n->value = value;
n->next = 0;
if (!l) {
cgiFormEntryFirst = n;
} else {
l->next = n;
}
l = n;
if (!foundAmp) {
break;
}
}
return cgiParseSuccess;
}
static int cgiHexValue[256];
cgiUnescapeResultType cgiUnescapeChars(char **sp, char *cp, int len) {
char *s;
cgiEscapeState escapeState = cgiEscapeRest;
int escapedValue = 0;
int srcPos = 0;
int dstPos = 0;
s = (char *) malloc(len + 1);
if (!s) {
return cgiUnescapeMemory;
}
while (srcPos < len) {
int ch = cp[srcPos];
switch (escapeState) {
case cgiEscapeRest:
if (ch == '%') {
escapeState = cgiEscapeFirst;
} else if (ch
没有合适的资源?快使用搜索试试~ 我知道了~
C++软件下载管理程序源代码
共88个文件
cpp:39个
h:16个
plg:6个
需积分: 9 37 下载量 13 浏览量
2008-11-07
11:10:38
上传
评论 1
收藏 210KB ZIP 举报
温馨提示
很好的一个软件下载管理程序源码,不错!认真看一下,定会给你带来意想不到的效果!
资源推荐
资源详情
资源评论
收起资源包目录
C++软件下载管理程序源代码.zip (88个子文件)
admin
TestWeb.dsp 5KB
config.h 2KB
mydblib.cpp 7KB
EditSoft.cpp 7KB
UserLogin.cpp 2KB
mydblib.h 709B
cgic.cpp 24KB
ChangePass.cpp 2KB
TestWeb.dsw 537B
mymain.cpp 2KB
TestWeb.plg 1KB
addsoft.cpp 5KB
Config.cpp 4KB
TestWeb.opt 53KB
EditUser.cpp 4KB
System.cpp 746B
MyCall.cpp 5KB
cgic.h 4KB
DelSoft.cpp 3KB
TestWeb.ncb 137KB
show
config.h 935B
mydblib.cpp 2KB
showcode1.htm 2KB
mydblib.h 192B
cgic.cpp 24KB
mymain.cpp 5KB
Config.cpp 3KB
TestWeb1.ncb 89KB
TestWeb1.plg 1KB
MyCall.cpp 488B
cgic.h 4KB
TestWeb1.dsp 5KB
TestWeb1.dsw 539B
TestWeb1.opt 53KB
admin1
config.h 2KB
mydblib.cpp 6KB
mydblib.h 1KB
cgic.cpp 24KB
Backup.cpp 907B
mymain.cpp 838B
Config.cpp 4KB
MakeHtml.cpp 9KB
TestWeb1.ncb 129KB
TestWeb1.plg 1KB
MyCall.cpp 4KB
cgic.h 4KB
TestWeb1.dsp 5KB
TestWeb1.dsw 539B
EditCommend.cpp 2KB
TestWeb1.opt 53KB
EditNews.cpp 4KB
place
config.h 685B
place.dsw 533B
mydblib.cpp 3KB
mydblib.h 651B
placecode.htm 4KB
place.plg 1KB
mymain.cpp 4KB
place.ncb 73KB
Config.cpp 3KB
MyCall.cpp 84B
place.dsp 4KB
place.opt 53KB
softsel
softsel.plg 1KB
config.h 1KB
softsel.dsp 5KB
mydblib.cpp 6KB
mydblib.h 1KB
cgic.cpp 24KB
mymain.cpp 8KB
softsel.ncb 65KB
softsel.dsw 537B
Config.cpp 3KB
softsel.opt 53KB
listcode.htm 4KB
MyCall.cpp 1KB
cgic.h 4KB
dl
mydblib.cpp 1KB
mydblib.h 139B
cgic.cpp 24KB
dl.plg 1KB
dl.dsp 4KB
mymain.cpp 1KB
Config.cpp 46B
dl.ncb 65KB
dl.dsw 527B
cgic.h 4KB
dl.opt 53KB
共 88 条
- 1
资源评论
ngudream
- 粉丝: 3
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功