Added JNetLib framework.

CQTexperiment
vspader 2009-03-04 22:29:21 -08:00
parent ba32cf22fb
commit dd409e19d2
42 changed files with 9575 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.${PRODUCT_NAME:identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>

Binary file not shown.

View File

@ -0,0 +1,334 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 45;
objects = {
/* Begin PBXBuildFile section */
17F6C5F80F5F9D5B000D9DA9 /* asyncdns.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 17F6C5D50F5F9D5B000D9DA9 /* asyncdns.cpp */; };
17F6C5F90F5F9D5B000D9DA9 /* asyncdns.h in Headers */ = {isa = PBXBuildFile; fileRef = 17F6C5D60F5F9D5B000D9DA9 /* asyncdns.h */; settings = {ATTRIBUTES = (Public, ); }; };
17F6C5FB0F5F9D5B000D9DA9 /* connection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 17F6C5D80F5F9D5B000D9DA9 /* connection.cpp */; };
17F6C5FC0F5F9D5B000D9DA9 /* connection.h in Headers */ = {isa = PBXBuildFile; fileRef = 17F6C5D90F5F9D5B000D9DA9 /* connection.h */; settings = {ATTRIBUTES = (Public, ); }; };
17F6C5FD0F5F9D5B000D9DA9 /* httpget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 17F6C5DA0F5F9D5B000D9DA9 /* httpget.cpp */; };
17F6C5FE0F5F9D5B000D9DA9 /* httpget.h in Headers */ = {isa = PBXBuildFile; fileRef = 17F6C5DB0F5F9D5B000D9DA9 /* httpget.h */; settings = {ATTRIBUTES = (Public, ); }; };
17F6C5FF0F5F9D5B000D9DA9 /* httppost.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 17F6C5DC0F5F9D5B000D9DA9 /* httppost.cpp */; };
17F6C6000F5F9D5B000D9DA9 /* httppost.h in Headers */ = {isa = PBXBuildFile; fileRef = 17F6C5DD0F5F9D5B000D9DA9 /* httppost.h */; settings = {ATTRIBUTES = (Public, ); }; };
17F6C6010F5F9D5B000D9DA9 /* httpserv.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 17F6C5DE0F5F9D5B000D9DA9 /* httpserv.cpp */; };
17F6C6020F5F9D5B000D9DA9 /* httpserv.h in Headers */ = {isa = PBXBuildFile; fileRef = 17F6C5DF0F5F9D5B000D9DA9 /* httpserv.h */; settings = {ATTRIBUTES = (Public, ); }; };
17F6C6050F5F9D5B000D9DA9 /* jnetlib.h in Headers */ = {isa = PBXBuildFile; fileRef = 17F6C5E20F5F9D5B000D9DA9 /* jnetlib.h */; settings = {ATTRIBUTES = (Public, ); }; };
17F6C6060F5F9D5B000D9DA9 /* listen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 17F6C5E30F5F9D5B000D9DA9 /* listen.cpp */; };
17F6C6070F5F9D5B000D9DA9 /* listen.h in Headers */ = {isa = PBXBuildFile; fileRef = 17F6C5E40F5F9D5B000D9DA9 /* listen.h */; settings = {ATTRIBUTES = (Public, ); }; };
17F6C6090F5F9D5B000D9DA9 /* netinc.h in Headers */ = {isa = PBXBuildFile; fileRef = 17F6C5E60F5F9D5B000D9DA9 /* netinc.h */; settings = {ATTRIBUTES = (Public, ); }; };
17F6C60B0F5F9D5B000D9DA9 /* sslconnection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 17F6C5E80F5F9D5B000D9DA9 /* sslconnection.cpp */; };
17F6C60C0F5F9D5B000D9DA9 /* sslconnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 17F6C5E90F5F9D5B000D9DA9 /* sslconnection.h */; settings = {ATTRIBUTES = (Public, ); }; };
17F6C60D0F5F9D5B000D9DA9 /* ssllisten.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 17F6C5EA0F5F9D5B000D9DA9 /* ssllisten.cpp */; };
17F6C60E0F5F9D5B000D9DA9 /* ssllisten.h in Headers */ = {isa = PBXBuildFile; fileRef = 17F6C5EB0F5F9D5B000D9DA9 /* ssllisten.h */; settings = {ATTRIBUTES = (Public, ); }; };
17F6C6160F5F9D5B000D9DA9 /* udpconnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 17F6C5F30F5F9D5B000D9DA9 /* udpconnection.h */; settings = {ATTRIBUTES = (Public, ); }; };
17F6C6170F5F9D5B000D9DA9 /* util.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 17F6C5F40F5F9D5B000D9DA9 /* util.cpp */; };
17F6C6180F5F9D5B000D9DA9 /* util.h in Headers */ = {isa = PBXBuildFile; fileRef = 17F6C5F50F5F9D5B000D9DA9 /* util.h */; settings = {ATTRIBUTES = (Public, ); }; };
8DC2EF530486A6940098B216 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C1666FE841158C02AAC07 /* InfoPlist.strings */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
089C1667FE841158C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
17F6C5D50F5F9D5B000D9DA9 /* asyncdns.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = asyncdns.cpp; path = jnetlib/asyncdns.cpp; sourceTree = "<group>"; };
17F6C5D60F5F9D5B000D9DA9 /* asyncdns.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = asyncdns.h; path = jnetlib/asyncdns.h; sourceTree = "<group>"; };
17F6C5D80F5F9D5B000D9DA9 /* connection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = connection.cpp; path = jnetlib/connection.cpp; sourceTree = "<group>"; };
17F6C5D90F5F9D5B000D9DA9 /* connection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = connection.h; path = jnetlib/connection.h; sourceTree = "<group>"; };
17F6C5DA0F5F9D5B000D9DA9 /* httpget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = httpget.cpp; path = jnetlib/httpget.cpp; sourceTree = "<group>"; };
17F6C5DB0F5F9D5B000D9DA9 /* httpget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = httpget.h; path = jnetlib/httpget.h; sourceTree = "<group>"; };
17F6C5DC0F5F9D5B000D9DA9 /* httppost.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = httppost.cpp; path = jnetlib/httppost.cpp; sourceTree = "<group>"; };
17F6C5DD0F5F9D5B000D9DA9 /* httppost.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = httppost.h; path = jnetlib/httppost.h; sourceTree = "<group>"; };
17F6C5DE0F5F9D5B000D9DA9 /* httpserv.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = httpserv.cpp; path = jnetlib/httpserv.cpp; sourceTree = "<group>"; };
17F6C5DF0F5F9D5B000D9DA9 /* httpserv.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = httpserv.h; path = jnetlib/httpserv.h; sourceTree = "<group>"; };
17F6C5E20F5F9D5B000D9DA9 /* jnetlib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jnetlib.h; path = jnetlib/jnetlib.h; sourceTree = "<group>"; };
17F6C5E30F5F9D5B000D9DA9 /* listen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = listen.cpp; path = jnetlib/listen.cpp; sourceTree = "<group>"; };
17F6C5E40F5F9D5B000D9DA9 /* listen.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = listen.h; path = jnetlib/listen.h; sourceTree = "<group>"; };
17F6C5E60F5F9D5B000D9DA9 /* netinc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = netinc.h; path = jnetlib/netinc.h; sourceTree = "<group>"; };
17F6C5E80F5F9D5B000D9DA9 /* sslconnection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sslconnection.cpp; path = jnetlib/sslconnection.cpp; sourceTree = "<group>"; };
17F6C5E90F5F9D5B000D9DA9 /* sslconnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = sslconnection.h; path = jnetlib/sslconnection.h; sourceTree = "<group>"; };
17F6C5EA0F5F9D5B000D9DA9 /* ssllisten.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ssllisten.cpp; path = jnetlib/ssllisten.cpp; sourceTree = "<group>"; };
17F6C5EB0F5F9D5B000D9DA9 /* ssllisten.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ssllisten.h; path = jnetlib/ssllisten.h; sourceTree = "<group>"; };
17F6C5F30F5F9D5B000D9DA9 /* udpconnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = udpconnection.h; path = jnetlib/udpconnection.h; sourceTree = "<group>"; };
17F6C5F40F5F9D5B000D9DA9 /* util.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = util.cpp; path = jnetlib/util.cpp; sourceTree = "<group>"; };
17F6C5F50F5F9D5B000D9DA9 /* util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = util.h; path = jnetlib/util.h; sourceTree = "<group>"; };
8DC2EF5A0486A6940098B216 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8DC2EF5B0486A6940098B216 /* JNetLib.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = JNetLib.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
8DC2EF560486A6940098B216 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
034768DFFF38A50411DB9C8B /* Products */ = {
isa = PBXGroup;
children = (
8DC2EF5B0486A6940098B216 /* JNetLib.framework */,
);
name = Products;
sourceTree = "<group>";
};
0867D691FE84028FC02AAC07 /* JNetLib */ = {
isa = PBXGroup;
children = (
08FB77AEFE84172EC02AAC07 /* Classes */,
32C88DFF0371C24200C91783 /* Other Sources */,
089C1665FE841158C02AAC07 /* Resources */,
0867D69AFE84028FC02AAC07 /* External Frameworks and Libraries */,
034768DFFF38A50411DB9C8B /* Products */,
);
name = JNetLib;
sourceTree = "<group>";
};
0867D69AFE84028FC02AAC07 /* External Frameworks and Libraries */ = {
isa = PBXGroup;
children = (
);
name = "External Frameworks and Libraries";
sourceTree = "<group>";
};
089C1665FE841158C02AAC07 /* Resources */ = {
isa = PBXGroup;
children = (
8DC2EF5A0486A6940098B216 /* Info.plist */,
089C1666FE841158C02AAC07 /* InfoPlist.strings */,
);
name = Resources;
sourceTree = "<group>";
};
08FB77AEFE84172EC02AAC07 /* Classes */ = {
isa = PBXGroup;
children = (
17F6C5D50F5F9D5B000D9DA9 /* asyncdns.cpp */,
17F6C5D60F5F9D5B000D9DA9 /* asyncdns.h */,
17F6C5D80F5F9D5B000D9DA9 /* connection.cpp */,
17F6C5D90F5F9D5B000D9DA9 /* connection.h */,
17F6C5DA0F5F9D5B000D9DA9 /* httpget.cpp */,
17F6C5DB0F5F9D5B000D9DA9 /* httpget.h */,
17F6C5DC0F5F9D5B000D9DA9 /* httppost.cpp */,
17F6C5DD0F5F9D5B000D9DA9 /* httppost.h */,
17F6C5DE0F5F9D5B000D9DA9 /* httpserv.cpp */,
17F6C5DF0F5F9D5B000D9DA9 /* httpserv.h */,
17F6C5E20F5F9D5B000D9DA9 /* jnetlib.h */,
17F6C5E30F5F9D5B000D9DA9 /* listen.cpp */,
17F6C5E40F5F9D5B000D9DA9 /* listen.h */,
17F6C5E60F5F9D5B000D9DA9 /* netinc.h */,
17F6C5E80F5F9D5B000D9DA9 /* sslconnection.cpp */,
17F6C5E90F5F9D5B000D9DA9 /* sslconnection.h */,
17F6C5EA0F5F9D5B000D9DA9 /* ssllisten.cpp */,
17F6C5EB0F5F9D5B000D9DA9 /* ssllisten.h */,
17F6C5F30F5F9D5B000D9DA9 /* udpconnection.h */,
17F6C5F40F5F9D5B000D9DA9 /* util.cpp */,
17F6C5F50F5F9D5B000D9DA9 /* util.h */,
);
name = Classes;
sourceTree = "<group>";
};
32C88DFF0371C24200C91783 /* Other Sources */ = {
isa = PBXGroup;
children = (
);
name = "Other Sources";
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
8DC2EF500486A6940098B216 /* Headers */ = {
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
17F6C5F90F5F9D5B000D9DA9 /* asyncdns.h in Headers */,
17F6C5FC0F5F9D5B000D9DA9 /* connection.h in Headers */,
17F6C5FE0F5F9D5B000D9DA9 /* httpget.h in Headers */,
17F6C6000F5F9D5B000D9DA9 /* httppost.h in Headers */,
17F6C6020F5F9D5B000D9DA9 /* httpserv.h in Headers */,
17F6C6050F5F9D5B000D9DA9 /* jnetlib.h in Headers */,
17F6C6070F5F9D5B000D9DA9 /* listen.h in Headers */,
17F6C6090F5F9D5B000D9DA9 /* netinc.h in Headers */,
17F6C60C0F5F9D5B000D9DA9 /* sslconnection.h in Headers */,
17F6C60E0F5F9D5B000D9DA9 /* ssllisten.h in Headers */,
17F6C6160F5F9D5B000D9DA9 /* udpconnection.h in Headers */,
17F6C6180F5F9D5B000D9DA9 /* util.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXHeadersBuildPhase section */
/* Begin PBXNativeTarget section */
8DC2EF4F0486A6940098B216 /* JNetLib */ = {
isa = PBXNativeTarget;
buildConfigurationList = 1DEB91AD08733DA50010E9CD /* Build configuration list for PBXNativeTarget "JNetLib" */;
buildPhases = (
8DC2EF500486A6940098B216 /* Headers */,
8DC2EF520486A6940098B216 /* Resources */,
8DC2EF540486A6940098B216 /* Sources */,
8DC2EF560486A6940098B216 /* Frameworks */,
);
buildRules = (
);
dependencies = (
);
name = JNetLib;
productInstallPath = "$(HOME)/Library/Frameworks";
productName = JNetLib;
productReference = 8DC2EF5B0486A6940098B216 /* JNetLib.framework */;
productType = "com.apple.product-type.framework";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
0867D690FE84028FC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB91B108733DA50010E9CD /* Build configuration list for PBXProject "JNetLib" */;
compatibilityVersion = "Xcode 3.1";
hasScannedForEncodings = 1;
mainGroup = 0867D691FE84028FC02AAC07 /* JNetLib */;
productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
8DC2EF4F0486A6940098B216 /* JNetLib */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
8DC2EF520486A6940098B216 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8DC2EF530486A6940098B216 /* InfoPlist.strings in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
8DC2EF540486A6940098B216 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
17F6C5F80F5F9D5B000D9DA9 /* asyncdns.cpp in Sources */,
17F6C5FB0F5F9D5B000D9DA9 /* connection.cpp in Sources */,
17F6C5FD0F5F9D5B000D9DA9 /* httpget.cpp in Sources */,
17F6C5FF0F5F9D5B000D9DA9 /* httppost.cpp in Sources */,
17F6C6010F5F9D5B000D9DA9 /* httpserv.cpp in Sources */,
17F6C6060F5F9D5B000D9DA9 /* listen.cpp in Sources */,
17F6C60B0F5F9D5B000D9DA9 /* sslconnection.cpp in Sources */,
17F6C60D0F5F9D5B000D9DA9 /* ssllisten.cpp in Sources */,
17F6C6170F5F9D5B000D9DA9 /* util.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXVariantGroup section */
089C1666FE841158C02AAC07 /* InfoPlist.strings */ = {
isa = PBXVariantGroup;
children = (
089C1667FE841158C02AAC07 /* English */,
);
name = InfoPlist.strings;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */
1DEB91AE08733DA50010E9CD /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
COPY_PHASE_STRIP = NO;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
FRAMEWORK_VERSION = A;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "@loader_path/../Frameworks";
PRODUCT_NAME = JNetLib;
SYMROOT = ../../build;
WRAPPER_EXTENSION = framework;
};
name = Debug;
};
1DEB91AF08733DA50010E9CD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
FRAMEWORK_VERSION = A;
GCC_MODEL_TUNING = G5;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "@loader_path/../Frameworks";
PRODUCT_NAME = JNetLib;
SYMROOT = ../../build;
WRAPPER_EXTENSION = framework;
};
name = Release;
};
1DEB91B208733DA50010E9CD /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO;
SDKROOT = macosx10.5;
};
name = Debug;
};
1DEB91B308733DA50010E9CD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
SDKROOT = macosx10.5;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
1DEB91AD08733DA50010E9CD /* Build configuration list for PBXNativeTarget "JNetLib" */ = {
isa = XCConfigurationList;
buildConfigurations = (
1DEB91AE08733DA50010E9CD /* Debug */,
1DEB91AF08733DA50010E9CD /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
1DEB91B108733DA50010E9CD /* Build configuration list for PBXProject "JNetLib" */ = {
isa = XCConfigurationList;
buildConfigurations = (
1DEB91B208733DA50010E9CD /* Debug */,
1DEB91B308733DA50010E9CD /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 0867D690FE84028FC02AAC07 /* Project object */;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,425 @@
// !$*UTF8*$!
{
0867D690FE84028FC02AAC07 /* Project object */ = {
activeBuildConfigurationName = Release;
activeTarget = 8DC2EF4F0486A6940098B216 /* JNetLib */;
addToTargets = (
8DC2EF4F0486A6940098B216 /* JNetLib */,
);
codeSenseManager = 17F6C47F0F5F9D26000D9DA9 /* Code sense */;
perUserDictionary = {
PBXConfiguration.PBXFileTableDataSource3.PBXFileTableDataSource = {
PBXFileTableDataSourceColumnSortingDirectionKey = "-1";
PBXFileTableDataSourceColumnSortingKey = PBXFileDataSource_Filename_ColumnID;
PBXFileTableDataSourceColumnWidthsKey = (
20,
631,
20,
48,
43,
43,
20,
);
PBXFileTableDataSourceColumnsKey = (
PBXFileDataSource_FiletypeID,
PBXFileDataSource_Filename_ColumnID,
PBXFileDataSource_Built_ColumnID,
PBXFileDataSource_ObjectSize_ColumnID,
PBXFileDataSource_Errors_ColumnID,
PBXFileDataSource_Warnings_ColumnID,
PBXFileDataSource_Target_ColumnID,
);
};
PBXConfiguration.PBXTargetDataSource.PBXTargetDataSource = {
PBXFileTableDataSourceColumnSortingDirectionKey = "-1";
PBXFileTableDataSourceColumnSortingKey = PBXFileDataSource_Filename_ColumnID;
PBXFileTableDataSourceColumnWidthsKey = (
20,
591,
60,
20,
48.16259765625,
43,
43,
);
PBXFileTableDataSourceColumnsKey = (
PBXFileDataSource_FiletypeID,
PBXFileDataSource_Filename_ColumnID,
PBXTargetDataSource_PrimaryAttribute,
PBXFileDataSource_Built_ColumnID,
PBXFileDataSource_ObjectSize_ColumnID,
PBXFileDataSource_Errors_ColumnID,
PBXFileDataSource_Warnings_ColumnID,
);
};
PBXPerProjectTemplateStateSaveDate = 257925053;
PBXWorkspaceStateSaveDate = 257925053;
};
perUserProjectItems = {
17F6C6290F5F9E23000D9DA9 /* PlistBookmark */ = 17F6C6290F5F9E23000D9DA9 /* PlistBookmark */;
17F6C62A0F5F9E23000D9DA9 /* PBXTextBookmark */ = 17F6C62A0F5F9E23000D9DA9 /* PBXTextBookmark */;
17F6C62B0F5F9E23000D9DA9 /* PBXTextBookmark */ = 17F6C62B0F5F9E23000D9DA9 /* PBXTextBookmark */;
17F6C62C0F5F9E23000D9DA9 /* PBXTextBookmark */ = 17F6C62C0F5F9E23000D9DA9 /* PBXTextBookmark */;
17F6C62D0F5F9E23000D9DA9 /* PBXTextBookmark */ = 17F6C62D0F5F9E23000D9DA9 /* PBXTextBookmark */;
17F6C62E0F5F9E23000D9DA9 /* PBXTextBookmark */ = 17F6C62E0F5F9E23000D9DA9 /* PBXTextBookmark */;
17F6C62F0F5F9E23000D9DA9 /* PBXTextBookmark */ = 17F6C62F0F5F9E23000D9DA9 /* PBXTextBookmark */;
17F6C6300F5F9E23000D9DA9 /* PBXTextBookmark */ = 17F6C6300F5F9E23000D9DA9 /* PBXTextBookmark */;
17F6C6320F5F9E23000D9DA9 /* PlistBookmark */ = 17F6C6320F5F9E23000D9DA9 /* PlistBookmark */;
17F6C6330F5F9E23000D9DA9 /* PBXTextBookmark */ = 17F6C6330F5F9E23000D9DA9 /* PBXTextBookmark */;
17F6C6340F5F9E23000D9DA9 /* PBXTextBookmark */ = 17F6C6340F5F9E23000D9DA9 /* PBXTextBookmark */;
17F6C6350F5F9E23000D9DA9 /* PBXTextBookmark */ = 17F6C6350F5F9E23000D9DA9 /* PBXTextBookmark */;
17F6C6360F5F9E23000D9DA9 /* PBXTextBookmark */ = 17F6C6360F5F9E23000D9DA9 /* PBXTextBookmark */;
17F6C6370F5F9E23000D9DA9 /* PBXTextBookmark */ = 17F6C6370F5F9E23000D9DA9 /* PBXTextBookmark */;
17F6C6380F5F9E23000D9DA9 /* PBXTextBookmark */ = 17F6C6380F5F9E23000D9DA9 /* PBXTextBookmark */;
17F6C6390F5F9E23000D9DA9 /* PBXTextBookmark */ = 17F6C6390F5F9E23000D9DA9 /* PBXTextBookmark */;
17F6C6C50F5FA4D4000D9DA9 /* PBXTextBookmark */ = 17F6C6C50F5FA4D4000D9DA9 /* PBXTextBookmark */;
17F6C6C60F5FA4D4000D9DA9 /* PBXTextBookmark */ = 17F6C6C60F5FA4D4000D9DA9 /* PBXTextBookmark */;
17F6C6C70F5FA4D4000D9DA9 /* PBXTextBookmark */ = 17F6C6C70F5FA4D4000D9DA9 /* PBXTextBookmark */;
17F6C6C80F5FA4D4000D9DA9 /* PBXTextBookmark */ = 17F6C6C80F5FA4D4000D9DA9 /* PBXTextBookmark */;
17F6C6C90F5FA4D4000D9DA9 /* PBXTextBookmark */ = 17F6C6C90F5FA4D4000D9DA9 /* PBXTextBookmark */;
17F6C6CA0F5FA4D4000D9DA9 /* PBXTextBookmark */ = 17F6C6CA0F5FA4D4000D9DA9 /* PBXTextBookmark */;
17F6C6CB0F5FA4D4000D9DA9 /* PBXTextBookmark */ = 17F6C6CB0F5FA4D4000D9DA9 /* PBXTextBookmark */;
17F6C6CC0F5FA4D4000D9DA9 /* PBXTextBookmark */ = 17F6C6CC0F5FA4D4000D9DA9 /* PBXTextBookmark */;
};
sourceControlManager = 17F6C47E0F5F9D26000D9DA9 /* Source Control */;
userBuildSettings = {
};
};
089C1667FE841158C02AAC07 /* English */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {809, 513}}";
sepNavSelRange = "{0, 0}";
sepNavVisRange = "{0, 45}";
};
};
17F6C47E0F5F9D26000D9DA9 /* Source Control */ = {
isa = PBXSourceControlManager;
fallbackIsa = XCSourceControlManager;
isSCMEnabled = 0;
scmConfiguration = {
};
};
17F6C47F0F5F9D26000D9DA9 /* Code sense */ = {
isa = PBXCodeSenseManager;
indexTemplatePath = "";
};
17F6C5DA0F5F9D5B000D9DA9 /* httpget.cpp */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {519, 6860}}";
sepNavSelRange = "{0, 0}";
sepNavVisRange = "{0, 403}";
};
};
17F6C5DB0F5F9D5B000D9DA9 /* httpget.h */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {1194, 1414}}";
sepNavSelRange = "{2253, 0}";
sepNavVisRange = "{2162, 1171}";
};
};
17F6C5DC0F5F9D5B000D9DA9 /* httppost.cpp */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {439, 5796}}";
sepNavSelRange = "{319, 0}";
sepNavVisRange = "{186, 269}";
};
};
17F6C5DD0F5F9D5B000D9DA9 /* httppost.h */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {809, 1792}}";
sepNavSelRange = "{2769, 11}";
sepNavVisRange = "{2118, 667}";
};
};
17F6C5E20F5F9D5B000D9DA9 /* jnetlib.h */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {809, 714}}";
sepNavSelRange = "{952, 0}";
sepNavVisRange = "{394, 1204}";
};
};
17F6C5E30F5F9D5B000D9DA9 /* listen.cpp */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {519, 1050}}";
sepNavSelRange = "{0, 0}";
sepNavVisRange = "{0, 400}";
};
};
17F6C5E60F5F9D5B000D9DA9 /* netinc.h */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {519, 1162}}";
sepNavSelRange = "{0, 0}";
sepNavVisRange = "{0, 370}";
};
};
17F6C5E80F5F9D5B000D9DA9 /* sslconnection.cpp */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {918, 4396}}";
sepNavSelRange = "{0, 0}";
sepNavVisRange = "{0, 290}";
};
};
17F6C5E90F5F9D5B000D9DA9 /* sslconnection.h */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {809, 854}}";
sepNavSelRange = "{0, 0}";
sepNavVisRange = "{439, 1350}";
};
};
17F6C5EA0F5F9D5B000D9DA9 /* ssllisten.cpp */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {762, 1820}}";
sepNavSelRange = "{0, 0}";
sepNavVisRange = "{0, 498}";
};
};
17F6C5EB0F5F9D5B000D9DA9 /* ssllisten.h */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {519, 686}}";
sepNavSelRange = "{0, 0}";
sepNavVisRange = "{0, 636}";
};
};
17F6C6290F5F9E23000D9DA9 /* PlistBookmark */ = {
isa = PlistBookmark;
fRef = 8DC2EF5A0486A6940098B216 /* Info.plist */;
fallbackIsa = PBXBookmark;
isK = 0;
kPath = (
);
name = /Users/vspader/Projects/Cog/Frameworks/JNetLib/Info.plist;
rLen = 0;
rLoc = 2147483647;
};
17F6C62A0F5F9E23000D9DA9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 17F6C5DC0F5F9D5B000D9DA9 /* httppost.cpp */;
name = "httppost.cpp: 17";
rLen = 0;
rLoc = 319;
rType = 0;
vrLen = 418;
vrLoc = 258;
};
17F6C62B0F5F9E23000D9DA9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 17F6C5DA0F5F9D5B000D9DA9 /* httpget.cpp */;
name = "httpget.cpp: 1";
rLen = 0;
rLoc = 0;
rType = 0;
vrLen = 403;
vrLoc = 0;
};
17F6C62C0F5F9E23000D9DA9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 17F6C5E30F5F9D5B000D9DA9 /* listen.cpp */;
name = "listen.cpp: 1";
rLen = 0;
rLoc = 0;
rType = 0;
vrLen = 400;
vrLoc = 0;
};
17F6C62D0F5F9E23000D9DA9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 17F6C5E60F5F9D5B000D9DA9 /* netinc.h */;
name = "netinc.h: 1";
rLen = 0;
rLoc = 0;
rType = 0;
vrLen = 370;
vrLoc = 0;
};
17F6C62E0F5F9E23000D9DA9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 17F6C5E80F5F9D5B000D9DA9 /* sslconnection.cpp */;
name = "sslconnection.cpp: 1";
rLen = 0;
rLoc = 0;
rType = 0;
vrLen = 290;
vrLoc = 0;
};
17F6C62F0F5F9E23000D9DA9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 17F6C5EB0F5F9D5B000D9DA9 /* ssllisten.h */;
name = "ssllisten.h: 1";
rLen = 0;
rLoc = 0;
rType = 0;
vrLen = 636;
vrLoc = 0;
};
17F6C6300F5F9E23000D9DA9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 17F6C5EA0F5F9D5B000D9DA9 /* ssllisten.cpp */;
name = "ssllisten.cpp: 1";
rLen = 0;
rLoc = 0;
rType = 0;
vrLen = 498;
vrLoc = 0;
};
17F6C6320F5F9E23000D9DA9 /* PlistBookmark */ = {
isa = PlistBookmark;
fRef = 8DC2EF5A0486A6940098B216 /* Info.plist */;
fallbackIsa = PBXBookmark;
isK = 0;
kPath = (
);
name = /Users/vspader/Projects/Cog/Frameworks/JNetLib/Info.plist;
rLen = 0;
rLoc = 2147483647;
};
17F6C6330F5F9E23000D9DA9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 17F6C5DC0F5F9D5B000D9DA9 /* httppost.cpp */;
name = "httppost.cpp: 17";
rLen = 0;
rLoc = 319;
rType = 0;
vrLen = 418;
vrLoc = 258;
};
17F6C6340F5F9E23000D9DA9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 17F6C5DA0F5F9D5B000D9DA9 /* httpget.cpp */;
name = "httpget.cpp: 1";
rLen = 0;
rLoc = 0;
rType = 0;
vrLen = 403;
vrLoc = 0;
};
17F6C6350F5F9E23000D9DA9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 17F6C5E30F5F9D5B000D9DA9 /* listen.cpp */;
name = "listen.cpp: 1";
rLen = 0;
rLoc = 0;
rType = 0;
vrLen = 400;
vrLoc = 0;
};
17F6C6360F5F9E23000D9DA9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 17F6C5E60F5F9D5B000D9DA9 /* netinc.h */;
name = "netinc.h: 1";
rLen = 0;
rLoc = 0;
rType = 0;
vrLen = 370;
vrLoc = 0;
};
17F6C6370F5F9E23000D9DA9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 17F6C5E80F5F9D5B000D9DA9 /* sslconnection.cpp */;
name = "sslconnection.cpp: 1";
rLen = 0;
rLoc = 0;
rType = 0;
vrLen = 290;
vrLoc = 0;
};
17F6C6380F5F9E23000D9DA9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 17F6C5EB0F5F9D5B000D9DA9 /* ssllisten.h */;
name = "ssllisten.h: 1";
rLen = 0;
rLoc = 0;
rType = 0;
vrLen = 636;
vrLoc = 0;
};
17F6C6390F5F9E23000D9DA9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 17F6C5EA0F5F9D5B000D9DA9 /* ssllisten.cpp */;
name = "ssllisten.cpp: 1";
rLen = 0;
rLoc = 0;
rType = 0;
vrLen = 498;
vrLoc = 0;
};
17F6C6C50F5FA4D4000D9DA9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 17F6C5E90F5F9D5B000D9DA9 /* sslconnection.h */;
name = "sslconnection.h: 1";
rLen = 0;
rLoc = 0;
rType = 0;
vrLen = 1350;
vrLoc = 439;
};
17F6C6C60F5FA4D4000D9DA9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 089C1667FE841158C02AAC07 /* English */;
name = "InfoPlist.strings: 1";
rLen = 0;
rLoc = 0;
rType = 0;
vrLen = 45;
vrLoc = 0;
};
17F6C6C70F5FA4D4000D9DA9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 17F6C5E20F5F9D5B000D9DA9 /* jnetlib.h */;
name = "jnetlib.h: 25";
rLen = 0;
rLoc = 952;
rType = 0;
vrLen = 1204;
vrLoc = 394;
};
17F6C6C80F5FA4D4000D9DA9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 17F6C5DD0F5F9D5B000D9DA9 /* httppost.h */;
rLen = 11;
rLoc = 2769;
rType = 0;
};
17F6C6C90F5FA4D4000D9DA9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 17F6C5E90F5F9D5B000D9DA9 /* sslconnection.h */;
name = "sslconnection.h: 1";
rLen = 0;
rLoc = 0;
rType = 0;
vrLen = 1350;
vrLoc = 439;
};
17F6C6CA0F5FA4D4000D9DA9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 089C1667FE841158C02AAC07 /* English */;
name = "InfoPlist.strings: 1";
rLen = 0;
rLoc = 0;
rType = 0;
vrLen = 45;
vrLoc = 0;
};
17F6C6CB0F5FA4D4000D9DA9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 17F6C5E20F5F9D5B000D9DA9 /* jnetlib.h */;
name = "jnetlib.h: 25";
rLen = 0;
rLoc = 952;
rType = 0;
vrLen = 1204;
vrLoc = 394;
};
17F6C6CC0F5FA4D4000D9DA9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 17F6C5DD0F5F9D5B000D9DA9 /* httppost.h */;
name = "httppost.h: 77";
rLen = 11;
rLoc = 2769;
rType = 0;
vrLen = 667;
vrLoc = 2118;
};
8DC2EF4F0486A6940098B216 /* JNetLib */ = {
activeExec = 0;
};
}

BIN
Frameworks/JNetLib/jnetlib/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,6 @@
+03/06/2006 Joshua Teitelbaum : Added file CHANGES.txt
+03/06/2006 Joshua Teitelbaum : Added file README.txt
+03/06/2006 Joshua Teitelbaum : Basic Integration with SSL
+03/06/2006 Joshua Teitelbaum : Added new HTTP POST Test
+03/06/2006 Joshua Teitelbaum : Added HTTPS Listen Test
+03/06/2006 Joshua Teitelbaum : Added HTTPS Get Test

View File

@ -0,0 +1,20 @@
# freebsd3 makefile
default: jnl.a
LDFLAGS = -pthread
CFLAGS = -s -O2 -Wall -DTHREAD_SAFE -D_THREAD_SAFE -D_REENTRANT
CC = gcc
CPP = g++
CXX = g++
OBJS = asyncdns.o connection.o httpget.o httpserv.o listen.o util.o sercon.o
jnl.a: ${OBJS}
-rm -f jnl.a
ar rcs jnl.a ${OBJS}
test: ${OBJS} test.o
$(CC) ${CFLAGS} -o test test.o ${OBJS} ${LDFLAGS}
clean:
-rm -f ${OBJS} test jnl.a test.o

View File

@ -0,0 +1,76 @@
JNetLib Readme.txt
/*
**
** Justin Frankel
** www.cockos.com
**
** Joshua Teitelbaum
** www.cryptomail.org
*/
Table of Contents:
I) License
II) Introduction
III) Features
IV) SSL Integration
V) Postamble
I) License
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution
II) Introduction
Welcome to the JNetLib library, a C++ asynchronous network abstraction layer.
III) Features
* Works under Linux, FreeBSD, Win32, and other operating systems.
* TCP connections support
* Listening sockets support
* Asynchronous DNS support
* HTTP serving and getting support (including basic authentication, GET/POST and HTTP/1.1 support)
* Basic HTTPS serving, getting support (including basic authentication, and HTTP/1.1 support)
* Completely asynchronous love for single threaded apps.
* Coming soon: support for UDP, as well as serial i/o.
IV) SSL Integration
JNetLib now employs the OpenSSL encryption library from www.openssl.org.
However, it is not compiled in as the default.
If you would like to have SSL support compiled in you have to:
1) uncomment the #define _JNETLIB_SSL_ 1 in netinc.h
2) Obtain the openssl requisite libraries libeay32.lib and ssleay32.lib
2a) You can obtain these libraries either by building them yourself via aquring the source yourself or...
2b) Download the SSL quickpack for windows, and ensure that you have the SSL quickpack in your build environment
You will need the proper include and library paths.
If you downloaded the quickpack to C:\, then the appropriate build environment include directory would be "c:\openssl\include", and so forth.
Disclaimer:
SSL functionality is new, and not entirely feature complete.
The current certification authentication tactic is to allow all certificates through, without checking any CA signatures.
V) Postamble
Questions/Comments
joshuat@cryptomail.org

View File

@ -0,0 +1,262 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: asyncdns.cpp - JNL portable asynchronous DNS implementation
** License: see jnetlib.h
*/
#include "netinc.h"
#include "util.h"
#include "asyncdns.h"
JNL_AsyncDNS::JNL_AsyncDNS(int max_cache_entries)
{
m_thread_kill=1;
m_thread=0;
m_cache_size=max_cache_entries;
m_cache=(cache_entry *)::malloc(sizeof(cache_entry)*m_cache_size);
memset(m_cache,0,sizeof(cache_entry)*m_cache_size);
}
JNL_AsyncDNS::~JNL_AsyncDNS()
{
#ifndef NO_DNS_SUPPORT
m_thread_kill=1;
#ifdef _WIN32
if (m_thread)
{
WaitForSingleObject(m_thread,INFINITE);
CloseHandle(m_thread);
}
#else
if (m_thread)
{
void *p;
pthread_join(m_thread,&p);
}
#endif//!_WIN32
#endif//NO_DNS_SUPPORT
free(m_cache);
}
#ifdef _WIN32
unsigned long WINAPI JNL_AsyncDNS::_threadfunc(LPVOID _d)
#else
unsigned int JNL_AsyncDNS::_threadfunc(void *_d)
#endif
{
#ifndef NO_DNS_SUPPORT
int nowinsock=JNL::open_socketlib();
JNL_AsyncDNS *_this=(JNL_AsyncDNS*)_d;
int x;
for (x = 0; x < _this->m_cache_size && !_this->m_thread_kill; x ++)
{
if (_this->m_cache[x].last_used && !_this->m_cache[x].resolved)
{
if (!nowinsock)
{
if (_this->m_cache[x].mode==0)
{
struct hostent *hostentry;
hostentry=::gethostbyname(_this->m_cache[x].hostname);
if (hostentry)
{
_this->m_cache[x].addr=*((int*)hostentry->h_addr);
}
else
_this->m_cache[x].addr=INADDR_NONE;
}
else if (_this->m_cache[x].mode==1)
{
struct hostent *ent;
ent=::gethostbyaddr((const char *)&_this->m_cache[x].addr,4,AF_INET);
if (ent)
{
strncpy(_this->m_cache[x].hostname,ent->h_name,255);
_this->m_cache[x].hostname[255]=0;
}
else
{
_this->m_cache[x].hostname[0]=0;
}
}
_this->m_cache[x].resolved=1;
}
else
{
if (_this->m_cache[x].mode==0)
{
_this->m_cache[x].addr=INADDR_NONE;
_this->m_cache[x].resolved=1;
}
else if (_this->m_cache[x].mode==1)
{
_this->m_cache[x].hostname[0]=0;
_this->m_cache[x].resolved=1;
}
}
}
}
if (!nowinsock) JNL::close_socketlib();
_this->m_thread_kill=1;
#endif // NO_DNS_SUPPORT
return 0;
}
int JNL_AsyncDNS::resolve(char *hostname, unsigned long *addr)
{
// return 0 on success, 1 on wait, -1 on unresolvable
int x;
unsigned long ip=inet_addr(hostname);
if (ip != INADDR_NONE)
{
*addr=ip;
return 0;
}
#ifndef NO_DNS_SUPPORT
for (x = 0; x < m_cache_size; x ++)
{
if (!strcasecmp(m_cache[x].hostname,hostname) && m_cache[x].mode==0)
{
m_cache[x].last_used=time(NULL);
if (m_cache[x].resolved)
{
if (m_cache[x].addr == INADDR_NONE)
{
return -1;
}
struct in_addr in;
in.s_addr=m_cache[x].addr;
*addr=m_cache[x].addr;
return 0;
}
makesurethreadisrunning();
return 1;
}
}
// add to resolve list
int oi=-1;
for (x = 0; x < m_cache_size; x ++)
{
if (!m_cache[x].last_used)
{
oi=x;
break;
}
if ((oi==-1 || m_cache[x].last_used < m_cache[oi].last_used) && m_cache[x].resolved)
{
oi=x;
}
}
if (oi == -1)
{
return -1;
}
strcpy(m_cache[oi].hostname,hostname);
m_cache[oi].mode=0;
m_cache[oi].addr=INADDR_NONE;
m_cache[oi].resolved=0;
m_cache[oi].last_used=time(NULL);
makesurethreadisrunning();
return 1;
#else
return -1;
#endif
}
int JNL_AsyncDNS::reverse(unsigned long addr, char *hostname)
{
// return 0 on success, 1 on wait, -1 on unresolvable
int x;
if (addr == INADDR_NONE)
{
return -1;
}
#ifndef NO_DNS_SUPPORT
for (x = 0; x < m_cache_size; x ++)
{
if (m_cache[x].addr==addr && m_cache[x].mode==1)
{
m_cache[x].last_used=time(NULL);
if (m_cache[x].resolved)
{
if (!m_cache[x].hostname[0])
{
return -1;
}
strncpy(hostname,m_cache[x].hostname,255);
hostname[255]=0;
return 0;
}
makesurethreadisrunning();
return 1;
}
}
// add to resolve list
int oi=-1;
for (x = 0; x < m_cache_size; x ++)
{
if (!m_cache[x].last_used)
{
oi=x;
break;
}
if ((oi==-1 || m_cache[x].last_used < m_cache[oi].last_used) && m_cache[x].resolved)
{
oi=x;
}
}
if (oi == -1)
{
return -1;
}
m_cache[oi].addr=addr;
m_cache[oi].hostname[0]=0;
m_cache[oi].resolved=0;
m_cache[oi].mode=1;
m_cache[oi].last_used=time(NULL);
makesurethreadisrunning();
return 1;
#else
return -1;
#endif
}
void JNL_AsyncDNS::makesurethreadisrunning(void)
{
#ifndef NO_DNS_SUPPORT
if (m_thread_kill)
{
#ifdef _WIN32
if (m_thread)
{
WaitForSingleObject(m_thread,INFINITE);
CloseHandle(m_thread);
}
DWORD id;
m_thread_kill=0;
m_thread=CreateThread(NULL,0,_threadfunc,(LPVOID)this,0,&id);
if (!m_thread)
{
#else
if (m_thread)
{
void *p;
pthread_join(m_thread,&p);
}
m_thread_kill=0;
if (pthread_create(&m_thread,NULL,(void *(*) (void *))_threadfunc,(void*)this) != 0)
{
#endif
m_thread_kill=1;
}
}
#endif//NO_DNS_SUPPORT
}

View File

@ -0,0 +1,55 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: asyncdns.h - JNL portable asynchronous DNS interface
** License: see jnetlib.h
**
** Usage:
** 1. Create JNL_AsyncDNS object, optionally with the number of cache entries.
** 2. call resolve() to resolve a hostname into an address. The return value of
** resolve is 0 on success (host successfully resolved), 1 on wait (meaning
** try calling resolve() with the same hostname in a few hundred milliseconds
** or so), or -1 on error (i.e. the host can't resolve).
** 3. call reverse() to do reverse dns (ala resolve()).
** 4. enjoy.
*/
#ifndef _ASYNCDNS_H_
#define _ASYNCDNS_H_
class JNL_AsyncDNS
{
public:
JNL_AsyncDNS(int max_cache_entries=64);
~JNL_AsyncDNS();
int resolve(char *hostname, unsigned long *addr); // return 0 on success, 1 on wait, -1 on unresolvable
int reverse(unsigned long addr, char *hostname); // return 0 on success, 1 on wait, -1 on unresolvable. hostname must be at least 256 bytes.
private:
typedef struct
{
int last_used; // timestamp.
char resolved;
char mode; // 1=reverse
char hostname[256];
unsigned long addr;
}
cache_entry;
cache_entry *m_cache;
int m_cache_size;
volatile int m_thread_kill;
#ifdef _WIN32
HANDLE m_thread;
static unsigned long WINAPI _threadfunc(LPVOID _d);
#else
pthread_t m_thread;
static unsigned int _threadfunc(void *_d);
#endif
void makesurethreadisrunning(void);
};
#endif //_ASYNCDNS_H_

View File

@ -0,0 +1,520 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: connection.cpp - JNL TCP connection implementation
** License: see jnetlib.h
*/
#include "netinc.h"
#include "util.h"
#include "connection.h"
JNL_Connection::JNL_Connection(JNL_AsyncDNS *dns, int sendbufsize, int recvbufsize)
{
m_errorstr="";
if (dns == JNL_CONNECTION_AUTODNS)
{
m_dns=new JNL_AsyncDNS();
m_dns_owned=1;
}
else
{
m_dns=dns;
m_dns_owned=0;
}
m_recv_buffer_len=recvbufsize;
m_send_buffer_len=sendbufsize;
m_recv_buffer=(char*)malloc(m_recv_buffer_len);
m_send_buffer=(char*)malloc(m_send_buffer_len);
m_socket=-1;
memset(m_recv_buffer,0,recvbufsize);
memset(m_send_buffer,0,sendbufsize);
m_remote_port=0;
m_state=STATE_NOCONNECTION;
m_recv_len=m_recv_pos=0;
m_send_len=m_send_pos=0;
m_host[0]=0;
m_saddr = new struct sockaddr_in;
memset(m_saddr,0,sizeof(m_saddr));
}
void JNL_Connection::connect(int s, struct sockaddr_in *loc)
{
close(1);
m_socket=s;
m_remote_port=0;
m_dns=NULL;
if (loc) *m_saddr=*loc;
else memset(m_saddr,0,sizeof(m_saddr));
if (m_socket != -1)
{
SET_SOCK_BLOCK(m_socket,0);
m_state=STATE_CONNECTED;
}
else
{
m_errorstr="invalid socket passed to connect";
m_state=STATE_ERROR;
}
}
void JNL_Connection::connect(char *hostname, int port)
{
close(1);
m_remote_port=(short)port;
m_socket=::socket(AF_INET,SOCK_STREAM,0);
if (m_socket==-1)
{
m_errorstr="creating socket";
m_state=STATE_ERROR;
}
else
{
SET_SOCK_BLOCK(m_socket,0);
strncpy(m_host,hostname,sizeof(m_host)-1);
m_host[sizeof(m_host)-1]=0;
memset(m_saddr,0,sizeof(m_saddr));
if (!m_host[0])
{
m_errorstr="empty hostname";
m_state=STATE_ERROR;
}
else
{
m_state=STATE_RESOLVING;
m_saddr->sin_family=AF_INET;
m_saddr->sin_port=htons((unsigned short)port);
m_saddr->sin_addr.s_addr=inet_addr(hostname);
}
}
}
/*
** Joshua Teitelbaum 1/27/2006
** socket_shutdown
** virtualization for ssl
*/
/* Virtual */
void JNL_Connection::socket_shutdown()
{
if (m_socket >= 0)
{
::shutdown(m_socket, SHUT_RDWR);
::closesocket(m_socket);
m_socket=-1;
}
}
/*
** Joshua Teitelbaum 1/27/2006
** socket_recv
** virtualization for ssl
*/
/* Virtual */
int JNL_Connection::socket_recv(char *buf, int len, int options)
{
return ::recv(m_socket,buf,len,options);
}
/*
** Joshua Teitelbaum 1/27/2006
** socket_send
** virtualization for ssl
*/
/* Virtual */
int JNL_Connection::socket_send(char *buf, int len, int options)
{
return ::send(m_socket,buf,len,options);
}
int JNL_Connection::socket_connect()
{
return ::connect(m_socket,(struct sockaddr *)m_saddr,16);
}
JNL_Connection::~JNL_Connection()
{
/*
** Joshua Teitelbaum 1/27/2006
** virtualization for ssl, calling socket_shtudown()
*/
socket_shutdown();
free(m_recv_buffer);
free(m_send_buffer);
if (m_dns_owned)
{
delete m_dns;
}
delete m_saddr;
}
void JNL_Connection::run(int max_send_bytes, int max_recv_bytes, int *bytes_sent, int *bytes_rcvd)
{
int bytes_allowed_to_send=(max_send_bytes<0)?m_send_buffer_len:max_send_bytes;
int bytes_allowed_to_recv=(max_recv_bytes<0)?m_recv_buffer_len:max_recv_bytes;
if (bytes_sent) *bytes_sent=0;
if (bytes_rcvd) *bytes_rcvd=0;
switch (m_state)
{
case STATE_RESOLVING:
if (m_saddr->sin_addr.s_addr == INADDR_NONE)
{
int a=m_dns?m_dns->resolve(m_host,(unsigned long int *)&m_saddr->sin_addr.s_addr):-1;
if (!a) { m_state=STATE_CONNECTING; }
else if (a == 1)
{
m_state=STATE_RESOLVING;
break;
}
else
{
m_errorstr="resolving hostname";
m_state=STATE_ERROR;
return;
}
}
/*
** Joshua Teitelbaum 1/27/2006
** virtualization for ssl
*/
if(!socket_connect())
{
m_state=STATE_CONNECTED;
on_socket_connected();
}
else if (ERRNO!=EINPROGRESS)
{
m_errorstr="connecting to host";
m_state=STATE_ERROR;
}
else { m_state=STATE_CONNECTING; }
break;
case STATE_CONNECTING:
{
fd_set f[3];
FD_ZERO(&f[0]);
FD_ZERO(&f[1]);
FD_ZERO(&f[2]);
FD_SET(m_socket,&f[0]);
FD_SET(m_socket,&f[1]);
FD_SET(m_socket,&f[2]);
struct timeval tv;
memset(&tv,0,sizeof(tv));
if (select(m_socket+1,&f[0],&f[1],&f[2],&tv)==-1)
{
m_errorstr="connecting to host (calling select())";
m_state=STATE_ERROR;
}
else if (FD_ISSET(m_socket,&f[1]))
{
m_state=STATE_CONNECTED;
on_socket_connected();
}
else if (FD_ISSET(m_socket,&f[2]))
{
m_errorstr="connecting to host";
m_state=STATE_ERROR;
}
}
break;
case STATE_CONNECTED:
case STATE_CLOSING:
if (m_send_len>0 && bytes_allowed_to_send>0)
{
int len=m_send_buffer_len-m_send_pos;
if (len > m_send_len) len=m_send_len;
if (len > bytes_allowed_to_send) len=bytes_allowed_to_send;
if (len > 0)
{
int res=socket_send(m_send_buffer+m_send_pos,len,0);
if (res==-1 && ERRNO != EWOULDBLOCK)
{
// m_state=STATE_CLOSED;
// return;
}
if (res>0)
{
bytes_allowed_to_send-=res;
if (bytes_sent) *bytes_sent+=res;
m_send_pos+=res;
m_send_len-=res;
}
}
if (m_send_pos>=m_send_buffer_len)
{
m_send_pos=0;
if (m_send_len>0)
{
len=m_send_buffer_len-m_send_pos;
if (len > m_send_len) len=m_send_len;
if (len > bytes_allowed_to_send) len=bytes_allowed_to_send;
int res=socket_send(m_send_buffer+m_send_pos,len,0);
if (res==-1 && ERRNO != EWOULDBLOCK)
{
// m_state=STATE_CLOSED;
}
if (res>0)
{
bytes_allowed_to_send-=res;
if (bytes_sent) *bytes_sent+=res;
m_send_pos+=res;
m_send_len-=res;
}
}
}
}
if (m_recv_len<m_recv_buffer_len)
{
int len=m_recv_buffer_len-m_recv_pos;
if (len > m_recv_buffer_len-m_recv_len) len=m_recv_buffer_len-m_recv_len;
if (len > bytes_allowed_to_recv) len=bytes_allowed_to_recv;
if (len>0)
{
/*
** Joshua Teitelbaum 1/27/2006
** virtualization for SSL
*/
int res = socket_recv(m_recv_buffer+m_recv_pos,len,0);
if (res == 0 || (res < 0 && ERRNO != EWOULDBLOCK))
{
m_state=STATE_CLOSED;
break;
}
if (res > 0)
{
bytes_allowed_to_recv-=res;
if (bytes_rcvd) *bytes_rcvd+=res;
m_recv_pos+=res;
m_recv_len+=res;
}
}
if (m_recv_pos >= m_recv_buffer_len)
{
m_recv_pos=0;
if (m_recv_len < m_recv_buffer_len)
{
len=m_recv_buffer_len-m_recv_len;
if (len > bytes_allowed_to_recv) len=bytes_allowed_to_recv;
if (len > 0)
{
int res=socket_recv(m_recv_buffer+m_recv_pos,len,0);
if (res == 0 || (res < 0 && ERRNO != EWOULDBLOCK))
{
m_state=STATE_CLOSED;
break;
}
if (res > 0)
{
bytes_allowed_to_recv-=res;
if (bytes_rcvd) *bytes_rcvd+=res;
m_recv_pos+=res;
m_recv_len+=res;
}
}
}
}
}
if (m_state == STATE_CLOSING)
{
if (m_send_len < 1) m_state = STATE_CLOSED;
}
break;
default: break;
}
}
void JNL_Connection::on_socket_connected(void)
{
return;
}
void JNL_Connection::close(int quick)
{
if (quick || m_state == STATE_RESOLVING || m_state == STATE_CONNECTING)
{
m_state=STATE_CLOSED;
/*
** Joshua Teitelbaum 1/27/2006
** virualization for ssl
*/
socket_shutdown();
m_socket=-1;
memset(m_recv_buffer,0,m_recv_buffer_len);
memset(m_send_buffer,0,m_send_buffer_len);
m_remote_port=0;
m_recv_len=m_recv_pos=0;
m_send_len=m_send_pos=0;
m_host[0]=0;
memset(m_saddr,0,sizeof(m_saddr));
}
else
{
if (m_state == STATE_CONNECTED) m_state=STATE_CLOSING;
}
}
int JNL_Connection::send_bytes_in_queue(void)
{
return m_send_len;
}
int JNL_Connection::send_bytes_available(void)
{
return m_send_buffer_len-m_send_len;
}
int JNL_Connection::send(const void *_data, int length)
{
const char *data = static_cast<const char *>(_data);
if (length > send_bytes_available())
{
return -1;
}
int write_pos=m_send_pos+m_send_len;
if (write_pos >= m_send_buffer_len)
{
write_pos-=m_send_buffer_len;
}
int len=m_send_buffer_len-write_pos;
if (len > length)
{
len=length;
}
memcpy(m_send_buffer+write_pos,data,len);
if (length > len)
{
memcpy(m_send_buffer,data+len,length-len);
}
m_send_len+=length;
return 0;
}
int JNL_Connection::send_string(const char *line)
{
return send(line,strlen(line));
}
int JNL_Connection::recv_bytes_available(void)
{
return m_recv_len;
}
int JNL_Connection::peek_bytes(void *_data, int maxlength)
{
char *data = static_cast<char *>(_data);
if (maxlength > m_recv_len)
{
maxlength=m_recv_len;
}
int read_pos=m_recv_pos-m_recv_len;
if (read_pos < 0)
{
read_pos += m_recv_buffer_len;
}
int len=m_recv_buffer_len-read_pos;
if (len > maxlength)
{
len=maxlength;
}
if (data != NULL) {
memcpy(data,m_recv_buffer+read_pos,len);
if (len < maxlength)
{
memcpy(data+len,m_recv_buffer,maxlength-len);
}
}
return maxlength;
}
int JNL_Connection::recv_bytes(void *_data, int maxlength)
{
char *data = static_cast<char *>(_data);
int ml=peek_bytes(data,maxlength);
m_recv_len-=ml;
return ml;
}
int JNL_Connection::getbfromrecv(int pos, int remove)
{
int read_pos=m_recv_pos-m_recv_len + pos;
if (pos < 0 || pos > m_recv_len) return -1;
if (read_pos < 0)
{
read_pos += m_recv_buffer_len;
}
if (read_pos >= m_recv_buffer_len)
{
read_pos-=m_recv_buffer_len;
}
if (remove) m_recv_len--;
return m_recv_buffer[read_pos];
}
int JNL_Connection::recv_lines_available(void)
{
int l=recv_bytes_available();
int lcount=0;
int lastch=0;
int pos;
for (pos=0; pos < l; pos ++)
{
int t=getbfromrecv(pos,0);
if (t == -1) return lcount;
if ((t=='\r' || t=='\n') &&(
(lastch != '\r' && lastch != '\n') || lastch==t
)) lcount++;
lastch=t;
}
return lcount;
}
int JNL_Connection::recv_line(char *line, int maxlength)
{
if (maxlength > m_recv_len) maxlength=m_recv_len;
while (maxlength--)
{
int t=getbfromrecv(0,1);
if (t == -1)
{
*line=0;
return 0;
}
if (t == '\r' || t == '\n')
{
int r=getbfromrecv(0,0);
if ((r == '\r' || r == '\n') && r != t) getbfromrecv(0,1);
*line=0;
return 0;
}
*line++=(char)t;
}
return 1;
}
unsigned long JNL_Connection::get_interface(void)
{
if (m_socket==-1) return 0;
struct sockaddr_in sin;
memset(&sin,0,sizeof(sin));
socklen_t len=16;
if (::getsockname(m_socket,(struct sockaddr *)&sin,&len)) return 0;
return (unsigned long) sin.sin_addr.s_addr;
}
unsigned long JNL_Connection::get_remote()
{
return m_saddr->sin_addr.s_addr;
}
short JNL_Connection::get_remote_port()
{
return m_remote_port;
}

View File

@ -0,0 +1,153 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: connection.h - JNL TCP connection interface
** License: see jnetlib.h
**
** Usage:
** 1. Create a JNL_Connection object, optionally specifying a JNL_AsyncDNS
** object to use (or NULL for none, or JNL_CONNECTION_AUTODNS for auto),
** and the send and receive buffer sizes.
** 2. Call connect() to have it connect to a host/port (the hostname will be
** resolved if possible).
** 3. call run() with the maximum send/recv amounts, and optionally parameters
** so you can tell how much has been send/received. You want to do this a lot, while:
** 4. check get_state() to check the state of the connection. The states are:
** JNL_Connection::STATE_ERROR
** - an error has occured on the connection. the connection has closed,
** and you can no longer write to the socket (there still might be
** data in the receive buffer - use recv_bytes_available()).
** JNL_Connection::STATE_NOCONNECTION
** - no connection has been made yet. call connect() already! :)
** JNL_Connection::STATE_RESOLVING
** - the connection is still waiting for a JNL_AsycnDNS to resolve the
** host.
** JNL_Connection::STATE_CONNECTING
** - the asynchronous call to connect() is still running.
** JNL_Connection::STATE_CONNECTED
** - the connection has connected, all is well.
** JNL_Connection::STATE_CLOSING
** - the connection is closing. This happens after a call to close,
** without the quick parameter set. This means that the connection
** will close once the data in the send buffer is sent (data could
** still be being received when it would be closed). After it is
** closed, the state will transition to:
** JNL_Connection::STATE_CLOSED
** - the connection has closed, generally without error. There still
** might be data in the receieve buffer, use recv_bytes_available().
** 5. Use send() and send_string() to send data. You can use
** send_bytes_in_queue() to see how much has yet to go out, or
** send_bytes_available() to see how much you can write. If you use send()
** or send_string() and not enough room is available, both functions will
** return error ( < 0)
** 6. Use recv() and recv_line() to get data. If you want to see how much data
** there is, use recv_bytes_available() and recv_lines_available(). If you
** call recv() and not enough data is available, recv() will return how much
** data was actually read. See comments at the function defs.
**
** 7. To close, call close(1) for a quick close, or close() for a close that will
** make the socket close after sending all the data sent.
**
** 8. delete ye' ol' object.
*/
#ifndef _CONNECTION_H_
#define _CONNECTION_H_
#include "asyncdns.h"
#define JNL_CONNECTION_AUTODNS ((JNL_AsyncDNS*)-1)
struct sockaddr_in;
class JNL_Connection
{
public:
typedef enum
{
STATE_ERROR,
STATE_NOCONNECTION,
STATE_RESOLVING,
STATE_CONNECTING,
STATE_CONNECTED,
STATE_CLOSING,
STATE_CLOSED
} state;
/*
** Joshua Teitelbaum, 1/27/2006 adding virtual
*/
JNL_Connection(JNL_AsyncDNS *dns=JNL_CONNECTION_AUTODNS, int sendbufsize=8192, int recvbufsize=8192);
virtual ~JNL_Connection();
public:
void connect(char *hostname, int port);
virtual void connect(int sock, struct sockaddr_in *loc=NULL); // used by the listen object, usually not needed by users.
/*
** Joshua Teitelbaum 2/2/2006
** Need to make this virtual to ensure SSL can init properly
*/
virtual void run(int max_send_bytes=-1, int max_recv_bytes=-1, int *bytes_sent=NULL, int *bytes_rcvd=NULL);
int get_state() { return m_state; }
char *get_errstr() { return m_errorstr; }
void close(int quick=0);
void flush_send(void) { m_send_len=m_send_pos=0; }
int send_bytes_in_queue(void);
int send_bytes_available(void);
int send(const void *data, int length); // returns -1 if not enough room
inline int send_bytes(const void *data, int length) { return send(data, length); }
int send_string(const char *line); // returns -1 if not enough room
int recv_bytes_available(void);
int recv_bytes(void *data, int maxlength); // returns actual bytes read
unsigned int recv_int(void);
int recv_lines_available(void);
int recv_line(char *line, int maxlength); // returns 0 if the line was terminated with a \r or \n, 1 if not.
// (i.e. if you specify maxlength=10, and the line is 12 bytes long
// it will return 1. or if there is no \r or \n and that's all the data
// the connection has.)
int peek_bytes(void *data, int maxlength); // returns bytes peeked
unsigned long get_interface(void); // this returns the interface the connection is on
unsigned long get_remote(void); // remote host ip.
short get_remote_port(void); // this returns the remote port of connection
protected:
int m_socket;
short m_remote_port;
char *m_recv_buffer;
char *m_send_buffer;
int m_recv_buffer_len;
int m_send_buffer_len;
int m_recv_pos;
int m_recv_len;
int m_send_pos;
int m_send_len;
struct sockaddr_in *m_saddr;
char m_host[256];
JNL_AsyncDNS *m_dns;
int m_dns_owned;
state m_state;
char *m_errorstr;
int getbfromrecv(int pos, int remove); // used by recv_line*
/*
** Joshua Teitelbaum 1/27/2006 Adding new BSD socket analogues for SSL compatibility
*/
virtual void socket_shutdown();
virtual int socket_recv(char *buf, int len, int options);
virtual int socket_send(char *buf, int len, int options);
virtual int socket_connect();
virtual void on_socket_connected();
};
#endif // _Connection_H_

View File

@ -0,0 +1,490 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: httpget.cpp - JNL HTTP GET implementation
** License: see jnetlib.h
*/
/*
** Undefine this if you don't want SSL compiled in
*/
#include "netinc.h"
#include "util.h"
#include "httpget.h"
#include "sslconnection.h"
JNL_HTTPGet::JNL_HTTPGet(JNL_AsyncDNS *dns, int recvbufsize, char *proxy)
{
m_recvbufsize=recvbufsize;
m_dns=dns;
m_con=NULL;
m_http_proxylpinfo=0;
m_http_proxyhost=0;
m_http_proxyport=0;
if (proxy && *proxy)
{
char *p=(char*)malloc(strlen(proxy)+1);
if (p)
{
char *r=NULL;
strcpy(p,proxy);
do_parse_url(p,&m_http_proxyhost,&m_http_proxyport,&r,&m_http_proxylpinfo);
free(r);
free(p);
}
}
m_sendheaders=NULL;
m_http_redir_url=0;
reinit();
}
void JNL_HTTPGet::reinit()
{
m_errstr=0;
m_recvheaders=NULL;
m_recvheaders_size=0;
m_http_state=0;
m_http_port=0;
m_http_url=0;
m_reply=0;
m_http_host=m_http_lpinfo=m_http_request=NULL;
}
void JNL_HTTPGet::deinit()
{
delete m_con; m_con = NULL;
free(m_recvheaders);
free(m_http_url);
free(m_http_host);
free(m_http_lpinfo);
free(m_http_request);
free(m_errstr);
free(m_reply);
reinit();
}
JNL_HTTPGet::~JNL_HTTPGet()
{
deinit();
free(m_sendheaders);
free(m_http_proxylpinfo);
free(m_http_proxyhost);
free(m_http_redir_url);
}
void JNL_HTTPGet::addheader(const char *header)
{
if (strstr(header,"\r") || strstr(header,"\n")) return;
if (!m_sendheaders)
{
m_sendheaders=(char*)malloc(strlen(header)+3);
if (m_sendheaders)
{
strcpy(m_sendheaders,header);
strcat(m_sendheaders,"\r\n");
}
}
else
{
char *t=(char*)malloc(strlen(header)+strlen(m_sendheaders)+1+2);
if (t)
{
strcpy(t,m_sendheaders);
strcat(t,header);
strcat(t,"\r\n");
free(m_sendheaders);
m_sendheaders=t;
}
}
}
void JNL_HTTPGet::do_encode_mimestr(char *in, char *out)
{
char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int shift = 0;
int accum = 0;
while (*in)
{
if (*in)
{
accum <<= 8;
shift += 8;
accum |= *in++;
}
while ( shift >= 6 )
{
shift -= 6;
*out++ = alphabet[(accum >> shift) & 0x3F];
}
}
if (shift == 4)
{
*out++ = alphabet[(accum & 0xF)<<2];
*out++='=';
}
else if (shift == 2)
{
*out++ = alphabet[(accum & 0x3)<<4];
*out++='=';
*out++='=';
}
*out++=0;
}
void JNL_HTTPGet::connect(const char *url, int ver, char *requestmethod)
{
deinit();
m_http_url=(char*)malloc(strlen(url)+1);
strcpy(m_http_url,url);
do_parse_url(m_http_url,&m_http_host,&m_http_port,&m_http_request, &m_http_lpinfo);
strcpy(m_http_url,url);
if (!m_http_host || !m_http_host[0] || !m_http_port)
{
m_http_state=-1;
seterrstr("invalid URL");
return;
}
int sendbufferlen=0;
if (!m_http_proxyhost || !m_http_proxyhost[0])
{
sendbufferlen += strlen(requestmethod)+1 /* GET */ + strlen(m_http_request) + 9 /* HTTP/1.0 */ + 2;
}
else
{
sendbufferlen += strlen(requestmethod)+1 /* GET */ + strlen(m_http_url) + 9 /* HTTP/1.0 */ + 2;
if (m_http_proxylpinfo&&m_http_proxylpinfo[0])
{
sendbufferlen+=58+strlen(m_http_proxylpinfo)*2; // being safe here
}
}
sendbufferlen += 5 /* Host: */ + strlen(m_http_host) + 2;
if (m_http_lpinfo&&m_http_lpinfo[0])
{
sendbufferlen+=46+strlen(m_http_lpinfo)*2; // being safe here
}
if (m_sendheaders) sendbufferlen+=strlen(m_sendheaders);
char *str=(char*)malloc(sendbufferlen+1024);
if (!str)
{
seterrstr("error allocating memory");
m_http_state=-1;
}
if (!m_http_proxyhost || !m_http_proxyhost[0])
{
wsprintf(str,"%s %s HTTP/1.%d\r\n",requestmethod,m_http_request,ver%10);
}
else
{
wsprintf(str,"%s %s HTTP/1.%d\r\n",requestmethod, m_http_url,ver%10);
}
wsprintf(str+strlen(str),"Host:%s\r\n",m_http_host);
if (m_http_lpinfo&&m_http_lpinfo[0])
{
strcat(str,"Authorization: Basic ");
do_encode_mimestr(m_http_lpinfo,str+strlen(str));
strcat(str,"\r\n");
}
if (m_http_proxylpinfo&&m_http_proxylpinfo[0])
{
strcat(str,"Proxy-Authorization: Basic ");
do_encode_mimestr(m_http_proxylpinfo,str+strlen(str));
strcat(str,"\r\n");
}
if (m_sendheaders) strcat(str,m_sendheaders);
strcat(str,"\r\n");
int a=m_recvbufsize;
if (a < 4096) a=4096;
//m_con=new JNL_Connection(m_dns,strlen(str)+4,a);
/*
** Joshua Teitelbaum delta 1/15/2006
*/
#ifdef _JNETLIB_SSL_
/*
** Joshua Teitelbaum 1/27/2006
** Check for secure
*/
if(!strnicmp(m_http_url,"https:",strlen("https:")))
{
m_con=new JNL_SSL_Connection(NULL,m_dns,8192,a);
}
else
{
m_con=new JNL_Connection(m_dns,8192,a);
}
#else
m_con=new JNL_Connection(m_dns,8192,a);
#endif
if (m_con)
{
if (!m_http_proxyhost || !m_http_proxyhost[0])
{
m_con->connect(m_http_host,m_http_port);
}
else
{
m_con->connect(m_http_proxyhost,m_http_proxyport);
}
m_con->send_string(str);
}
else
{
m_http_state=-1;
seterrstr("could not create connection object");
}
free(str);
}
void JNL_HTTPGet::do_parse_url(char *url, char **host, int *port, char **req, char **lp)
{
char *p,*np;
free(*host); *host=0;
free(*req); *req=0;
free(*lp); *lp=0;
if (strstr(url,"://")) np=p=strstr(url,"://")+3;
else np=p=url;
while (*np != '/' && *np) np++;
if (*np)
{
*req=(char*)malloc(strlen(np)+1);
if (*req) strcpy(*req,np);
*np++=0;
}
else
{
*req=(char*)malloc(2);
if (*req) strcpy(*req,"/");
}
np=p;
while (*np != '@' && *np) np++;
if (*np)
{
*np++=0;
*lp=(char*)malloc(strlen(p)+1);
if (*lp) strcpy(*lp,p);
p=np;
}
else
{
*lp=(char*)malloc(1);
if (*lp) strcpy(*lp,"");
}
np=p;
while (*np != ':' && *np) np++;
if (*np)
{
*np++=0;
*port=atoi(np);
}
else
{
/*
** Joshua Teitelbaum 1/27/2006
** HTTPS enhancements
*/
if(!strnicmp(url,"https:",strlen("https:")))
{
*port = 443;
}
else
*port=80;
}
*host=(char*)malloc(strlen(p)+1);
if (*host) strcpy(*host,p);
}
char *JNL_HTTPGet::getallheaders()
{ // double null terminated, null delimited list
if (m_recvheaders) return m_recvheaders;
else return "\0\0";
}
char *JNL_HTTPGet::getheader(char *headername)
{
char *ret=NULL;
if (strlen(headername)<1||!m_recvheaders) return NULL;
char *buf=(char*)malloc(strlen(headername)+2);
strcpy(buf,headername);
if (buf[strlen(buf)-1]!=':') strcat(buf,":");
char *p=m_recvheaders;
while (*p)
{
if (!strnicmp(buf,p,strlen(buf)))
{
ret=p+strlen(buf);
while (*ret == ' ') ret++;
break;
}
p+=strlen(p)+1;
}
free(buf);
return ret;
}
int JNL_HTTPGet::run()
{
int cnt=0;
if (m_http_state==-1||!m_con) return -1; // error
run_again:
m_con->run();
if (m_con->get_state()==JNL_Connection::STATE_ERROR)
{
seterrstr(m_con->get_errstr());
return -1;
}
if (m_con->get_state()==JNL_Connection::STATE_CLOSED) return 1;
if (m_http_state==0) // connected, waiting for reply
{
if (m_con->recv_lines_available()>0)
{
char buf[4096];
m_con->recv_line(buf,4095);
buf[4095]=0;
m_reply=(char*)malloc(strlen(buf)+1);
strcpy(m_reply,buf);
int code=getreplycode();
if (code == 200 || code==206) m_http_state=2; // proceed to read headers normally
else if (code == 301 || code==302)
{
m_http_state=1; // redirect city
}
else
{
seterrstr(buf);
m_http_state=-1;
return -1;
}
cnt=0;
}
else if (!cnt++) goto run_again;
}
if (m_http_state == 1) // redirect
{
while (m_con->recv_lines_available() > 0)
{
char buf[4096];
m_con->recv_line(buf,4096);
if (!buf[0])
{
m_http_state=-1;
return -1;
}
if (!strnicmp(buf,"Location:",9))
{
char *p=buf+9; while (*p== ' ') p++;
if (*p)
{
free(m_http_redir_url);
m_http_redir_url = strdup(p);
connect(p);
return 0;
}
}
}
}
if (m_http_state==2)
{
if (!cnt++ && m_con->recv_lines_available() < 1) goto run_again;
while (m_con->recv_lines_available() > 0)
{
char buf[4096];
m_con->recv_line(buf,4096);
if (!buf[0]) { m_http_state=3; break; }
if (!m_recvheaders)
{
m_recvheaders_size=strlen(buf)+1;
m_recvheaders=(char*)malloc(m_recvheaders_size+1);
if (m_recvheaders)
{
strcpy(m_recvheaders,buf);
m_recvheaders[m_recvheaders_size]=0;
}
}
else
{
int oldsize=m_recvheaders_size;
m_recvheaders_size+=strlen(buf)+1;
char *n=(char*)malloc(m_recvheaders_size+1);
if (n)
{
memcpy(n,m_recvheaders,oldsize);
strcpy(n+oldsize,buf);
n[m_recvheaders_size]=0;
free(m_recvheaders);
m_recvheaders=n;
}
}
}
}
if (m_http_state==3)
{
}
return 0;
}
int JNL_HTTPGet::get_status() // returns 0 if connecting, 1 if reading headers,
// 2 if reading content, -1 if error.
{
if (m_http_state < 0) return -1;
if (m_http_state < 2) return 0;
if (m_http_state == 2) return 1;
if (m_http_state == 3) return 2;
return -1;
}
int JNL_HTTPGet::getreplycode()// returns 0 if none yet, otherwise returns http reply code.
{
if (!m_reply) return 0;
char *p=m_reply;
while (*p && *p != ' ') p++; // skip over HTTP/x.x
if (!*p) return 0;
return atoi(++p);
}
int JNL_HTTPGet::bytes_available()
{
if (m_con && m_http_state==3) return m_con->recv_bytes_available();
return 0;
}
char *JNL_HTTPGet::getredirurl() { return m_http_redir_url; }
int JNL_HTTPGet::get_bytes(char *buf, int len)
{
if (m_con && m_http_state==3) return m_con->recv_bytes(buf,len);
return 0;
}
int JNL_HTTPGet::peek_bytes(char *buf, int len)
{
if (m_con && m_http_state==3) return m_con->peek_bytes(buf,len);
return 0;
}

View File

@ -0,0 +1,112 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: httpget.h - JNL interface for doing HTTP GETs.
** License: see jnetlib.h
**
** Usage:
** 1. Create a JNL_HTTPGet object, optionally specifying a JNL_AsyncDNS
** object to use (or NULL for none, or JNL_CONNECTION_AUTODNS for auto),
** and the receive buffer size, and a string specifying proxy (or NULL
** for none). See note on proxy string below.
** 2. call addheader() to add whatever headers you want. It is recommended to
** add at least the following two:
** addheader("User-Agent:MyApp (Mozilla)");
*/// addheader("Accept:*/*");
/* ( the comment weirdness is there so I Can do the star-slash :)
** 3. Call connect() with the URL you wish to GET (see URL string note below)
** 4. Call run() once in a while, checking to see if it returns -1
** (if it does return -1, call geterrorstr() to see what the error is).
** (if it returns 1, no big deal, the connection has closed).
** 5. While you're at it, you can call bytes_available() to see if any data
** from the http stream is available, or getheader() to see if any headers
** are available, or getreply() to see the HTTP reply, or getallheaders()
** to get a double null terminated, null delimited list of headers returned.
** 6. If you want to read from the stream, call get_bytes (which returns how much
** was actually read).
** 7. content_length() is a helper function that uses getheader() to check the
** content-length header.
** 8. Delete ye' ol' object when done.
**
** Proxy String:
** should be in the format of host:port, or user@host:port, or
** user:password@host:port. if port is not specified, 80 is assumed.
** URL String:
** should be in the format of http://user:pass@host:port/requestwhatever
** note that user, pass, port, and /requestwhatever are all optional :)
** note that also, http:// is really not important. if you do poo://
** or even leave out the http:// altogether, it will still work.
*/
#ifndef _HTTPGET_H_
#define _HTTPGET_H_
#include "connection.h"
class JNL_HTTPGet
{
public:
JNL_HTTPGet(JNL_AsyncDNS *dns=JNL_CONNECTION_AUTODNS, int recvbufsize=16384, char *proxy=NULL);
~JNL_HTTPGet();
void addheader(const char *header);
void connect(const char *url, int ver=0, char *requestmethod="GET");
int run(); // returns: 0 if all is OK. -1 if error (call geterrorstr()). 1 if connection closed.
int get_status(); // returns 0 if connecting, 1 if reading headers,
// 2 if reading content, -1 if error.
char *getallheaders(); // double null terminated, null delimited list
char *getheader(char *headername);
char *getreply() { return m_reply; }
int getreplycode(); // returns 0 if none yet, otherwise returns http reply code.
char *geterrorstr() { return m_errstr;}
char *getredirurl();
int bytes_available();
int get_bytes(char *buf, int len);
int peek_bytes(char *buf, int len);
int content_length() { char *p=getheader("content-length"); if (p) return atoi(p); return 0; }
JNL_Connection *get_con() { return m_con; }
protected:
void reinit();
void deinit();
void seterrstr(char *str) { if (m_errstr) free(m_errstr); m_errstr=(char*)malloc(strlen(str)+1); strcpy(m_errstr,str); }
void do_parse_url(char *url, char **host, int *port, char **req, char **lp);
void do_encode_mimestr(char *in, char *out);
JNL_AsyncDNS *m_dns;
JNL_Connection *m_con;
int m_recvbufsize;
int m_http_state;
int m_http_port;
char *m_http_url;
char *m_http_redir_url;
char *m_http_host;
char *m_http_lpinfo;
char *m_http_request;
char *m_http_proxylpinfo;
char *m_http_proxyhost;
int m_http_proxyport;
char *m_sendheaders;
char *m_recvheaders;
int m_recvheaders_size;
char *m_reply;
char *m_errstr;
};
#endif // _HTTPGET_H_

View File

@ -0,0 +1,412 @@
/*
** JNetLib
** Copyright (C) Joshua Teitelbaum, sergent first class, 1014 army.
** Author: Joshua Teitelbaum
** File: httppost.cpp
** License: see jnetlib.h
*/
#ifdef _WIN32
#include <windows.h>
#include <malloc.h>
#endif
#include "netinc.h"
#include "util.h"
#include "httppost.h"
#include <malloc/malloc.h>
#include <sys/stat.h>
static char *PREFIX = "--";
static char *NEWLINE = "\r\n";
/*
** Joshua Teitelbaum 1/15/2006
** 1014 Army, Sergent First Class
** HTTP Post implementation employing HTTPGet as base class.
*/
/*
** _endstack
** when building the POST stack for a FORM, need a postamble
*/
void JNL_HTTPPost::_endstack()
{
std::string cd;
cd = PREFIX;
cd += m_boundary;
cd += PREFIX;
cd += NEWLINE;
FILEStackObject fso;
fso.m_otype = 2;
fso.m_str = cd;
m_filestack.push_back(fso);
}
/*
** prepares one field and puts it on the stack
*/
void JNL_HTTPPost::_preparefield(std::string &name)
{
std::string cd;
cd = PREFIX;
cd += m_boundary;
cd += NEWLINE;
cd += "content-disposition: form-data; name=\"";
cd += name;
cd += "\"";
cd += NEWLINE;
cd += NEWLINE;
cd += m_fields[name];
cd += "\r\n";
FILEStackObject fso;
fso.m_otype = 3;
fso.m_str = cd;
m_filestack.push_back(fso);
}
/*
** prepare all the fields, and push them on the stack
*/
void JNL_HTTPPost::_preparefieldstack()
{
std::map<std::string, std::string>::iterator it;
for(it = m_fields.begin(); it != m_fields.end(); it++)
{
std::string str = (*it).first;
_preparefield(str);
}
}
/*
** prepare files and put them on the stack
*/
void JNL_HTTPPost::_preparefilestack()
{
std::map<std::string, std::string>::iterator it;
for(it = m_paths.begin(); it != m_paths.end(); it++)
{
/*
--boundary\r\n
Content-Disposition: form-data; name="<fieldName>"; filename="<filename>"\r\n
Content-Type: <mime-type>\r\n
\r\n
<file-data>\r\n
*/
std::string cd ;
cd = PREFIX;
cd += m_boundary;
cd += NEWLINE;
cd += "content-disposition: form-data; name=\"";
cd += (*it).first;
cd += "\"; filename=\"";
cd += m_filenames[(*it).first];
cd += "\"";
cd += NEWLINE;
cd += "content-type: ";
cd += m_content_type[(*it).first];
cd += NEWLINE;
cd += NEWLINE;
FILEStackObject fso;
fso.m_otype = 0;
fso.m_str = cd;
m_filestack.push_back(fso);
fso.m_otype = 1;
fso.m_str = (*it).first;
m_filestack.push_back(fso);
cd = NEWLINE;
fso.m_otype = 2;
fso.m_str = cd;
m_filestack.push_back(fso);
}
}
/*
** payload function, run.
** the tactic is this:
** if we can't write, do normal run.
**
** while there is stuff on the POST stack
** pop and item
** write to the buffers as much as we can
** if we can't write more, stop
** end while
** do normal run
*/
int JNL_HTTPPost::run()
{
bool stop = 0;
std::map<std::string, std::string>::iterator it;
int ntowrite;
int retval;
do
{
if(m_con->send_bytes_available() <= 0)
{
/*
** rut roh, no buffa
*/
break;
}
if(m_filestack.size() <= 0)
{
/*
** Nothing to do
*/
break;
}
/*
** Get the current object off the stack
*/
switch(m_filestack.front().m_otype)
{
case 0: /*preamble*/
case 2: /*postamble*/
case 3: /*plain jane field*/
{
ntowrite = m_filestack.front().m_str.length() - m_filestack.front().nwritten;
if(m_con->send_bytes_available() < ntowrite)
{
ntowrite = m_con->send_bytes_available();
}
if(ntowrite>0)
{
retval = m_con->send(m_filestack.front().m_str.c_str() + m_filestack.front().nwritten,ntowrite);
if(retval < 0)
{
break;
}
m_filestack.front().nwritten += ntowrite;
m_nwritten += ntowrite;
if( m_filestack.front().nwritten == m_filestack.front().m_str.length())
{
/*
** all done with this object
*/
m_filestack.pop_front();
}
}
else
{
retval = 0;
stop = true;
}
}
break;
case 1: /*MEAT*/
{
FILE *fp;
int sresult;
fp = fopen(m_paths[m_filestack.front().m_str].c_str(),"rb");
if(fp == NULL)
{
/*
** someone gave this process a hot foot?
*/
return -1;
}
sresult = fseek(fp,m_filestack.front().nwritten,SEEK_SET);
if(sresult < 0)
{
/*
** someone gave this process a hot foot?
*/
fclose(fp);
return -1;
}
if(((m_content_length[m_filestack.front().m_str] - m_filestack.front().nwritten)) > (unsigned long)m_con->send_bytes_available())
{
ntowrite = m_con->send_bytes_available();
}
else
{
ntowrite = (m_content_length[m_filestack.front().m_str] - m_filestack.front().nwritten);
}
char *b=NULL;
b = (char *)malloc(ntowrite);
if(b == NULL)
{
return -1;
/*
** whiskey tango foxtrot
*/
}
/*
** read from where we left off
*/
sresult = fread(b,1,ntowrite,fp);
if(sresult != ntowrite)
{
/*
** hot foot with matches again
*/
if(b)
{
free(b);
}
fclose(fp);
return -1;
}
fclose(fp);
retval = m_con->send(b,ntowrite);
free(b);
if(retval < 0)
{
return retval;
}
m_filestack.front().nwritten += ntowrite;
m_nwritten += ntowrite;
if(m_filestack.front().nwritten == m_content_length[m_filestack.front().m_str])
{
m_filestack.pop_front();
}
}
break;
}
} while(!stop);
return JNL_HTTPGet::run();
}
/*
** addfield, adds field
*/
int JNL_HTTPPost::addfield(char *name, char *val)
{
if(name == NULL || val == NULL)
{
return -1;
}
m_fields[name]=val;
return 0;
}
/*
** addfile, adds file
*/
int JNL_HTTPPost::addfile(char *name, char *mimetype, char *filename, char *filepath)
{
struct stat buffer;
FILE *fp=NULL;
if(name==NULL || filepath == NULL || mimetype == NULL || filename == NULL || (!(fp=fopen(filepath,"rb"))))
{
return -1;
}
m_content_type[name] = mimetype;
m_paths[name] = filepath;
m_filenames[name] = filename;
fstat(fileno(fp),&buffer);
fclose(fp);
m_content_length[name] = buffer.st_size;
return 0;
}
/*
** After adding fields and files, get the content length
*/
int JNL_HTTPPost::contentlength()
{
std::map<std::string,std::string>::iterator it;
std::string tmp;
int length = 0;
// fields
{
for (it = m_fields.begin(); it != m_fields.end(); it++)
{
std::string name = (*it).first;
std::string value = (*it).second;
tmp = "--" + m_boundary + "\r\n"
"content-disposition: form-data; name=\"" + name + "\"\r\n"
"\r\n";
tmp += value + "\r\n";
length += tmp.size();
}
}
// files
{
for (it = m_filenames.begin(); it != m_filenames.end(); it++)
{
std::string name = (*it).first;
std::string filename = (*it).second;
long content_length = m_content_length[name];
std::string content_type = m_content_type[name];
tmp = "--" + m_boundary + "\r\n"
"content-disposition: form-data; name=\"" + name + "\"; filename=\"" + filename + "\"\r\n"
"content-type: " + content_type + "\r\n"
"\r\n";
length += tmp.size();
length += content_length;
length += 2; // crlf after file
}
}
// end
tmp = "--" + m_boundary + "--\r\n";
length += tmp.size();
return length;
}
void JNL_HTTPPost::_addformheader()
{
char *h;
#ifdef _WIN32
srand(GetTickCount());
#else
srand(time(NULL));
#endif
int x;
char *preamble = "content-type:multipart/form-data; boundary=";
char *dashes = "----";
char *post_boundary = (char*)alloca(10+strlen(dashes));
memcpy(post_boundary,dashes,strlen(dashes));
for(x=strlen(dashes); x < (int)strlen(dashes)+9; x++)
{
post_boundary[x] = (char)(rand() % 9) + '0';
}
post_boundary[x] = 0;
h = (char *)alloca(strlen(preamble) + strlen(post_boundary) + 1);
sprintf(h,"%s%s",preamble,post_boundary);
addheader(h);
m_boundary = post_boundary;
}

View File

@ -0,0 +1,129 @@
/*
** JNetLib
** Copyright (C) Joshua Teitelbaum, sergent first class, 1014 army.
** Author: Joshua Teitelbaum
** File: httppost.cpp/h
** License: see jnetlib.h
** Usage:
** 1. Create a JNL_HTTPPost object, optionally specifying a JNL_AsyncDNS
** object to use (or NULL for none, or JNL_CONNECTION_AUTODNS for auto),
** and the receive buffer size, and a string specifying proxy (or NULL
** for none). See note on proxy string below.
** 2. call addheader() to add whatever headers you want. It is recommended to
** add at least the following two:
** addheader("User-Agent:MyApp (Mozilla)");
*/// addheader("Accept:*/*");
/* Joshua Teitelbaum 1/15/2006
** 2.5 call addfield to add field items to your POST
** 2.9 call addfile to add file items to your POST
*/
/* ( the comment weirdness is there so I Can do the star-slash :)
** 3. Call connect() with the URL you wish to Post (see URL string note below)
** 4. Call run() once in a while, checking to see if it returns -1
** (if it does return -1, call geterrorstr() to see what the error is).
** (if it returns 1, no big deal, the connection has closed).
** 5. While you're at it, you can call bytes_available() to see if any data
** from the http stream is available, or getheader() to see if any headers
** are available, or getreply() to see the HTTP reply, or getallheaders()
** to get a double null terminated, null delimited list of headers returned.
** 6. If you want to read from the stream, call get_bytes (which returns how much
** was actually read).
** 7. content_length() is a helper function that uses getheader() to check the
** content-length header.
** 8. Delete ye' ol' object when done.
**
** Proxy String:
** should be in the format of host:port, or user@host:port, or
** user:password@host:port. if port is not specified, 80 is assumed.
** URL String:
** should be in the format of http://user:pass@host:port/requestwhatever
** note that user, pass, port, and /requestwhatever are all optional :)
** note that also, http:// is really not important. if you do poo://
** or even leave out the http:// altogether, it will still work.
*/
#ifndef _HTTPPOST_H_
#define _HTTPPOST_H_
#include "connection.h"
#include "httpget.h"
/*
** VC6 SPEW
*/
#pragma warning(disable:4786)
/*
** END VC6 SPEW
*/
#include <string>
#include <list>
#include <map>
class FILEStackObject
{
public:
int m_otype; /* 0 = PREAMBLE, 1 = DO THE FILE , 2 = POSTAMBLE, 3 = FIELD */
std::string m_str;
unsigned long nwritten;
public:
FILEStackObject()
{
m_otype = 0;
m_str = "";
nwritten = 0;
}
};
class JNL_HTTPPost : public JNL_HTTPGet
{
public:
int run(void);
void connect(const char *url, int ver=1, char *requestmethod="POST")
{
m_nwritten = 0;
_addformheader();
_preparefieldstack();
_preparefilestack();
_addcontentlength();
_endstack();
JNL_HTTPGet::connect(url,ver,requestmethod);
}
int addfield(char *name, char *val);
int addfile(char *name, char *mimetype, char *filename, char *filepath);
int contentlength();
unsigned long written(){return m_nwritten;};
protected:
void _preparefield(std::string &str);
void _preparefieldstack();
void _preparefilestack();
void _endstack();
void _addformheader();
void _addcontentlength()
{
char sz[1024];
sprintf(sz,"Content-length:%d",contentlength());
addheader(sz);
}
unsigned long m_nwritten;
std::string m_boundary;
std::string m_strcurrentfileformname;
std::map<std::string /*name*/ ,std::string /*value*/> m_fields;
std::map<std::string /*name*/ ,std::string /*content type*/> m_content_type;
std::map<std::string /*name*/ ,std::string /*path*/> m_paths;
std::map<std::string /*name*/ ,std::string /*filename*/> m_filenames;
std::map<std::string /*name */,unsigned long /*size*/> m_content_length;
std::list<FILEStackObject> m_filestack;
};
#endif // _HTTPPOST_H_

View File

@ -0,0 +1,233 @@
/*
** JNetLib
** Copyright (C) 2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: httpserv.cpp - JNL HTTP GET/POST serving implementation
** License: see jnetlib.h
**
** This class just manages the http reply/sending, not where the data
** comes from, etc.
*/
#include "netinc.h"
#include "util.h"
#include "httpserv.h"
/*
States for m_state:
-1 error (connection closed, etc)
0 not read request yet.
1 reading headers
2 headers read, have not sent reply
3 sent reply
4 closed
*/
JNL_HTTPServ::JNL_HTTPServ(JNL_Connection *con)
{
m_con=con;
m_state=0;
m_reply_headers=0;
m_reply_string=0;
m_recvheaders=0;
m_recv_request=0;
m_recvheaders_size=0;
m_errstr=0;
m_reply_ready=0;
}
JNL_HTTPServ::~JNL_HTTPServ()
{
free(m_recv_request);
free(m_recvheaders);
free(m_reply_string);
free(m_reply_headers);
free(m_errstr);
delete m_con;
}
int JNL_HTTPServ::run()
{ // returns: < 0 on error, 0 on connection close, 1 if reading request, 2 if reply not sent, 3 if reply sent, sending data.
int cnt=0;
run_again:
m_con->run();
if (m_con->get_state()==JNL_Connection::STATE_ERROR)
{
seterrstr(m_con->get_errstr());
return -1;
}
if (m_con->get_state()==JNL_Connection::STATE_CLOSED) return 4;
if (m_state == 0)
{
if (m_con->recv_lines_available()>0)
{
char *buf=(char*)malloc(m_con->recv_bytes_available()-1);
m_con->recv_line(buf,m_con->recv_bytes_available()-1);
free(m_recv_request);
m_recv_request=(char*)malloc(strlen(buf)+2);
strcpy(m_recv_request,buf);
m_recv_request[strlen(m_recv_request)+1]=0;
free(buf);
buf=m_recv_request;
while (*buf) buf++;
while (buf >= m_recv_request && *buf != ' ') buf--;
if (strncmp(buf+1,"HTTP",4) || strncmp(m_recv_request,"GET ",3))
{
seterrstr("malformed HTTP request");
m_state=-1;
}
else
{
m_state=1;
cnt=0;
if (buf >= m_recv_request) buf[0]=buf[1]=0;
buf=strstr(m_recv_request,"?");
if (buf)
{
*buf++=0; // change &'s into 0s now.
char *t=buf;
int stat=1;
while (*t)
{
if (*t == '&' && !stat) { stat=1; *t=0; }
else stat=0;
t++;
}
}
}
}
else if (!cnt++) goto run_again;
}
if (m_state == 1)
{
if (!cnt++ && m_con->recv_lines_available()<1) goto run_again;
while (m_con->recv_lines_available()>0)
{
char buf[4096];
buf[0]=0;
m_con->recv_line(buf,4096);
if (!buf[0]) { m_state=2; break; }
if (!m_recvheaders)
{
m_recvheaders_size=strlen(buf)+1;
m_recvheaders=(char*)malloc(m_recvheaders_size+1);
if (m_recvheaders)
{
strcpy(m_recvheaders,buf);
m_recvheaders[m_recvheaders_size]=0;
}
}
else
{
int oldsize=m_recvheaders_size;
m_recvheaders_size+=strlen(buf)+1;
char *n=(char*)malloc(m_recvheaders_size+1);
if (n)
{
memcpy(n,m_recvheaders,oldsize);
strcpy(n+oldsize,buf);
n[m_recvheaders_size]=0;
free(m_recvheaders);
m_recvheaders=n;
}
}
}
}
if (m_state == 2)
{
if (m_reply_ready)
{
// send reply
m_con->send_string((char*)(m_reply_string?m_reply_string:"HTTP/1.1 200 OK"));
m_con->send_string("\r\n");
if (m_reply_headers) m_con->send_string(m_reply_headers);
m_con->send_string("\r\n");
m_state=3;
}
}
if (m_state == 3)
{
// nothing.
}
return m_state;
}
char *JNL_HTTPServ::get_request_file()
{
// file portion of http request
if (!m_recv_request) return NULL;
char *t=m_recv_request;
while (*t != ' ' && *t) t++;
if (!*t) return NULL;
while (*t == ' ') t++;
return t;
}
char *JNL_HTTPServ::get_request_parm(char *parmname) // parameter portion (after ?)
{
char *t=m_recv_request;
while (*t) t++;
t++;
while (*t)
{
while (*t == '&') t++;
if (!strnicmp(t,parmname,strlen(parmname)) && t[strlen(parmname)] == '=')
{
return t+strlen(parmname)+1;
}
t+=strlen(t)+1;
}
return NULL;
}
char *JNL_HTTPServ::getheader(char *headername)
{
char *ret=NULL;
if (strlen(headername)<1||!m_recvheaders) return NULL;
char *buf=(char*)malloc(strlen(headername)+2);
strcpy(buf,headername);
if (buf[strlen(buf)-1]!=':') strcat(buf,":");
char *p=m_recvheaders;
while (*p)
{
if (!strnicmp(buf,p,strlen(buf)))
{
ret=p+strlen(buf);
while (*ret == ' ') ret++;
break;
}
p+=strlen(p)+1;
}
free(buf);
return ret;
}
void JNL_HTTPServ::set_reply_string(char *reply_string) // should be HTTP/1.1 OK or the like
{
free(m_reply_string);
m_reply_string=(char*)malloc(strlen(reply_string)+1);
strcpy(m_reply_string,reply_string);
}
void JNL_HTTPServ::set_reply_header(char *header) // "Connection: close" for example
{
if (m_reply_headers)
{
char *tmp=(char*)malloc(strlen(m_reply_headers)+strlen(header)+3);
strcpy(tmp,m_reply_headers);
strcat(tmp,header);
strcat(tmp,"\r\n");
free(m_reply_headers);
m_reply_headers=tmp;
}
else
{
m_reply_headers=(char*)malloc(strlen(header)+3);
strcpy(m_reply_headers,header);
strcat(m_reply_headers,"\r\n");
}
}

View File

@ -0,0 +1,62 @@
/*
** JNetLib
** Copyright (C) 2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: httpserv.h - JNL interface for doing HTTP GET/POST serving.
** License: see jnetlib.h
** This class just manages the http reply/sending, not where the data
** comes from, etc.
** for a mini-web server see webserver.h
*/
#ifndef _HTTPSERV_H_
#define _HTTPSERV_H_
#include "connection.h"
class JNL_HTTPServ
{
public:
JNL_HTTPServ(JNL_Connection *con);
~JNL_HTTPServ();
int run(); // returns: < 0 on error, 0 on request not read yet, 1 if reading headers, 2 if reply not sent, 3 if reply sent, sending data. 4 on connection closed.
char *geterrorstr() { return m_errstr;}
// use these when state returned by run() is 2
char *get_request_file(); // file portion of http request
char *get_request_parm(char *parmname); // parameter portion (after ?)
char *getallheaders() { return m_recvheaders; } // double null terminated, null delimited list
char *getheader(char *headername);
void set_reply_string(char *reply_string); // should be HTTP/1.1 OK or the like
void set_reply_header(char *header); // i.e. "content-size: 12345"
void send_reply() { m_reply_ready=1; } // send reply, state will advance to 3.
////////// sending data ///////////////
int bytes_inqueue() { if (m_state == 3 || m_state == -1 || m_state ==4) return m_con->send_bytes_in_queue(); else return 0; }
int bytes_cansend() { if (m_state == 3) return m_con->send_bytes_available(); else return 0; }
void write_bytes(char *bytes, int length) { m_con->send(bytes,length); }
void close(int quick) { m_con->close(quick); m_state=4; }
JNL_Connection *get_con() { return m_con; }
protected:
void seterrstr(char *str) { if (m_errstr) free(m_errstr); m_errstr=(char*)malloc(strlen(str)+1); strcpy(m_errstr,str); }
int m_reply_ready;
int m_state;
char *m_errstr;
char *m_reply_headers;
char *m_reply_string;
char *m_recvheaders;
int m_recvheaders_size;
char *m_recv_request; // either double-null terminated, or may contain parameters after first null.
JNL_Connection *m_con;
};
#endif // _HTTPSERV_H_

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,472 @@
#ifndef _JNL_IRCCLIENT_H_
#define _JNL_IRCCLIENT_H_
#ifdef WIN32
#include <malloc.h>
#endif
#include "connection.h"
#include <string>
#include <list>
#include <ctype.h>
/*
** ERRORS
*/
#define ERR_NOSUCHNICK 401
#define ERR_NOSUCHSERVER 402
#define ERR_NOSUCHCHANNEL 403
#define ERR_CANNOTSENDTOCHAN 404
#define ERR_TOOMANYCHANNELS 405
#define ERR_WASNOSUCHNICK 406
#define ERR_TOOMANYTARGETS 407
#define ERR_NOORIGIN 409
#define ERR_NORECIPIENT 411
#define ERR_NOTEXTTOSEND 412
#define ERR_NOTOPLEVEL 413
#define ERR_WILDTOPLEVEL 414
#define ERR_UNKNOWNCOMMAND 421
#define ERR_NOMOTD 422
#define ERR_NOADMININFO 423
#define ERR_FILEERROR 424
#define ERR_NONICKNAMEGIVEN 431
#define ERR_ERRONEUSNICKNAME 432
#define ERR_NICKNAMEINUSE 433
#define ERR_NICKCOLLISION 436
#define ERR_USERNOTINCHANNEL 441
#define ERR_NOTONCHANNEL 442
#define ERR_USERONCHANNEL 443
#define ERR_NOLOGIN 444
#define ERR_SUMMONDISABLED 445
#define ERR_USERSDISABLED 446
#define ERR_NOTREGISTERED 451
#define ERR_NEEDMOREPARAMS 461
#define ERR_ALREADYREGISTRED 462
#define ERR_NOPERMFORHOST 463
#define ERR_PASSWDMISMATCH 464
#define ERR_YOUREBANNEDCREEP 465
#define ERR_KEYSET 467
#define ERR_CHANNELISFULL 471
#define ERR_UNKNOWNMODE 472
#define ERR_INVITEONLYCHAN 473
#define ERR_BANNEDFROMCHAN 474
#define ERR_BADCHANNELKEY 475
#define ERR_NOPRIVILEGES 481
#define ERR_CHANOPRIVSNEEDED 482
#define ERR_CANTKILLSERVER 483
#define ERR_NOOPERHOST 491
#define ERR_UMODEUNKNOWNFLAG 501
#define ERR_USERSDONTMATCH 502
/*
** Replies
*/
#define RPL_NONE 300
#define RPL_USERHOST 302
#define RPL_ISON 303
#define RPL_AWAY 301
#define RPL_UNAWAY 305
#define RPL_NOWAWAY 306
#define RPL_WHOISUSER 311
#define RPL_WHOISSERVER 312
#define RPL_WHOISOPERATOR 313
#define RPL_WHOISIDLE 317
#define RPL_ENDOFWHOIS 318
#define RPL_WHOISCHANNELS 319
#define RPL_WHOWASUSER 314
#define RPL_ENDOFWHOWAS 369
#define RPL_LISTSTART 321
#define RPL_LIST 322
#define RPL_LISTEND 323
#define RPL_CHANNELMODEIS 324
#define RPL_NOTOPIC 331
#define RPL_TOPIC 332
#define RPL_WHOISREALIP 338
#define RPL_INVITING 341
#define RPL_SUMMONING 342
#define RPL_VERSION 351
#define RPL_WHOREPLY 352
#define RPL_ENDOFWHO 315
#define RPL_NAMREPLY 353
#define RPL_ENDOFNAMES 366
#define RPL_LINKS 364
#define RPL_ENDOFLINKS 365
#define RPL_BANLIST 367
#define RPL_ENDOFBANLIST 368
#define RPL_INFO 371
#define RPL_ENDOFINFO 374
#define RPL_MOTDSTART 375
#define RPL_MOTD 372
#define RPL_ENDOFMOTD 376
#define RPL_YOUREOPER 381
#define RPL_REHASHING 382
#define RPL_TIME 391
#define RPL_USERSSTART 392
#define RPL_USERS 393
#define RPL_ENDOFUSERS 394
#define RPL_NOUSERS 395
#define RPL_TRACELINK 200
#define RPL_TRACECONNECTING 201
#define RPL_TRACEHANDSHAKE 202
#define RPL_TRACEUNKNOWN 203
#define RPL_TRACEOPERATOR 204
#define RPL_TRACEUSER 205
#define RPL_TRACESERVER 206
#define RPL_TRACENEWTYPE 208
#define RPL_TRACELOG 261
#define RPL_STATSLINKINFO 211
#define RPL_STATSCOMMANDS 212
#define RPL_STATSCLINE 213
#define RPL_STATSNLINE 214
#define RPL_STATSILINE 215
#define RPL_STATSKLINE 216
#define RPL_STATSYLINE 218
#define RPL_ENDOFSTATS 219
#define RPL_STATSLLINE 241
#define RPL_STATSUPTIME 242
#define RPL_STATSOLINE 243
#define RPL_STATSHLINE 244
#define RPL_STATSULINE 246
#define RPL_UMODEIS 221
#define RPL_LUSERCLIENT 251
#define RPL_LUSEROP 252
#define RPL_LUSERUNKNOWN 253
#define RPL_LUSERCHANNELS 254
#define RPL_LUSERME 255
#define RPL_ADMINME 256
#define RPL_ADMINLOC1 257
#define RPL_ADMINLOC2 258
#define RPL_ADMINEMAIL 259
#define RPL_LUSERLOCAL 265
#define RPL_LUSERGLOBAL 266
typedef enum
{
JNL_IRC_RETVAL_OK = 0,
JNL_IRC_RETVAL_FAIL
}JNL_IRC_RETVAL;
class JNL_IRCParams
{
public:
std::string middle;
std::string trailing;
JNL_IRCParams *m_params;
JNL_IRCParams::JNL_IRCParams()
{
m_params = NULL;
}
~JNL_IRCParams()
{
if(m_params)
{
/*
** delete children first.
*/
delete m_params;
m_params = NULL;
}
}
};
class JNL_IRCMessage
{
public:
JNL_IRCMessage()
{
}
~JNL_IRCMessage()
{
}
public:
std::string m_prefix;
std::string m_command;
JNL_IRCParams m_params;
const char *command()
{
return m_command.c_str();
}
int messagenum()
{
if(isdigit(m_command[0]))
{
return atoi(m_command.c_str());
}
return 0;
}
};
/*
** JNL_IRCConnection:
** sends and receives IRC messages
** When run is called, it stores IRC messages in its queue.
** After run, you may then call get_message() until there are none (null).
**
** The JNL_IRCClient exemplifies this in its version
** of run.
*/
class JNL_IRCConnection
{
protected:
JNL_Connection *m_con;
std::list<JNL_IRCMessage*> m_messagequeue;
public:
JNL_IRCConnection();
virtual ~JNL_IRCConnection();
bool connect(char *szHost, unsigned short nPort=6667);
void close()
{
m_con->close(1);
}
bool send_message(const char *fmt,...);
bool run(void);
JNL_IRCMessage *get_message();
protected:
bool _process_line(const char *szline);
int _parse_paramlist(const char *szline,JNL_IRCParams &p);
};
/*
** JNL_IRCClient
** Very basic, and woefully incomplete client
** Here's what it can do, and what you probably should use from this:
** Use the 'sending' block of commands
** They are, sendpass, nick, oper, quit....etc.
**
** Next, there are quite a few virtual methods at your disposal to override.
** They will be called if this, the base class, JNL_IRCClient's process_message is called.
** If you want to short circuit those events, then override process_message and do your own
** event dispatching.
**
** Else, just let JNL_IRCClient's process_message run, and you override the on*** methods.
*/
class JNL_IRCClient
{
protected:
JNL_IRCConnection m_con;
public:
JNL_IRCClient()
{
}
virtual ~JNL_IRCClient()
{
m_con.close();
}
void close()
{
m_con.close();
}
bool connect(char *szHost, unsigned short nPort=6667)
{
return m_con.connect(szHost,nPort);
}
bool run(void);
virtual JNL_IRC_RETVAL process_message(JNL_IRCMessage &m);
bool sendpass(char *password);
bool nick(char *nick);
bool oper(char *user, char *password);
bool quit(char *swansong);
bool part(char *swansong);
bool join(char *channel, char *key=NULL);
bool setmode(char *channel, int isadd, char mode, char *param=NULL);
bool topic(char *channel, char *topic=NULL);
bool userregistration(char *username="poopoo", char *hostname="hostname", char *servername="servername", char *realname="poopoo platter");
bool opuser(char *channel, char *nick)
{
return setmode(channel,1,'o',nick);
}
bool deopuser(char *channel, char *nick)
{
return setmode(channel,0,'o',nick);
}
bool voiceuser(char *channel, char *nick)
{
return setmode(channel,1,'v',nick);
}
bool devoiceuser(char *channel, char *nick)
{
return setmode(channel,0,'v',nick);
}
bool banuser(char *channel, char *banstring)
{
return setmode(channel,1,'b',banstring);
}
bool unbanuser(char *channel, char *banstring)
{
return setmode(channel,0,'b',banstring);
}
bool names(char *channel=NULL);
bool list(char *channel=NULL);
bool invite(char *nick, char *channel);
bool kick(char *channel, char *user, char *swansong=NULL);
bool version(char *server=NULL);
bool stats(char query = 0, char *server=NULL);
bool links(char *remote=NULL, char *mask=NULL);
bool time(char *server=NULL);
/*
** Missing trace and connect
*/
bool admin(char *server=NULL);
bool info(char *server=NULL);
bool privmsg(char *recipient, char *msg, bool baction=false);
bool notice(char *recipient, char *msg);
bool who(char *nick, char o=0);
bool whois(char *server,char *nick);
bool ping(char *server);
bool pong(char *server);
/*
** Missing whowas and kill, and error
*/
protected:
virtual JNL_IRC_RETVAL onErrNoSuckNick(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrNoSuchServer(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrNoSuchChannel(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrCannotSendToChan(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrTooManyChannels(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrWasNoSuchNick(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrTooManyTargets(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrNoOrigin(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrNoRecipient(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrNoTextToSend(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrNoTopLevel(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrWildTopLevel(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrUnknownCommand(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrNoMOTD(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrNoAdminInfo(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrFileError(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrNoNickNameGiven(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrOneUSNickName(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrNickNameInUse(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrNickCollision(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrNotOnChannel(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrUserNotInChannel(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrUserOnChannel(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrNoLogin(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrSummonDisabled(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrUserDisabled(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrNotRegistered(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrNeedMoreParams(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrAlreadyRegistered(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrNoPermForHost(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrPasswdMismatch(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrYourBannedCreep(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrKeySet(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrChannelIsFull(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrUnknownMode(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrInviteOnlyChan(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrBannedFromChan(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrBadChannelKey(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrNoPrivileges(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrChanOpPrivsNeeded(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrCantKillServer(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrNoOperHost(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrUModeUnknownFlag(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onErrUsersDontMatch(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
/*
** REPLY BLOCK
*/
virtual JNL_IRC_RETVAL onRplNone(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplUserHost(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplIsOn(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplAway(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplNoAway(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplUnAway(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplWhoIsUser(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplWhoIsServer(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplWhoIsIdle(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplWhoIsOperator(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplEndOfWhoIs(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplWhoIsChannels(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplWhoWasUser(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplEndOfWhoWas(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplListStart(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplList(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplListEnd(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplChannelModeIs(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplNoTopic(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplTopic(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplWhoIsRealIP(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplInviting(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplSummoning(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplVersion(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplWhoReply(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplEndWho(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplNameReply(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplEndOfNames(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplLinks(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplEndOfLinks(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplBanList(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplEndOfBanList(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplInfo(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplEnofOfInfo(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplMOTDStart(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplMOTD(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplEndOfMOTD(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplYoureOper(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplRehasing(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplTime(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplUserStart(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplUser(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplEndOfUsers(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplNoUsers(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplTraceLink(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplTraceConnecting(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplTraceHandleShake(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplTraceUnknown(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplTraceOperator(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplTraceUser(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplTraceServer(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplTraceNewType(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplTraceLog(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplStatsLinkInfo(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplStatsCommands(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplStatsCLine(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplStatsNLine(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplStatsILine(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplStatsKLine(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplStatsYLine(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplEndOfStats(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplStatsLLine(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplStatsUptime(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplStatsOLine(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplStatsHLine(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplStatsULine(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplUModeIs(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplLUserClient(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplLUserOp(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplLUserUknown(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplLUserChannels(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplLUserMe(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplAdminMe(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplAdminLoc1(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplAdminLoc2(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplAdminEmail(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplLUserLocal(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onRplLUserGlobal(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
/*
** Messages from server
*/
virtual JNL_IRC_RETVAL onJoin(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onPart(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onMode(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onTopic(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onInvite(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onKick(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onStats(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onPrivMsg(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
virtual JNL_IRC_RETVAL onNotice(JNL_IRCMessage &m){m.messagenum();return JNL_IRC_RETVAL_OK;};
/*
** Don't override this one (onPing), or if you do...make sure you call the base class.
*/
virtual JNL_IRC_RETVAL onPing(JNL_IRCMessage &m){pong((char*)m.m_params.trailing.c_str());return JNL_IRC_RETVAL_OK;};
};
#endif

View File

@ -0,0 +1,50 @@
/*
** JNetLib
** Copyright (C) 2000-2003 Nullsoft, Inc.
** Author: Justin Frankel
** File: jnetlib.h - JNL main include file (not really necessary).
**
** For documentation, look at the following files:
** Generic network initialization: netinc.h
** DNS: asyncdns.h
** TCP connections: connection.h
** HTTP GET connections: httpget.h
** TCP listen: listen.h
**
** license:
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any damages
** arising from the use of this software.
**
** Permission is granted to anyone to use this software for any purpose,
** including commercial applications, and to alter it and redistribute it
** freely, subject to the following restrictions:
**
** 1. The origin of this software must not be misrepresented; you must not
** claim that you wrote the original software. If you use this software
** in a product, an acknowledgment in the product documentation would be
** appreciated but is not required.
** 2. Altered source versions must be plainly marked as such, and must not be
** misrepresented as being the original software.
** 3. This notice may not be removed or altered from any source distribution.
**
*/
#ifndef _JNETLIB_H_
#define _JNETLIB_H_
#include "netinc.h"
#include "util.h"
#include "asyncdns.h"
#include "connection.h"
#include "sslconnection.h"
#include "httpget.h"
#include "httppost.h"
#include "httpserv.h"
#include "listen.h"
#include "ssllisten.h"
#endif//_JNETLIB_H_

View File

@ -0,0 +1,72 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: listen.cpp - JNL TCP listen implementation
** License: see jnetlib.h
*/
#include "netinc.h"
#include "util.h"
#include "listen.h"
JNL_Listen::JNL_Listen(short port, unsigned long which_interface)
{
m_port=port;
m_socket = ::socket(AF_INET,SOCK_STREAM,0);
if (m_socket < 0)
{
}
else
{
struct sockaddr_in sin;
SET_SOCK_BLOCK(m_socket,0);
#ifndef _WIN32
int bflag = 1;
setsockopt(m_socket, SOL_SOCKET, SO_REUSEADDR, &bflag, sizeof(bflag));
#endif
memset((char *) &sin, 0,sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = htons( (short) port );
sin.sin_addr.s_addr = which_interface?which_interface:INADDR_ANY;
if (::bind(m_socket,(struct sockaddr *)&sin,sizeof(sin)))
{
closesocket(m_socket);
m_socket=-1;
}
else
{
if (::listen(m_socket,8)==-1)
{
closesocket(m_socket);
m_socket=-1;
}
}
}
}
JNL_Listen::~JNL_Listen()
{
if (m_socket>=0)
{
closesocket(m_socket);
}
}
JNL_Connection *JNL_Listen::get_connect(int sendbufsize, int recvbufsize)
{
if (m_socket < 0)
{
return NULL;
}
struct sockaddr_in saddr;
socklen_t length = sizeof(struct sockaddr_in);
int s = accept(m_socket, (struct sockaddr *) &saddr, &length);
if (s != -1)
{
JNL_Connection *c=new JNL_Connection(NULL,sendbufsize, recvbufsize);
c->connect(s,&saddr);
return c;
}
return NULL;
}

View File

@ -0,0 +1,39 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: listen.h - JNL interface for opening a TCP listen
** License: see jnetlib.h
**
** Usage:
** 1. create a JNL_Listen object with the port and (optionally) the interface
** to listen on.
** 2. call get_connect() to get any new connections (optionally specifying what
** buffer sizes the connection should be created with)
** 3. check is_error() to see if an error has occured
** 4. call port() if you forget what port the listener is on.
**
*/
#ifndef _LISTEN_H_
#define _LISTEN_H_
#include "connection.h"
class JNL_Listen
{
public:
JNL_Listen(short port, unsigned long which_interface=0);
/*
** Joshua Teitelbaum 1/28/2006
*/
virtual ~JNL_Listen();
virtual JNL_Connection *get_connect(int sendbufsize=8192, int recvbufsize=8192);
short port(void) { return m_port; }
int is_error(void) { return (m_socket<0); }
protected:
int m_socket;
short m_port;
};
#endif //_LISTEN_H_

View File

@ -0,0 +1,80 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: netinc.h - network includes and portability defines (used internally)
** License: see jnetlib.h
*/
/*
** Undefine this if you don't want SSL compiled in
*/
//#define _JNETLIB_SSL_ 1
#ifndef _NETINC_H_
#define _NETINC_H_
#ifdef _WIN32
#include <windows.h>
#include <stdio.h>
#include <time.h>
#define strcasecmp(x,y) stricmp(x,y)
#define ERRNO (WSAGetLastError())
#define SET_SOCK_BLOCK(s,block) { unsigned long __i=block?0:1; ioctlsocket(s,FIONBIO,&__i); }
#define EWOULDBLOCK WSAEWOULDBLOCK
#define EINPROGRESS WSAEWOULDBLOCK
typedef int socklen_t;
#else
#ifndef THREAD_SAFE
#define THREAD_SAFE
#endif
#ifndef _REENTRANT
#define _REENTRANT
#endif
#include <pthread.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdarg.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#define ERRNO errno
#define closesocket(s) close(s)
#define SET_SOCK_BLOCK(s,block) { int __flags; if ((__flags = fcntl(s, F_GETFL, 0)) != -1) { if (!block) __flags |= O_NONBLOCK; else __flags &= ~O_NONBLOCK; fcntl(s, F_SETFL, __flags); } }
#define stricmp(x,y) strcasecmp(x,y)
#define strnicmp(x,y,z) strncasecmp(x,y,z)
#define wsprintf sprintf
#ifdef MACOSX
typedef int socklen_t;
#endif
#endif // !_WIN32
#ifndef INADDR_NONE
#define INADDR_NONE 0xffffffff
#endif
#ifndef INADDR_ANY
#define INADDR_ANY 0
#endif
#ifndef SHUT_RDWR
#define SHUT_RDWR 2
#endif
#endif //_NETINC_H_

View File

@ -0,0 +1,324 @@
#include "netinc.h"
#include "util.h"
#include "connection.h"
#include "sslconnection.h"
#ifdef _JNETLIB_SSL_
SSL_CTX *sslContext = 0;
#ifdef _DEBUG
extern "C" void apps_ssl_info_callback (const SSL * s, int where, int ret)
{
/*
** DEBUG INFO HERE
*/
}
#endif
/*
** Well, you should probably change this based on like...
** well, you're level of trust heh
** For now, this basically trusts all certs :)
**
*/
extern "C" int verify_callback(int ok, X509_STORE_CTX * ctx)
{
/* For certificate verification */
int verify_depth = 0;
int verify_error = X509_V_OK;
char buf[1024];
X509 * err_cert = X509_STORE_CTX_get_current_cert(ctx);
int err = X509_STORE_CTX_get_error(ctx);
int depth = X509_STORE_CTX_get_error_depth(ctx);
X509_NAME_oneline(X509_get_subject_name(err_cert), buf, sizeof(buf));
if (!ok)
{
if (verify_depth >= depth)
{
ok = 1;
verify_error = X509_V_OK;
}
else
{
ok = 0;
verify_error = X509_V_ERR_CERT_CHAIN_TOO_LONG;
}
}
switch (ctx->error)
{
case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert), buf, sizeof(buf));
break;
case X509_V_ERR_CERT_NOT_YET_VALID:
case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
break;
case X509_V_ERR_CERT_HAS_EXPIRED:
case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
break;
}
return ok;
}
JNL_SSL_Connection::JNL_SSL_Connection(SSL* pssl, JNL_AsyncDNS *dns, int sendbufsize, int recvbufsize) : JNL_Connection(dns, sendbufsize, recvbufsize),
forceConnect(false)
{
m_ssl = pssl;
m_bsslinit = false;
if (m_ssl)
{
m_bcontextowned = false;
}
else
{
m_bcontextowned = true;
}
if (m_bcontextowned == false)
{
return ;
}
m_bsslinit = true;
/* See the SSL states in our own callback */
#ifdef _DEBUG
// SSL_CTX_set_info_callback(m_app_ctx, apps_ssl_info_callback);
#endif
/* Set the certificate verification callback */
//SSL_CTX_set_verify(sslContext, SSL_VERIFY_PEER, verify_callback);
/* Not sure what this does */
//SSL_CTX_set_session_cache_mode(sslContext, SSL_SESS_CACHE_CLIENT);
if(sslContext == NULL)
{
SSL_METHOD * meth = NULL;
SSLeay_add_ssl_algorithms();
SSL_load_error_strings();
meth = SSLv23_client_method();
if ((sslContext = SSL_CTX_new(meth)) == NULL)
{
return;
}
}
return ;
}
int JNL_SSL_Connection::socket_connect()
{
int retval;
if (m_bcontextowned == false)
{
/*
** WTF?
*/
return -1;
}
if (m_ssl != NULL)
{
return -1;
}
retval = JNL_Connection::socket_connect();
if (retval != 0)
{
if (ERRNO != EINPROGRESS)
{
return retval; // benski> if the underlying socket hasn't connected yet, then we can't start the SSL connection
/*
** Joshua Teitelbaum 3/2/2006
** Fatal error here
*/
}
}
m_ssl = SSL_new(sslContext);
if (m_ssl == NULL)
{
return -1;
}
/* Tell that we are in connect mode */
SSL_set_connect_state(m_ssl);
/* Set socket descriptor with the socket we already have open */
if(SSL_set_fd(m_ssl, m_socket) != 0)
{
return -1;
}
return retval;
}
void JNL_SSL_Connection::socket_shutdown()
{
if (m_ssl)
SSL_shutdown(m_ssl);
JNL_Connection::socket_shutdown();
if (m_ssl)
{
SSL_free(m_ssl);
m_ssl = NULL;
}
return ;
}
void JNL_SSL_Connection::run(int max_send_bytes, int max_recv_bytes, int *bytes_sent, int *bytes_rcvd)
{
if (!m_bsslinit)
{
int rval = 0;
int e = 0;
rval = SSL_accept(m_ssl);
if (rval == -1)
{
e = SSL_get_error(m_ssl, rval);
if (!((e == SSL_ERROR_WANT_READ) || (e == SSL_ERROR_WANT_WRITE)))
{
m_state = STATE_ERROR;
}
return ;
}
else
{
m_bsslinit = true;
}
}
/**
** benski - march 2, 2006
**if the underlying socket didn't connected yet, we need to try the SSL connection again
*/
if (forceConnect)
{
if(init_ssl_connection() == false)
{
return;
}
}
JNL_Connection::run(max_send_bytes, max_recv_bytes, bytes_sent, bytes_rcvd);
}
/*
** init_ssl_connection:
** Returns true, meaning can continue
** Else, cannot continue with underlying run
** side effects:
** sets forceConnect
*/
bool JNL_SSL_Connection::init_ssl_connection()
{
if(m_ssl == NULL)
{
/*
** WTF?
** cascade up.
*/
return true;
}
int retval = SSL_connect(m_ssl);
if (retval < 0)
{
int err = SSL_get_error(m_ssl, retval);
switch (err)
{
case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE:
case SSL_ERROR_WANT_CONNECT:
forceConnect = true;
break;
// fall through
default: // TODO: benski> MOST other errors are OK, (especially "want read" and "want write", but we need to think through all the scenarios here
forceConnect=false;
}
}
else if(retval)
{
/*
** success
*/
forceConnect = false;
}
/*
** If retval == 0
** socket is closed, or serious error occurred.
** cascade up.
*/
return forceConnect==false;
}
void JNL_SSL_Connection::on_socket_connected(void)
{
init_ssl_connection();
}
void JNL_SSL_Connection::connect(int s, struct sockaddr_in *loc)
{
/*
** Joshua Teitelbaum 2/01/2006
** No need to close
** This is the reason for divergence as well as setting
** the connect state
*/
m_socket = s;
m_remote_port = 0;
m_dns = NULL;
if (loc) *m_saddr = *loc;
else memset(m_saddr, 0, sizeof(m_saddr));
if (m_socket != -1)
{
SET_SOCK_BLOCK(m_socket, 0);
m_state = STATE_CONNECTED;
SSL_set_fd(m_ssl, m_socket);
}
else
{
m_errorstr = "invalid socket passed to connect";
m_state = STATE_ERROR;
}
}
int JNL_SSL_Connection::socket_recv(char *buf, int len, int options)
{
return SSL_read(m_ssl, buf, len);
}
int JNL_SSL_Connection::socket_send(char *buf, int len, int options)
{
return SSL_write(m_ssl, buf, len);
}
JNL_SSL_Connection::~JNL_SSL_Connection()
{
if (m_ssl)
{
SSL_free(m_ssl);
m_ssl = NULL;
}
}
#endif

View File

@ -0,0 +1,63 @@
/*
** JNetLib
** Copyright (C) 2000-2006 CockOS, Inc.
** Author: Justin Frankel, Joshua Teitelbaum
** File: sslconnection.h - JNL SSL TCP connection interface
** License: see jnetlib.h
*/
#ifdef _JNETLIB_SSL_
#ifndef _JNETLIB_SSL_H_
#define _JNETLIB_SSL_H_
/*
** AUTOLINK WITH THESE GUYS NOT IN PROJECT HEH HEH :)
** Build and go, for you :)
*/
#pragma comment(lib,"libeay32.lib")
#pragma comment(lib,"ssleay32.lib")
#pragma comment(lib,"ADVAPI32.LIB")
#pragma comment(lib,"USER32.LIB")
#include <openssl/ssl.h>
#include "connection.h"
class JNL_SSL_Connection : public JNL_Connection
{
protected:
SSL *m_ssl;
bool m_bcontextowned;
bool m_bsslinit;
public:
JNL_SSL_Connection(SSL* pssl = NULL,JNL_AsyncDNS *dns=JNL_CONNECTION_AUTODNS, int sendbufsize=8192, int recvbufsize=8192);
//JNL_SSL_Connection(SSL* pssl = NULL,api_dns *dns=API_DNS_AUTODNS, int sendbufsize=8192, int recvbufsize=8192);
virtual ~JNL_SSL_Connection();
virtual void connect(int sock, struct sockaddr_in *loc=NULL); // used by the listen object, usually not needed by users.
virtual void run(int max_send_bytes=-1, int max_recv_bytes=-1, int *bytes_sent=NULL, int *bytes_rcvd=NULL);
/*
** Joshua Teitelbaum 1/27/2006 Adding new BSD socket analogues for SSL compatibility
*/
protected:
virtual void socket_shutdown();
virtual int socket_recv(char *buf, int len, int options);
virtual int socket_send(char *buf, int len, int options);
virtual int socket_connect();
virtual void on_socket_connected();
/*
** init_ssl_connection:
** returns true if can continue onwards (could be error, in which case
** we want the error to cascade through).
** Else, false if connection was not made, and we have to call this
** again.
*/
bool init_ssl_connection();
bool forceConnect;
};
extern SSL_CTX *sslContext;
#endif
#endif

View File

@ -0,0 +1,135 @@
/*
** JNetLib
** Copyright (C) 2000-2006 CockOS, Inc.
** Author: Justin Frankel, Joshua Teitelbaum
** File: ssllisten.cpp - JNL SSL TCP listen implementation
** License: see jnetlib.h
*/
#include "netinc.h"
#include "util.h"
#include "ssllisten.h"
#ifdef _JNETLIB_SSL_
JNL_SSL_Listen::JNL_SSL_Listen(short port, unsigned long which_interface, const char *certpath, const char *privatekeypath) :
JNL_Listen(port,which_interface) ,m_app_ctx(NULL)
{
SSL_METHOD *p_ssl_method;
m_lasterror[0] = 0;
unsigned long e;
if(m_socket <= 0 || (certpath==NULL) || (privatekeypath==NULL))
{
return ;
}
SSL_load_error_strings();
SSLeay_add_ssl_algorithms();
p_ssl_method = SSLv23_server_method();
m_app_ctx = SSL_CTX_new (p_ssl_method);
if (!m_app_ctx)
{
e = ERR_get_error();
ERR_error_string_n(e, m_lasterror, sizeof(m_lasterror) - 1);
if (m_socket>=0)
{
closesocket(m_socket);
m_socket = -1;
}
return;
}
if (SSL_CTX_use_certificate_file(m_app_ctx, certpath, SSL_FILETYPE_PEM) <= 0)
{
e = ERR_get_error();
ERR_error_string_n(e, m_lasterror, sizeof(m_lasterror) - 1);
if (m_socket>=0)
{
closesocket(m_socket);
m_socket = -1;
}
return;
}
if (SSL_CTX_use_RSAPrivateKey_file(m_app_ctx, privatekeypath, SSL_FILETYPE_PEM) <= 0)
{
e = ERR_get_error();
ERR_error_string_n(e, m_lasterror, sizeof(m_lasterror) - 1);
if (m_socket>=0)
{
closesocket(m_socket);
m_socket = -1;
}
return;
}
if (!SSL_CTX_check_private_key(m_app_ctx))
{
e = ERR_get_error();
ERR_error_string_n(e, m_lasterror, sizeof(m_lasterror) - 1);
if (m_socket>=0)
{
closesocket(m_socket);
m_socket = -1;
}
return;
}
return;
}
JNL_SSL_Listen::~JNL_SSL_Listen()
{
}
JNL_Connection *JNL_SSL_Listen::get_connect(int sendbufsize, int recvbufsize)
{
if(m_app_ctx == NULL)
{
return NULL;
}
if (m_socket < 0)
{
return NULL;
}
struct sockaddr_in saddr;
socklen_t length = sizeof(struct sockaddr_in);
int s = accept(m_socket, (struct sockaddr *) &saddr, &length);
if(s == -1)
{
return NULL;
}
SSL* p_ssl = SSL_new(m_app_ctx);
if( p_ssl == NULL || m_socket < 0)
{
sprintf(m_lasterror,"Could not create SSL Context");
(m_socket>=0) ? closesocket(m_socket) : 0;
m_socket = -1;
if(p_ssl != NULL)
SSL_free(p_ssl);
return NULL;
}
else
{
JNL_Connection *c=new JNL_SSL_Connection(p_ssl,NULL,sendbufsize, recvbufsize);
c->connect(s,&saddr);
return c;
}
return NULL;
}
#endif

View File

@ -0,0 +1,50 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel, Joshua Teitelbaum
** File: ssllisten.h - JNL interface for opening a SSL TCP listen
** License: see jnetlib.h
**
** Usage:
** 1. create a JNL_Listen object with the port and (optionally) the interface
** to listen on.
** 2. call get_connect() to get any new connections (optionally specifying what
** buffer sizes the connection should be created with)
** 3. check is_error() to see if an error has occured
** 4. call port() if you forget what port the listener is on.
**
*/
#include "netinc.h"
#include "listen.h"
#ifdef _JNETLIB_SSL_
#ifndef _SSL_LISTEN_H_
#define _SSL_LISTEN_H_
#include "sslconnection.h"
#include <openssl/rsa.h>
#include <openssl/crypto.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/conf.h>
class JNL_SSL_Listen : public JNL_Listen
{
protected:
SSL_CTX *m_app_ctx;
char m_lasterror[1024];
public:
JNL_SSL_Listen(short port, unsigned long which_interface=0,const char *certpath=NULL, const char *privatekeypath=NULL);
virtual ~JNL_SSL_Listen();
virtual JNL_Connection *get_connect(int sendbufsize=8192, int recvbufsize=8192);
};
#endif //_SSL_LISTEN_H_
#endif //_JNETLIB_SSL_

View File

@ -0,0 +1,931 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: test.cpp - JNL test code
** License: see jnetlib.h
*/
#ifdef _WIN32
#include <windows.h>
#else
#define Sleep(x) usleep((x)*1000)
#endif
#include <stdio.h>
#include "jnetlib.h"
#include "ircclient.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#define TEST_ASYNCDNS 0
#define TEST_CONNECTION 0
#define TEST_LISTEN 0
#define TEST_TELNET_GATEWAY 0
#define TEST_HTTPGET 0
#define TEST_WEBSERVER 0
#define TEST_IRCCLIENT 0
#define TEST_HTTPSGET 0
#define TEST_SSLLISTEN 0
#define TEST_HTTPPOST 1
#define TEST_UDP 0 //udp is not done yet tho :)
#if (TEST_WEBSERVER)
#include "webserver.h"
class MemPageGenerator : public IPageGenerator
{
public:
virtual ~MemPageGenerator() { free(m_buf); }
MemPageGenerator(char *buf, int buf_len=-1) { m_buf=buf; if (buf_len >= 0) m_buf_size=buf_len; else m_buf_size=strlen(buf); m_buf_pos=0; }
virtual int GetData(char *buf, int size) // return 0 when done
{
int a=m_buf_size-m_buf_pos;
if (a < size) size=a;
memcpy(buf,m_buf+m_buf_pos,size);
m_buf_pos+=size;
return size;
}
private:
char *m_buf;
int m_buf_size;
int m_buf_pos;
};
class wwwServer : public WebServerBaseClass
{
public:
wwwServer() { }
virtual IPageGenerator *onConnection(JNL_HTTPServ *serv, int port)
{
serv->set_reply_header("Server:jnetlib_test/0.0");
if (!strcmp(serv->get_request_file(),"/"))
{
serv->set_reply_string("HTTP/1.1 200 OK");
serv->set_reply_header("Content-Type:text/html");
serv->send_reply();
return new MemPageGenerator(strdup("Test Web Server v0.0"));
}
else
{
serv->set_reply_string("HTTP/1.1 404 NOT FOUND");
serv->send_reply();
return 0; // no data
}
}
};
int main(int argc, char **argv)
{
JNL::open_socketlib();
{
wwwServer foo;
foo.addListenPort(8080);
JNL_IRC_ERROR e;
while (1)
{
e = foo.run();
if(e != JNL_IRC_ERROR_NONE)
{
return 0;
}
Sleep(10);
}
}
JNL::close_socketlib();
return 0;
}
#endif
#if (TEST_HTTPGET)
int main(int argc, char **argv)
{
if (argc != 3)
{
printf("usage: httpget <url> <outfile>\n");
exit(0);
}
JNL_HTTPGet get;
JNL::open_socketlib();
get.addheader("User-Agent:PooHead (Mozilla)");
get.addheader("Accept:*/*");
get.addheader("Host:www.stashbox.org");
get.connect(argv[1]);
FILE *fp=fopen(argv[2],"wb");
int headerstate=0;
int has_printed_headers=0;
int has_printed_reply=0;
while (1)
{
int st=get.run();
if (st<0)
{
printf("HTTPGet error: %s\n",get.geterrorstr());
break;
}
if (get.get_status()>0)
{
if (!has_printed_reply)
{
has_printed_reply=1;
printf("reply: %s (code:%d)\n",get.getreply(),get.getreplycode());
}
if (get.get_status()==2)
{
int len;
if (!has_printed_headers)
{
has_printed_headers=1;
printf("headers:\n");
char *p=get.getallheaders();
while (p&&*p)
{
printf("%s\n",p);
p+=strlen(p)+1;
}
}
while ((len=get.bytes_available()) > 0)
{
char buf[4096];
if (len > 4096) len=4096;
len=get.get_bytes(buf,len);
if (len>0)fwrite(buf,len,1,fp);
}
}
}
if (st==1) // 1 means connection closed
{
printf("HTTPGet done!\n");
break;
}
}
if (fp) fclose(fp);
JNL::close_socketlib();
return 0;
}
#endif
#if (TEST_HTTPPOST)
int main(int argc, char **argv)
{
if (argc != 3)
{
printf("usage: httppost <url> <outfile>\n");
exit(0);
}
JNL::open_socketlib();
JNL_HTTPPost post;
post.addheader("User-Agent: 1014 Army Agent");
post.addheader("Accept: text/html, */*");
post.addheader("Accept-Language: en-us, en;q=0.5");
post.addheader("Accept-Encoding: gzip,deflate");
post.addheader("Accept-Charset: ISO-8859-1, utf-8;q=0.7,*;q=0.7");
post.addheader("Connection: close");
post.addfield("t","1");
post.addfield("pof","");
post.addfield("rss","on");
post.addfield("tags","");
post.addfile("file","application/octet-stream","poopoo.txt","c:/temp/poopoo.txt");
post.connect(argv[1]);
int has_printed_reply = 0;
int has_printed_headers = 0;
FILE *fp=fopen(argv[2],"wb");
while (1)
{
int st=post.run();
if (st<0)
{
printf("HTTPPost error: %s\n",post.geterrorstr());
break;
}
if (post.get_status()>0)
{
if (!has_printed_reply)
{
has_printed_reply=1;
printf("reply: %s (code:%d)\n",post.getreply(),post.getreplycode());
}
if (post.get_status()==2)
{
int len;
if (!has_printed_headers)
{
has_printed_headers=1;
printf("headers:\n");
char *p=post.getallheaders();
while (p&&*p)
{
printf("%s\n",p);
p+=strlen(p)+1;
}
}
while ((len=post.bytes_available()) > 0)
{
char buf[4096];
if (len > 4096) len=4096;
len=post.get_bytes(buf,len);
if (len>0)fwrite(buf,len,1,fp);
}
}
}
if (st==1) // 1 means connection closed
{
printf("HTTPGet done!\n");
break;
}
}
if (fp) fclose(fp);
JNL::close_socketlib();
return 0;
}
#endif
#if (TEST_TELNET_GATEWAY)
int main()
{
JNL_Connection *cons[32]={0,};
JNL_Connection *outcons[32]={0,};
char textpos[32][256];
int n_cons=0;
int states[32]={0,};
JNL::open_socketlib();
JNL_AsyncDNS dns;
JNL_Listen l(23);
while (!l.is_error())
{
Sleep(30);
if (n_cons<32)
{
JNL_Connection *con=l.get_connect();
if (con)
{
int x;
for (x = 0; x < 32; x ++)
{
if (!cons[x])
{
cons[x]=con;
outcons[x]=0;
states[x]=0;
n_cons++;
break;
}
}
}
}
int x;
for (x = 0; x < 32; x ++)
{
if (cons[x])
{
cons[x]->run();
if (outcons[x]) outcons[x]->run();
if (cons[x]->get_state() == JNL_Connection::STATE_ERROR || cons[x]->get_state()==JNL_Connection::STATE_CLOSED ||
(outcons[x] && (cons[x]->get_state() == JNL_Connection::STATE_ERROR || cons[x]->get_state()==JNL_Connection::STATE_CLOSED)))
{
delete cons[x];
if (outcons[x]) delete outcons[x];
outcons[x]=0;
cons[x]=0;
states[x]=0;
n_cons--;
}
else
{
if (states[x]==0)
{
cons[x]->send_string("\r\nwelcome ");
states[x]++;
}
if (states[x]==1)
{
char hoststr[256];
int ret=dns.reverse(cons[x]->get_remote(),hoststr);
if (ret==0)
{
cons[x]->send_string(hoststr);
cons[x]->send_string(". host: ");
states[x]++;
textpos[x][0]=0;
}
if (ret==-1)
{
JNL::addr_to_ipstr(cons[x]->get_remote(),hoststr,256);
cons[x]->send_string(hoststr);
cons[x]->send_string(". host: ");
states[x]++;
textpos[x][0]=0;
}
}
if (states[x]==2)
{
char b;
while (cons[x]->recv_bytes(&b,1) && states[x]==2)
{
if (b == '\r' || b == '\n')
{
if (strlen(textpos[x]))
{
char *p=strstr(textpos[x],":");
int port=23;
if (p)
{
*p++=0;
if (atoi(p)) port=atoi(p);
}
outcons[x]=new JNL_Connection(&dns);
outcons[x]->connect(textpos[x],port);
char str[512];
sprintf(str,"\r\nconnecting to port %d of %s\r\n",port,textpos[x]);
cons[x]->send_string(str);
states[x]++;
}
else states[x]=0;
}
else if (b == '\b')
{
if (textpos[x][0])
{
textpos[x][strlen(textpos[x])-1]=0;
cons[x]->send_string("\b \b");
}
}
else
{
textpos[x][strlen(textpos[x])+1]=0;
textpos[x][strlen(textpos[x])]=b;
cons[x]->send(&b,1);
}
}
}
if (states[x]==3)
{
char buf[1024];
outcons[x]->run();
int l=cons[x]->recv_bytes(buf,1024);
if (l) outcons[x]->send(buf,l);
l=outcons[x]->recv_bytes(buf,1024);
if (l) cons[x]->send(buf,l);
}
}
}
}
}
JNL::close_socketlib();
return 0;
}
#endif
#if (TEST_LISTEN)
int main()
{
JNL_HTTPServ *cons[32]={0,};
char *contents[32]={0,};
int n_cons=0;
JNL::open_socketlib();
JNL_AsyncDNS dns;
JNL_Listen l(8000);
while (!l.is_error())
{
Sleep(100);
if (n_cons<32)
{
JNL_Connection *con=l.get_connect();
if (con)
{
int x;
for (x = 0; x < 32; x ++)
{
if (!cons[x])
{
cons[x]=new JNL_HTTPServ(con);
n_cons++;
break;
}
}
}
}
int x;
for (x = 0; x < 32; x ++)
{
if (cons[x])
{
int r=cons[x]->run();
if (r == -1 || r == 4)
{
if (r == -1) printf("error:%s\n",cons[x]->geterrorstr());
delete cons[x];
cons[x]=0;
free(contents[x]);
contents[x]=0;
n_cons--;
}
if (r == 2)
{
cons[x]->set_reply_string("HTTP/1.1 200 OK");
cons[x]->set_reply_header("Content-type:text/plain");
cons[x]->set_reply_header("Server:JNLTest");
contents[x]=(char*)malloc(32768);
char *poop=cons[x]->get_request_parm("poop");
sprintf(contents[x],"test, sucka\r\n%s\r\n\r\n",poop?poop:"no poop");
cons[x]->send_reply();
}
if (r == 3)
{
if (contents[x] && cons[x]->bytes_cansend()>strlen(contents[x]))
{
cons[x]->write_bytes(contents[x],strlen(contents[x]));
cons[x]->close(0);
free(contents[x]);
contents[x]=0;
}
}
}
}
}
JNL::close_socketlib();
return 0;
}
#endif
#if (TEST_SSLLISTEN)
/*
** ARGS:
** 0 Program
** 1 Port
** 2 Certificate File
** 3 PrivateKey File
*/
int main(int argc, char **argv)
{
JNL_HTTPServ *cons[32]={0,};
char *contents[32]={0,};
int n_cons=0;
unsigned short nport;
char *szprivkeyfile;
char *szcertfile;
JNL::open_socketlib();
JNL_AsyncDNS dns;
/*
** Two key things for listening via SSL
** 1) You need a private key
** 2) You need a certificate
**
** For the impatient:
** Create a private key
** openssl genrsa -des3 -out privkey.pem 2048
** Create a self signed cert
** openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095
**
** If you created your private key with a passphrase,
** you better have access to STDIN to unlock the private key.
*/
if(argc < 2)
{
nport = 8443;
szcertfile = "c:/openssl/etc/cacert.pem";
szprivkeyfile = "c:/openssl/etc/privkey.pem";
}
else if(argc < 3)
{
nport = atoi(argv[1]);
if(nport <= 0)
{
nport = 8443;
}
szcertfile = "c:/openssl/etc/cacert.pem";
szprivkeyfile = "c:/openssl/etc/privkey.pem";
}
else if(argc < 4)
{
struct stat buf;
nport = atoi(argv[1]);
if(nport <= 0)
{
nport = 8443;
}
szcertfile = argv[2];
if(stat(szcertfile,&buf)<0)
{
fprintf(stderr,"Could not open %s\n",szcertfile);
exit(-1);
}
szprivkeyfile = "c:/openssl/etc/privkey.pem";
}
else
{
struct stat buf;
nport = atoi(argv[1]);
if(nport <= 0)
{
nport = 8443;
}
szcertfile = argv[2];
if(stat(szcertfile,&buf)<0)
{
fprintf(stderr,"Could not open %s\n",szcertfile);
exit(-1);
}
szprivkeyfile = argv[3];
if(stat(szprivkeyfile,&buf)<0)
{
fprintf(stderr,"Could not open %s\n",szprivkeyfile);
exit(-1);
}
}
JNL_SSL_Listen l(nport,0,szcertfile,szprivkeyfile);
while (!l.is_error())
{
Sleep(100);
if (n_cons<32)
{
JNL_Connection *con=l.get_connect();
if (con)
{
int x;
for (x = 0; x < 32; x ++)
{
if (!cons[x])
{
cons[x]=new JNL_HTTPServ(con);
n_cons++;
break;
}
}
}
}
int x;
for (x = 0; x < 32; x ++)
{
if (cons[x])
{
int r=cons[x]->run();
if (r == -1 || r == 4)
{
if (r == -1) printf("error:%s\n",cons[x]->geterrorstr());
delete cons[x];
cons[x]=0;
free(contents[x]);
contents[x]=0;
n_cons--;
}
if (r == 2)
{
cons[x]->set_reply_string("HTTP/1.1 200 OK");
cons[x]->set_reply_header("Content-type:text/plain");
cons[x]->set_reply_header("Server:JNLTest");
contents[x]=(char*)malloc(32768);
char *poop=cons[x]->get_request_parm("poop");
sprintf(contents[x],"test, sucka\r\n%s\r\n\r\n",poop?poop:"no poop");
cons[x]->send_reply();
}
if (r == 3)
{
if (contents[x] && cons[x]->bytes_cansend()>strlen(contents[x]))
{
cons[x]->write_bytes(contents[x],strlen(contents[x]));
cons[x]->close(0);
free(contents[x]);
contents[x]=0;
}
}
}
}
}
JNL::close_socketlib();
return 0;
}
#endif
#if (TEST_CONNECTION)
int main()
{
JNL::open_socketlib();
{
JNL_AsyncDNS dns;
JNL_Connection con(&dns);
con.connect("localhost",80);
FILE *fp=fopen("c:\\hi.raw","wb");
while (1)
{
con.run();
if (con.get_state()==JNL_Connection::STATE_ERROR)
{
printf("error %s\n",con.get_errstr());
}
if (con.get_state()==JNL_Connection::STATE_CLOSED)
{
}
while (con.recv_bytes_available()>0)
{
char buf[1024];
int a=con.recv_bytes_available();
if (a > 1024) a=1024;
con.recv_bytes(buf,a);
fwrite(buf,a,1,fp);
}
}
if (fp) fclose(fp);
}
JNL::close_socketlib();
return 0;
}
#endif
#if (TEST_ASYNCDNS)
int main()
{
JNL_AsyncDNS dns;
char *hosts[]=
{
"www.firehose.net",
"gnutella.com",
"207.48.52.200",
"www.slashdot.org",
"www.google.com",
"www.winamp.com",
"www.genekan.com",
};
char *reverses[]=
{
"64.0.160.98",
"205.188.245.120",
"207.48.52.222",
"207.48.52.200",
};
int n=0;
int pass=0;
while (n<sizeof(hosts)/sizeof(hosts[0])+sizeof(reverses)/sizeof(reverses[0]))
{
int x;
n=0;
printf("pass %d\n",pass++);
for (x = 0; x < sizeof(hosts)/sizeof(hosts[0]); x ++)
{
unsigned long addr;
printf("%-30s",hosts[x]);
switch (dns.resolve(hosts[x],&addr))
{
case 0:
{
char str[256];
JNL::addr_to_ipstr(addr,str,256);
printf("%s\n",str);
n++;
}
break;
case 1: printf("looking up\n"); break;
case -1: printf("error\n"); n++; break;
}
}
for (x = 0; x < sizeof(reverses)/sizeof(reverses[0]); x ++)
{
printf("reverse: %-21s",reverses[x]);
char hn[512];
switch (dns.reverse(JNL::ipstr_to_addr(reverses[x]),hn))
{
case 0: printf("%s\n",hn); n++; break;
case 1: printf("looking up\n"); break;
case -1: printf("error\n"); n++; break;
}
}
Sleep(100);
}
return 0;
};
#endif
#if (TEST_UDP)
int main(int argc, char **argv)
{
if (argc != 2)
{
printf("usage: udptest <mode>\n");
printf("mode: 0 for client, 1 for server\n");
exit(0);
}
int mode=atoi(argv[1]);
JNL::open_socketlib();
switch(mode)
{
case 0: // client mode
{
JNL_AsyncDNS dns;
JNL_UDPConnection con(0,&dns); // 0 chooses a random port
con.setpeer("localhost",80);
printf("Sending message...\n");
con.send("blah",5);
while (1)
{
con.run();
if (con.get_state()==JNL_UDPConnection::STATE_ERROR)
{
printf("error %s\n",con.get_errstr());
}
while (con.recv_bytes_available()>0)
{
char buf[1024];
int s=min(con.recv_bytes_available(), sizeof(buf));
con.recv_bytes(buf,s);
printf("received message: %s\n", buf);
}
}
}
break;
case 1: // server (listening) mode
{
JNL_UDPConnection con(80);
printf("Waiting for messages...\n");
while(1)
{
con.run();
if (con.get_state()==JNL_UDPConnection::STATE_ERROR)
{
printf("error %s\n",con.get_errstr());
}
while (con.recv_bytes_available()>0)
{
char buf[1024];
int s=min(con.recv_bytes_available(), sizeof(buf));
con.recv_bytes(buf,s);
printf("message received: %s. Replying...\n", buf);
// reply on the addr:port from sender
struct sockaddr from;
con.get_last_recv_msg_addr(&from);
con.setpeer(&from);
con.send("blorp",6);
}
}
}
break;
}
JNL::close_socketlib();
return 0;
}
#endif
#if (TEST_IRCCLIENT)
int main(int argc, char **argv)
{
if (argc != 3)
{
printf("usage: ircclient host port\n");
exit(0);
}
JNL_IRCClient irccli;
JNL::open_socketlib();
if(irccli.connect(argv[1],atoi(argv[2])) != true)
{
printf("%s could not connect\n",argv[0]);
return 0;
}
irccli.nick("poopoo2");
irccli.userregistration();
irccli.join("#poopoo");
while (1)
{
bool st=irccli.run();
if (st != true)
{
break;
}
Sleep(200);
}
return 0;
}
#endif
#if (TEST_HTTPSGET)
int main(int argc, char **argv)
{
if (argc != 3)
{
printf("usage: httpsget <url> <outfile>\n");
exit(0);
}
JNL_HTTPGet get;
JNL::open_socketlib();
get.addheader("User-Agent:PooHead (Mozilla)");
get.addheader("Accept:*/*");
get.addheader("Host:www.stashbox.org");
get.connect(argv[1]);
FILE *fp=fopen(argv[2],"wb");
int headerstate=0;
int has_printed_headers=0;
int has_printed_reply=0;
while (1)
{
int st=get.run();
if (st<0)
{
printf("HTTPGet error: %s\n",get.geterrorstr());
break;
}
if (get.get_status()>0)
{
if (!has_printed_reply)
{
has_printed_reply=1;
printf("reply: %s (code:%d)\n",get.getreply(),get.getreplycode());
}
if (get.get_status()==2)
{
int len;
if (!has_printed_headers)
{
has_printed_headers=1;
printf("headers:\n");
char *p=get.getallheaders();
while (p&&*p)
{
printf("%s\n",p);
p+=strlen(p)+1;
}
}
while ((len=get.bytes_available()) > 0)
{
char buf[4096];
if (len > 4096) len=4096;
len=get.get_bytes(buf,len);
if (len>0)fwrite(buf,len,1,fp);
}
}
}
if (st==1) // 1 means connection closed
{
printf("HTTPGet done!\n");
break;
}
}
if (fp) fclose(fp);
JNL::close_socketlib();
return 0;
}
#endif

View File

@ -0,0 +1,166 @@
# Microsoft Developer Studio Project File - Name="test" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=test - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "test.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "test.mak" CFG="test - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "test - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "test - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""$/jnetlib", NTGAAAAA"
# PROP Scc_LocalPath "."
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "test - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "test - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W4 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "test - Win32 Release"
# Name "test - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\asyncdns.cpp
# End Source File
# Begin Source File
SOURCE=.\connection.cpp
# End Source File
# Begin Source File
SOURCE=.\httpget.cpp
# End Source File
# Begin Source File
SOURCE=.\httpserv.cpp
# End Source File
# Begin Source File
SOURCE=.\listen.cpp
# End Source File
# Begin Source File
SOURCE=.\test.cpp
# End Source File
# Begin Source File
SOURCE=.\util.cpp
# End Source File
# Begin Source File
SOURCE=.\webserver.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\asyncdns.h
# End Source File
# Begin Source File
SOURCE=.\connection.h
# End Source File
# Begin Source File
SOURCE=.\httpget.h
# End Source File
# Begin Source File
SOURCE=.\httpserv.h
# End Source File
# Begin Source File
SOURCE=.\jnetlib.h
# End Source File
# Begin Source File
SOURCE=.\listen.h
# End Source File
# Begin Source File
SOURCE=.\netinc.h
# End Source File
# Begin Source File
SOURCE=.\util.h
# End Source File
# Begin Source File
SOURCE=.\webserver.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

View File

@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "test"=.\test.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@ -0,0 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test.vcproj", "{23B88BB3-B7CA-4ADA-8B14-E153F629CA23}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{23B88BB3-B7CA-4ADA-8B14-E153F629CA23}.Debug.ActiveCfg = Debug|Win32
{23B88BB3-B7CA-4ADA-8B14-E153F629CA23}.Debug.Build.0 = Debug|Win32
{23B88BB3-B7CA-4ADA-8B14-E153F629CA23}.Release.ActiveCfg = Release|Win32
{23B88BB3-B7CA-4ADA-8B14-E153F629CA23}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal

Binary file not shown.

View File

@ -0,0 +1,344 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="test"
ProjectGUID="{1F43D4A8-6793-4634-A14D-9BDCBD415E8A}"
SccProjectName="&quot;$/jnetlib&quot;, NTGAAAAA"
SccLocalPath=".">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory=".\Release"
IntermediateDirectory=".\Release"
ConfigurationType="1"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
StringPooling="TRUE"
RuntimeLibrary="0"
EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="2"
PrecompiledHeaderFile=".\Release/test.pch"
AssemblerListingLocation=".\Release/"
ObjectFile=".\Release/"
ProgramDataBaseFileName=".\Release/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="odbc32.lib odbccp32.lib wsock32.lib"
OutputFile=".\Release/test.exe"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
ProgramDatabaseFile=".\Release/test.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\Release/test.tlb"
HeaderFileName=""/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\Debug"
IntermediateDirectory=".\Debug"
ConfigurationType="1"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="2"
PrecompiledHeaderFile=".\Debug/test.pch"
AssemblerListingLocation=".\Debug/"
ObjectFile=".\Debug/"
ProgramDataBaseFileName=".\Debug/"
WarningLevel="4"
SuppressStartupBanner="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="odbc32.lib odbccp32.lib wsock32.lib"
OutputFile=".\Debug/test.exe"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile=".\Debug/test.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\Debug/test.tlb"
HeaderFileName=""/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
<File
RelativePath="asyncdns.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions=""
BasicRuntimeChecks="3"/>
</FileConfiguration>
</File>
<File
RelativePath="connection.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions=""
BasicRuntimeChecks="3"/>
</FileConfiguration>
</File>
<File
RelativePath="httpget.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions=""
BasicRuntimeChecks="3"/>
</FileConfiguration>
</File>
<File
RelativePath=".\httppost.cpp">
</File>
<File
RelativePath="httpserv.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions=""
BasicRuntimeChecks="3"/>
</FileConfiguration>
</File>
<File
RelativePath=".\ircclient.cpp">
</File>
<File
RelativePath=".\ircclient.h">
</File>
<File
RelativePath="listen.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions=""
BasicRuntimeChecks="3"/>
</FileConfiguration>
</File>
<File
RelativePath=".\sslconnection.cpp">
</File>
<File
RelativePath=".\ssllisten.cpp">
</File>
<File
RelativePath="test.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions=""
BasicRuntimeChecks="3"/>
</FileConfiguration>
</File>
<File
RelativePath="util.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions=""
BasicRuntimeChecks="3"/>
</FileConfiguration>
</File>
<File
RelativePath="webserver.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions=""
BasicRuntimeChecks="3"/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl">
<File
RelativePath="asyncdns.h">
</File>
<File
RelativePath="connection.h">
</File>
<File
RelativePath="httpget.h">
</File>
<File
RelativePath=".\httppost.h">
</File>
<File
RelativePath="httpserv.h">
</File>
<File
RelativePath="jnetlib.h">
</File>
<File
RelativePath="listen.h">
</File>
<File
RelativePath="netinc.h">
</File>
<File
RelativePath=".\sslconnection.h">
</File>
<File
RelativePath="util.h">
</File>
<File
RelativePath="webserver.h">
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,102 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: testbnc.cpp - JNL network bounce test code
** License: see jnetlib.h
*/
#ifdef _WIN32
#include <windows.h>
#else
#define Sleep(x) usleep((x)*1000)
#endif
#include <stdio.h>
#include "jnetlib.h"
int main(int argc, char *argv[])
{
JNL_Connection *cons[32]={0,};
JNL_Connection *outcons[32]={0,};
int n_cons=0;
if (argc != 4 || !atoi(argv[1]) || !atoi(argv[3]) || !argv[2][0])
{
printf("usage: redir localport host remoteport\n");
exit(1);
}
JNL::open_socketlib();
JNL_AsyncDNS dns;
JNL_Listen l((short)atoi(argv[1]));
printf("running...\n");
while (!l.is_error())
{
Sleep(10);
if (n_cons<32)
{
JNL_Connection *con=l.get_connect();
if (con)
{
int x;
for (x = 0; x < 32; x ++)
{
if (!cons[x])
{
outcons[x]=new JNL_Connection();
outcons[x]->connect(argv[2],atoi(argv[3]));
cons[x]=con;
char host[256];
JNL::addr_to_ipstr(cons[x]->get_remote(),host,sizeof(host));
n_cons++;
printf("Connection %d (%s) opened (%d).\n",x,host,n_cons);
break;
}
}
}
}
int x;
for (x = 0; x < 32; x ++)
{
if (cons[x])
{
cons[x]->run();
outcons[x]->run();
int cerr=(cons[x]->get_state() == JNL_Connection::STATE_ERROR || cons[x]->get_state()==JNL_Connection::STATE_CLOSED);
int oerr=(outcons[x]->get_state() == JNL_Connection::STATE_ERROR || outcons[x]->get_state()==JNL_Connection::STATE_CLOSED);
if ((!outcons[x]->send_bytes_in_queue() && !cons[x]->recv_bytes_available() && cerr) ||
(!cons[x]->send_bytes_in_queue() && !outcons[x]->recv_bytes_available() && oerr) ||
(cerr && oerr))
{
char host[256];
JNL::addr_to_ipstr(cons[x]->get_remote(),host,sizeof(host));
delete cons[x];
delete outcons[x];
outcons[x]=0;
cons[x]=0;
n_cons--;
printf("Connection %d (%s) closed (%d)\n",x,host,n_cons);
}
else
{
char buf[4096];
int l;
l=outcons[x]->send_bytes_available();
if (l > 4096) l=4096;
if (l) l=cons[x]->recv_bytes(buf,l);
if (l) outcons[x]->send(buf,l);
l=cons[x]->send_bytes_available();
if (l > 4096) l=4096;
if (l) l=outcons[x]->recv_bytes(buf,l);
if (l) cons[x]->send(buf,l);
}
}
}
}
JNL::close_socketlib();
return 0;
}

View File

@ -0,0 +1,32 @@
/*
** JNetLib
** Copyright (C) 2000-2006 CockOS, Inc.
** Author: Justin Frankel, Joshua Teitelbaum
** File: udpconnection.h - JNL SSL TCP connection interface
** License: see jnetlib.h
*/
#ifndef _UDPCONNECTION_H_
#define _UDPCONNECTION_H_
#include "connection.h"
class JNL_UDP_Connection : public JNL_Connection
{
public:
JNL_UDP_Connection(struct sockaddr_in *listenon, JNL_AsyncDNS *dns=JNL_CONNECTION_AUTODNS, int sendbufsize=8192, int recvbufsize=8192);
virtual ~JNL_UDP_Connection();
virtual void connect(int sock, struct sockaddr_in *loc=NULL); // used by the listen object, usually not needed by users.
/*
** Joshua Teitelbaum 1/27/2006 Adding new BSD socket analogues for SSL compatibility
*/
protected:
virtual void socket_shutdown();
virtual int socket_recv(char *buf, int len, int options);
virtual int socket_send(char *buf, int len, int options);
virtual int socket_connect();
};
#endif

View File

@ -0,0 +1,36 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: util.cpp - JNL implementation of basic network utilities
** License: see jnetlib.h
*/
#include "netinc.h"
#include "util.h"
int JNL::open_socketlib()
{
#ifdef _WIN32
WSADATA wsaData;
if (WSAStartup(MAKEWORD(1, 1), &wsaData)) return 1;
#endif
return 0;
}
void JNL::close_socketlib()
{
#ifdef _WIN32
WSACleanup();
#endif
}
unsigned long JNL::ipstr_to_addr(const char *cp)
{
return ::inet_addr(cp);
}
void JNL::addr_to_ipstr(unsigned long addr, char *host, int maxhostlen)
{
struct in_addr a; a.s_addr=addr;
char *p=::inet_ntoa(a); strncpy(host,p?p:"",maxhostlen);
}

View File

@ -0,0 +1,39 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: util.h - JNL interface for basic network utilities
** License: see jnetlib.h
**
** routines you may be interested in:
** JNL::open_socketlib();
** opens the socket library. Call this once before using any network
** code. If you create a new thread, call this again. Only really an
** issue for Win32 support, but use it anyway for portability/
**
** JNL::close_Socketlib();
** closes the socketlib. Call this when you're done with the network,
** after all your JNetLib objects have been destroyed.
**
** unsigned long JNL::ipstr_to_addr(const char *cp);
** gives you the integer representation of a ip address in dotted
** decimal form.
**
** JNL::addr_to_ipstr(unsigned long addr, char *host, int maxhostlen);
** gives you the dotted decimal notation of an integer ip address.
**
*/
#ifndef _UTIL_H_
#define _UTIL_H_
class JNL
{
public:
static int open_socketlib();
static void close_socketlib();
static unsigned long ipstr_to_addr(const char *cp);
static void addr_to_ipstr(unsigned long addr, char *host, int maxhostlen);
};
#endif //_UTIL_H_

View File

@ -0,0 +1,376 @@
/*
** JNetLib
** Copyright (C) 2000-2003 Nullsoft, Inc.
** Author: Justin Frankel
** File: webserver.cpp - Generic simple webserver baseclass
** License: see jnetlib.h
** see test.cpp for an example of how to use this class
*/
#include <windows.h>
#include "jnetlib.h"
#include "webserver.h"
class WS_ItemList
{
public:
WS_ItemList() { m_size=0; m_list=0; }
~WS_ItemList() { ::free(m_list); }
void *Add(void *i);
void *Get(int w);
void Del(int idx);
int GetSize(void) { return m_size; }
protected:
void **m_list;
int m_size;
};
class WS_conInst
{
public:
WS_conInst(JNL_Connection *c, int which_port);
~WS_conInst();
// these will be used by WebServerBaseClass::onConnection yay
JNL_HTTPServ m_serv;
IPageGenerator *m_pagegen;
int m_port; // port this came in on
time_t m_connect_time;
};
void *WS_ItemList::Add(void *i)
{
if (!m_list || !(m_size&31))
{
m_list=(void**)::realloc(m_list,sizeof(void*)*(m_size+32));
}
m_list[m_size++]=i;
return i;
}
void *WS_ItemList::Get(int w) { if (w >= 0 && w < m_size) return m_list[w]; return NULL; }
void WS_ItemList::Del(int idx)
{
if (m_list && idx >= 0 && idx < m_size)
{
m_size--;
if (idx != m_size) ::memcpy(m_list+idx,m_list+idx+1,sizeof(void *)*(m_size-idx));
if (!(m_size&31)&&m_size) // resize down
{
m_list=(void**)::realloc(m_list,sizeof(void*)*m_size);
}
}
}
WS_conInst::WS_conInst(JNL_Connection *c, int which_port) : m_serv(c), m_port(which_port)
{
m_pagegen=0;
time(&m_connect_time);
}
WS_conInst::~WS_conInst()
{
delete m_pagegen;
}
WebServerBaseClass::~WebServerBaseClass()
{
int x;
for (x = 0; x < m_connections->GetSize(); x ++)
{
delete (WS_conInst *)m_connections->Get(x);
}
delete m_connections;
for (x = 0; x < m_listeners->GetSize(); x ++)
{
delete (JNL_Listen *)m_listeners->Get(x);
}
delete m_listeners;
}
WebServerBaseClass::WebServerBaseClass()
{
m_connections=new WS_ItemList;
m_listeners=new WS_ItemList;
m_listener_rot=0;
m_timeout_s=15;
m_max_con=100;
}
void WebServerBaseClass::setMaxConnections(int max_con)
{
m_max_con=max_con;
}
void WebServerBaseClass::setRequestTimeout(int timeout_s)
{
m_timeout_s=timeout_s;
}
int WebServerBaseClass::addListenPort(int port, unsigned long which_interface)
{
int ffree=-1;
removeListenPort(port);
JNL_Listen *p=new JNL_Listen(port,which_interface);
m_listeners->Add((void *)p);
if (p->is_error()) return -1;
return 0;
}
void WebServerBaseClass::removeListenPort(int port)
{
int x;
for (x = 0; x < m_listeners->GetSize(); x ++)
{
JNL_Listen *p=(JNL_Listen *)m_listeners->Get(x);
if (p->port()==port)
{
delete p;
m_listeners->Del(x);
break;
}
}
}
void WebServerBaseClass::removeListenIdx(int idx)
{
if (idx >= 0 && idx < m_listeners->GetSize())
{
JNL_Listen *p=(JNL_Listen *)m_listeners->Get(idx);
delete p;
m_listeners->Del(idx);
}
}
int WebServerBaseClass::getListenPort(int idx, int *err)
{
JNL_Listen *p=(JNL_Listen *)m_listeners->Get(idx);
if (p)
{
if (err) *err=p->is_error();
return p->port();
}
return 0;
}
void WebServerBaseClass::attachConnection(JNL_Connection *con, int port)
{
m_connections->Add((void*)new WS_conInst(con,port));
}
void WebServerBaseClass::run(void)
{
int nl;
if (m_connections->GetSize() < m_max_con && (nl=m_listeners->GetSize()))
{
JNL_Listen *l=(JNL_Listen *)m_listeners->Get(m_listener_rot++ % nl);
JNL_Connection *c=l->get_connect();
if (c)
{
attachConnection(c,l->port());
}
}
int x;
for (x = 0; x < m_connections->GetSize(); x ++)
{
if (run_connection((WS_conInst *)m_connections->Get(x)))
{
delete ((WS_conInst *)m_connections->Get(x));
m_connections->Del(x--);
}
}
}
int WebServerBaseClass::run_connection(WS_conInst *con)
{
int s=con->m_serv.run();
if (s < 0)
{
// m_serv.geterrorstr()
return 1;
}
if (s < 2)
{
// return 1 if we timed out
return time(NULL)-con->m_connect_time > m_timeout_s;
}
if (s < 3)
{
con->m_pagegen=onConnection(&con->m_serv,con->m_port);
return 0;
}
if (s < 4)
{
if (!con->m_pagegen)
{
return !con->m_serv.bytes_inqueue();
}
char buf[16384];
int l=con->m_serv.bytes_cansend();
if (l > 0)
{
if (l > sizeof(buf))l=sizeof(buf);
l=con->m_pagegen->GetData(buf,l);
if (l < (con->m_pagegen->IsNonBlocking() ? 0 : 1)) // if nonblocking, this is l < 0, otherwise it's l<1
{
return !con->m_serv.bytes_inqueue();
}
if (l>0)
con->m_serv.write_bytes(buf,l);
}
return 0;
}
return 1; // we're done by this point
}
void WebServerBaseClass::url_encode(char *in, char *out, int max_out)
{
while (*in && max_out > 4)
{
if ((*in >= 'A' && *in <= 'Z')||
(*in >= 'a' && *in <= 'z')||
(*in >= '0' && *in <= '9')|| *in == '.' || *in == '_' || *in == '-')
{
*out++=*in++;
max_out--;
}
else
{
int i=*in++;
*out++ = '%';
int b=(i>>4)&15;
if (b < 10) *out++='0'+b;
else *out++='A'+b-10;
b=i&15;
if (b < 10) *out++='0'+b;
else *out++='A'+b-10;
max_out-=3;
}
}
*out=0;
}
void WebServerBaseClass::url_decode(char *in, char *out, int maxlen)
{
while (*in && maxlen>1)
{
if (*in == '+')
{
in++;
*out++=' ';
}
else if (*in == '%' && in[1] != '%' && in[1])
{
int a=0;
int b=0;
for ( b = 0; b < 2; b ++)
{
int r=in[1+b];
if (r>='0'&&r<='9') r-='0';
else if (r>='a'&&r<='z') r-='a'-10;
else if (r>='A'&&r<='Z') r-='A'-10;
else break;
a*=16;
a+=r;
}
if (b < 2) *out++=*in++;
else { *out++=a; in += 3;}
}
else *out++=*in++;
maxlen--;
}
*out=0;
}
void WebServerBaseClass::base64decode(char *src, char *dest, int destsize)
{
int accum=0;
int nbits=0;
while (*src)
{
int x=0;
char c=*src++;
if (c >= 'A' && c <= 'Z') x=c-'A';
else if (c >= 'a' && c <= 'z') x=c-'a' + 26;
else if (c >= '0' && c <= '9') x=c-'0' + 52;
else if (c == '+') x=62;
else if (c == '/') x=63;
else break;
accum <<= 6;
accum |= x;
nbits += 6;
while (nbits >= 8)
{
if (--destsize<=0) break;
nbits-=8;
*dest++ = (char)((accum>>nbits)&0xff);
}
}
*dest=0;
}
void WebServerBaseClass::base64encode(char *in, char *out)
{
char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int shift = 0;
int accum = 0;
while (*in)
{
if (*in)
{
accum <<= 8;
shift += 8;
accum |= *in++;
}
while ( shift >= 6 )
{
shift -= 6;
*out++ = alphabet[(accum >> shift) & 0x3F];
}
}
if (shift == 4)
{
*out++ = alphabet[(accum & 0xF)<<2];
*out++='=';
}
else if (shift == 2)
{
*out++ = alphabet[(accum & 0x3)<<4];
*out++='=';
*out++='=';
}
*out++=0;
}
int WebServerBaseClass::parseAuth(char *auth_header, char *out, int out_len)//returns 0 on unknown auth, 1 on basic
{
char *authstr=auth_header;
*out=0;
if (!auth_header || !*auth_header) return 0;
while (*authstr == ' ') authstr++;
if (strnicmp(authstr,"basic ",6)) return 0;
authstr+=6;
while (*authstr == ' ') authstr++;
base64decode(authstr,out,out_len);
return 1;
}

View File

@ -0,0 +1,142 @@
/*
** JNetLib
** Copyright (C) 2003 Nullsoft, Inc.
** Author: Justin Frankel
** File: webserver.h - Generic simple webserver baseclass
** License: see jnetlib.h
**
** You can derive your object from WebServerBaseClass to do simple web serving. Example:
class wwwServer : public WebServerBaseClass
{
public:
wwwServer() { }
virtual IPageGenerator *onConnection(JNL_HTTPServ *serv, int port)
{
serv->set_reply_header("Server:jnetlib_test/0.0");
if (!strcmp(serv->get_request_file(),"/"))
{
serv->set_reply_string("HTTP/1.1 200 OK");
serv->set_reply_header("Content-Type:text/html");
serv->send_reply();
return new MemPageGenerator(strdup("Test Web Server v0.0"));
}
else
{
serv->set_reply_string("HTTP/1.1 404 NOT FOUND");
serv->send_reply();
return 0; // no data
}
}
};
wwwServer foo;
foo.addListenPort(8080);
while (1)
{
foo.run();
Sleep(10);
}
You will also need to derive from the IPageGenerator interface to provide a data stream, here is an
example of MemPageGenerator:
class MemPageGenerator : public IPageGenerator
{
public:
virtual ~MemPageGenerator() { free(m_buf); }
MemPageGenerator(char *buf, int buf_len=-1) { m_buf=buf; if (buf_len >= 0) m_buf_size=buf_len; else m_buf_size=strlen(buf); m_buf_pos=0; }
virtual int GetData(char *buf, int size) // return 0 when done
{
int a=m_buf_size-m_buf_pos;
if (a < size) size=a;
memcpy(buf,m_buf+m_buf_pos,size);
m_buf_pos+=size;
return size;
}
private:
char *m_buf;
int m_buf_size;
int m_buf_pos;
};
**
*/
#ifndef _JNL_WEBSERVER_H_
#define _JNL_WEBSERVER_H_
#include "httpserv.h"
class IPageGenerator
{
public:
virtual ~IPageGenerator() { };
virtual int IsNonBlocking() { return 0; } // override this and return 1 if GetData should be allowed to return 0
virtual int GetData(char *buf, int size)=0; // return < 0 when done (or 0 if IsNonBlocking() is 1)
};
class WS_ItemList;
class WS_conInst;
class WebServerBaseClass
{
protected: // never create one of these directly, always derive
WebServerBaseClass();
public:
virtual ~WebServerBaseClass();
// stuff for setting limits/timeouts
void setMaxConnections(int max_con);
void setRequestTimeout(int timeout_s);
// stuff for setting listener port
int addListenPort(int port, unsigned long which_interface=0);
int getListenPort(int idx, int *err=0);
void removeListenPort(int port);
void removeListenIdx(int idx);
// call this a lot :)
void run(void);
// if you want to manually attach a connection, use this:
// you need to specify the port it came in on so the web server can build
// links
void attachConnection(JNL_Connection *con, int port);
// derived classes need to override this one =)
virtual IPageGenerator *onConnection(JNL_HTTPServ *serv, int port)=0;
// stats getting functions
// these can be used externally, as well as are used by the web server
static void url_encode(char *in, char *out, int max_out);
static void url_decode(char *in, char *out, int maxlen);
static void base64decode(char *src, char *dest, int destsize);
static void base64encode(char *in, char *out);
static int parseAuth(char *auth_header, char *out, int out_len);//returns 0 on unknown auth, 1 on basic
private:
int run_connection(WS_conInst *con);
int m_timeout_s;
int m_max_con;
JNL_AsyncDNS m_dns;
WS_ItemList *m_listeners;
int m_listener_rot;
WS_ItemList *m_connections;
};
#endif//_JNL_WEBSERVER_H_