diff --git a/Sources/WCConnect.m b/Sources/WCConnect.m
index 10f33d0a..2c43709a 100644
--- a/Sources/WCConnect.m
+++ b/Sources/WCConnect.m
@@ -50,14 +50,13 @@ - (id)_initConnectWithURL:(WIURL *)url bookmark:(NSDictionary *)bookmark {
_url = [url retain];
// check that bookmark password was loaded from keychain
- if (_url.password == nil) {
+ if (_url.password == nil)
[_url setPassword:[[WCKeychain keychain] passwordForBookmark:bookmark]];
- }
_connection = [[WCServerConnection connection] retain];
[_connection setURL:url];
[_connection setBookmark:bookmark];
-
+
theme = [[WCSettings settings] themeWithIdentifier:[bookmark objectForKey:WCBookmarksTheme]];
if(!theme)
diff --git a/Sources/WCLinkConnection.m b/Sources/WCLinkConnection.m
index 7ba6e3e8..9fa2915b 100644
--- a/Sources/WCLinkConnection.m
+++ b/Sources/WCLinkConnection.m
@@ -351,6 +351,9 @@ - (WIError *)linkDisconnectedError:(WIP7Link *)link {
- (NSUInteger)linkCipher:(WIP7Link *)link {
+ if(_bookmark && [_bookmark objectForKey:WCBookmarksEncryptionCipher])
+ return [[_bookmark objectForKey:WCBookmarksEncryptionCipher] integerValue];
+
if([[WCSettings settings] objectForKey:WCNetworkEncryptionCipher])
return [[[WCSettings settings] objectForKey:WCNetworkEncryptionCipher] integerValue];
diff --git a/Sources/WCPreferences.m b/Sources/WCPreferences.m
index 29440f5b..e555dfe2 100644
--- a/Sources/WCPreferences.m
+++ b/Sources/WCPreferences.m
@@ -118,34 +118,31 @@ - (void)_bookmarkDidChange:(NSDictionary *)bookmark {
#pragma mark -
- (void)_updateTheme:(NSMutableDictionary *)theme {
- [theme setObject:WIStringFromColor([_themesChatTextColorWell color]) forKey:WCThemesChatTextColor];
- [theme setObject:WIStringFromColor([_themesChatBackgroundColorWell color]) forKey:WCThemesChatBackgroundColor];
- [theme setObject:WIStringFromColor([_themesChatEventsColorWell color]) forKey:WCThemesChatEventsColor];
- [theme setObject:WIStringFromColor([_themesChatTimestampEveryLineColorWell color]) forKey:WCThemesChatTimestampEveryLineColor];
- [theme setObject:WIStringFromColor([_themesChatURLsColorWell color]) forKey:WCThemesChatURLsColor];
-
- [theme setObject:WIStringFromColor([_themesMessagesTextColorWell color]) forKey:WCThemesMessagesTextColor];
- [theme setObject:WIStringFromColor([_themesMessagesBackgroundColorWell color]) forKey:WCThemesMessagesBackgroundColor];
- [theme setObject:WIStringFromColor([_themesBoardsTextColorWell color]) forKey:WCThemesBoardsTextColor];
- [theme setObject:WIStringFromColor([_themesBoardsBackgroundColorWell color]) forKey:WCThemesBoardsBackgroundColor];
-
- [theme setBool:[_themesShowSmileysButton state] forKey:WCThemesShowSmileys];
-
- [theme setBool:[_themesChatTimestampEveryLineButton state] forKey:WCThemesChatTimestampEveryLine];
-
- [theme setInteger:[_themesUserListIconSizeMatrix selectedTag] forKey:WCThemesUserListIconSize];
- [theme setBool:[_themesUserListAlternateRowsButton state] forKey:WCThemesUserListAlternateRows];
-
- [theme setInteger:[_themesFileListIconSizeMatrix selectedTag] forKey:WCThemesFileListIconSize];
- [theme setBool:[_themesFileListAlternateRowsButton state] forKey:WCThemesFileListAlternateRows];
-
- [theme setBool:[_themesTransferListShowProgressBarButton state] forKey:WCThemesTransferListShowProgressBar];
- [theme setBool:[_themesTransferListAlternateRowsButton state] forKey:WCThemesTransferListAlternateRows];
-
- [theme setBool:[_themesTrackerListAlternateRowsButton state] forKey:WCThemesTrackerListAlternateRows];
-
- [theme setInteger:[_themesMonitorIconSizeMatrix selectedTag] forKey:WCThemesMonitorIconSize];
- [theme setBool:[_themesMonitorAlternateRowsButton state] forKey:WCThemesMonitorAlternateRows];
+// [theme setObject:WIStringFromColor([_themesChatTextColorWell color]) forKey:WCThemesChatTextColor];
+// [theme setObject:WIStringFromColor([_themesChatBackgroundColorWell color]) forKey:WCThemesChatBackgroundColor];
+// [theme setObject:WIStringFromColor([_themesMessagesTextColorWell color]) forKey:WCThemesMessagesTextColor];
+// [theme setObject:WIStringFromColor([_themesMessagesBackgroundColorWell color]) forKey:WCThemesMessagesBackgroundColor];
+// [theme setObject:WIStringFromColor([_themesBoardsTextColorWell color]) forKey:WCThemesBoardsTextColor];
+// [theme setObject:WIStringFromColor([_themesBoardsBackgroundColorWell color]) forKey:WCThemesBoardsBackgroundColor];
+
+ [theme setObject:WIStringFromColor([_themesChatEventsColorWell color]) forKey:WCThemesChatEventsColor];
+ [theme setObject:WIStringFromColor([_themesChatTimestampEveryLineColorWell color]) forKey:WCThemesChatTimestampEveryLineColor];
+ [theme setObject:WIStringFromColor([_themesChatURLsColorWell color]) forKey:WCThemesChatURLsColor];
+ [theme setBool:[_themesShowSmileysButton state] forKey:WCThemesShowSmileys];
+ [theme setBool:[_themesChatTimestampEveryLineButton state] forKey:WCThemesChatTimestampEveryLine];
+ [theme setInteger:[_themesUserListIconSizeMatrix selectedTag] forKey:WCThemesUserListIconSize];
+ [theme setBool:[_themesUserListAlternateRowsButton state] forKey:WCThemesUserListAlternateRows];
+
+ [theme setInteger:[_themesFileListIconSizeMatrix selectedTag] forKey:WCThemesFileListIconSize];
+ [theme setBool:[_themesFileListAlternateRowsButton state] forKey:WCThemesFileListAlternateRows];
+
+ [theme setBool:[_themesTransferListShowProgressBarButton state] forKey:WCThemesTransferListShowProgressBar];
+ [theme setBool:[_themesTransferListAlternateRowsButton state] forKey:WCThemesTransferListAlternateRows];
+
+ [theme setBool:[_themesTrackerListAlternateRowsButton state] forKey:WCThemesTrackerListAlternateRows];
+
+ [theme setInteger:[_themesMonitorIconSizeMatrix selectedTag] forKey:WCThemesMonitorIconSize];
+ [theme setBool:[_themesMonitorAlternateRowsButton state] forKey:WCThemesMonitorAlternateRows];
}
- (NSInteger)_selectedThemeRow {
diff --git a/Sources/WCServerBookmarkController.h b/Sources/WCServerBookmarkController.h
index f94cc9be..584395b4 100644
--- a/Sources/WCServerBookmarkController.h
+++ b/Sources/WCServerBookmarkController.h
@@ -9,11 +9,11 @@
#import "WCBookmarkController.h"
@interface WCServerBookmarkController : WCBookmarkController {
- IBOutlet NSPopUpButton *_bookmarksThemePopUpButton;
IBOutlet NSButton *_bookmarksAutoConnectButton;
IBOutlet NSButton *_bookmarksAutoReconnectButton;
IBOutlet NSTextField *_bookmarksNickTextField;
IBOutlet NSTextField *_bookmarksStatusTextField;
+ IBOutlet NSPopUpButton *_bookmarksCipherPopUpButton;
}
@end
diff --git a/Sources/WCServerBookmarkController.m b/Sources/WCServerBookmarkController.m
index e3747785..973272a2 100644
--- a/Sources/WCServerBookmarkController.m
+++ b/Sources/WCServerBookmarkController.m
@@ -15,7 +15,7 @@
@interface WCServerBookmarkController (Private)
- (void)_savePasswordForBookmark:(NSArray *)arguments;
-- (void)_reloadThemes;
+- (void)_reloadCiphers;
@end
@@ -41,24 +41,22 @@ - (void)_savePasswordForBookmark:(NSArray *)arguments {
#pragma mark -
-- (void)_reloadThemes {
-// NSEnumerator *enumerator;
-// NSDictionary *theme;
-// NSMenuItem *item;
-// NSInteger index;
-//
-// while((index = [_bookmarksThemePopUpButton indexOfItemWithTag:0]) != -1)
-// [_bookmarksThemePopUpButton removeItemAtIndex:index];
-//
-// enumerator = [[[WCSettings settings] objectForKey:WCThemes] objectEnumerator];
-//
-// while((theme = [enumerator nextObject])) {
-// item = [NSMenuItem itemWithTitle:[theme objectForKey:WCThemesName]];
-// [item setRepresentedObject:[theme objectForKey:WCThemesIdentifier]];
-// [item setImage:[[WCPreferences preferences] imageForTheme:theme size:NSMakeSize(16.0, 12.0)]];
-//
-// [[_bookmarksThemePopUpButton menu] addItem:item];
-// }
+- (void)_reloadCiphers {
+ NSMenuItem *item;
+ NSDictionary *schemes;
+ NSArray *schemeKeys;
+
+ [[_bookmarksCipherPopUpButton menu] removeAllItems];
+
+ schemes = [WCP7Spec encryptionSchemes];
+ schemeKeys = [[schemes allKeys] sortedArrayUsingSelector:@selector(compare:)];
+
+ for(NSNumber *key in schemeKeys) {
+ NSString *name = [WCP7Spec nameForEncryptionSchemeID:[key stringValue]];
+ item = [NSMenuItem itemWithTitle:name tag:[key intValue]];
+
+ [[_bookmarksCipherPopUpButton menu] addItem:item];
+ }
}
@@ -69,10 +67,9 @@ @implementation WCServerBookmarkController
#pragma mark -
- (void)load {
- NSDictionary *theme;
- NSInteger index;
+ NSNumber *encryptionCipher;
- [self _reloadThemes];
+ [self _reloadCiphers];
if(_bookmark) {
[_bookmarksNameTextField setStringValue:[_bookmark objectForKey:WCBookmarksName]];
@@ -87,12 +84,12 @@ - (void)load {
else
[_bookmarksPasswordTextField setStringValue:@""];
-// theme = [_bookmark objectForKey:WCBookmarksTheme];
-//
-// if(theme && (index = [_bookmarksThemePopUpButton indexOfItemWithRepresentedObject:theme]) != -1)
-// [_bookmarksThemePopUpButton selectItemAtIndex:index];
-// else
-// [_bookmarksThemePopUpButton selectItemAtIndex:0];
+ encryptionCipher = [_bookmark objectForKey:WCBookmarksEncryptionCipher];
+
+ if (encryptionCipher)
+ [_bookmarksCipherPopUpButton selectItemWithTag:[encryptionCipher intValue]];
+ else
+ [_bookmarksCipherPopUpButton selectItemWithTag:[[WCSettings settings] intForKey:WCNetworkEncryptionCipher]];
[_bookmarksAutoConnectButton setState:[_bookmark boolForKey:WCBookmarksAutoConnect]];
[_bookmarksAutoReconnectButton setState:[_bookmark boolForKey:WCBookmarksAutoReconnect]];
@@ -123,11 +120,6 @@ - (void)save {
[_bookmark setObject:[_bookmarksAddressTextField stringValue] forKey:WCBookmarksAddress];
[_bookmark setObject:[_bookmarksLoginTextField stringValue] forKey:WCBookmarksLogin];
-// if([_bookmarksThemePopUpButton representedObjectOfSelectedItem])
-// [_bookmark setObject:[_bookmarksThemePopUpButton representedObjectOfSelectedItem] forKey:WCBookmarksTheme];
-// else
-// [_bookmark removeObjectForKey:WCBookmarksTheme];
-
[_bookmark setBool:[_bookmarksAutoConnectButton state] forKey:WCBookmarksAutoConnect];
[_bookmark setBool:[_bookmarksAutoReconnectButton state] forKey:WCBookmarksAutoReconnect];
[_bookmark setObject:[_bookmarksNickTextField stringValue] forKey:WCBookmarksNick];
@@ -149,6 +141,10 @@ - (void)save {
passwordChanged = YES;
}
+ if(([_bookmarksCipherPopUpButton selectedTag] != [[WCSettings settings] intForKey:WCNetworkEncryptionCipher]) ||
+ ([_bookmark integerForKey:WCBookmarksEncryptionCipher] != [_bookmarksCipherPopUpButton selectedTag]))
+ [_bookmark setObject:[NSNumber numberWithInt:[_bookmarksCipherPopUpButton selectedTag]] forKey:WCBookmarksEncryptionCipher];
+
if(![_oldBookmark isEqualToDictionary:_bookmark] || passwordChanged) {
[[WCSettings settings] replaceObjectAtIndex:row withObject:_bookmark inArrayForKey:WCBookmarks];
@@ -167,16 +163,14 @@ - (void)save {
[_bookmark setObject:[_bookmarksAddressTextField stringValue] forKey:WCBookmarksAddress];
[_bookmark setObject:[_bookmarksLoginTextField stringValue] forKey:WCBookmarksLogin];
-// if([_bookmarksThemePopUpButton representedObjectOfSelectedItem])
-// [_bookmark setObject:[_bookmarksThemePopUpButton representedObjectOfSelectedItem] forKey:WCBookmarksTheme];
-// else
-// [_bookmark removeObjectForKey:WCBookmarksTheme];
-
[_bookmark setBool:[_bookmarksAutoConnectButton state] forKey:WCBookmarksAutoConnect];
[_bookmark setBool:[_bookmarksAutoReconnectButton state] forKey:WCBookmarksAutoReconnect];
[_bookmark setObject:[_bookmarksNickTextField stringValue] forKey:WCBookmarksNick];
[_bookmark setObject:[_bookmarksStatusTextField stringValue] forKey:WCBookmarksStatus];
+ if([[WCSettings settings] intForKey:WCNetworkEncryptionCipher] != [_bookmarksCipherPopUpButton selectedTag])
+ [_bookmark setObject:[NSNumber numberWithInt:[_bookmarksCipherPopUpButton selectedTag]] forKey:WCBookmarksEncryptionCipher];
+
[[WCKeychain keychain] setPassword:password forBookmark:_bookmark];
[_bookmarksPassword release];
diff --git a/Sources/WCServerInfo.h b/Sources/WCServerInfo.h
index 3434031c..f2de9e8b 100644
--- a/Sources/WCServerInfo.h
+++ b/Sources/WCServerInfo.h
@@ -48,6 +48,8 @@
IBOutlet NSTextField *_protocolTextField;
IBOutlet NSTextField *_cipherTitleTextField;
IBOutlet NSTextField *_cipherTextField;
+ IBOutlet NSTextField *_checksumTitleTextField;
+ IBOutlet NSTextField *_checksumTextField;
IBOutlet NSTextField *_serializationTitleTextField;
IBOutlet NSTextField *_serializationTextField;
IBOutlet NSTextField *_compressionTitleTextField;
diff --git a/Sources/WCServerInfo.m b/Sources/WCServerInfo.m
index 4b0ca04d..78723f96 100644
--- a/Sources/WCServerInfo.m
+++ b/Sources/WCServerInfo.m
@@ -96,6 +96,28 @@ - (void)_updateServerInfo {
} else {
[_cipherTextField setStringValue:NSLS(@"None", @"Encryption disabled")];
}
+
+ wi_p7_options_t options = wi_p7_socket_options([socket P7Socket]);
+
+ if (options & WI_P7_ENCRYPTION_RSA_AES128_SHA1 ||
+ options & WI_P7_ENCRYPTION_RSA_AES192_SHA1 ||
+ options & WI_P7_ENCRYPTION_RSA_AES256_SHA1 ||
+ options & WI_P7_ENCRYPTION_RSA_BF128_SHA1 ||
+ options & WI_P7_ENCRYPTION_RSA_3DES192_SHA1) {
+ [_checksumTextField setStringValue:@"SHA1"];
+ } else if (options & WI_P7_ENCRYPTION_RSA_AES128_SHA256 ||
+ options & WI_P7_ENCRYPTION_RSA_AES192_SHA256 ||
+ options & WI_P7_ENCRYPTION_RSA_AES256_SHA256 ||
+ options & WI_P7_ENCRYPTION_RSA_BF128_SHA256 ||
+ options & WI_P7_ENCRYPTION_RSA_3DES192_SHA256) {
+ [_checksumTextField setStringValue:@"SHA256"];
+ } else if (options & WI_P7_ENCRYPTION_RSA_AES128_SHA512 ||
+ options & WI_P7_ENCRYPTION_RSA_AES192_SHA512 ||
+ options & WI_P7_ENCRYPTION_RSA_AES256_SHA512 ||
+ options & WI_P7_ENCRYPTION_RSA_BF128_SHA512 ||
+ options & WI_P7_ENCRYPTION_RSA_3DES192_SHA512) {
+ [_checksumTextField setStringValue:@"SHA512"];
+ }
if([socket usesCompression]) {
[_compressionTextField setStringValue:[NSSWF:NSLS(@"Yes, compression ratio %.2f", @"Compression enabled (ratio)"),
@@ -108,6 +130,7 @@ - (void)_updateServerInfo {
[self resizeTitleTextField:_compressionTitleTextField withTextField:_compressionTextField];
[self resizeTitleTextField:_serializationTitleTextField withTextField:_serializationTextField];
+ [self resizeTitleTextField:_checksumTitleTextField withTextField:_checksumTextField];
[self resizeTitleTextField:_cipherTitleTextField withTextField:_cipherTextField];
[self resizeTitleTextField:_protocolTitleTextField withTextField:_protocolTextField];
[self resizeTitleTextField:_versionTitleTextField withTextField:_versionTextField];
diff --git a/Sources/WCSettings.h b/Sources/WCSettings.h
index 1a18e956..7d2b8cd5 100644
--- a/Sources/WCSettings.h
+++ b/Sources/WCSettings.h
@@ -114,6 +114,7 @@ extern NSString * const WCBookmarksStatus;
extern NSString * const WCBookmarksAutoConnect;
extern NSString * const WCBookmarksAutoReconnect;
extern NSString * const WCBookmarksTheme;
+extern NSString * const WCBookmarksEncryptionCipher;
extern NSString * const WCChatHistoryScrollback;
extern NSString * const WCChatHistoryScrollbackModifier;
diff --git a/Sources/WCSettings.m b/Sources/WCSettings.m
index e33783a8..e2364719 100644
--- a/Sources/WCSettings.m
+++ b/Sources/WCSettings.m
@@ -132,6 +132,7 @@
NSString * const WCBookmarksAutoConnect = @"AutoJoin";
NSString * const WCBookmarksAutoReconnect = @"AutoReconnect";
NSString * const WCBookmarksTheme = @"Theme";
+NSString * const WCBookmarksEncryptionCipher = @"EncryptionCipher";
NSString * const WCChatHistoryScrollback = @"WCHistoryScrollback";
NSString * const WCChatHistoryScrollbackModifier = @"WCHistoryScrollbackModifier";
diff --git a/WiredClient.xcodeproj/project.pbxproj b/WiredClient.xcodeproj/project.pbxproj
index ad385dd3..f9d4437a 100644
--- a/WiredClient.xcodeproj/project.pbxproj
+++ b/WiredClient.xcodeproj/project.pbxproj
@@ -2344,7 +2344,7 @@
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
- CURRENT_PROJECT_VERSION = 49;
+ CURRENT_PROJECT_VERSION = 50;
DEVELOPMENT_TEAM = 7KTXA5Y36K;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
@@ -2598,7 +2598,7 @@
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
- CURRENT_PROJECT_VERSION = 49;
+ CURRENT_PROJECT_VERSION = 50;
DEVELOPMENT_TEAM = 7KTXA5Y36K;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
@@ -2700,7 +2700,7 @@
ALWAYS_SEARCH_USER_PATHS = NO;
CODE_SIGN_ENTITLEMENTS = "Wired Client.entitlements";
CODE_SIGN_IDENTITY = "-";
- CURRENT_PROJECT_VERSION = 49;
+ CURRENT_PROJECT_VERSION = 50;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
diff --git a/WiredClient.xcodeproj/xcuserdata/nark.xcuserdatad/xcschemes/xcschememanagement.plist b/WiredClient.xcodeproj/xcuserdata/nark.xcuserdatad/xcschemes/xcschememanagement.plist
index f332eb7b..8672c56a 100644
--- a/WiredClient.xcodeproj/xcuserdata/nark.xcuserdatad/xcschemes/xcschememanagement.plist
+++ b/WiredClient.xcodeproj/xcuserdata/nark.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -12,12 +12,12 @@
Localize Strings.xcscheme_^#shared#^_
orderHint
- 24
+ 25
Neo.xcscheme_^#shared#^_
orderHint
- 25
+ 24
Wired Client (Distribute Debug).xcscheme_^#shared#^_
diff --git a/de.lproj/Preferences.xib b/de.lproj/Preferences.xib
index 9fc74de6..68f4f828 100755
--- a/de.lproj/Preferences.xib
+++ b/de.lproj/Preferences.xib
@@ -10,8 +10,6 @@
-
-
@@ -65,34 +63,26 @@
-
-
-
-
-
-
-
-
@@ -102,9 +92,9 @@
-
+
@@ -122,7 +112,7 @@
-
+
@@ -130,7 +120,7 @@
-
+
@@ -139,7 +129,7 @@
-
+
@@ -148,7 +138,7 @@
-
+
@@ -162,7 +152,7 @@
-
+
@@ -171,7 +161,7 @@
-
+
@@ -180,7 +170,7 @@
-
+
@@ -189,7 +179,7 @@
-
+
@@ -209,7 +199,7 @@
-
+
@@ -245,9 +235,9 @@
+
@@ -1546,688 +1536,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-DQ
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-DQ
-
-
-
-
-
-
-
-
-
-
-
-
-
-Gw
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-DQ
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/fr.lproj/PublicChatWindow.xib b/fr.lproj/PublicChatWindow.xib
index 7c7939bf..60915139 100644
--- a/fr.lproj/PublicChatWindow.xib
+++ b/fr.lproj/PublicChatWindow.xib
@@ -63,7 +63,7 @@
-
+
@@ -205,7 +205,7 @@
-
+
@@ -228,14 +228,14 @@
-
+
-
+
-
+
@@ -247,7 +247,7 @@
-
+
@@ -259,7 +259,7 @@
-
+
@@ -268,7 +268,7 @@
-
+
@@ -277,7 +277,7 @@
-
+
@@ -286,7 +286,7 @@
-
+
@@ -298,15 +298,15 @@
-
+
-
+
-
+
@@ -315,7 +315,7 @@
-
+
@@ -324,7 +324,7 @@
-
+
@@ -336,7 +336,7 @@
-
+
@@ -345,7 +345,7 @@
-
+
@@ -353,7 +353,7 @@
-
+
@@ -389,7 +389,7 @@ Gw
-
+
@@ -401,7 +401,7 @@ Gw
-
+
@@ -410,12 +410,30 @@ Gw
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -548,6 +566,7 @@ Gw
+
diff --git a/fr.lproj/ServerInfo.xib b/fr.lproj/ServerInfo.xib
index 02d160cb..5c848883 100644
--- a/fr.lproj/ServerInfo.xib
+++ b/fr.lproj/ServerInfo.xib
@@ -1,8 +1,8 @@
-
+
-
+
@@ -11,6 +11,8 @@
+
+
@@ -42,20 +44,20 @@
-
-
+
+
-
+
-
-
+
+
-
-
+
+
@@ -63,182 +65,200 @@
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -248,6 +268,7 @@
+
diff --git a/vendor/WiredFrameworks/WiredNetworking/NSString-WINetworking.m b/vendor/WiredFrameworks/WiredNetworking/NSString-WINetworking.m
index c299f26c..7c343620 100644
--- a/vendor/WiredFrameworks/WiredNetworking/NSString-WINetworking.m
+++ b/vendor/WiredFrameworks/WiredNetworking/NSString-WINetworking.m
@@ -51,7 +51,7 @@ - (id)initWithWiredString:(wi_string_t *)string {
#pragma mark -
- (wi_string_t *)wiredString {
- return wi_string_with_cstring([self UTF8String]);
+ return wi_string_with_cstring([self cStringUsingEncoding:NSUTF8StringEncoding]);
}
@end
diff --git a/vendor/WiredFrameworks/WiredNetworking/WIP7Link.m b/vendor/WiredFrameworks/WiredNetworking/WIP7Link.m
index aca7bb62..ae91e174 100644
--- a/vendor/WiredFrameworks/WiredNetworking/WIP7Link.m
+++ b/vendor/WiredFrameworks/WiredNetworking/WIP7Link.m
@@ -145,17 +145,26 @@ - (NSUInteger)_TLSOptions {
if(cipherTag != -1) {
switch (cipherTag) {
- case 0: options = options | WIP7EncryptionRSA_AES128_SHA1; break;
- case 1: options = options | WIP7EncryptionRSA_AES192_SHA1; break;
- case 2: options = options | WIP7EncryptionRSA_AES256_SHA1; break;
- case 3: options = options | WIP7EncryptionRSA_BF128_SHA1; break;
- case 4: options = options | WIP7EncryptionRSA_3DES192_SHA1; break;
- case 5: options = options | WIP7EncryptionRSA_AES256_SHA256; break;
+ case 0: options = options | WIP7EncryptionRSA_AES128_SHA1; break;
+ case 1: options = options | WIP7EncryptionRSA_AES192_SHA1; break;
+ case 2: options = options | WIP7EncryptionRSA_AES256_SHA1; break;
+ case 3: options = options | WIP7EncryptionRSA_BF128_SHA1; break;
+ case 4: options = options | WIP7EncryptionRSA_3DES192_SHA1; break;
+ case 5: options = options | WIP7EncryptionRSA_AES128_SHA256; break;
+ case 6: options = options | WIP7EncryptionRSA_AES192_SHA256; break;
+ case 7: options = options | WIP7EncryptionRSA_AES256_SHA256; break;
+ case 8: options = options | WIP7EncryptionRSA_BF128_SHA256; break;
+ case 9: options = options | WIP7EncryptionRSA_3DES192_SHA256; break;
+ case 10: options = options | WIP7EncryptionRSA_AES128_SHA512; break;
+ case 11: options = options | WIP7EncryptionRSA_AES192_SHA512; break;
+ case 12: options = options | WIP7EncryptionRSA_AES256_SHA512; break;
+ case 13: options = options | WIP7EncryptionRSA_BF128_SHA512; break;
+ case 14: options = options | WIP7EncryptionRSA_3DES192_SHA512; break;
}
} else {
options = options | WIP7EncryptionRSA_AES256_SHA1;
}
-
+
options = options | WIP7ChecksumSHA1;
return options;
diff --git a/vendor/WiredFrameworks/WiredNetworking/WIP7Socket.h b/vendor/WiredFrameworks/WiredNetworking/WIP7Socket.h
index 9a1d0daf..f46919f9 100644
--- a/vendor/WiredFrameworks/WiredNetworking/WIP7Socket.h
+++ b/vendor/WiredFrameworks/WiredNetworking/WIP7Socket.h
@@ -35,10 +35,20 @@ enum _WIP7Options {
WIP7EncryptionRSA_AES256_SHA1 = WI_P7_ENCRYPTION_RSA_AES256_SHA1,
WIP7EncryptionRSA_BF128_SHA1 = WI_P7_ENCRYPTION_RSA_BF128_SHA1,
WIP7EncryptionRSA_3DES192_SHA1 = WI_P7_ENCRYPTION_RSA_3DES192_SHA1,
- WIP7EncryptionRSA_AES256_SHA256 = WI_P7_ENCRYPTION_RSA_AES256_SHA256,
- WIP7ChecksumSHA1 = WI_P7_CHECKSUM_SHA1,
+ WIP7EncryptionRSA_AES128_SHA256 = WI_P7_ENCRYPTION_RSA_AES128_SHA256,
+ WIP7EncryptionRSA_AES192_SHA256 = WI_P7_ENCRYPTION_RSA_AES192_SHA256,
+ WIP7EncryptionRSA_AES256_SHA256 = WI_P7_ENCRYPTION_RSA_AES256_SHA256,
+ WIP7EncryptionRSA_BF128_SHA256 = WI_P7_ENCRYPTION_RSA_BF128_SHA256,
+ WIP7EncryptionRSA_3DES192_SHA256 = WI_P7_ENCRYPTION_RSA_3DES192_SHA256,
+ WIP7EncryptionRSA_AES128_SHA512 = WI_P7_ENCRYPTION_RSA_AES128_SHA512,
+ WIP7EncryptionRSA_AES192_SHA512 = WI_P7_ENCRYPTION_RSA_AES192_SHA512,
+ WIP7EncryptionRSA_AES256_SHA512 = WI_P7_ENCRYPTION_RSA_AES256_SHA512,
+ WIP7EncryptionRSA_BF128_SHA512 = WI_P7_ENCRYPTION_RSA_BF128_SHA512,
+ WIP7EncryptionRSA_3DES192_SHA512 = WI_P7_ENCRYPTION_RSA_3DES192_SHA512,
+ WIP7ChecksumSHA1 = WI_P7_CHECKSUM_SHA1,
WIP7ChecksumSHA256 = WI_P7_CHECKSUM_SHA256,
- WIP7All = WI_P7_ALL
+ WIP7ChecksumSHA512 = WI_P7_CHECKSUM_SHA512,
+ WIP7All = WI_P7_ALL
};
typedef enum _WIP7Options WIP7Options;
diff --git a/vendor/WiredFrameworks/WiredNetworking/WIP7Spec.h b/vendor/WiredFrameworks/WiredNetworking/WIP7Spec.h
index f43ff013..8f2c4aa8 100644
--- a/vendor/WiredFrameworks/WiredNetworking/WIP7Spec.h
+++ b/vendor/WiredFrameworks/WiredNetworking/WIP7Spec.h
@@ -36,7 +36,7 @@ enum _WIP7Originator {
typedef enum _WIP7Originator WIP7Originator;
-@class WIP7SpecMessage, WIP7Message, WIError;
+@class WIP7SpecMessage, WIP7Message, WIError, WIP7SpecField;
@interface WIP7Spec : WIObject {
wi_p7_spec_t *_spec;
@@ -63,6 +63,9 @@ typedef enum _WIP7Originator WIP7Originator;
- (NSArray *)messages;
- (WIP7SpecMessage *)messageWithName:(NSString *)name;
+- (NSDictionary *)encryptionSchemes;
+- (NSString *)nameForEncryptionSchemeID:(NSString *)encryptionID;
+
- (BOOL)verifyMessage:(WIP7Message *)message error:(WIError **)error;
@end
diff --git a/vendor/WiredFrameworks/WiredNetworking/WIP7Spec.m b/vendor/WiredFrameworks/WiredNetworking/WIP7Spec.m
index 3b16a16a..43c425e5 100644
--- a/vendor/WiredFrameworks/WiredNetworking/WIP7Spec.m
+++ b/vendor/WiredFrameworks/WiredNetworking/WIP7Spec.m
@@ -225,6 +225,7 @@ - (NSUInteger)fieldIDForName:(NSString *)name {
+
#pragma mark -
- (NSArray *)fields {
@@ -297,6 +298,96 @@ - (WIP7SpecMessage *)messageWithName:(NSString *)name {
+- (NSDictionary *)encryptionSchemes {
+ NSMutableDictionary *dictionary;
+ wi_dictionary_t *schemes;
+ wi_pool_t *pool;
+ wi_enumerator_t *enumerator;
+ wi_p7_spec_field_t *field;
+ wi_string_t *key;
+ wi_integer_t value;
+
+ pool = wi_pool_init(wi_pool_alloc());
+
+ dictionary = [NSMutableDictionary dictionary];
+ field = wi_p7_spec_field_with_name(wi_p7_spec_builtin_spec(), WI_STR("p7.handshake.encryption"));
+ schemes = wi_p7_spec_field_enums_by_name(field);
+ enumerator = wi_dictionary_key_enumerator(schemes);
+
+ while((key = wi_enumerator_next_data(enumerator))) {
+ value = (wi_integer_t) wi_dictionary_data_for_key(schemes, key);
+
+ [dictionary setObject:[NSString stringWithWiredString:key]
+ forKey:[NSNumber numberWithLongLong:value]];
+ }
+
+ wi_release(pool);
+
+ return dictionary;
+}
+
+
+
+- (NSString *)nameForEncryptionSchemeID:(NSString *)encryptionID {
+ switch ([encryptionID intValue]) {
+ case 0:
+ return @"RSA - AES/128 - SHA1";
+ break;
+ case 1:
+ return @"RSA - AES/192 - SHA1";
+ break;
+ case 2:
+ return @"RSA - AES/256 - SHA1";
+ break;
+ case 3:
+ return @"RSA - BF/128 - SHA1";
+ break;
+ case 4:
+ return @"RSA - 3DES/192 - SHA1";
+ break;
+
+ case 5:
+ return @"RSA - AES/128 - SHA256";
+ break;
+ case 6:
+ return @"RSA - AES/192 - SHA256";
+ break;
+ case 7:
+ return @"RSA - AES/256 - SHA256";
+ break;
+ case 8:
+ return @"RSA - BF/128 - SHA256";
+ break;
+ case 9:
+ return @"RSA - 3DES/192 - SHA256";
+ break;
+
+ case 10:
+ return @"RSA - AES/128 - SHA512";
+ break;
+ case 11:
+ return @"RSA - AES/192 - SHA512";
+ break;
+ case 12:
+ return @"RSA - AES/256 - SHA512";
+ break;
+ case 13:
+ return @"RSA - BF/128 - SHA512";
+ break;
+ case 14:
+ return @"RSA - 3DES/192 - SHA512";
+ break;
+
+ default:
+ return NULL;
+ break;
+ }
+
+ return NULL;
+}
+
+
+
#pragma mark -
- (BOOL)verifyMessage:(WIP7Message *)message error:(WIError **)error {
diff --git a/vendor/WiredFrameworks/libwired/libwired/base/wi-assert.c b/vendor/WiredFrameworks/libwired/libwired/base/wi-assert.c
index 09e1442f..a4ffca9f 100644
--- a/vendor/WiredFrameworks/libwired/libwired/base/wi-assert.c
+++ b/vendor/WiredFrameworks/libwired/libwired/base/wi-assert.c
@@ -51,5 +51,5 @@ static void wi_assert_default_handler(const char *file, unsigned int line, wi_st
wi_release(string);
- __builtin_trap();
+ wi_crash();
}
diff --git a/vendor/WiredFrameworks/libwired/libwired/base/wi-base.c b/vendor/WiredFrameworks/libwired/libwired/base/wi-base.c
index 5d27dd1c..ac8b74ef 100644
--- a/vendor/WiredFrameworks/libwired/libwired/base/wi-base.c
+++ b/vendor/WiredFrameworks/libwired/libwired/base/wi-base.c
@@ -218,8 +218,13 @@ void wi_abort(void) {
abort();
}
-void __builtin_trap (void);
-
+void wi_crash(void) {
+#if __has_builtin(__builtin_trap)
+ __builtin_trap();
+#else
+ *((char *) NULL) = 0;
+#endif
+}
#pragma mark -
diff --git a/vendor/WiredFrameworks/libwired/libwired/base/wi-byteorder.h b/vendor/WiredFrameworks/libwired/libwired/base/wi-byteorder.h
index 49a9d004..7fbc057e 100644
--- a/vendor/WiredFrameworks/libwired/libwired/base/wi-byteorder.h
+++ b/vendor/WiredFrameworks/libwired/libwired/base/wi-byteorder.h
@@ -61,110 +61,110 @@
#endif
-#define WI_SWAP_INT16(n) \
-((uint16_t) ((((uint16_t) (n) & 0xFF00) >> 8) | \
-(((uint16_t) (n) & 0x00FF) << 8)))
-
-#define WI_SWAP_INT32(n) \
-((uint32_t) ((((uint32_t) (n) & 0xFF000000) >> 24) | \
-(((uint32_t) (n) & 0x00FF0000) >> 8) | \
-(((uint32_t) (n) & 0x0000FF00) << 8) | \
-(((uint32_t) (n) & 0x000000FF) << 24)))
-
-#define WI_SWAP_INT64(n) \
-((uint64_t) ((((uint64_t) (n) & 0xFF00000000000000ULL) >> 56) | \
-(((uint64_t) (n) & 0x00FF000000000000ULL) >> 40) | \
-(((uint64_t) (n) & 0x0000FF0000000000ULL) >> 24) | \
-(((uint64_t) (n) & 0x000000FF00000000ULL) >> 8) | \
-(((uint64_t) (n) & 0x00000000FF000000ULL) << 8) | \
-(((uint64_t) (n) & 0x0000000000FF0000ULL) << 24) | \
-(((uint64_t) (n) & 0x000000000000FF00ULL) << 40) | \
-(((uint64_t) (n) & 0x00000000000000FFULL) << 56)))
+#define WI_SWAP_INT16(n) \
+ ((uint16_t) ((((uint16_t) (n) & 0xFF00) >> 8) | \
+ (((uint16_t) (n) & 0x00FF) << 8)))
+
+#define WI_SWAP_INT32(n) \
+ ((uint32_t) ((((uint32_t) (n) & 0xFF000000) >> 24) | \
+ (((uint32_t) (n) & 0x00FF0000) >> 8) | \
+ (((uint32_t) (n) & 0x0000FF00) << 8) | \
+ (((uint32_t) (n) & 0x000000FF) << 24)))
+
+#define WI_SWAP_INT64(n) \
+ ((uint64_t) ((((uint64_t) (n) & 0xFF00000000000000ULL) >> 56) | \
+ (((uint64_t) (n) & 0x00FF000000000000ULL) >> 40) | \
+ (((uint64_t) (n) & 0x0000FF0000000000ULL) >> 24) | \
+ (((uint64_t) (n) & 0x000000FF00000000ULL) >> 8) | \
+ (((uint64_t) (n) & 0x00000000FF000000ULL) << 8) | \
+ (((uint64_t) (n) & 0x0000000000FF0000ULL) << 24) | \
+ (((uint64_t) (n) & 0x000000000000FF00ULL) << 40) | \
+ (((uint64_t) (n) & 0x00000000000000FFULL) << 56)))
#ifdef WI_BIG_ENDIAN
-#define WI_SWAP_HOST_TO_BIG_INT16(n) (n)
-#define WI_SWAP_HOST_TO_BIG_INT32(n) (n)
-#define WI_SWAP_HOST_TO_BIG_INT64(n) (n)
+#define WI_SWAP_HOST_TO_BIG_INT16(n) (n)
+#define WI_SWAP_HOST_TO_BIG_INT32(n) (n)
+#define WI_SWAP_HOST_TO_BIG_INT64(n) (n)
-#define WI_SWAP_HOST_TO_LITTLE_INT16(n) WI_SWAP_INT16(n)
-#define WI_SWAP_HOST_TO_LITTLE_INT32(n) WI_SWAP_INT32(n)
-#define WI_SWAP_HOST_TO_LITTLE_INT64(n) WI_SWAP_INT64(n)
-
-#define WI_SWAP_BIG_TO_HOST_INT16(n) (n)
-#define WI_SWAP_BIG_TO_HOST_INT32(n) (n)
-#define WI_SWAP_BIG_TO_HOST_INT64(n) (n)
-
-#define WI_SWAP_LITTLE_TO_HOST_INT16(n) WI_SWAP_INT16(n)
-#define WI_SWAP_LITTLE_TO_HOST_INT32(n) WI_SWAP_INT32(n)
-#define WI_SWAP_LITTLE_TO_HOST_INT64(n) WI_SWAP_INT64(n)
+#define WI_SWAP_HOST_TO_LITTLE_INT16(n) WI_SWAP_INT16(n)
+#define WI_SWAP_HOST_TO_LITTLE_INT32(n) WI_SWAP_INT32(n)
+#define WI_SWAP_HOST_TO_LITTLE_INT64(n) WI_SWAP_INT64(n)
+
+#define WI_SWAP_BIG_TO_HOST_INT16(n) (n)
+#define WI_SWAP_BIG_TO_HOST_INT32(n) (n)
+#define WI_SWAP_BIG_TO_HOST_INT64(n) (n)
+
+#define WI_SWAP_LITTLE_TO_HOST_INT16(n) WI_SWAP_INT16(n)
+#define WI_SWAP_LITTLE_TO_HOST_INT32(n) WI_SWAP_INT32(n)
+#define WI_SWAP_LITTLE_TO_HOST_INT64(n) WI_SWAP_INT64(n)
#else
-#define WI_SWAP_HOST_TO_BIG_INT16(n) WI_SWAP_INT16(n)
-#define WI_SWAP_HOST_TO_BIG_INT32(n) WI_SWAP_INT32(n)
-#define WI_SWAP_HOST_TO_BIG_INT64(n) WI_SWAP_INT64(n)
+#define WI_SWAP_HOST_TO_BIG_INT16(n) WI_SWAP_INT16(n)
+#define WI_SWAP_HOST_TO_BIG_INT32(n) WI_SWAP_INT32(n)
+#define WI_SWAP_HOST_TO_BIG_INT64(n) WI_SWAP_INT64(n)
-#define WI_SWAP_HOST_TO_LITTLE_INT16(n) (n)
-#define WI_SWAP_HOST_TO_LITTLE_INT32(n) (n)
-#define WI_SWAP_HOST_TO_LITTLE_INT64(n) (n)
+#define WI_SWAP_HOST_TO_LITTLE_INT16(n) (n)
+#define WI_SWAP_HOST_TO_LITTLE_INT32(n) (n)
+#define WI_SWAP_HOST_TO_LITTLE_INT64(n) (n)
-#define WI_SWAP_BIG_TO_HOST_INT16(n) WI_SWAP_INT16(n)
-#define WI_SWAP_BIG_TO_HOST_INT32(n) WI_SWAP_INT32(n)
-#define WI_SWAP_BIG_TO_HOST_INT64(n) WI_SWAP_INT64(n)
+#define WI_SWAP_BIG_TO_HOST_INT16(n) WI_SWAP_INT16(n)
+#define WI_SWAP_BIG_TO_HOST_INT32(n) WI_SWAP_INT32(n)
+#define WI_SWAP_BIG_TO_HOST_INT64(n) WI_SWAP_INT64(n)
-#define WI_SWAP_LITTLE_TO_HOST_INT16(n) (n)
-#define WI_SWAP_LITTLE_TO_HOST_INT32(n) (n)
-#define WI_SWAP_LITTLE_TO_HOST_INT64(n) (n)
+#define WI_SWAP_LITTLE_TO_HOST_INT16(n) (n)
+#define WI_SWAP_LITTLE_TO_HOST_INT32(n) (n)
+#define WI_SWAP_LITTLE_TO_HOST_INT64(n) (n)
#endif
static inline uint16_t wi_read_swap_big_to_host_int16(void *base, uintptr_t offset) {
- uint16_t n;
-
- n = *(uint16_t *) ((uintptr_t) base + offset);
-
- return WI_SWAP_BIG_TO_HOST_INT16(n);
+ uint16_t n;
+
+ n = *(uint16_t *) ((uintptr_t) base + offset);
+
+ return WI_SWAP_BIG_TO_HOST_INT16(n);
}
static inline uint32_t wi_read_swap_big_to_host_int32(void *base, uintptr_t offset) {
- uint32_t n;
-
- n = *(uint32_t *) ((uintptr_t) base + offset);
-
- return WI_SWAP_BIG_TO_HOST_INT32(n);
+ uint32_t n;
+
+ n = *(uint32_t *) ((uintptr_t) base + offset);
+
+ return WI_SWAP_BIG_TO_HOST_INT32(n);
}
static inline uint64_t wi_read_swap_big_to_host_int64(void *base, uintptr_t offset) {
- uint64_t n;
-
- n = *(uint64_t *) ((uintptr_t) base + offset);
-
- return WI_SWAP_BIG_TO_HOST_INT64(n);
+ uint64_t n;
+
+ n = *(uint64_t *) ((uintptr_t) base + offset);
+
+ return WI_SWAP_BIG_TO_HOST_INT64(n);
}
static inline void wi_write_swap_host_to_big_int16(void *base, uintptr_t offset, uint16_t n) {
- *(uint16_t *) ((uintptr_t) base + offset) = WI_SWAP_HOST_TO_BIG_INT16(n);
+ *(uint16_t *) ((uintptr_t) base + offset) = WI_SWAP_HOST_TO_BIG_INT16(n);
}
static inline void wi_write_swap_host_to_big_int32(void *base, uintptr_t offset, uint32_t n) {
- *(uint32_t *) ((uintptr_t) base + offset) = WI_SWAP_HOST_TO_BIG_INT32(n);
+ *(uint32_t *) ((uintptr_t) base + offset) = WI_SWAP_HOST_TO_BIG_INT32(n);
}
static inline void wi_write_swap_host_to_big_int64(void *base, uintptr_t offset, uint64_t n) {
- *(uint64_t *) ((uintptr_t) base + offset) = WI_SWAP_HOST_TO_BIG_INT64(n);
+ *(uint64_t *) ((uintptr_t) base + offset) = WI_SWAP_HOST_TO_BIG_INT64(n);
}
diff --git a/vendor/WiredFrameworks/libwired/libwired/crypto/wi-cipher.c b/vendor/WiredFrameworks/libwired/libwired/crypto/wi-cipher.c
index 2f3e100e..87b75180 100644
--- a/vendor/WiredFrameworks/libwired/libwired/crypto/wi-cipher.c
+++ b/vendor/WiredFrameworks/libwired/libwired/crypto/wi-cipher.c
@@ -315,7 +315,6 @@ static wi_boolean_t _wi_cipher_set_type(wi_cipher_t *cipher, wi_cipher_type_t ty
#endif
#ifdef WI_CIPHER_COMMONCRYPTO
- printf("WI_CIPHER_COMMONCRYPTO : %d\n", cipher->type);
switch(cipher->type) {
case WI_CIPHER_AES128:
case WI_CIPHER_AES192:
diff --git a/vendor/WiredFrameworks/libwired/libwired/crypto/wi-digest.c b/vendor/WiredFrameworks/libwired/libwired/crypto/wi-digest.c
index bafa0226..32dc8e28 100644
--- a/vendor/WiredFrameworks/libwired/libwired/crypto/wi-digest.c
+++ b/vendor/WiredFrameworks/libwired/libwired/crypto/wi-digest.c
@@ -87,17 +87,29 @@ typedef struct _wi_sha1_ctx _wi_sha1_ctx_t;
struct _wi_sha256_ctx {
#ifdef WI_DIGEST_OPENSSL
- SHA256_CTX openssl_ctx;
+ SHA256_CTX openssl_ctx;
#endif
-
+
#ifdef WI_DIGEST_COMMONCRYPTO
- CC_SHA256_CTX commondigest_ctx;
+ CC_SHA256_CTX commondigest_ctx;
#endif
};
-typedef struct _wi_sha256_ctx _wi_sha256_ctx_t;
+typedef struct _wi_sha256_ctx _wi_sha256_ctx_t;
+struct _wi_sha512_ctx {
+#ifdef WI_DIGEST_OPENSSL
+ SHA512_CTX openssl_ctx;
+#endif
+
+#ifdef WI_DIGEST_COMMONCRYPTO
+ CC_SHA512_CTX commondigest_ctx;
+#endif
+};
+typedef struct _wi_sha512_ctx _wi_sha512_ctx_t;
+
+
struct _wi_md5 {
wi_runtime_base_t base;
@@ -122,16 +134,26 @@ struct _wi_sha1 {
struct _wi_sha256 {
- wi_runtime_base_t base;
-
- _wi_sha256_ctx_t ctx;
-
- unsigned char buffer[WI_SHA256_DIGEST_LENGTH];
-
- wi_boolean_t closed;
+ wi_runtime_base_t base;
+
+ _wi_sha256_ctx_t ctx;
+
+ unsigned char buffer[WI_SHA256_DIGEST_LENGTH];
+
+ wi_boolean_t closed;
};
+struct _wi_sha512 {
+ wi_runtime_base_t base;
+
+ _wi_sha512_ctx_t ctx;
+
+ unsigned char buffer[WI_SHA512_DIGEST_LENGTH];
+
+ wi_boolean_t closed;
+};
+
static void _wi_md5_ctx_init(_wi_md5_ctx_t *);
@@ -159,14 +181,24 @@ static wi_runtime_class_t _wi_sha1_runtime_class = {
NULL
};
-static wi_runtime_id_t _wi_sha256_runtime_id = WI_RUNTIME_ID_NULL;
-static wi_runtime_class_t _wi_sha256_runtime_class = {
- "wi_sha256_t",
- NULL,
- NULL,
- NULL,
- NULL,
- NULL
+static wi_runtime_id_t _wi_sha256_runtime_id = WI_RUNTIME_ID_NULL;
+static wi_runtime_class_t _wi_sha256_runtime_class = {
+ "wi_sha256_t",
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+static wi_runtime_id_t _wi_sha512_runtime_id = WI_RUNTIME_ID_NULL;
+static wi_runtime_class_t _wi_sha512_runtime_class = {
+ "wi_sha512_t",
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL
};
@@ -176,7 +208,8 @@ static wi_runtime_class_t _wi_sha256_runtime_class = {
void wi_digest_register(void) {
_wi_md5_runtime_id = wi_runtime_register_class(&_wi_md5_runtime_class);
_wi_sha1_runtime_id = wi_runtime_register_class(&_wi_sha1_runtime_class);
- _wi_sha256_runtime_id = wi_runtime_register_class(&_wi_sha256_runtime_class);
+ _wi_sha256_runtime_id = wi_runtime_register_class(&_wi_sha256_runtime_class);
+ _wi_sha512_runtime_id = wi_runtime_register_class(&_wi_sha512_runtime_class);
}
@@ -262,15 +295,16 @@ static void _wi_sha1_ctx_final(unsigned char *buffer, _wi_sha1_ctx_t *ctx) {
+
#pragma mark -
static void _wi_sha256_ctx_init(_wi_sha256_ctx_t *ctx) {
#ifdef WI_DIGEST_OPENSSL
- SHA256_Init(&ctx->openssl_ctx);
+ SHA256_Init(&ctx->openssl_ctx);
#endif
#ifdef WI_DIGEST_COMMONCRYPTO
- CC_SHA256_Init(&ctx->commondigest_ctx);
+ CC_SHA256_Init(&ctx->commondigest_ctx);
#endif
}
@@ -278,11 +312,11 @@ static void _wi_sha256_ctx_init(_wi_sha256_ctx_t *ctx) {
static void _wi_sha256_ctx_update(_wi_sha256_ctx_t *ctx, const void *data, unsigned long length) {
#ifdef WI_DIGEST_OPENSSL
- SHA256_Update(&ctx->openssl_ctx, data, length);
+ SHA256_Update(&ctx->openssl_ctx, data, length);
#endif
#ifdef WI_DIGEST_COMMONCRYPTO
- CC_SHA256_Update(&ctx->commondigest_ctx, data, length);
+ CC_SHA256_Update(&ctx->commondigest_ctx, data, length);
#endif
}
@@ -290,16 +324,56 @@ static void _wi_sha256_ctx_update(_wi_sha256_ctx_t *ctx, const void *data, unsig
static void _wi_sha256_ctx_final(unsigned char *buffer, _wi_sha256_ctx_t *ctx) {
#ifdef WI_DIGEST_OPENSSL
- SHA256_Final(buffer, &ctx->openssl_ctx);
+ SHA256_Final(buffer, &ctx->openssl_ctx);
#endif
#ifdef WI_DIGEST_COMMONCRYPTO
- CC_SHA256_Final(buffer, &ctx->commondigest_ctx);
+ CC_SHA256_Final(buffer, &ctx->commondigest_ctx);
#endif
}
+#pragma mark -
+
+static void _wi_sha512_ctx_init(_wi_sha512_ctx_t *ctx) {
+#ifdef WI_DIGEST_OPENSSL
+ SHA512_Init(&ctx->openssl_ctx);
+#endif
+
+#ifdef WI_DIGEST_COMMONCRYPTO
+ CC_SHA512_Init(&ctx->commondigest_ctx);
+#endif
+}
+
+
+
+static void _wi_sha512_ctx_update(_wi_sha512_ctx_t *ctx, const void *data, unsigned long length) {
+#ifdef WI_DIGEST_OPENSSL
+ SHA512_Update(&ctx->openssl_ctx, data, length);
+#endif
+
+#ifdef WI_DIGEST_COMMONCRYPTO
+ CC_SHA512_Update(&ctx->commondigest_ctx, data, length);
+#endif
+}
+
+
+
+static void _wi_sha512_ctx_final(unsigned char *buffer, _wi_sha512_ctx_t *ctx) {
+#ifdef WI_DIGEST_OPENSSL
+ SHA512_Final(buffer, &ctx->openssl_ctx);
+#endif
+
+#ifdef WI_DIGEST_COMMONCRYPTO
+ CC_SHA512_Final(buffer, &ctx->commondigest_ctx);
+#endif
+}
+
+
+
+
+
#pragma mark -
@@ -514,27 +588,32 @@ wi_string_t * wi_sha1_string(wi_sha1_t *sha1) {
+
+
+
+
+
#pragma mark -
void wi_sha256_digest(const void *data, wi_uinteger_t length, unsigned char *buffer) {
- _wi_sha256_ctx_t c;
+ _wi_sha256_ctx_t c;
- _wi_sha256_ctx_init(&c);
- _wi_sha256_ctx_update(&c, data, length);
- _wi_sha256_ctx_final(buffer, &c);
+ _wi_sha256_ctx_init(&c);
+ _wi_sha256_ctx_update(&c, data, length);
+ _wi_sha256_ctx_final(buffer, &c);
}
wi_string_t * wi_sha256_digest_string(wi_data_t *data) {
- wi_sha256_t *sha256;
-
- sha256 = wi_sha256();
-
- wi_sha256_update(sha256, wi_data_bytes(data), wi_data_length(data));
- wi_sha256_close(sha256);
-
- return wi_sha256_string(sha256);
+ wi_sha256_t *sha256;
+
+ sha256 = wi_sha256();
+
+ wi_sha256_update(sha256, wi_data_bytes(data), wi_data_length(data));
+ wi_sha256_close(sha256);
+
+ return wi_sha256_string(sha256);
}
@@ -542,7 +621,7 @@ wi_string_t * wi_sha256_digest_string(wi_data_t *data) {
#pragma mark -
wi_sha256_t * wi_sha256(void) {
- return wi_autorelease(wi_sha256_init(wi_sha256_alloc()));
+ return wi_autorelease(wi_sha256_init(wi_sha256_alloc()));
}
@@ -550,15 +629,15 @@ wi_sha256_t * wi_sha256(void) {
#pragma mark -
wi_sha256_t * wi_sha256_alloc(void) {
- return wi_runtime_create_instance_with_options(_wi_sha256_runtime_id, sizeof(wi_sha256_t), 0);
+ return wi_runtime_create_instance_with_options(_wi_sha256_runtime_id, sizeof(wi_sha256_t), 0);
}
wi_sha256_t * wi_sha256_init(wi_sha256_t *sha256) {
- _wi_sha256_ctx_init(&sha256->ctx);
-
- return sha256;
+ _wi_sha256_ctx_init(&sha256->ctx);
+
+ return sha256;
}
@@ -566,59 +645,169 @@ wi_sha256_t * wi_sha256_init(wi_sha256_t *sha256) {
#pragma mark -
void wi_sha256_update(wi_sha256_t *sha256, const void *data, wi_uinteger_t length) {
- _WI_DIGEST_ASSERT_OPEN(sha256);
-
- _wi_sha256_ctx_update(&sha256->ctx, data, length);
+ _WI_DIGEST_ASSERT_OPEN(sha256);
+
+ _wi_sha256_ctx_update(&sha256->ctx, data, length);
}
void wi_sha256_close(wi_sha256_t *sha256) {
- _WI_DIGEST_ASSERT_OPEN(sha256);
-
- _wi_sha256_ctx_final(sha256->buffer, &sha256->ctx);
-
- sha256->closed = true;
+ _WI_DIGEST_ASSERT_OPEN(sha256);
+
+ _wi_sha256_ctx_final(sha256->buffer, &sha256->ctx);
+
+ sha256->closed = true;
}
+
#pragma mark -
void wi_sha256_get_data(wi_sha256_t *sha256, unsigned char *buffer) {
- _WI_DIGEST_ASSERT_CLOSED(sha256);
-
- memcpy(buffer, sha256->buffer, sizeof(sha256->buffer));
+ _WI_DIGEST_ASSERT_CLOSED(sha256);
+
+ memcpy(buffer, sha256->buffer, sizeof(sha256->buffer));
}
wi_data_t * wi_sha256_data(wi_sha256_t *sha256) {
- _WI_DIGEST_ASSERT_CLOSED(sha256);
-
- return wi_data_with_bytes(sha256->buffer, sizeof(sha256->buffer));
+ _WI_DIGEST_ASSERT_CLOSED(sha256);
+
+ return wi_data_with_bytes(sha256->buffer, sizeof(sha256->buffer));
}
wi_string_t * wi_sha256_string(wi_sha256_t *sha256) {
- static unsigned char hex[] = "0123456789abcdef";
- char sha256_hex[sizeof(sha256->buffer) * 2 + 1];
- wi_uinteger_t i;
+ static unsigned char hex[] = "0123456789abcdef";
+ char sha256_hex[sizeof(sha256->buffer) * 2 + 1];
+ wi_uinteger_t i;
- _WI_DIGEST_ASSERT_CLOSED(sha256);
-
- for(i = 0; i < sizeof(sha256->buffer); i++) {
- sha256_hex[i+i] = hex[sha256->buffer[i] >> 4];
- sha256_hex[i+i+1] = hex[sha256->buffer[i] & 0x0F];
- }
+ _WI_DIGEST_ASSERT_CLOSED(sha256);
+
+ for(i = 0; i < sizeof(sha256->buffer); i++) {
+ sha256_hex[i+i] = hex[sha256->buffer[i] >> 4];
+ sha256_hex[i+i+1] = hex[sha256->buffer[i] & 0x0F];
+ }
- sha256_hex[i+i] = '\0';
+ sha256_hex[i+i] = '\0';
- return wi_string_with_cstring(sha256_hex);
+ return wi_string_with_cstring(sha256_hex);
}
+
+#pragma mark -
+
+void wi_sha512_digest(const void *data, wi_uinteger_t length, unsigned char *buffer) {
+ _wi_sha512_ctx_t c;
+
+ _wi_sha512_ctx_init(&c);
+ _wi_sha512_ctx_update(&c, data, length);
+ _wi_sha512_ctx_final(buffer, &c);
+}
+
+
+
+wi_string_t * wi_sha512_digest_string(wi_data_t *data) {
+ wi_sha512_t *sha512;
+
+ sha512 = wi_sha512();
+
+ wi_sha512_update(sha512, wi_data_bytes(data), wi_data_length(data));
+ wi_sha512_close(sha512);
+
+ return wi_sha512_string(sha512);
+}
+
+
+
+#pragma mark -
+
+wi_sha512_t * wi_sha512(void) {
+ return wi_autorelease(wi_sha512_init(wi_sha512_alloc()));
+}
+
+
+
+#pragma mark -
+
+wi_sha512_t * wi_sha512_alloc(void) {
+ return wi_runtime_create_instance_with_options(_wi_sha512_runtime_id, sizeof(wi_sha512_t), 0);
+}
+
+
+
+wi_sha512_t * wi_sha512_init(wi_sha512_t *sha512) {
+ _wi_sha512_ctx_init(&sha512->ctx);
+
+ return sha512;
+}
+
+
+
+#pragma mark -
+
+void wi_sha512_update(wi_sha512_t *sha512, const void *data, wi_uinteger_t length) {
+ _WI_DIGEST_ASSERT_OPEN(sha512);
+
+ _wi_sha512_ctx_update(&sha512->ctx, data, length);
+}
+
+
+
+void wi_sha512_close(wi_sha512_t *sha512) {
+ _WI_DIGEST_ASSERT_OPEN(sha512);
+
+ _wi_sha512_ctx_final(sha512->buffer, &sha512->ctx);
+
+ sha512->closed = true;
+}
+
+
+
+
+#pragma mark -
+
+void wi_sha512_get_data(wi_sha512_t *sha512, unsigned char *buffer) {
+ _WI_DIGEST_ASSERT_CLOSED(sha512);
+
+ memcpy(buffer, sha512->buffer, sizeof(sha512->buffer));
+}
+
+
+
+wi_data_t * wi_sha512_data(wi_sha512_t *sha512) {
+ _WI_DIGEST_ASSERT_CLOSED(sha512);
+
+ return wi_data_with_bytes(sha512->buffer, sizeof(sha512->buffer));
+}
+
+
+
+wi_string_t * wi_sha512_string(wi_sha512_t *sha512) {
+ static unsigned char hex[] = "0123456789abcdef";
+ char sha512_hex[sizeof(sha512->buffer) * 2 + 1];
+ wi_uinteger_t i;
+
+ _WI_DIGEST_ASSERT_CLOSED(sha512);
+
+ for(i = 0; i < sizeof(sha512->buffer); i++) {
+ sha512_hex[i+i] = hex[sha512->buffer[i] >> 4];
+ sha512_hex[i+i+1] = hex[sha512->buffer[i] & 0x0F];
+ }
+
+ sha512_hex[i+i] = '\0';
+
+ return wi_string_with_cstring(sha512_hex);
+}
+
+
+
+
#endif
diff --git a/vendor/WiredFrameworks/libwired/libwired/crypto/wi-digest.h b/vendor/WiredFrameworks/libwired/libwired/crypto/wi-digest.h
index 9cb1ca89..3b320bcd 100644
--- a/vendor/WiredFrameworks/libwired/libwired/crypto/wi-digest.h
+++ b/vendor/WiredFrameworks/libwired/libwired/crypto/wi-digest.h
@@ -35,15 +35,13 @@
#define WI_MD5_DIGEST_LENGTH 16
#define WI_SHA1_DIGEST_LENGTH 20
-#define WI_SHA256_DIGEST_LENGTH 32
-
+#define WI_SHA256_DIGEST_LENGTH 32
+#define WI_SHA512_DIGEST_LENGTH 64
typedef struct _wi_md5 wi_md5_t;
typedef struct _wi_sha1 wi_sha1_t;
-typedef struct _wi_sha256 wi_sha256_t;
-
-
-#pragma mark -
+typedef struct _wi_sha256 wi_sha256_t;
+typedef struct _wi_sha512 wi_sha512_t;
WI_EXPORT void wi_md5_digest(const void *, wi_uinteger_t, unsigned char *);
WI_EXPORT wi_string_t * wi_md5_digest_string(wi_data_t *);
@@ -60,7 +58,6 @@ WI_EXPORT void wi_md5_get_data(wi_md5_t *, unsigned char *);
WI_EXPORT wi_data_t * wi_md5_data(wi_md5_t *);
WI_EXPORT wi_string_t * wi_md5_string(wi_md5_t *);
-#pragma mark -
WI_EXPORT void wi_sha1_digest(const void *, wi_uinteger_t, unsigned char *);
WI_EXPORT wi_string_t * wi_sha1_digest_string(wi_data_t *);
@@ -77,25 +74,40 @@ WI_EXPORT void wi_sha1_get_data(wi_sha1_t *, unsigned char *);
WI_EXPORT wi_data_t * wi_sha1_data(wi_sha1_t *);
WI_EXPORT wi_string_t * wi_sha1_string(wi_sha1_t *);
-#pragma mark -
-WI_EXPORT void wi_sha256_digest(const void *, wi_uinteger_t, unsigned char *);
-WI_EXPORT wi_string_t * wi_sha256_digest_string(wi_data_t *);
+WI_EXPORT void wi_sha256_digest(const void *, wi_uinteger_t, unsigned char *);
+WI_EXPORT wi_string_t * wi_sha256_digest_string(wi_data_t *);
+
+WI_EXPORT wi_sha256_t * wi_sha256(void);
+
+WI_EXPORT wi_sha256_t * wi_sha256_alloc(void);
+WI_EXPORT wi_sha256_t * wi_sha256_init(wi_sha256_t *);
+
+WI_EXPORT void wi_sha256_update(wi_sha256_t *, const void *, wi_uinteger_t);
+WI_EXPORT void wi_sha256_close(wi_sha256_t *);
+
+WI_EXPORT void wi_sha256_get_data(wi_sha256_t *, unsigned char *);
+WI_EXPORT wi_data_t * wi_sha256_data(wi_sha256_t *);
+WI_EXPORT wi_string_t * wi_sha256_string(wi_sha256_t *);
+
+
+WI_EXPORT void wi_sha512_digest(const void *, wi_uinteger_t, unsigned char *);
+WI_EXPORT wi_string_t * wi_sha512_digest_string(wi_data_t *);
+
+WI_EXPORT wi_sha512_t * wi_sha512(void);
-WI_EXPORT wi_sha256_t * wi_sha256(void);
+WI_EXPORT wi_sha512_t * wi_sha512_alloc(void);
+WI_EXPORT wi_sha512_t * wi_sha512_init(wi_sha512_t *);
-WI_EXPORT wi_sha256_t * wi_sha256_alloc(void);
-WI_EXPORT wi_sha256_t * wi_sha256_init(wi_sha256_t *);
+WI_EXPORT void wi_sha512_update(wi_sha512_t *, const void *, wi_uinteger_t);
+WI_EXPORT void wi_sha512_close(wi_sha512_t *);
-WI_EXPORT void wi_sha256_update(wi_sha256_t *, const void *, wi_uinteger_t);
-WI_EXPORT void wi_sha256_close(wi_sha256_t *);
+WI_EXPORT void wi_sha512_get_data(wi_sha512_t *, unsigned char *);
+WI_EXPORT wi_data_t * wi_sha512_data(wi_sha512_t *);
+WI_EXPORT wi_string_t * wi_sha512_string(wi_sha512_t *);
-WI_EXPORT void wi_sha256_get_data(wi_sha256_t *, unsigned char *);
-WI_EXPORT wi_data_t * wi_sha256_data(wi_sha256_t *);
-WI_EXPORT wi_string_t * wi_sha256_string(wi_sha256_t *);
-#pragma mark -
WI_EXPORT wi_string_t * wi_base64_string_from_data(wi_data_t *);
WI_EXPORT wi_data_t * wi_data_from_base64_string(wi_string_t *);
diff --git a/vendor/WiredFrameworks/libwired/libwired/crypto/wi-rsa.c b/vendor/WiredFrameworks/libwired/libwired/crypto/wi-rsa.c
index a18c20cd..65dc1c61 100644
--- a/vendor/WiredFrameworks/libwired/libwired/crypto/wi-rsa.c
+++ b/vendor/WiredFrameworks/libwired/libwired/crypto/wi-rsa.c
@@ -96,14 +96,24 @@ wi_rsa_t * wi_rsa_alloc(void) {
wi_rsa_t * wi_rsa_init_with_bits(wi_rsa_t *rsa, wi_uinteger_t size) {
- rsa->rsa = RSA_generate_key((int)size, RSA_F4, NULL, NULL);
- if(!rsa->rsa) {
- wi_release(rsa);
-
- return NULL;
- }
-
- return rsa;
+ int rc;
+ BIGNUM *e;
+
+ e = BN_new();
+
+ rsa->rsa = RSA_new();
+
+ BN_set_word(e, 65537);
+
+ rc = RSA_generate_key_ex(rsa->rsa, (int)size, e, NULL);
+
+ BN_free(e);
+
+ if (rc == -1 || !rsa->rsa) {
+ return NULL;
+ }
+
+ return rsa;
}
diff --git a/vendor/WiredFrameworks/libwired/libwired/data/wi-data.c b/vendor/WiredFrameworks/libwired/libwired/data/wi-data.c
index 9a3c7e9b..ffceee5c 100644
--- a/vendor/WiredFrameworks/libwired/libwired/data/wi-data.c
+++ b/vendor/WiredFrameworks/libwired/libwired/data/wi-data.c
@@ -383,10 +383,12 @@ wi_string_t * wi_data_sha1(wi_data_t *data) {
return wi_sha1_digest_string(data);
}
-
-
wi_string_t * wi_data_sha256(wi_data_t *data) {
- return wi_sha256_digest_string(data);
+ return wi_sha256_digest_string(data);
+}
+
+wi_string_t * wi_data_sha512(wi_data_t *data) {
+ return wi_sha512_digest_string(data);
}
diff --git a/vendor/WiredFrameworks/libwired/libwired/data/wi-data.h b/vendor/WiredFrameworks/libwired/libwired/data/wi-data.h
index c84df91b..b68a0318 100644
--- a/vendor/WiredFrameworks/libwired/libwired/data/wi-data.h
+++ b/vendor/WiredFrameworks/libwired/libwired/data/wi-data.h
@@ -65,7 +65,8 @@ WI_EXPORT wi_data_t * wi_data_by_appending_bytes(wi_data_t *, const void *,
WI_EXPORT wi_string_t * wi_data_md5(wi_data_t *);
WI_EXPORT wi_string_t * wi_data_sha1(wi_data_t *);
-WI_EXPORT wi_string_t * wi_data_sha256(wi_data_t *);
+WI_EXPORT wi_string_t * wi_data_sha256(wi_data_t *);
+WI_EXPORT wi_string_t * wi_data_sha512(wi_data_t *data);
WI_EXPORT wi_string_t * wi_data_base64(wi_data_t *);
WI_EXPORT wi_boolean_t wi_data_write_to_file(wi_data_t *, wi_string_t *);
diff --git a/vendor/WiredFrameworks/libwired/libwired/data/wi-string.c b/vendor/WiredFrameworks/libwired/libwired/data/wi-string.c
index 8794dc46..762020d6 100644
--- a/vendor/WiredFrameworks/libwired/libwired/data/wi-string.c
+++ b/vendor/WiredFrameworks/libwired/libwired/data/wi-string.c
@@ -1582,13 +1582,13 @@ wi_string_t * wi_string_sha1(wi_string_t *string) {
return wi_sha1_digest_string(wi_string_data(string));
}
-
-
wi_string_t * wi_string_sha256(wi_string_t *string) {
- return wi_sha256_digest_string(wi_string_data(string));
+ return wi_sha256_digest_string(wi_string_data(string));
}
-
+wi_string_t * wi_string_sha512(wi_string_t *string) {
+ return wi_sha512_digest_string(wi_string_data(string));
+}
#endif
diff --git a/vendor/WiredFrameworks/libwired/libwired/data/wi-string.h b/vendor/WiredFrameworks/libwired/libwired/data/wi-string.h
index a1bbb612..9d7e6570 100644
--- a/vendor/WiredFrameworks/libwired/libwired/data/wi-string.h
+++ b/vendor/WiredFrameworks/libwired/libwired/data/wi-string.h
@@ -154,7 +154,8 @@ WI_EXPORT double wi_string_double(wi_string_t *);
WI_EXPORT wi_data_t * wi_string_data(wi_string_t *);
WI_EXPORT wi_string_t * wi_string_md5(wi_string_t *);
WI_EXPORT wi_string_t * wi_string_sha1(wi_string_t *);
-WI_EXPORT wi_string_t * wi_string_sha256(wi_string_t *);
+WI_EXPORT wi_string_t * wi_string_sha256(wi_string_t *string);
+WI_EXPORT wi_string_t * wi_string_sha512(wi_string_t *string);
WI_EXPORT wi_string_t * wi_string_base64(wi_string_t *);
WI_EXPORT wi_string_t * wi_string_by_converting_encoding(wi_string_t *, wi_string_encoding_t *, wi_string_encoding_t *);
diff --git a/vendor/WiredFrameworks/libwired/libwired/p7/wi-p7-socket.c b/vendor/WiredFrameworks/libwired/libwired/p7/wi-p7-socket.c
index 25bccf1d..ed999ae4 100644
--- a/vendor/WiredFrameworks/libwired/libwired/p7/wi-p7-socket.c
+++ b/vendor/WiredFrameworks/libwired/libwired/p7/wi-p7-socket.c
@@ -57,188 +57,288 @@ int wi_p7_socket_dummy = 0;
#include
-#define _WI_P7_SOCKET_XML_MAGIC 0x3C3F786D
-#define _WI_P7_SOCKET_LENGTH_SIZE 4
-#define _WI_P7_SOCKET_MAX_BINARY_SIZE (10 * 1024 * 1024)
-
-#define _WI_P7_COMPRESSION_DEFLATE 0
-
-#define _WI_P7_ENCRYPTION_RSA_AES128_SHA1 0
-#define _WI_P7_ENCRYPTION_RSA_AES192_SHA1 1
-#define _WI_P7_ENCRYPTION_RSA_AES256_SHA1 2
-#define _WI_P7_ENCRYPTION_RSA_BF128_SHA1 3
-#define _WI_P7_ENCRYPTION_RSA_3DES192_SHA1 4
-#define _WI_P7_ENCRYPTION_RSA_AES256_SHA256 5
-
-#define _WI_P7_CHECKSUM_SHA1 0
-#define _WI_P7_CHECKSUM_SHA256 1
-
-#define _WI_P7_COMPRESSION_ENUM_TO_OPTIONS(flag) \
- ((flag) == _WI_P7_COMPRESSION_DEFLATE ? \
- WI_P7_COMPRESSION_DEFLATE : -1)
-
-#define _WI_P7_ENCRYPTION_ENUM_TO_OPTIONS(flag) \
- ((flag) == _WI_P7_ENCRYPTION_RSA_AES128_SHA1 ? \
- WI_P7_ENCRYPTION_RSA_AES128_SHA1 : \
- (flag) == _WI_P7_ENCRYPTION_RSA_AES192_SHA1 ? \
- WI_P7_ENCRYPTION_RSA_AES192_SHA1 : \
- (flag) == _WI_P7_ENCRYPTION_RSA_AES256_SHA1 ? \
- WI_P7_ENCRYPTION_RSA_AES256_SHA1 : \
- (flag) == _WI_P7_ENCRYPTION_RSA_BF128_SHA1 ? \
- WI_P7_ENCRYPTION_RSA_BF128_SHA1 : \
- (flag) == _WI_P7_ENCRYPTION_RSA_3DES192_SHA1 ? \
- WI_P7_ENCRYPTION_RSA_3DES192_SHA1 : \
- (flag) == _WI_P7_ENCRYPTION_RSA_AES256_SHA256 ? \
- WI_P7_ENCRYPTION_RSA_AES256_SHA256 : -1)
-
-#define _WI_P7_CHECKSUM_ENUM_TO_OPTIONS(flag) \
- ((flag) == _WI_P7_CHECKSUM_SHA1 ? \
- WI_P7_CHECKSUM_SHA1 : \
- (flag) == _WI_P7_CHECKSUM_SHA256 ? \
- WI_P7_CHECKSUM_SHA256 : -1)
-
-#define _WI_P7_COMPRESSION_OPTIONS_TO_ENUM(options) \
- ((options) & WI_P7_COMPRESSION_DEFLATE ? \
- _WI_P7_COMPRESSION_DEFLATE : -1)
-
-#define _WI_P7_ENCRYPTION_OPTIONS_TO_ENUM(options) \
- ((options) & WI_P7_ENCRYPTION_RSA_AES128_SHA1 ? \
- _WI_P7_ENCRYPTION_RSA_AES128_SHA1 : \
- (options) & WI_P7_ENCRYPTION_RSA_AES192_SHA1 ? \
- _WI_P7_ENCRYPTION_RSA_AES192_SHA1 : \
- (options) & WI_P7_ENCRYPTION_RSA_AES256_SHA1 ? \
- _WI_P7_ENCRYPTION_RSA_AES256_SHA1 : \
- (options) & WI_P7_ENCRYPTION_RSA_BF128_SHA1 ? \
- _WI_P7_ENCRYPTION_RSA_BF128_SHA1 : \
- (options) & WI_P7_ENCRYPTION_RSA_3DES192_SHA1 ? \
- _WI_P7_ENCRYPTION_RSA_3DES192_SHA1 : \
- (options) & WI_P7_ENCRYPTION_RSA_AES256_SHA256 ? \
- _WI_P7_ENCRYPTION_RSA_AES256_SHA256 : -1)
-
-#define _WI_P7_CHECKSUM_OPTIONS_TO_ENUM(options) \
- ((options) & WI_P7_CHECKSUM_SHA1 ? \
- _WI_P7_CHECKSUM_SHA1 : \
- (options) & WI_P7_CHECKSUM_SHA256 ? \
- _WI_P7_CHECKSUM_SHA256 : -1)
-
-#define _WI_P7_CHECKSUM_OPTIONS_TO_LENGTH(options) \
- ((options) & WI_P7_CHECKSUM_SHA1 ? \
- WI_SHA1_DIGEST_LENGTH : \
- (options) & WI_P7_CHECKSUM_SHA256 ? \
- WI_SHA256_DIGEST_LENGTH : WI_SHA1_DIGEST_LENGTH)
-
-#define _WI_P7_ENCRYPTION_OPTIONS_TO_CIPHER(options) \
- ((options) & WI_P7_ENCRYPTION_RSA_AES128_SHA1 ? \
- WI_CIPHER_AES128 : \
- (options) & WI_P7_ENCRYPTION_RSA_AES192_SHA1 ? \
- WI_CIPHER_AES192 : \
- (options) & WI_P7_ENCRYPTION_RSA_AES256_SHA1 ? \
- WI_CIPHER_AES256 : \
- (options) & WI_P7_ENCRYPTION_RSA_BF128_SHA1 ? \
- WI_CIPHER_BF128 : \
- (options) & WI_P7_ENCRYPTION_RSA_3DES192_SHA1 ? \
- WI_CIPHER_3DES192 : \
- (options) & WI_P7_ENCRYPTION_RSA_AES256_SHA256 ? \
- WI_CIPHER_AES256 : -1)
+#define _WI_P7_SOCKET_XML_MAGIC 0x3C3F786D
+#define _WI_P7_SOCKET_LENGTH_SIZE 4
+#define _WI_P7_SOCKET_MAX_BINARY_SIZE (10 * 1024 * 1024)
+
+#define _WI_P7_COMPRESSION_DEFLATE 0
+
+#define _WI_P7_ENCRYPTION_RSA_AES128_SHA1 0
+#define _WI_P7_ENCRYPTION_RSA_AES192_SHA1 1
+#define _WI_P7_ENCRYPTION_RSA_AES256_SHA1 2
+#define _WI_P7_ENCRYPTION_RSA_BF128_SHA1 3
+#define _WI_P7_ENCRYPTION_RSA_3DES192_SHA1 4
+#define _WI_P7_ENCRYPTION_RSA_AES128_SHA256 5
+#define _WI_P7_ENCRYPTION_RSA_AES192_SHA256 6
+#define _WI_P7_ENCRYPTION_RSA_AES256_SHA256 7
+#define _WI_P7_ENCRYPTION_RSA_BF128_SHA256 8
+#define _WI_P7_ENCRYPTION_RSA_3DES192_SHA256 9
+#define _WI_P7_ENCRYPTION_RSA_AES128_SHA512 10
+#define _WI_P7_ENCRYPTION_RSA_AES192_SHA512 11
+#define _WI_P7_ENCRYPTION_RSA_AES256_SHA512 12
+#define _WI_P7_ENCRYPTION_RSA_BF128_SHA512 13
+#define _WI_P7_ENCRYPTION_RSA_3DES192_SHA512 14
+
+#define _WI_P7_CHECKSUM_SHA1 0
+#define _WI_P7_CHECKSUM_SHA256 1
+#define _WI_P7_CHECKSUM_SHA512 2
+
+#define _WI_P7_COMPRESSION_ENUM_TO_OPTIONS(flag) \
+ ((flag) == _WI_P7_COMPRESSION_DEFLATE ? \
+ WI_P7_COMPRESSION_DEFLATE : -1)
+
+#define _WI_P7_ENCRYPTION_ENUM_TO_OPTIONS(flag) \
+ ((flag) == _WI_P7_ENCRYPTION_RSA_AES128_SHA1 ? \
+ WI_P7_ENCRYPTION_RSA_AES128_SHA1 : \
+ (flag) == _WI_P7_ENCRYPTION_RSA_AES192_SHA1 ? \
+ WI_P7_ENCRYPTION_RSA_AES192_SHA1 : \
+ (flag) == _WI_P7_ENCRYPTION_RSA_AES256_SHA1 ? \
+ WI_P7_ENCRYPTION_RSA_AES256_SHA1 : \
+ (flag) == _WI_P7_ENCRYPTION_RSA_BF128_SHA1 ? \
+ WI_P7_ENCRYPTION_RSA_BF128_SHA1 : \
+ (flag) == _WI_P7_ENCRYPTION_RSA_3DES192_SHA1 ? \
+ WI_P7_ENCRYPTION_RSA_3DES192_SHA1 : \
+ (flag) == _WI_P7_ENCRYPTION_RSA_AES128_SHA256 ? \
+ WI_P7_ENCRYPTION_RSA_AES128_SHA256 : \
+ (flag) == _WI_P7_ENCRYPTION_RSA_AES192_SHA256 ? \
+ WI_P7_ENCRYPTION_RSA_AES192_SHA256 : \
+ (flag) == _WI_P7_ENCRYPTION_RSA_AES256_SHA256 ? \
+ WI_P7_ENCRYPTION_RSA_AES256_SHA256 : \
+ (flag) == _WI_P7_ENCRYPTION_RSA_BF128_SHA256 ? \
+ WI_P7_ENCRYPTION_RSA_BF128_SHA256 : \
+ (flag) == _WI_P7_ENCRYPTION_RSA_3DES192_SHA256 ? \
+ WI_P7_ENCRYPTION_RSA_3DES192_SHA256 : \
+ (flag) == _WI_P7_ENCRYPTION_RSA_AES128_SHA512 ? \
+ WI_P7_ENCRYPTION_RSA_AES128_SHA512 : \
+ (flag) == _WI_P7_ENCRYPTION_RSA_AES192_SHA512 ? \
+ WI_P7_ENCRYPTION_RSA_AES192_SHA512 : \
+ (flag) == _WI_P7_ENCRYPTION_RSA_AES256_SHA512 ? \
+ WI_P7_ENCRYPTION_RSA_AES256_SHA512 : \
+ (flag) == _WI_P7_ENCRYPTION_RSA_BF128_SHA512 ? \
+ WI_P7_ENCRYPTION_RSA_BF128_SHA512 : \
+ (flag) == _WI_P7_ENCRYPTION_RSA_3DES192_SHA512 ? \
+ WI_P7_ENCRYPTION_RSA_3DES192_SHA512 : -1)
+
+#define _WI_P7_CHECKSUM_ENUM_TO_OPTIONS(flag) \
+ ((flag) == _WI_P7_CHECKSUM_SHA1 ? \
+ WI_P7_CHECKSUM_SHA1 : \
+ (flag) == _WI_P7_CHECKSUM_SHA256 ? \
+ WI_P7_CHECKSUM_SHA256 : \
+ (flag) == _WI_P7_CHECKSUM_SHA512 ? \
+ WI_P7_CHECKSUM_SHA512 : -1)
+
+#define _WI_P7_COMPRESSION_OPTIONS_TO_ENUM(options) \
+ ((options) & WI_P7_COMPRESSION_DEFLATE ? \
+ _WI_P7_COMPRESSION_DEFLATE : -1)
+
+#define _WI_P7_ENCRYPTION_OPTIONS_TO_ENUM(options) \
+ ((options) & WI_P7_ENCRYPTION_RSA_AES128_SHA1 ? \
+ _WI_P7_ENCRYPTION_RSA_AES128_SHA1 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES192_SHA1 ? \
+ _WI_P7_ENCRYPTION_RSA_AES192_SHA1 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES256_SHA1 ? \
+ _WI_P7_ENCRYPTION_RSA_AES256_SHA1 : \
+ (options) & WI_P7_ENCRYPTION_RSA_BF128_SHA1 ? \
+ _WI_P7_ENCRYPTION_RSA_BF128_SHA1 : \
+ (options) & WI_P7_ENCRYPTION_RSA_3DES192_SHA1 ? \
+ _WI_P7_ENCRYPTION_RSA_3DES192_SHA1 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES128_SHA256 ? \
+ _WI_P7_ENCRYPTION_RSA_AES128_SHA256 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES192_SHA256 ? \
+ _WI_P7_ENCRYPTION_RSA_AES192_SHA256 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES256_SHA256 ? \
+ _WI_P7_ENCRYPTION_RSA_AES256_SHA256 : \
+ (options) & WI_P7_ENCRYPTION_RSA_BF128_SHA256 ? \
+ _WI_P7_ENCRYPTION_RSA_BF128_SHA256 : \
+ (options) & WI_P7_ENCRYPTION_RSA_3DES192_SHA256 ? \
+ _WI_P7_ENCRYPTION_RSA_3DES192_SHA256 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES128_SHA512 ? \
+ _WI_P7_ENCRYPTION_RSA_AES128_SHA512 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES192_SHA512 ? \
+ _WI_P7_ENCRYPTION_RSA_AES192_SHA512 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES256_SHA512 ? \
+ _WI_P7_ENCRYPTION_RSA_AES256_SHA512 : \
+ (options) & WI_P7_ENCRYPTION_RSA_BF128_SHA512 ? \
+ _WI_P7_ENCRYPTION_RSA_BF128_SHA512 : \
+ (options) & WI_P7_ENCRYPTION_RSA_3DES192_SHA512 ? \
+ _WI_P7_ENCRYPTION_RSA_3DES192_SHA512 : -1)
+
+#define _WI_P7_CHECKSUM_OPTIONS_TO_ENUM(options) \
+ ((options) & WI_P7_CHECKSUM_SHA1 ? \
+ _WI_P7_CHECKSUM_SHA1 : \
+ (options) & WI_P7_CHECKSUM_SHA256 ? \
+ _WI_P7_CHECKSUM_SHA256 : \
+ (options) & WI_P7_CHECKSUM_SHA512 ? \
+ _WI_P7_CHECKSUM_SHA512 : -1)
+
+#define _WI_P7_CHECKSUM_OPTIONS_TO_LENGTH(options) \
+ ((options) & _WI_P7_CHECKSUM_SHA1 ? \
+ WI_SHA1_DIGEST_LENGTH : \
+ (options) & _WI_P7_CHECKSUM_SHA256 ? \
+ WI_SHA256_DIGEST_LENGTH : \
+ (options) & _WI_P7_CHECKSUM_SHA512 ? \
+ WI_SHA512_DIGEST_LENGTH : WI_SHA1_DIGEST_LENGTH)
+
+#define _WI_P7_ENCRYPTION_OPTIONS_TO_CHECKSUM(options) \
+ ((options) & WI_P7_ENCRYPTION_RSA_AES128_SHA1 ? \
+ _WI_P7_CHECKSUM_SHA1 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES192_SHA1 ? \
+ _WI_P7_CHECKSUM_SHA1 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES256_SHA1 ? \
+ _WI_P7_CHECKSUM_SHA1 : \
+ (options) & WI_P7_ENCRYPTION_RSA_BF128_SHA1 ? \
+ _WI_P7_CHECKSUM_SHA1 : \
+ (options) & WI_P7_ENCRYPTION_RSA_3DES192_SHA1 ? \
+ _WI_P7_CHECKSUM_SHA1 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES128_SHA256 ? \
+ _WI_P7_CHECKSUM_SHA256 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES192_SHA256 ? \
+ _WI_P7_CHECKSUM_SHA256 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES256_SHA256 ? \
+ _WI_P7_CHECKSUM_SHA256 : \
+ (options) & WI_P7_ENCRYPTION_RSA_BF128_SHA256 ? \
+ _WI_P7_CHECKSUM_SHA256 : \
+ (options) & WI_P7_ENCRYPTION_RSA_3DES192_SHA256 ? \
+ _WI_P7_CHECKSUM_SHA256 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES128_SHA512 ? \
+ _WI_P7_CHECKSUM_SHA512 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES192_SHA512 ? \
+ _WI_P7_CHECKSUM_SHA512 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES256_SHA512 ? \
+ _WI_P7_CHECKSUM_SHA512 : \
+ (options) & WI_P7_ENCRYPTION_RSA_BF128_SHA512 ? \
+ _WI_P7_CHECKSUM_SHA512 : \
+ (options) & WI_P7_ENCRYPTION_RSA_3DES192_SHA512 ? \
+ _WI_P7_CHECKSUM_SHA512 : -1)
+
+#define _WI_P7_ENCRYPTION_OPTIONS_TO_CIPHER(options) \
+ ((options) & WI_P7_ENCRYPTION_RSA_AES128_SHA1 ? \
+ WI_CIPHER_AES128 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES192_SHA1 ? \
+ WI_CIPHER_AES192 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES256_SHA1 ? \
+ WI_CIPHER_AES256 : \
+ (options) & WI_P7_ENCRYPTION_RSA_BF128_SHA1 ? \
+ WI_CIPHER_BF128 : \
+ (options) & WI_P7_ENCRYPTION_RSA_3DES192_SHA1 ? \
+ WI_CIPHER_3DES192 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES128_SHA256 ? \
+ WI_CIPHER_AES128 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES192_SHA256 ? \
+ WI_CIPHER_AES192 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES256_SHA256 ? \
+ WI_CIPHER_AES256 : \
+ (options) & WI_P7_ENCRYPTION_RSA_BF128_SHA256 ? \
+ WI_CIPHER_BF128 : \
+ (options) & WI_P7_ENCRYPTION_RSA_3DES192_SHA256 ? \
+ WI_CIPHER_3DES192 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES128_SHA512 ? \
+ WI_CIPHER_AES128 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES192_SHA512 ? \
+ WI_CIPHER_AES192 : \
+ (options) & WI_P7_ENCRYPTION_RSA_AES256_SHA512 ? \
+ WI_CIPHER_AES256 : \
+ (options) & WI_P7_ENCRYPTION_RSA_BF128_SHA512 ? \
+ WI_CIPHER_BF128 : \
+ (options) & WI_P7_ENCRYPTION_RSA_3DES192_SHA512 ? \
+ WI_CIPHER_3DES192 : -1)
struct _wi_p7_socket {
- wi_runtime_base_t base;
-
- wi_socket_t *socket;
- wi_p7_spec_t *spec;
- wi_p7_spec_t *merged_spec;
-
- wi_string_t *remote_name;
- wi_string_t *remote_version;
-
- wi_string_t *user_name;
-
- wi_p7_serialization_t serialization;
- wi_uinteger_t options;
-
- uint32_t message_binary_size;
-
+ wi_runtime_base_t base;
+
+ wi_socket_t *socket;
+ wi_p7_spec_t *spec;
+ wi_p7_spec_t *merged_spec;
+
+ wi_string_t *remote_name;
+ wi_string_t *remote_version;
+
+ wi_string_t *user_name;
+
+ wi_p7_serialization_t serialization;
+ wi_uinteger_t options;
+
+ uint32_t message_binary_size;
+
#ifdef WI_RSA
- wi_boolean_t encryption_enabled;
- wi_rsa_t *private_key;
- wi_rsa_t *public_key;
- wi_cipher_t *cipher;
+ wi_boolean_t encryption_enabled;
+ wi_rsa_t *private_key;
+ wi_rsa_t *public_key;
+ wi_cipher_t *cipher;
#endif
-
- wi_boolean_t compression_enabled;
- z_stream deflate_stream;
- z_stream inflate_stream;
-
- wi_boolean_t checksum_enabled;
- wi_uinteger_t checksum_length;
-
- wi_p7_boolean_t local_compatibility_check;
- wi_p7_boolean_t remote_compatibility_check;
-
- void *compression_buffer;
- wi_uinteger_t compression_buffer_length;
- void *encryption_buffer;
- wi_uinteger_t encryption_buffer_length;
- void *decryption_buffer;
- wi_uinteger_t decryption_buffer_length;
- void *oobdata_read_buffer;
- wi_uinteger_t oobdata_read_buffer_length;
-
- wi_p7_socket_message_callback_func_t *read_message_callback;
- void *read_message_context;
-
- wi_p7_socket_message_callback_func_t *wrote_message_callback;
- void *wrote_message_context;
-
- uint64_t read_raw_bytes, read_processed_bytes;
- uint64_t sent_raw_bytes, sent_processed_bytes;
+
+ wi_boolean_t compression_enabled;
+ z_stream deflate_stream;
+ z_stream inflate_stream;
+
+ wi_boolean_t checksum_enabled;
+ wi_uinteger_t checksum_length;
+
+ wi_p7_boolean_t local_compatibility_check;
+ wi_p7_boolean_t remote_compatibility_check;
+
+ void *compression_buffer;
+ wi_uinteger_t compression_buffer_length;
+ void *encryption_buffer;
+ wi_uinteger_t encryption_buffer_length;
+ void *decryption_buffer;
+ wi_uinteger_t decryption_buffer_length;
+ void *oobdata_read_buffer;
+ wi_uinteger_t oobdata_read_buffer_length;
+
+ wi_p7_socket_message_callback_func_t *read_message_callback;
+ void *read_message_context;
+
+ wi_p7_socket_message_callback_func_t *wrote_message_callback;
+ void *wrote_message_context;
+
+ uint64_t read_raw_bytes, read_processed_bytes;
+ uint64_t sent_raw_bytes, sent_processed_bytes;
};
enum _wi_p7_socket_compression {
- _WI_P7_SOCKET_COMPRESS,
- _WI_P7_SOCKET_DECOMPRESS,
+ _WI_P7_SOCKET_COMPRESS,
+ _WI_P7_SOCKET_DECOMPRESS,
};
-typedef enum _wi_p7_socket_compression _wi_p7_socket_compression_t;
+typedef enum _wi_p7_socket_compression _wi_p7_socket_compression_t;
-static void _wi_p7_socket_dealloc(wi_runtime_instance_t *);
-static wi_string_t * _wi_p7_socket_description(wi_runtime_instance_t *);
+static void _wi_p7_socket_dealloc(wi_runtime_instance_t *);
+static wi_string_t * _wi_p7_socket_description(wi_runtime_instance_t *);
-static wi_boolean_t _wi_p7_socket_connect_handshake(wi_p7_socket_t *, wi_time_interval_t, wi_uinteger_t);
-static wi_boolean_t _wi_p7_socket_accept_handshake(wi_p7_socket_t *, wi_time_interval_t, wi_uinteger_t);
+static wi_boolean_t _wi_p7_socket_connect_handshake(wi_p7_socket_t *, wi_time_interval_t, wi_uinteger_t);
+static wi_boolean_t _wi_p7_socket_accept_handshake(wi_p7_socket_t *, wi_time_interval_t, wi_uinteger_t);
#ifdef WI_RSA
-static wi_boolean_t _wi_p7_socket_connect_key_exchange(wi_p7_socket_t *, wi_time_interval_t, wi_string_t *, wi_string_t *);
-static wi_boolean_t _wi_p7_socket_accept_key_exchange(wi_p7_socket_t *, wi_time_interval_t);
-static wi_boolean_t _wi_p7_password_is_equal(wi_string_t *, wi_string_t *);
+static wi_boolean_t _wi_p7_socket_connect_key_exchange(wi_p7_socket_t *, wi_time_interval_t, wi_string_t *, wi_string_t *);
+static wi_boolean_t _wi_p7_socket_accept_key_exchange(wi_p7_socket_t *, wi_time_interval_t);
+static wi_boolean_t _wi_p7_password_is_equal(wi_string_t *, wi_string_t *);
#endif
-static wi_boolean_t _wi_p7_socket_send_compatibility_check(wi_p7_socket_t *, wi_time_interval_t);
-static wi_boolean_t _wi_p7_socket_receive_compatibility_check(wi_p7_socket_t *, wi_time_interval_t);
+static wi_boolean_t _wi_p7_socket_send_compatibility_check(wi_p7_socket_t *, wi_time_interval_t);
+static wi_boolean_t _wi_p7_socket_receive_compatibility_check(wi_p7_socket_t *, wi_time_interval_t);
-static wi_boolean_t _wi_p7_socket_write_binary_message(wi_p7_socket_t *, wi_time_interval_t, wi_p7_message_t *);
-static wi_boolean_t _wi_p7_socket_write_xml_message(wi_p7_socket_t *, wi_time_interval_t, wi_p7_message_t *);
-static wi_p7_message_t * _wi_p7_socket_read_binary_message(wi_p7_socket_t *, wi_time_interval_t, uint32_t);
-static wi_p7_message_t * _wi_p7_socket_read_xml_message(wi_p7_socket_t *, wi_time_interval_t, wi_string_t *);
+static wi_boolean_t _wi_p7_socket_write_binary_message(wi_p7_socket_t *, wi_time_interval_t, wi_p7_message_t *);
+static wi_boolean_t _wi_p7_socket_write_xml_message(wi_p7_socket_t *, wi_time_interval_t, wi_p7_message_t *);
+static wi_p7_message_t * _wi_p7_socket_read_binary_message(wi_p7_socket_t *, wi_time_interval_t, uint32_t);
+static wi_p7_message_t * _wi_p7_socket_read_xml_message(wi_p7_socket_t *, wi_time_interval_t, wi_string_t *);
-static wi_boolean_t _wi_p7_socket_configure_compression(wi_p7_socket_t *);
-static wi_integer_t _wi_p7_socket_deflate(wi_p7_socket_t *, const void *, uint32_t);
-static wi_integer_t _wi_p7_socket_inflate(wi_p7_socket_t *, const void *, uint32_t);
+static wi_boolean_t _wi_p7_socket_configure_compression(wi_p7_socket_t *);
+static wi_integer_t _wi_p7_socket_deflate(wi_p7_socket_t *, const void *, uint32_t);
+static wi_integer_t _wi_p7_socket_inflate(wi_p7_socket_t *, const void *, uint32_t);
-static void _wi_p7_socket_configure_checksum(wi_p7_socket_t *);
-static void _wi_p7_socket_checksum_binary_message(wi_p7_socket_t *, wi_p7_message_t *, void *);
-static void _wi_p7_socket_checksum_buffer(wi_p7_socket_t *, const void *, uint32_t, void *);
+static void _wi_p7_socket_configure_checksum(wi_p7_socket_t *);
+static void _wi_p7_socket_checksum_binary_message(wi_p7_socket_t *, wi_p7_message_t *, void *);
+static void _wi_p7_socket_checksum_buffer(wi_p7_socket_t *, const void *, uint32_t, void *);
-static wi_string_t * _wi_p7_socket_string_checksum(wi_p7_socket_t *, wi_string_t *);
-static wi_string_t * _wi_p7_socket_data_checksum(wi_p7_socket_t *, wi_data_t *);
-wi_boolean_t wi_p7_socket_debug = false;
-wi_p7_socket_password_provider_func_t *wi_p7_socket_password_provider = NULL;
+wi_boolean_t wi_p7_socket_debug = false;
+wi_p7_socket_password_provider_func_t *wi_p7_socket_password_provider = NULL;
-static wi_runtime_id_t _wi_p7_socket_runtime_id = WI_RUNTIME_ID_NULL;
-static wi_runtime_class_t _wi_p7_socket_runtime_class = {
+static wi_runtime_id_t _wi_p7_socket_runtime_id = WI_RUNTIME_ID_NULL;
+static wi_runtime_class_t _wi_p7_socket_runtime_class = {
"wi_p7_socket_t",
_wi_p7_socket_dealloc,
NULL,
@@ -256,15 +356,15 @@ void wi_p7_socket_register(void) {
void wi_p7_socket_initialize(void) {
- char *env;
-
- env = getenv("wi_p7_socket_debug");
-
- if(env) {
- wi_p7_socket_debug = (strcmp(env, "0") != 0);
-
- printf("*** wi_p7_socket_initialize(): wi_p7_socket_debug = %u\n", wi_p7_socket_debug);
- }
+ char *env;
+
+ env = getenv("wi_p7_socket_debug");
+
+ if(env) {
+ wi_p7_socket_debug = (strcmp(env, "0") != 0);
+
+ printf("*** wi_p7_socket_initialize(): wi_p7_socket_debug = %u\n", wi_p7_socket_debug);
+ }
}
@@ -286,60 +386,60 @@ wi_p7_socket_t * wi_p7_socket_alloc(void) {
wi_p7_socket_t * wi_p7_socket_init_with_descriptor(wi_p7_socket_t *p7_socket, int sd, wi_p7_spec_t *p7_spec) {
- p7_socket->socket = wi_socket_init_with_descriptor(wi_socket_alloc(), sd);
- p7_socket->spec = wi_retain(p7_spec);
+ p7_socket->socket = wi_socket_init_with_descriptor(wi_socket_alloc(), sd);
+ p7_socket->spec = wi_retain(p7_spec);
- return p7_socket;
+ return p7_socket;
}
wi_p7_socket_t * wi_p7_socket_init_with_socket(wi_p7_socket_t *p7_socket, wi_socket_t *socket, wi_p7_spec_t *p7_spec) {
- p7_socket->socket = wi_retain(socket);
- p7_socket->spec = wi_retain(p7_spec);
-
- return p7_socket;
+ p7_socket->socket = wi_retain(socket);
+ p7_socket->spec = wi_retain(p7_spec);
+
+ return p7_socket;
}
static void _wi_p7_socket_dealloc(wi_runtime_instance_t *instance) {
- wi_p7_socket_t *p7_socket = instance;
-
- if(p7_socket->compression_enabled) {
- deflateEnd(&p7_socket->deflate_stream);
- inflateEnd(&p7_socket->inflate_stream);
- }
-
- wi_free(p7_socket->compression_buffer);
- wi_free(p7_socket->encryption_buffer);
- wi_free(p7_socket->decryption_buffer);
- wi_free(p7_socket->oobdata_read_buffer);
-
- wi_release(p7_socket->socket);
- wi_release(p7_socket->spec);
- wi_release(p7_socket->merged_spec);
- wi_release(p7_socket->remote_name);
- wi_release(p7_socket->remote_version);
- wi_release(p7_socket->user_name);
-
+ wi_p7_socket_t *p7_socket = instance;
+
+ if(p7_socket->compression_enabled) {
+ deflateEnd(&p7_socket->deflate_stream);
+ inflateEnd(&p7_socket->inflate_stream);
+ }
+
+ wi_free(p7_socket->compression_buffer);
+ wi_free(p7_socket->encryption_buffer);
+ wi_free(p7_socket->decryption_buffer);
+ wi_free(p7_socket->oobdata_read_buffer);
+
+ wi_release(p7_socket->socket);
+ wi_release(p7_socket->spec);
+ wi_release(p7_socket->merged_spec);
+ wi_release(p7_socket->remote_name);
+ wi_release(p7_socket->remote_version);
+ wi_release(p7_socket->user_name);
+
#ifdef WI_RSA
- wi_release(p7_socket->private_key);
- wi_release(p7_socket->public_key);
- wi_release(p7_socket->cipher);
+ wi_release(p7_socket->private_key);
+ wi_release(p7_socket->public_key);
+ wi_release(p7_socket->cipher);
#endif
}
static wi_string_t * _wi_p7_socket_description(wi_runtime_instance_t *instance) {
- wi_p7_socket_t *p7_socket = instance;
+ wi_p7_socket_t *p7_socket = instance;
- return wi_string_with_format(WI_STR("<%@ %p>{options = 0x%X, socket = %@}"),
- wi_runtime_class_name(p7_socket),
- p7_socket,
- p7_socket->options,
- p7_socket->socket);
+ return wi_string_with_format(WI_STR("<%@ %p>{options = 0x%X, socket = %@}"),
+ wi_runtime_class_name(p7_socket),
+ p7_socket,
+ p7_socket->options,
+ p7_socket->socket);
}
@@ -349,21 +449,21 @@ static wi_string_t * _wi_p7_socket_description(wi_runtime_instance_t *instance)
#ifdef WI_RSA
void wi_p7_socket_set_private_key(wi_p7_socket_t *p7_socket, wi_rsa_t *rsa) {
- wi_release(p7_socket->private_key);
-
- p7_socket->private_key = wi_copy(rsa);
+ wi_release(p7_socket->private_key);
+
+ p7_socket->private_key = wi_copy(rsa);
}
wi_rsa_t * wi_p7_socket_private_key(wi_p7_socket_t *p7_socket) {
- return p7_socket->private_key;
+ return p7_socket->private_key;
}
wi_rsa_t * wi_p7_socket_public_key(wi_p7_socket_t *p7_socket) {
- return p7_socket->public_key;
+ return p7_socket->public_key;
}
#endif
@@ -371,15 +471,15 @@ wi_rsa_t * wi_p7_socket_public_key(wi_p7_socket_t *p7_socket) {
void wi_p7_socket_set_read_message_callback(wi_p7_socket_t *p7_socket, wi_p7_socket_message_callback_func_t *callback, void *context) {
- p7_socket->read_message_callback = callback;
- p7_socket->read_message_context = context;
+ p7_socket->read_message_callback = callback;
+ p7_socket->read_message_context = context;
}
void wi_p7_socket_set_wrote_message_callback(wi_p7_socket_t *p7_socket, wi_p7_socket_message_callback_func_t *callback, void *context) {
- p7_socket->wrote_message_callback = callback;
- p7_socket->wrote_message_context = context;
+ p7_socket->wrote_message_callback = callback;
+ p7_socket->wrote_message_context = context;
}
@@ -387,13 +487,13 @@ void wi_p7_socket_set_wrote_message_callback(wi_p7_socket_t *p7_socket, wi_p7_so
#pragma mark -
wi_socket_t * wi_p7_socket_socket(wi_p7_socket_t *p7_socket) {
- return p7_socket->socket;
+ return p7_socket->socket;
}
wi_p7_spec_t * wi_p7_socket_spec(wi_p7_socket_t *p7_socket) {
- return p7_socket->spec;
+ return p7_socket->spec;
}
@@ -401,7 +501,7 @@ wi_p7_spec_t * wi_p7_socket_spec(wi_p7_socket_t *p7_socket) {
#ifdef WI_RSA
wi_cipher_t * wi_p7_socket_cipher(wi_p7_socket_t *p7_socket) {
- return p7_socket->cipher;
+ return p7_socket->cipher;
}
#endif
@@ -409,38 +509,38 @@ wi_cipher_t * wi_p7_socket_cipher(wi_p7_socket_t *p7_socket) {
wi_uinteger_t wi_p7_socket_options(wi_p7_socket_t *p7_socket) {
- return p7_socket->options;
+ return p7_socket->options;
}
wi_p7_serialization_t wi_p7_socket_serialization(wi_p7_socket_t *p7_socket) {
- return p7_socket->serialization;
+ return p7_socket->serialization;
}
wi_string_t * wi_p7_socket_remote_protocol_name(wi_p7_socket_t *p7_socket) {
- return p7_socket->remote_name;
+ return p7_socket->remote_name;
}
wi_string_t * wi_p7_socket_remote_protocol_version(wi_p7_socket_t *p7_socket) {
- return p7_socket->remote_version;
+ return p7_socket->remote_version;
}
wi_string_t * wi_p7_socket_user_name(wi_p7_socket_t *p7_socket) {
- return p7_socket->user_name;
+ return p7_socket->user_name;
}
double wi_p7_socket_compression_ratio(wi_p7_socket_t *p7_socket) {
- return ((double) (p7_socket->sent_raw_bytes + p7_socket->read_processed_bytes) /
- (double) (p7_socket->sent_processed_bytes + p7_socket->read_raw_bytes));
+ return ((double) (p7_socket->sent_raw_bytes + p7_socket->read_processed_bytes) /
+ (double) (p7_socket->sent_processed_bytes + p7_socket->read_raw_bytes));
}
@@ -448,287 +548,287 @@ double wi_p7_socket_compression_ratio(wi_p7_socket_t *p7_socket) {
#pragma mark -
static wi_boolean_t _wi_p7_socket_connect_handshake(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout, wi_uinteger_t options) {
- wi_string_t *version;
- wi_p7_message_t *p7_message;
- wi_p7_enum_t flag;
-
- p7_message = wi_p7_message_with_name(WI_STR("p7.handshake.client_handshake"), wi_p7_socket_spec(p7_socket));
-
- if(!p7_message)
- return false;
-
- if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_version(wi_p7_spec_builtin_spec()), WI_STR("p7.handshake.version")))
- return false;
-
- if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_name(p7_socket->spec), WI_STR("p7.handshake.protocol.name")))
- return false;
-
- if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_version(p7_socket->spec), WI_STR("p7.handshake.protocol.version")))
- return false;
-
- if(p7_socket->serialization == WI_P7_BINARY) {
- if(WI_P7_COMPRESSION_ENABLED(options)) {
- if(!wi_p7_message_set_enum_for_name(p7_message,
- _WI_P7_COMPRESSION_OPTIONS_TO_ENUM(options),
- WI_STR("p7.handshake.compression"))) {
- return false;
- }
- }
-
- if(WI_P7_ENCRYPTION_ENABLED(options)) {
+ wi_string_t *version;
+ wi_p7_message_t *p7_message;
+ wi_p7_enum_t flag;
+
+ p7_message = wi_p7_message_with_name(WI_STR("p7.handshake.client_handshake"), wi_p7_socket_spec(p7_socket));
+
+ if(!p7_message)
+ return false;
+
+ if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_version(wi_p7_spec_builtin_spec()), WI_STR("p7.handshake.version")))
+ return false;
+
+ if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_name(p7_socket->spec), WI_STR("p7.handshake.protocol.name")))
+ return false;
+
+ if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_version(p7_socket->spec), WI_STR("p7.handshake.protocol.version")))
+ return false;
+
+ if(p7_socket->serialization == WI_P7_BINARY) {
+ if(WI_P7_COMPRESSION_ENABLED(options)) {
+ if(!wi_p7_message_set_enum_for_name(p7_message,
+ _WI_P7_COMPRESSION_OPTIONS_TO_ENUM(options),
+ WI_STR("p7.handshake.compression"))) {
+ return false;
+ }
+ }
+
+ if(WI_P7_ENCRYPTION_ENABLED(options)) {
#ifdef WI_RSA
- if(!wi_p7_message_set_enum_for_name(p7_message,
- _WI_P7_ENCRYPTION_OPTIONS_TO_ENUM(options),
- WI_STR("p7.handshake.encryption"))) {
- return false;
- }
+ if(!wi_p7_message_set_enum_for_name(p7_message,
+ _WI_P7_ENCRYPTION_OPTIONS_TO_ENUM(options),
+ WI_STR("p7.handshake.encryption"))) {
+ return false;
+ }
#else
- wi_error_set_libwired_error(WI_ERROR_P7_RSANOTSUPP);
-
- return false;
+ wi_error_set_libwired_error(WI_ERROR_P7_RSANOTSUPP);
+
+ return false;
#endif
- }
-
- if(WI_P7_CHECKSUM_ENABLED(options)) {
- if(!wi_p7_message_set_enum_for_name(p7_message,
- _WI_P7_CHECKSUM_OPTIONS_TO_ENUM(options),
- WI_STR("p7.handshake.checksum"))) {
- return false;
- }
- }
- }
-
- if(!wi_p7_socket_write_message(p7_socket, timeout, p7_message))
- return false;
-
- p7_message = wi_p7_socket_read_message(p7_socket, timeout);
-
- if(!p7_message)
- return false;
-
- if(!wi_is_equal(p7_message->name, WI_STR("p7.handshake.server_handshake"))) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Message should be \"p7.handshake.server_handshake\", not \"%@\""),
- p7_message->name);
-
- return false;
- }
-
- version = wi_p7_message_string_for_name(p7_message, WI_STR("p7.handshake.version"));
-
- if(!version) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Message has no \"p7.handshake.version\" field"));
-
- return false;
- }
-
- if(!wi_is_equal(version, wi_p7_spec_version(wi_p7_spec_builtin_spec()))) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Remote P7 protocol %.1f is not compatible"),
- version);
-
- return false;
- }
-
- p7_socket->remote_name = wi_retain(wi_p7_message_string_for_name(p7_message, WI_STR("p7.handshake.protocol.name")));
-
- if(!p7_socket->remote_name) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Message has no \"p7.handshake.protocol.name\" field"));
-
- return false;
- }
-
- p7_socket->remote_version = wi_retain(wi_p7_message_string_for_name(p7_message, WI_STR("p7.handshake.protocol.version")));
-
- if(!p7_socket->remote_version) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Message has no \"p7.handshake.protocol.version\" field"));
-
- return false;
- }
-
- p7_socket->local_compatibility_check = !wi_p7_spec_is_compatible_with_protocol(p7_socket->spec, p7_socket->remote_name, p7_socket->remote_version);
-
- if(p7_socket->serialization == WI_P7_BINARY) {
- if(wi_p7_message_get_enum_for_name(p7_message, &flag, WI_STR("p7.handshake.compression")))
- p7_socket->options |= _WI_P7_COMPRESSION_ENUM_TO_OPTIONS(flag);
-
- if(wi_p7_message_get_enum_for_name(p7_message, &flag, WI_STR("p7.handshake.encryption")))
- p7_socket->options |= _WI_P7_ENCRYPTION_ENUM_TO_OPTIONS(flag);
-
- if(wi_p7_message_get_enum_for_name(p7_message, &flag, WI_STR("p7.handshake.checksum")))
- p7_socket->options |= _WI_P7_CHECKSUM_ENUM_TO_OPTIONS(flag);
- }
-
- if(!wi_p7_message_get_bool_for_name(p7_message, &p7_socket->remote_compatibility_check, WI_STR("p7.handshake.compatibility_check")))
- p7_socket->remote_compatibility_check = false;
-
- p7_message = wi_p7_message_with_name(WI_STR("p7.handshake.acknowledge"), wi_p7_socket_spec(p7_socket));
-
- if(!p7_message)
- return false;
-
- if(p7_socket->local_compatibility_check) {
- if(!wi_p7_message_set_bool_for_name(p7_message, true, WI_STR("p7.handshake.compatibility_check")))
- return false;
- }
-
- if(!wi_p7_socket_write_message(p7_socket, timeout, p7_message))
- return false;
-
- return true;
+ }
+
+ if(WI_P7_CHECKSUM_ENABLED(options)) {
+ if(!wi_p7_message_set_enum_for_name(p7_message,
+ _WI_P7_CHECKSUM_OPTIONS_TO_ENUM(options),
+ WI_STR("p7.handshake.checksum"))) {
+ return false;
+ }
+ }
+ }
+
+ if(!wi_p7_socket_write_message(p7_socket, timeout, p7_message))
+ return false;
+
+ p7_message = wi_p7_socket_read_message(p7_socket, timeout);
+
+ if(!p7_message)
+ return false;
+
+ if(!wi_is_equal(p7_message->name, WI_STR("p7.handshake.server_handshake"))) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Message should be \"p7.handshake.server_handshake\", not \"%@\""),
+ p7_message->name);
+
+ return false;
+ }
+
+ version = wi_p7_message_string_for_name(p7_message, WI_STR("p7.handshake.version"));
+
+ if(!version) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Message has no \"p7.handshake.version\" field"));
+
+ return false;
+ }
+
+ if(!wi_is_equal(version, wi_p7_spec_version(wi_p7_spec_builtin_spec()))) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Remote P7 protocol %.1f is not compatible"),
+ version);
+
+ return false;
+ }
+
+ p7_socket->remote_name = wi_retain(wi_p7_message_string_for_name(p7_message, WI_STR("p7.handshake.protocol.name")));
+
+ if(!p7_socket->remote_name) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Message has no \"p7.handshake.protocol.name\" field"));
+
+ return false;
+ }
+
+ p7_socket->remote_version = wi_retain(wi_p7_message_string_for_name(p7_message, WI_STR("p7.handshake.protocol.version")));
+
+ if(!p7_socket->remote_version) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Message has no \"p7.handshake.protocol.version\" field"));
+
+ return false;
+ }
+
+ p7_socket->local_compatibility_check = !wi_p7_spec_is_compatible_with_protocol(p7_socket->spec, p7_socket->remote_name, p7_socket->remote_version);
+
+ if(p7_socket->serialization == WI_P7_BINARY) {
+ if(wi_p7_message_get_enum_for_name(p7_message, &flag, WI_STR("p7.handshake.compression")))
+ p7_socket->options |= _WI_P7_COMPRESSION_ENUM_TO_OPTIONS(flag);
+
+ if(wi_p7_message_get_enum_for_name(p7_message, &flag, WI_STR("p7.handshake.encryption")))
+ p7_socket->options |= _WI_P7_ENCRYPTION_ENUM_TO_OPTIONS(flag);
+
+ if(wi_p7_message_get_enum_for_name(p7_message, &flag, WI_STR("p7.handshake.checksum")))
+ p7_socket->options |= _WI_P7_CHECKSUM_ENUM_TO_OPTIONS(flag);
+ }
+
+ if(!wi_p7_message_get_bool_for_name(p7_message, &p7_socket->remote_compatibility_check, WI_STR("p7.handshake.compatibility_check")))
+ p7_socket->remote_compatibility_check = false;
+
+ p7_message = wi_p7_message_with_name(WI_STR("p7.handshake.acknowledge"), wi_p7_socket_spec(p7_socket));
+
+ if(!p7_message)
+ return false;
+
+ if(p7_socket->local_compatibility_check) {
+ if(!wi_p7_message_set_bool_for_name(p7_message, true, WI_STR("p7.handshake.compatibility_check")))
+ return false;
+ }
+
+ if(!wi_p7_socket_write_message(p7_socket, timeout, p7_message))
+ return false;
+
+ return true;
}
static wi_boolean_t _wi_p7_socket_accept_handshake(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout, wi_uinteger_t options) {
- wi_string_t *version;
- wi_p7_message_t *p7_message;
- wi_p7_enum_t flag;
- wi_uinteger_t client_options;
-
- p7_message = wi_p7_socket_read_message(p7_socket, timeout);
-
- if(!p7_message)
- return false;
-
- if(!wi_is_equal(p7_message->name, WI_STR("p7.handshake.client_handshake"))) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Message should be \"p7.handshake.client_handshake\", not \"%@\""),
- p7_message->name);
-
- return false;
- }
-
- version = wi_p7_message_string_for_name(p7_message, WI_STR("p7.handshake.version"));
-
- if(!version) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Message has no \"p7.handshake.version\" field"));
-
- return false;
- }
-
- if(!wi_is_equal(version, wi_p7_spec_version(wi_p7_spec_builtin_spec()))) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Remote P7 protocol %.1f is not compatible"),
- version);
-
- return false;
- }
-
- p7_socket->remote_name = wi_retain(wi_p7_message_string_for_name(p7_message, WI_STR("p7.handshake.protocol.name")));
-
- if(!p7_socket->remote_name) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Message has no \"p7.handshake.protocol.name\" field"));
-
- return false;
- }
-
- p7_socket->remote_version = wi_retain(wi_p7_message_string_for_name(p7_message, WI_STR("p7.handshake.protocol.version")));
-
- if(!p7_socket->remote_version) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Message has no \"p7.handshake.protocol.version\" field"));
-
- return false;
- }
-
- p7_socket->local_compatibility_check = !wi_p7_spec_is_compatible_with_protocol(p7_socket->spec, p7_socket->remote_name, p7_socket->remote_version);
-
- if(p7_socket->serialization == WI_P7_BINARY) {
- if(wi_p7_message_get_enum_for_name(p7_message, &flag, WI_STR("p7.handshake.compression"))) {
- client_options = _WI_P7_COMPRESSION_ENUM_TO_OPTIONS(flag);
-
- if(options & client_options)
- p7_socket->options |= client_options;
- }
-
- if(wi_p7_message_get_enum_for_name(p7_message, &flag, WI_STR("p7.handshake.encryption"))) {
- client_options = _WI_P7_ENCRYPTION_ENUM_TO_OPTIONS(flag);
+ wi_string_t *version;
+ wi_p7_message_t *p7_message;
+ wi_p7_enum_t flag;
+ wi_uinteger_t client_options;
+
+ p7_message = wi_p7_socket_read_message(p7_socket, timeout);
+
+ if(!p7_message)
+ return false;
+
+ if(!wi_is_equal(p7_message->name, WI_STR("p7.handshake.client_handshake"))) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Message should be \"p7.handshake.client_handshake\", not \"%@\""),
+ p7_message->name);
+
+ return false;
+ }
+
+ version = wi_p7_message_string_for_name(p7_message, WI_STR("p7.handshake.version"));
+
+ if(!version) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Message has no \"p7.handshake.version\" field"));
+
+ return false;
+ }
+
+ if(!wi_is_equal(version, wi_p7_spec_version(wi_p7_spec_builtin_spec()))) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Remote P7 protocol %.1f is not compatible"),
+ version);
+
+ return false;
+ }
+
+ p7_socket->remote_name = wi_retain(wi_p7_message_string_for_name(p7_message, WI_STR("p7.handshake.protocol.name")));
+
+ if(!p7_socket->remote_name) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Message has no \"p7.handshake.protocol.name\" field"));
+
+ return false;
+ }
+
+ p7_socket->remote_version = wi_retain(wi_p7_message_string_for_name(p7_message, WI_STR("p7.handshake.protocol.version")));
+
+ if(!p7_socket->remote_version) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Message has no \"p7.handshake.protocol.version\" field"));
+
+ return false;
+ }
+
+ p7_socket->local_compatibility_check = !wi_p7_spec_is_compatible_with_protocol(p7_socket->spec, p7_socket->remote_name, p7_socket->remote_version);
+
+ if(p7_socket->serialization == WI_P7_BINARY) {
+ if(wi_p7_message_get_enum_for_name(p7_message, &flag, WI_STR("p7.handshake.compression"))) {
+ client_options = _WI_P7_COMPRESSION_ENUM_TO_OPTIONS(flag);
+
+ if(options & client_options)
+ p7_socket->options |= client_options;
+ }
+
+ if(wi_p7_message_get_enum_for_name(p7_message, &flag, WI_STR("p7.handshake.encryption"))) {
+ client_options = _WI_P7_ENCRYPTION_ENUM_TO_OPTIONS(flag);
#ifdef WI_RSA
- if(options & client_options)
- p7_socket->options |= client_options;
+ if(options & client_options)
+ p7_socket->options |= client_options;
#endif
- }
-
- if(wi_p7_message_get_enum_for_name(p7_message, &flag, WI_STR("p7.handshake.checksum"))) {
- client_options = _WI_P7_CHECKSUM_ENUM_TO_OPTIONS(flag);
-
- if(options & client_options)
- p7_socket->options |= client_options;
- }
- }
-
- p7_message = wi_p7_message_with_name(WI_STR("p7.handshake.server_handshake"), wi_p7_socket_spec(p7_socket));
-
- if(!p7_message)
- return false;
-
- if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_version(wi_p7_spec_builtin_spec()), WI_STR("p7.handshake.version")))
- return false;
-
- if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_name(p7_socket->spec), WI_STR("p7.handshake.protocol.name")))
- return false;
-
- if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_version(p7_socket->spec), WI_STR("p7.handshake.protocol.version")))
- return false;
-
- if(p7_socket->serialization == WI_P7_BINARY) {
- if(WI_P7_COMPRESSION_ENABLED(p7_socket->options)) {
- if(!wi_p7_message_set_enum_for_name(p7_message,
- _WI_P7_COMPRESSION_OPTIONS_TO_ENUM(p7_socket->options),
- WI_STR("p7.handshake.compression"))) {
- return false;
- }
- }
-
- if(WI_P7_ENCRYPTION_ENABLED(p7_socket->options)) {
- if(!wi_p7_message_set_enum_for_name(p7_message,
- _WI_P7_ENCRYPTION_OPTIONS_TO_ENUM(p7_socket->options),
- WI_STR("p7.handshake.encryption"))) {
- return false;
- }
- }
-
- if(WI_P7_CHECKSUM_ENABLED(p7_socket->options)) {
- if(!wi_p7_message_set_enum_for_name(p7_message,
- _WI_P7_CHECKSUM_OPTIONS_TO_ENUM(p7_socket->options),
- WI_STR("p7.handshake.checksum"))) {
- return false;
- }
- }
- }
-
- if(p7_socket->local_compatibility_check) {
- if(!wi_p7_message_set_bool_for_name(p7_message, true, WI_STR("p7.handshake.compatibility_check")))
- return false;
- }
-
- if(!wi_p7_socket_write_message(p7_socket, timeout, p7_message))
- return false;
-
- p7_message = wi_p7_socket_read_message(p7_socket, timeout);
-
- if(!p7_message)
- return false;
-
- if(!wi_is_equal(p7_message->name, WI_STR("p7.handshake.acknowledge"))) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Message should be \"p7.handshake.acknowledge\", not \"%@\""),
- p7_message->name);
-
- return false;
- }
-
- if(!wi_p7_message_get_bool_for_name(p7_message, &p7_socket->remote_compatibility_check, WI_STR("p7.handshake.compatibility_check")))
- p7_socket->remote_compatibility_check = false;
-
- return true;
+ }
+
+ if(wi_p7_message_get_enum_for_name(p7_message, &flag, WI_STR("p7.handshake.checksum"))) {
+ client_options = _WI_P7_CHECKSUM_ENUM_TO_OPTIONS(flag);
+
+ if(options & client_options)
+ p7_socket->options |= client_options;
+ }
+ }
+
+ p7_message = wi_p7_message_with_name(WI_STR("p7.handshake.server_handshake"), wi_p7_socket_spec(p7_socket));
+
+ if(!p7_message)
+ return false;
+
+ if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_version(wi_p7_spec_builtin_spec()), WI_STR("p7.handshake.version")))
+ return false;
+
+ if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_name(p7_socket->spec), WI_STR("p7.handshake.protocol.name")))
+ return false;
+
+ if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_version(p7_socket->spec), WI_STR("p7.handshake.protocol.version")))
+ return false;
+
+ if(p7_socket->serialization == WI_P7_BINARY) {
+ if(WI_P7_COMPRESSION_ENABLED(p7_socket->options)) {
+ if(!wi_p7_message_set_enum_for_name(p7_message,
+ _WI_P7_COMPRESSION_OPTIONS_TO_ENUM(p7_socket->options),
+ WI_STR("p7.handshake.compression"))) {
+ return false;
+ }
+ }
+
+ if(WI_P7_ENCRYPTION_ENABLED(p7_socket->options)) {
+ if(!wi_p7_message_set_enum_for_name(p7_message,
+ _WI_P7_ENCRYPTION_OPTIONS_TO_ENUM(p7_socket->options),
+ WI_STR("p7.handshake.encryption"))) {
+ return false;
+ }
+ }
+
+ if(WI_P7_CHECKSUM_ENABLED(p7_socket->options)) {
+ if(!wi_p7_message_set_enum_for_name(p7_message,
+ _WI_P7_CHECKSUM_OPTIONS_TO_ENUM(p7_socket->options),
+ WI_STR("p7.handshake.checksum"))) {
+ return false;
+ }
+ }
+ }
+
+ if(p7_socket->local_compatibility_check) {
+ if(!wi_p7_message_set_bool_for_name(p7_message, true, WI_STR("p7.handshake.compatibility_check")))
+ return false;
+ }
+
+ if(!wi_p7_socket_write_message(p7_socket, timeout, p7_message))
+ return false;
+
+ p7_message = wi_p7_socket_read_message(p7_socket, timeout);
+
+ if(!p7_message)
+ return false;
+
+ if(!wi_is_equal(p7_message->name, WI_STR("p7.handshake.acknowledge"))) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Message should be \"p7.handshake.acknowledge\", not \"%@\""),
+ p7_message->name);
+
+ return false;
+ }
+
+ if(!wi_p7_message_get_bool_for_name(p7_message, &p7_socket->remote_compatibility_check, WI_STR("p7.handshake.compatibility_check")))
+ p7_socket->remote_compatibility_check = false;
+
+ return true;
}
@@ -736,314 +836,350 @@ static wi_boolean_t _wi_p7_socket_accept_handshake(wi_p7_socket_t *p7_socket, wi
#ifdef WI_RSA
static wi_boolean_t _wi_p7_socket_connect_key_exchange(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout, wi_string_t *username, wi_string_t *password) {
- wi_p7_message_t *p7_message;
- wi_data_t *data, *rsa;
- wi_string_t *client_password1, *client_password2, *server_password;
-
- p7_message = wi_p7_socket_read_message(p7_socket, timeout);
-
- if(!p7_message)
- return false;
-
- if(!wi_is_equal(p7_message->name, WI_STR("p7.encryption.server_key"))) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Message should be \"p7.encryption\", not \"%@\""),
- p7_message->name);
-
- return false;
- }
-
- rsa = wi_p7_message_data_for_name(p7_message, WI_STR("p7.encryption.public_key"));
-
- if(!rsa) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Message has no \"p7.encryption.public_key\" field"));
-
- return false;
- }
-
- p7_socket->public_key = wi_rsa_init_with_public_key(wi_rsa_alloc(), rsa);
-
- if(!p7_socket->public_key)
- return false;
-
- p7_socket->cipher = wi_cipher_init_with_random_key(wi_cipher_alloc(), _WI_P7_ENCRYPTION_OPTIONS_TO_CIPHER(p7_socket->options));
-
- if(!p7_socket->cipher) {
- return false;
- }
-
- p7_message = wi_p7_message_with_name(WI_STR("p7.encryption.client_key"), wi_p7_socket_spec(p7_socket));
-
- if(!p7_message)
- return false;
-
- data = wi_rsa_encrypt(p7_socket->public_key, wi_cipher_key(p7_socket->cipher));
-
- if(!data)
- return false;
-
- if(!wi_p7_message_set_data_for_name(p7_message, data, WI_STR("p7.encryption.cipher.key")))
- return false;
-
- data = wi_cipher_iv(p7_socket->cipher);
-
- if(data) {
- data = wi_rsa_encrypt(p7_socket->public_key, data);
-
- if(!data)
- return false;
-
- if(!wi_p7_message_set_data_for_name(p7_message, data, WI_STR("p7.encryption.cipher.iv")))
- return false;
- }
-
- p7_socket->user_name = username ? wi_retain(username) : wi_retain(WI_STR(""));
-
- data = wi_rsa_encrypt(p7_socket->public_key, wi_string_data(p7_socket->user_name));
-
- if(!data)
- return false;
-
- if(!wi_p7_message_set_data_for_name(p7_message, data, WI_STR("p7.encryption.username")))
- return false;
-
- if(!password)
- password = _wi_p7_socket_string_checksum(p7_socket, WI_STR(""));
-
- client_password1 = _wi_p7_socket_data_checksum(p7_socket, wi_data_by_appending_data(wi_string_data(password), rsa));
- client_password2 = _wi_p7_socket_data_checksum(p7_socket, wi_data_by_appending_data(rsa, wi_string_data(password)));
-
- data = wi_rsa_encrypt(p7_socket->public_key, wi_string_data(client_password1));
-
- if(!data)
- return false;
-
- if(!wi_p7_message_set_data_for_name(p7_message, data, WI_STR("p7.encryption.client_password")))
- return false;
-
- if(!wi_p7_socket_write_message(p7_socket, timeout, p7_message))
- return false;
-
- p7_message = wi_p7_socket_read_message(p7_socket, timeout);
-
- if(!p7_message)
- return false;
-
- if(wi_is_equal(p7_message->name, WI_STR("p7.encryption.authentication_error"))) {
- wi_error_set_libwired_error(WI_ERROR_P7_AUTHENTICATIONFAILED);
-
- return false;
- }
-
- if(!wi_is_equal(p7_message->name, WI_STR("p7.encryption.acknowledge"))) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Message should be \"p7.encryption.acknowledge\", not \"%@\""),
- p7_message->name);
-
- return false;
- }
-
- data = wi_p7_message_data_for_name(p7_message, WI_STR("p7.encryption.server_password"));
-
- if(!data) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Message has no \"p7.encryption.server_password\" field"));
-
- return false;
- }
-
- data = wi_cipher_decrypt(p7_socket->cipher, data);
- if(!data)
- return false;
-
- server_password = wi_string_with_data(data);
-
- if(!_wi_p7_password_is_equal(server_password, client_password2)) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Password mismatch during key exchange"));
-
- return false;
- }
-
- p7_socket->encryption_enabled = true;
-
- return true;
+ wi_p7_message_t *p7_message;
+ wi_data_t *data, *rsa;
+ wi_string_t *client_password1, *client_password2, *server_password;
+
+ p7_message = wi_p7_socket_read_message(p7_socket, timeout);
+
+ if(!p7_message)
+ return false;
+
+ if(!wi_is_equal(p7_message->name, WI_STR("p7.encryption.server_key"))) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Message should be \"p7.encryption\", not \"%@\""),
+ p7_message->name);
+
+ return false;
+ }
+
+ rsa = wi_p7_message_data_for_name(p7_message, WI_STR("p7.encryption.public_key"));
+
+ if(!rsa) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Message has no \"p7.encryption.public_key\" field"));
+
+ return false;
+ }
+
+ p7_socket->public_key = wi_rsa_init_with_public_key(wi_rsa_alloc(), rsa);
+
+ if(!p7_socket->public_key)
+ return false;
+
+ p7_socket->cipher = wi_cipher_init_with_random_key(wi_cipher_alloc(), _WI_P7_ENCRYPTION_OPTIONS_TO_CIPHER(p7_socket->options));
+
+ if(!p7_socket->cipher) {
+ return false;
+ }
+
+ p7_message = wi_p7_message_with_name(WI_STR("p7.encryption.client_key"), wi_p7_socket_spec(p7_socket));
+
+ if(!p7_message)
+ return false;
+
+ data = wi_rsa_encrypt(p7_socket->public_key, wi_cipher_key(p7_socket->cipher));
+
+ if(!data)
+ return false;
+
+ if(!wi_p7_message_set_data_for_name(p7_message, data, WI_STR("p7.encryption.cipher.key")))
+ return false;
+
+ data = wi_cipher_iv(p7_socket->cipher);
+
+ if(data) {
+ data = wi_rsa_encrypt(p7_socket->public_key, data);
+
+ if(!data)
+ return false;
+
+ if(!wi_p7_message_set_data_for_name(p7_message, data, WI_STR("p7.encryption.cipher.iv")))
+ return false;
+ }
+
+ p7_socket->user_name = username ? wi_retain(username) : wi_retain(WI_STR(""));
+
+ data = wi_rsa_encrypt(p7_socket->public_key, wi_string_data(p7_socket->user_name));
+
+ if(!data)
+ return false;
+
+ if(!wi_p7_message_set_data_for_name(p7_message, data, WI_STR("p7.encryption.username")))
+ return false;
+
+ if(!password) {
+ if(_WI_P7_ENCRYPTION_OPTIONS_TO_CHECKSUM(p7_socket->options) == _WI_P7_CHECKSUM_SHA512)
+ password = wi_string_sha512(WI_STR(""));
+ else if(_WI_P7_ENCRYPTION_OPTIONS_TO_CHECKSUM(p7_socket->options) == _WI_P7_CHECKSUM_SHA256)
+ password = wi_string_sha256(WI_STR(""));
+ else
+ password = wi_string_sha1(WI_STR(""));
+ }
+
+ if(_WI_P7_ENCRYPTION_OPTIONS_TO_CHECKSUM(p7_socket->options) == _WI_P7_CHECKSUM_SHA512) {
+ client_password1 = wi_data_sha512(wi_data_by_appending_data(wi_string_data(password), rsa));
+ client_password2 = wi_data_sha512(wi_data_by_appending_data(rsa, wi_string_data(password)));
+ }
+ else if(_WI_P7_ENCRYPTION_OPTIONS_TO_CHECKSUM(p7_socket->options) == _WI_P7_CHECKSUM_SHA256) {
+ client_password1 = wi_data_sha256(wi_data_by_appending_data(wi_string_data(password), rsa));
+ client_password2 = wi_data_sha256(wi_data_by_appending_data(rsa, wi_string_data(password)));
+ }
+ else {
+ client_password1 = wi_data_sha1(wi_data_by_appending_data(wi_string_data(password), rsa));
+ client_password2 = wi_data_sha1(wi_data_by_appending_data(rsa, wi_string_data(password)));
+ }
+
+ data = wi_rsa_encrypt(p7_socket->public_key, wi_string_data(client_password1));
+
+ if(!data)
+ return false;
+
+ if(!wi_p7_message_set_data_for_name(p7_message, data, WI_STR("p7.encryption.client_password")))
+ return false;
+
+ if(!wi_p7_socket_write_message(p7_socket, timeout, p7_message))
+ return false;
+
+ p7_message = wi_p7_socket_read_message(p7_socket, timeout);
+
+ if(!p7_message)
+ return false;
+
+ if(wi_is_equal(p7_message->name, WI_STR("p7.encryption.authentication_error"))) {
+ wi_error_set_libwired_error(WI_ERROR_P7_AUTHENTICATIONFAILED);
+
+ return false;
+ }
+
+ if(!wi_is_equal(p7_message->name, WI_STR("p7.encryption.acknowledge"))) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Message should be \"p7.encryption.acknowledge\", not \"%@\""),
+ p7_message->name);
+
+ return false;
+ }
+
+ data = wi_p7_message_data_for_name(p7_message, WI_STR("p7.encryption.server_password"));
+
+ if(!data) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Message has no \"p7.encryption.server_password\" field"));
+
+ return false;
+ }
+
+ data = wi_cipher_decrypt(p7_socket->cipher, data);
+
+ if(!data)
+ return false;
+
+ server_password = wi_string_with_data(data);
+
+ if(!_wi_p7_password_is_equal(server_password, client_password2)) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Password mismatch during key exchange"));
+
+ return false;
+ }
+
+ p7_socket->encryption_enabled = true;
+
+ return true;
}
static wi_boolean_t _wi_p7_socket_accept_key_exchange(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout) {
- wi_p7_message_t *p7_message;
- wi_data_t *data, *rsa, *key, *iv;
- wi_string_t *string, *client_password, *server_password1, *server_password2;
-
- p7_message = wi_p7_message_with_name(WI_STR("p7.encryption.server_key"), wi_p7_socket_spec(p7_socket));
-
- if(!p7_message)
- return false;
-
- if(!p7_socket->private_key) {
- wi_error_set_libwired_error(WI_ERROR_P7_NORSAKEY);
-
- return false;
- }
-
- rsa = wi_rsa_public_key(p7_socket->private_key);
-
- if(!wi_p7_message_set_data_for_name(p7_message, rsa, WI_STR("p7.encryption.public_key")))
- return false;
-
- if(!wi_p7_socket_write_message(p7_socket, timeout, p7_message))
- return false;
-
- p7_message = wi_p7_socket_read_message(p7_socket, timeout);
-
- if(!p7_message)
- return false;
-
- if(!wi_is_equal(p7_message->name, WI_STR("p7.encryption.client_key"))) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Message should be \"p7.encryption.reply\", not \"%@\""),
- p7_message->name);
-
- return false;
- }
-
- key = wi_p7_message_data_for_name(p7_message, WI_STR("p7.encryption.cipher.key"));
- iv = wi_p7_message_data_for_name(p7_message, WI_STR("p7.encryption.cipher.iv"));
-
- if(!key) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Message has no \"p7.encryption.cipher.key\" field"));
-
- return false;
- }
-
- key = wi_rsa_decrypt(p7_socket->private_key, key);
-
- if(!key)
- return false;
-
- if(iv) {
- iv = wi_rsa_decrypt(p7_socket->private_key, iv);
-
- if(!iv)
- return false;
- }
-
- p7_socket->cipher = wi_cipher_init_with_key(wi_cipher_alloc(), _WI_P7_ENCRYPTION_OPTIONS_TO_CIPHER(p7_socket->options), key, iv);
-
- if(!p7_socket->cipher)
- return false;
-
- data = wi_p7_message_data_for_name(p7_message, WI_STR("p7.encryption.username"));
-
- if(!data) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Message has no \"p7.encryption.username\" field"));
-
- return false;
- }
-
- data = wi_rsa_decrypt(p7_socket->private_key, data);
-
- if(!data)
- return false;
-
- p7_socket->user_name = wi_string_init_with_data(wi_string_alloc(), data);
-
- data = wi_p7_message_data_for_name(p7_message, WI_STR("p7.encryption.client_password"));
-
- if(!data) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Message has no \"p7.encryption.client_password\" field"));
-
- return false;
- }
-
- data = wi_rsa_decrypt(p7_socket->private_key, data);
-
- if(!data)
- return false;
-
- client_password = wi_string_with_data(data);
-
- if(wi_p7_socket_password_provider) {
- string = (*wi_p7_socket_password_provider)(p7_socket->user_name);
-
- if(!string) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_AUTHENTICATIONFAILED,
- WI_STR("Unknown user \"%@\" during key exchange"),
- p7_socket->user_name);
-
- p7_message = wi_p7_message_with_name(WI_STR("p7.encryption.authentication_error"), wi_p7_socket_spec(p7_socket));
- wi_p7_socket_write_message(p7_socket, timeout, p7_message);
-
- return false;
- }
- } else {
- string = _wi_p7_socket_string_checksum(p7_socket, WI_STR(""));
- }
-
- server_password1 = _wi_p7_socket_data_checksum(p7_socket, wi_data_by_appending_data(wi_string_data(string), rsa));
- server_password2 = _wi_p7_socket_data_checksum(p7_socket, wi_data_by_appending_data(rsa, wi_string_data(string)));
-
- if(!_wi_p7_password_is_equal(client_password, server_password1)) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_AUTHENTICATIONFAILED,
- WI_STR("Password mismatch for \"%@\" during key exchange"),
- p7_socket->user_name);
-
- p7_message = wi_p7_message_with_name(WI_STR("p7.encryption.authentication_error"), wi_p7_socket_spec(p7_socket));
- wi_p7_socket_write_message(p7_socket, timeout, p7_message);
-
- return false;
- }
-
- p7_message = wi_p7_message_with_name(WI_STR("p7.encryption.acknowledge"), wi_p7_socket_spec(p7_socket));
-
- if(!p7_message)
- return false;
-
- data = wi_cipher_encrypt(p7_socket->cipher, wi_string_data(server_password2));
-
- if(!data)
- return false;
-
- if(!wi_p7_message_set_data_for_name(p7_message, data, WI_STR("p7.encryption.server_password")))
- return false;
-
- if(!wi_p7_socket_write_message(p7_socket, timeout, p7_message))
- return false;
-
- p7_socket->encryption_enabled = true;
-
- return true;
+ wi_p7_message_t *p7_message;
+ wi_data_t *data, *rsa, *key, *iv;
+ wi_string_t *string, *client_password, *server_password1, *server_password2;
+
+ p7_message = wi_p7_message_with_name(WI_STR("p7.encryption.server_key"), wi_p7_socket_spec(p7_socket));
+
+ if(!p7_message)
+ return false;
+
+ if(!p7_socket->private_key) {
+ wi_error_set_libwired_error(WI_ERROR_P7_NORSAKEY);
+
+ return false;
+ }
+
+ rsa = wi_rsa_public_key(p7_socket->private_key);
+
+ if(!wi_p7_message_set_data_for_name(p7_message, rsa, WI_STR("p7.encryption.public_key")))
+ return false;
+
+ if(!wi_p7_socket_write_message(p7_socket, timeout, p7_message))
+ return false;
+
+ p7_message = wi_p7_socket_read_message(p7_socket, timeout);
+
+ if(!p7_message)
+ return false;
+
+ if(!wi_is_equal(p7_message->name, WI_STR("p7.encryption.client_key"))) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Message should be \"p7.encryption.reply\", not \"%@\""),
+ p7_message->name);
+
+ return false;
+ }
+
+ key = wi_p7_message_data_for_name(p7_message, WI_STR("p7.encryption.cipher.key"));
+ iv = wi_p7_message_data_for_name(p7_message, WI_STR("p7.encryption.cipher.iv"));
+
+ if(!key) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Message has no \"p7.encryption.cipher.key\" field"));
+
+ return false;
+ }
+
+ key = wi_rsa_decrypt(p7_socket->private_key, key);
+
+ if(!key)
+ return false;
+
+ if(iv) {
+ iv = wi_rsa_decrypt(p7_socket->private_key, iv);
+
+ if(!iv)
+ return false;
+ }
+
+ p7_socket->cipher = wi_cipher_init_with_key(wi_cipher_alloc(), _WI_P7_ENCRYPTION_OPTIONS_TO_CIPHER(p7_socket->options), key, iv);
+
+ if(!p7_socket->cipher)
+ return false;
+
+ data = wi_p7_message_data_for_name(p7_message, WI_STR("p7.encryption.username"));
+
+ if(!data) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Message has no \"p7.encryption.username\" field"));
+
+ return false;
+ }
+
+ data = wi_rsa_decrypt(p7_socket->private_key, data);
+
+ if(!data)
+ return false;
+
+ p7_socket->user_name = wi_string_init_with_data(wi_string_alloc(), data);
+
+ data = wi_p7_message_data_for_name(p7_message, WI_STR("p7.encryption.client_password"));
+
+ if(!data) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Message has no \"p7.encryption.client_password\" field"));
+
+ return false;
+ }
+
+ data = wi_rsa_decrypt(p7_socket->private_key, data);
+
+ if(!data)
+ return false;
+
+ client_password = wi_string_with_data(data);
+
+ if(wi_p7_socket_password_provider) {
+ string = (*wi_p7_socket_password_provider)(p7_socket->user_name);
+
+ if(!string) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_AUTHENTICATIONFAILED,
+ WI_STR("Unknown user \"%@\" during key exchange"),
+ p7_socket->user_name);
+
+ p7_message = wi_p7_message_with_name(WI_STR("p7.encryption.authentication_error"), wi_p7_socket_spec(p7_socket));
+ wi_p7_socket_write_message(p7_socket, timeout, p7_message);
+
+ return false;
+ }
+ } else {
+ if(_WI_P7_ENCRYPTION_OPTIONS_TO_CHECKSUM(p7_socket->options) == _WI_P7_CHECKSUM_SHA512) {
+ string = wi_string_sha512(WI_STR(""));
+ }
+ else if(_WI_P7_ENCRYPTION_OPTIONS_TO_CHECKSUM(p7_socket->options) == _WI_P7_CHECKSUM_SHA256) {
+ string = wi_string_sha256(WI_STR(""));
+ }
+ else {
+ string = wi_string_sha1(WI_STR(""));
+ }
+ }
+
+ if(_WI_P7_ENCRYPTION_OPTIONS_TO_CHECKSUM(p7_socket->options) == _WI_P7_CHECKSUM_SHA512) {
+ server_password1 = wi_data_sha512(wi_data_by_appending_data(wi_string_data(string), rsa));
+ server_password2 = wi_data_sha512(wi_data_by_appending_data(rsa, wi_string_data(string)));
+
+ } else if(_WI_P7_ENCRYPTION_OPTIONS_TO_CHECKSUM(p7_socket->options) == _WI_P7_CHECKSUM_SHA256) {
+ server_password1 = wi_data_sha256(wi_data_by_appending_data(wi_string_data(string), rsa));
+ server_password2 = wi_data_sha256(wi_data_by_appending_data(rsa, wi_string_data(string)));
+ }
+ else {
+ server_password1 = wi_data_sha1(wi_data_by_appending_data(wi_string_data(string), rsa));
+ server_password2 = wi_data_sha1(wi_data_by_appending_data(rsa, wi_string_data(string)));
+ }
+
+
+ if(!_wi_p7_password_is_equal(client_password, server_password1)) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_AUTHENTICATIONFAILED,
+ WI_STR("Password mismatch for \"%@\" during key exchange"),
+ p7_socket->user_name);
+
+ p7_message = wi_p7_message_with_name(WI_STR("p7.encryption.authentication_error"), wi_p7_socket_spec(p7_socket));
+ wi_p7_socket_write_message(p7_socket, timeout, p7_message);
+
+ return false;
+ }
+
+ p7_message = wi_p7_message_with_name(WI_STR("p7.encryption.acknowledge"), wi_p7_socket_spec(p7_socket));
+
+ if(!p7_message)
+ return false;
+
+ data = wi_cipher_encrypt(p7_socket->cipher, wi_string_data(server_password2));
+
+ if(!data)
+ return false;
+
+ if(!wi_p7_message_set_data_for_name(p7_message, data, WI_STR("p7.encryption.server_password")))
+ return false;
+
+ if(!wi_p7_socket_write_message(p7_socket, timeout, p7_message))
+ return false;
+
+ p7_socket->encryption_enabled = true;
+
+ return true;
}
static wi_boolean_t _wi_p7_password_is_equal(wi_string_t *password1, wi_string_t *password2) {
- const char *cstring1, *cstring2;
- wi_uinteger_t length1, length2, i;
- wi_boolean_t result;
-
- length1 = wi_string_length(password1);
- length2 = wi_string_length(password2);
-
- if(length1 != length2)
- return false;
-
- cstring1 = wi_string_cstring(password1);
- cstring2 = wi_string_cstring(password2);
- result = true;
-
- for(i = 0; i < length1; i++) {
- if(cstring1[i] != cstring2[i])
- result = false;
- }
-
- return result;
+ const char *cstring1, *cstring2;
+ wi_uinteger_t length1, length2, i;
+ wi_boolean_t result;
+
+ length1 = wi_string_length(password1);
+ length2 = wi_string_length(password2);
+
+ if(length1 != length2)
+ return false;
+
+ cstring1 = wi_string_cstring(password1);
+ cstring2 = wi_string_cstring(password2);
+ result = true;
+
+ for(i = 0; i < length1; i++) {
+ if(cstring1[i] != cstring2[i])
+ result = false;
+ }
+
+ return result;
}
#endif
@@ -1051,115 +1187,115 @@ static wi_boolean_t _wi_p7_password_is_equal(wi_string_t *password1, wi_string_t
static wi_boolean_t _wi_p7_socket_send_compatibility_check(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout) {
- wi_p7_message_t *p7_message;
- wi_p7_boolean_t status;
-
- p7_message = wi_p7_message_with_name(WI_STR("p7.compatibility_check.specification"), wi_p7_socket_spec(p7_socket));
-
- if(!p7_message)
- return false;
-
- if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_xml(p7_socket->spec), WI_STR("p7.compatibility_check.specification")))
- return false;
-
- if(!wi_p7_socket_write_message(p7_socket, timeout, p7_message))
- return false;
-
- p7_message = wi_p7_socket_read_message(p7_socket, timeout);
-
- if(!p7_message)
- return false;
-
- if(!wi_is_equal(p7_message->name, WI_STR("p7.compatibility_check.status"))) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Message should be \"p7.compatibility_check.status\", not \"%@\""),
- p7_message->name);
-
- return false;
- }
-
- if(!wi_p7_message_get_bool_for_name(p7_message, &status, WI_STR("p7.compatibility_check.status"))) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Message has no \"p7.compatibility_check.status\" field"));
-
- return false;
- }
-
- if(!status) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
- WI_STR("Remote protocol %@ %@ is not compatible with local protocol %@ %@"),
- p7_socket->remote_name,
- p7_socket->remote_version,
- wi_p7_spec_name(p7_socket->spec),
- wi_p7_spec_version(p7_socket->spec));
- }
-
- return status;
+ wi_p7_message_t *p7_message;
+ wi_p7_boolean_t status;
+
+ p7_message = wi_p7_message_with_name(WI_STR("p7.compatibility_check.specification"), wi_p7_socket_spec(p7_socket));
+
+ if(!p7_message)
+ return false;
+
+ if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_xml(p7_socket->spec), WI_STR("p7.compatibility_check.specification")))
+ return false;
+
+ if(!wi_p7_socket_write_message(p7_socket, timeout, p7_message))
+ return false;
+
+ p7_message = wi_p7_socket_read_message(p7_socket, timeout);
+
+ if(!p7_message)
+ return false;
+
+ if(!wi_is_equal(p7_message->name, WI_STR("p7.compatibility_check.status"))) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Message should be \"p7.compatibility_check.status\", not \"%@\""),
+ p7_message->name);
+
+ return false;
+ }
+
+ if(!wi_p7_message_get_bool_for_name(p7_message, &status, WI_STR("p7.compatibility_check.status"))) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Message has no \"p7.compatibility_check.status\" field"));
+
+ return false;
+ }
+
+ if(!status) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
+ WI_STR("Remote protocol %@ %@ is not compatible with local protocol %@ %@"),
+ p7_socket->remote_name,
+ p7_socket->remote_version,
+ wi_p7_spec_name(p7_socket->spec),
+ wi_p7_spec_version(p7_socket->spec));
+ }
+
+ return status;
}
static wi_boolean_t _wi_p7_socket_receive_compatibility_check(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout) {
- wi_string_t *string;
- wi_p7_message_t *p7_message;
- wi_p7_spec_t *p7_spec;
- wi_boolean_t compatible;
-
- p7_message = wi_p7_socket_read_message(p7_socket, timeout);
-
- if(!p7_message)
- return false;
-
- if(!wi_is_equal(p7_message->name, WI_STR("p7.compatibility_check.specification"))) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Message should be \"p7.compatibility_check.specification\", not \"%@\""),
- p7_message->name);
-
- return false;
- }
-
- string = wi_p7_message_string_for_name(p7_message, WI_STR("p7.compatibility_check.specification"));
-
- if(!string) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Message has no \"p7.compatibility_check.specification\" field"));
-
- return false;
- }
-
- p7_spec = wi_autorelease(wi_p7_spec_init_with_string(wi_p7_spec_alloc(), string,
- wi_p7_spec_opposite_originator(wi_p7_spec_originator(p7_socket->spec))));
-
- if(!p7_spec)
- return false;
-
- compatible = wi_p7_spec_is_compatible_with_spec(p7_socket->spec, p7_spec);
-
- if(compatible) {
- p7_socket->merged_spec = wi_copy(p7_socket->spec);
-
- wi_p7_spec_merge_with_spec(p7_socket->merged_spec, p7_spec);
- } else {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
- WI_STR("Remote protocol %@ %@ is not compatible with local protocol %@ %@: %m"),
- p7_socket->remote_name,
- p7_socket->remote_version,
- wi_p7_spec_name(p7_socket->spec),
- wi_p7_spec_version(p7_socket->spec));
- }
-
- p7_message = wi_p7_message_with_name(WI_STR("p7.compatibility_check.status"), wi_p7_socket_spec(p7_socket));
-
- if(!p7_message)
- return false;
-
- if(!wi_p7_message_set_bool_for_name(p7_message, compatible, WI_STR("p7.compatibility_check.status")))
- return false;
-
- if(!wi_p7_socket_write_message(p7_socket, timeout, p7_message))
- return false;
-
- return compatible;
+ wi_string_t *string;
+ wi_p7_message_t *p7_message;
+ wi_p7_spec_t *p7_spec;
+ wi_boolean_t compatible;
+
+ p7_message = wi_p7_socket_read_message(p7_socket, timeout);
+
+ if(!p7_message)
+ return false;
+
+ if(!wi_is_equal(p7_message->name, WI_STR("p7.compatibility_check.specification"))) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Message should be \"p7.compatibility_check.specification\", not \"%@\""),
+ p7_message->name);
+
+ return false;
+ }
+
+ string = wi_p7_message_string_for_name(p7_message, WI_STR("p7.compatibility_check.specification"));
+
+ if(!string) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Message has no \"p7.compatibility_check.specification\" field"));
+
+ return false;
+ }
+
+ p7_spec = wi_autorelease(wi_p7_spec_init_with_string(wi_p7_spec_alloc(), string,
+ wi_p7_spec_opposite_originator(wi_p7_spec_originator(p7_socket->spec))));
+
+ if(!p7_spec)
+ return false;
+
+ compatible = wi_p7_spec_is_compatible_with_spec(p7_socket->spec, p7_spec);
+
+ if(compatible) {
+ p7_socket->merged_spec = wi_copy(p7_socket->spec);
+
+ wi_p7_spec_merge_with_spec(p7_socket->merged_spec, p7_spec);
+ } else {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
+ WI_STR("Remote protocol %@ %@ is not compatible with local protocol %@ %@: %m"),
+ p7_socket->remote_name,
+ p7_socket->remote_version,
+ wi_p7_spec_name(p7_socket->spec),
+ wi_p7_spec_version(p7_socket->spec));
+ }
+
+ p7_message = wi_p7_message_with_name(WI_STR("p7.compatibility_check.status"), wi_p7_socket_spec(p7_socket));
+
+ if(!p7_message)
+ return false;
+
+ if(!wi_p7_message_set_bool_for_name(p7_message, compatible, WI_STR("p7.compatibility_check.status")))
+ return false;
+
+ if(!wi_p7_socket_write_message(p7_socket, timeout, p7_message))
+ return false;
+
+ return compatible;
}
@@ -1167,222 +1303,215 @@ static wi_boolean_t _wi_p7_socket_receive_compatibility_check(wi_p7_socket_t *p7
#pragma mark -
static wi_boolean_t _wi_p7_socket_write_binary_message(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout, wi_p7_message_t *p7_message) {
- const void *send_buffer;
- char length_buffer[_WI_P7_SOCKET_LENGTH_SIZE];
- unsigned char checksum_buffer[_WI_P7_CHECKSUM_OPTIONS_TO_LENGTH(p7_socket->options)];
- wi_integer_t compressed_size;
+ const void *send_buffer;
+ char length_buffer[_WI_P7_SOCKET_LENGTH_SIZE];
+ unsigned char checksum_buffer[_WI_P7_CHECKSUM_OPTIONS_TO_LENGTH(p7_socket->options)];
+ wi_integer_t compressed_size;
#ifdef WI_RSA
- wi_integer_t encrypted_size;
-#endif
- uint32_t send_size;
-
- send_size = p7_message->binary_size;
- send_buffer = p7_message->binary_buffer;
-
- p7_socket->sent_raw_bytes += send_size;
-
- if(p7_socket->compression_enabled) {
- compressed_size = _wi_p7_socket_deflate(p7_socket, send_buffer, send_size);
-
- if(compressed_size < 0)
- return false;
-
- send_size = compressed_size;
- send_buffer = p7_socket->compression_buffer;
- }
-
+ wi_integer_t encrypted_size;
+#endif
+ uint32_t send_size;
+
+ send_size = p7_message->binary_size;
+ send_buffer = p7_message->binary_buffer;
+
+ p7_socket->sent_raw_bytes += send_size;
+
+ if(p7_socket->compression_enabled) {
+ compressed_size = _wi_p7_socket_deflate(p7_socket, send_buffer, send_size);
+
+ if(compressed_size < 0)
+ return false;
+
+ send_size = compressed_size;
+ send_buffer = p7_socket->compression_buffer;
+ }
+
#ifdef WI_RSA
- if(p7_socket->encryption_enabled) {
- encrypted_size = send_size + wi_cipher_block_size(p7_socket->cipher);
-
- if(!p7_socket->encryption_buffer) {
- p7_socket->encryption_buffer_length = encrypted_size;
- p7_socket->encryption_buffer = wi_malloc(p7_socket->encryption_buffer_length);
- }
- else if((wi_uinteger_t) encrypted_size > p7_socket->encryption_buffer_length) {
- p7_socket->encryption_buffer_length = encrypted_size * 2;
- p7_socket->encryption_buffer = wi_realloc(p7_socket->encryption_buffer, p7_socket->encryption_buffer_length);
- }
-
- encrypted_size = wi_cipher_encrypt_bytes(p7_socket->cipher,
- send_buffer,
- send_size,
- p7_socket->encryption_buffer);
-
- if(encrypted_size < 0)
- return false;
-
- send_size = encrypted_size;
- send_buffer = p7_socket->encryption_buffer;
- }
+ if(p7_socket->encryption_enabled) {
+ encrypted_size = send_size + wi_cipher_block_size(p7_socket->cipher);
+
+ if(!p7_socket->encryption_buffer) {
+ p7_socket->encryption_buffer_length = encrypted_size;
+ p7_socket->encryption_buffer = wi_malloc(p7_socket->encryption_buffer_length);
+ }
+ else if((wi_uinteger_t) encrypted_size > p7_socket->encryption_buffer_length) {
+ p7_socket->encryption_buffer_length = encrypted_size * 2;
+ p7_socket->encryption_buffer = wi_realloc(p7_socket->encryption_buffer, p7_socket->encryption_buffer_length);
+ }
+
+ encrypted_size = wi_cipher_encrypt_bytes(p7_socket->cipher,
+ send_buffer,
+ send_size,
+ p7_socket->encryption_buffer);
+
+ if(encrypted_size < 0)
+ return false;
+
+ send_size = encrypted_size;
+ send_buffer = p7_socket->encryption_buffer;
+ }
#endif
- p7_socket->sent_processed_bytes += send_size;
-
- wi_write_swap_host_to_big_int32(length_buffer, 0, send_size);
-
- if(wi_socket_write_buffer(p7_socket->socket, timeout, length_buffer, sizeof(length_buffer)) < 0)
- return false;
-
- if(wi_socket_write_buffer(p7_socket->socket, timeout, send_buffer, send_size) < 0)
- return false;
-
- if(p7_socket->checksum_enabled) {
- _wi_p7_socket_checksum_binary_message(p7_socket, p7_message, checksum_buffer);
-
- if(wi_socket_write_buffer(p7_socket->socket, timeout, checksum_buffer, p7_socket->checksum_length) < 0)
- return false;
- }
-
- return true;
+ p7_socket->sent_processed_bytes += send_size;
+
+ wi_write_swap_host_to_big_int32(length_buffer, 0, send_size);
+
+ if(wi_socket_write_buffer(p7_socket->socket, timeout, length_buffer, sizeof(length_buffer)) < 0)
+ return false;
+
+ if(wi_socket_write_buffer(p7_socket->socket, timeout, send_buffer, send_size) < 0)
+ return false;
+
+ if(p7_socket->checksum_enabled) {
+ _wi_p7_socket_checksum_binary_message(p7_socket, p7_message, checksum_buffer);
+
+ if(wi_socket_write_buffer(p7_socket->socket, timeout, checksum_buffer, p7_socket->checksum_length) < 0)
+ return false;
+ }
+
+ return true;
}
static wi_boolean_t _wi_p7_socket_write_xml_message(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout, wi_p7_message_t *p7_message) {
- if(wi_socket_write_format(p7_socket->socket, timeout, WI_STR("%s\r\n"), p7_message->xml_buffer) < 0)
- return false;
-
- p7_socket->sent_raw_bytes += p7_message->xml_length;
- p7_socket->sent_processed_bytes += p7_message->xml_length;
-
- return true;
+ if(wi_socket_write_format(p7_socket->socket, timeout, WI_STR("%s\r\n"), p7_message->xml_buffer) < 0)
+ return false;
+
+ p7_socket->sent_raw_bytes += p7_message->xml_length;
+ p7_socket->sent_processed_bytes += p7_message->xml_length;
+
+ return true;
}
static wi_p7_message_t * _wi_p7_socket_read_binary_message(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout, uint32_t message_size) {
- wi_p7_message_t *p7_message;
- unsigned char local_checksum_buffer[_WI_P7_CHECKSUM_OPTIONS_TO_LENGTH(p7_socket->options)];
- unsigned char remote_checksum_buffer[_WI_P7_CHECKSUM_OPTIONS_TO_LENGTH(p7_socket->options)];
- wi_integer_t decompressed_size;
+ wi_p7_message_t *p7_message;
+ unsigned char local_checksum_buffer[_WI_P7_CHECKSUM_OPTIONS_TO_LENGTH(p7_socket->options)];
+ unsigned char remote_checksum_buffer[_WI_P7_CHECKSUM_OPTIONS_TO_LENGTH(p7_socket->options)];
+ wi_integer_t decompressed_size;
#ifdef WI_RSA
- wi_integer_t decrypted_size;
+ wi_integer_t decrypted_size;
#endif
- int32_t length;
-
- if(message_size > _WI_P7_SOCKET_MAX_BINARY_SIZE) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_MESSAGETOOLARGE,
- WI_STR("%u bytes"), message_size);
-
- return NULL;
- }
-
- p7_message = wi_autorelease(wi_p7_message_init(wi_p7_message_alloc(), p7_socket->merged_spec ? p7_socket->merged_spec : p7_socket->spec));
- p7_message->binary_capacity = message_size;
- p7_message->binary_buffer = wi_malloc(p7_message->binary_capacity);
-
- length = wi_socket_read_buffer(p7_socket->socket, timeout, p7_message->binary_buffer, message_size);
-
- if(length <= 0)
- return NULL;
-
- p7_message->binary_size = length;
- p7_socket->message_binary_size = 0;
- p7_socket->read_raw_bytes += p7_message->binary_size;
+ int32_t length;
+
+ if(message_size > _WI_P7_SOCKET_MAX_BINARY_SIZE) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_MESSAGETOOLARGE,
+ WI_STR("%u bytes"), message_size);
+
+ return NULL;
+ }
+
+ p7_message = wi_autorelease(wi_p7_message_init(wi_p7_message_alloc(), p7_socket->merged_spec ? p7_socket->merged_spec : p7_socket->spec));
+ p7_message->binary_capacity = message_size;
+ p7_message->binary_buffer = wi_malloc(p7_message->binary_capacity);
+
+ length = wi_socket_read_buffer(p7_socket->socket, timeout, p7_message->binary_buffer, message_size);
+
+ if(length <= 0)
+ return NULL;
+
+ p7_message->binary_size = length;
+ p7_socket->message_binary_size = 0;
+ p7_socket->read_raw_bytes += p7_message->binary_size;
#ifdef WI_RSA
- if(p7_socket->encryption_enabled) {
- //printf("wi_cipher_block_size: %d\n", (int)wi_cipher_block_size(p7_socket->cipher));
-
- decrypted_size = p7_message->binary_size + wi_cipher_block_size(p7_socket->cipher);
-
- if(!p7_socket->decryption_buffer) {
- p7_socket->decryption_buffer_length = decrypted_size;
- p7_socket->decryption_buffer = wi_malloc(p7_socket->decryption_buffer_length);
- }
- else if((wi_uinteger_t) decrypted_size > p7_socket->decryption_buffer_length) {
- p7_socket->decryption_buffer_length = decrypted_size * 2;
- p7_socket->decryption_buffer = wi_realloc(p7_socket->decryption_buffer, p7_socket->decryption_buffer_length);
- }
-
- decrypted_size = wi_cipher_decrypt_bytes(p7_socket->cipher,
- p7_message->binary_buffer,
- p7_message->binary_size,
- p7_socket->decryption_buffer);
-
- if(decrypted_size < 0)
- return NULL;
-
- if((wi_uinteger_t) decrypted_size > p7_message->binary_capacity) {
- p7_message->binary_capacity = decrypted_size;
- p7_message->binary_buffer = wi_realloc(p7_message->binary_buffer, p7_message->binary_capacity);
- }
-
- memcpy(p7_message->binary_buffer, p7_socket->decryption_buffer, decrypted_size);
-
- p7_message->binary_size = decrypted_size;
- }
+ if(p7_socket->encryption_enabled) {
+ decrypted_size = p7_message->binary_size + wi_cipher_block_size(p7_socket->cipher);
+
+ if(!p7_socket->decryption_buffer) {
+ p7_socket->decryption_buffer_length = decrypted_size;
+ p7_socket->decryption_buffer = wi_malloc(p7_socket->decryption_buffer_length);
+ }
+ else if((wi_uinteger_t) decrypted_size > p7_socket->decryption_buffer_length) {
+ p7_socket->decryption_buffer_length = decrypted_size * 2;
+ p7_socket->decryption_buffer = wi_realloc(p7_socket->decryption_buffer, p7_socket->decryption_buffer_length);
+ }
+
+ decrypted_size = wi_cipher_decrypt_bytes(p7_socket->cipher,
+ p7_message->binary_buffer,
+ p7_message->binary_size,
+ p7_socket->decryption_buffer);
+
+ if(decrypted_size < 0)
+ return NULL;
+
+ if((wi_uinteger_t) decrypted_size > p7_message->binary_capacity) {
+ p7_message->binary_capacity = decrypted_size;
+ p7_message->binary_buffer = wi_realloc(p7_message->binary_buffer, p7_message->binary_capacity);
+ }
+
+ memcpy(p7_message->binary_buffer, p7_socket->decryption_buffer, decrypted_size);
+
+ p7_message->binary_size = decrypted_size;
+ }
#endif
-
- if(p7_socket->compression_enabled) {
- decompressed_size = _wi_p7_socket_inflate(p7_socket, p7_message->binary_buffer, p7_message->binary_size);
-
- if(decompressed_size < 0)
- return NULL;
-
- if((wi_uinteger_t) decompressed_size > p7_message->binary_capacity) {
- p7_message->binary_capacity = decompressed_size;
- p7_message->binary_buffer = wi_realloc(p7_message->binary_buffer, p7_message->binary_capacity);
- }
-
- memcpy(p7_message->binary_buffer, p7_socket->compression_buffer, decompressed_size);
-
- p7_message->binary_size = decompressed_size;
- }
-
- // for(int i = 0; i < 1024; i++) {
- // printf("%02x", p7_message->binary_buffer[i]);
- // }
- // printf("\n\n");
-
- p7_socket->read_processed_bytes += p7_message->binary_size;
-
- if(p7_socket->checksum_enabled) {
- length = wi_socket_read_buffer(p7_socket->socket, timeout, remote_checksum_buffer, p7_socket->checksum_length);
-
- if(length <= 0)
- return NULL;
-
- _wi_p7_socket_checksum_binary_message(p7_socket, p7_message, local_checksum_buffer);
-
- if(memcmp(remote_checksum_buffer, local_checksum_buffer, p7_socket->checksum_length) != 0) {
- wi_error_set_libwired_error(WI_ERROR_P7_CHECKSUMMISMATCH);
-
- return NULL;
- }
- }
-
- return p7_message;
+
+ if(p7_socket->compression_enabled) {
+ decompressed_size = _wi_p7_socket_inflate(p7_socket, p7_message->binary_buffer, p7_message->binary_size);
+
+ if(decompressed_size < 0)
+ return NULL;
+
+ if((wi_uinteger_t) decompressed_size > p7_message->binary_capacity) {
+ p7_message->binary_capacity = decompressed_size;
+ p7_message->binary_buffer = wi_realloc(p7_message->binary_buffer, p7_message->binary_capacity);
+ }
+
+ memcpy(p7_message->binary_buffer, p7_socket->compression_buffer, decompressed_size);
+
+ p7_message->binary_size = decompressed_size;
+ }
+
+ p7_socket->read_processed_bytes += p7_message->binary_size;
+
+ if(p7_socket->checksum_enabled) {
+ length = wi_socket_read_buffer(p7_socket->socket, timeout, remote_checksum_buffer, p7_socket->checksum_length);
+
+ if(length <= 0)
+ return NULL;
+
+ _wi_p7_socket_checksum_binary_message(p7_socket, p7_message, local_checksum_buffer);
+
+ if(memcmp(remote_checksum_buffer, local_checksum_buffer, p7_socket->checksum_length) != 0) {
+ wi_error_set_libwired_error(WI_ERROR_P7_CHECKSUMMISMATCH);
+
+ return NULL;
+ }
+ }
+
+ return p7_message;
}
static wi_p7_message_t * _wi_p7_socket_read_xml_message(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout, wi_string_t *prefix) {
- wi_string_t *string;
- wi_p7_message_t *p7_message;
- wi_uinteger_t length;
-
- p7_message = wi_autorelease(wi_p7_message_init(wi_p7_message_alloc(), p7_socket->merged_spec ? p7_socket->merged_spec : p7_socket->spec));
-
- string = wi_socket_read_to_string(p7_socket->socket, timeout, WI_STR("\r\n"));
-
- if(!string || wi_string_length(string) == 0)
- return NULL;
-
- p7_message->xml_string = wi_mutable_copy(wi_string_by_deleting_surrounding_whitespace(string));
-
- if(prefix)
- wi_mutable_string_insert_string_at_index(p7_message->xml_string, prefix, 0);
-
- length = wi_string_length(p7_message->xml_string);
-
- p7_socket->read_raw_bytes += length;
- p7_socket->read_processed_bytes += length;
-
- wi_mutable_string_delete_surrounding_whitespace(p7_message->xml_string);
-
- return p7_message;
+ wi_string_t *string;
+ wi_p7_message_t *p7_message;
+ wi_uinteger_t length;
+
+ p7_message = wi_autorelease(wi_p7_message_init(wi_p7_message_alloc(), p7_socket->merged_spec ? p7_socket->merged_spec : p7_socket->spec));
+
+ string = wi_socket_read_to_string(p7_socket->socket, timeout, WI_STR("\r\n"));
+
+ if(!string || wi_string_length(string) == 0)
+ return NULL;
+
+ p7_message->xml_string = wi_mutable_copy(wi_string_by_deleting_surrounding_whitespace(string));
+
+ if(prefix)
+ wi_mutable_string_insert_string_at_index(p7_message->xml_string, prefix, 0);
+
+ length = wi_string_length(p7_message->xml_string);
+
+ p7_socket->read_raw_bytes += length;
+ p7_socket->read_processed_bytes += length;
+
+ wi_mutable_string_delete_surrounding_whitespace(p7_message->xml_string);
+
+ return p7_message;
}
@@ -1390,161 +1519,138 @@ static wi_p7_message_t * _wi_p7_socket_read_xml_message(wi_p7_socket_t *p7_socke
#pragma mark -
static wi_boolean_t _wi_p7_socket_configure_compression(wi_p7_socket_t *p7_socket) {
- int err;
-
- p7_socket->deflate_stream.data_type = Z_UNKNOWN;
-
- err = deflateInit(&p7_socket->deflate_stream, Z_DEFAULT_COMPRESSION);
-
- if(err != Z_OK) {
- wi_error_set_zlib_error(err);
-
- return false;
- }
-
- err = inflateInit(&p7_socket->inflate_stream);
-
- if(err != Z_OK) {
- wi_error_set_zlib_error(err);
-
- return false;
- }
-
- p7_socket->compression_enabled = true;
-
- return true;
+ int err;
+
+ p7_socket->deflate_stream.data_type = Z_UNKNOWN;
+
+ err = deflateInit(&p7_socket->deflate_stream, Z_DEFAULT_COMPRESSION);
+
+ if(err != Z_OK) {
+ wi_error_set_zlib_error(err);
+
+ return false;
+ }
+
+ err = inflateInit(&p7_socket->inflate_stream);
+
+ if(err != Z_OK) {
+ wi_error_set_zlib_error(err);
+
+ return false;
+ }
+
+ p7_socket->compression_enabled = true;
+
+ return true;
}
static wi_integer_t _wi_p7_socket_deflate(wi_p7_socket_t *p7_socket, const void *in_buffer, uint32_t in_size) {
- wi_integer_t bytes;
- size_t length;
- int err, enderr;
-
- length = (in_size * 2) + 16;
-
- if(!p7_socket->compression_buffer) {
- p7_socket->compression_buffer = wi_malloc(length);
- p7_socket->compression_buffer_length = length;
- }
- else if(p7_socket->compression_buffer_length < length) {
- p7_socket->compression_buffer = wi_realloc(p7_socket->compression_buffer, length);
- p7_socket->compression_buffer_length = length;
- }
-
- p7_socket->deflate_stream.next_in = (unsigned char *) in_buffer;
- p7_socket->deflate_stream.avail_in = in_size;
- p7_socket->deflate_stream.next_out = p7_socket->compression_buffer;
- p7_socket->deflate_stream.avail_out = p7_socket->compression_buffer_length;
-
- err = deflate(&p7_socket->deflate_stream, Z_FINISH);
- bytes = p7_socket->deflate_stream.total_out;
- enderr = deflateReset(&p7_socket->deflate_stream);
-
- if(err != Z_STREAM_END) {
- if(err == Z_OK)
- wi_error_set_zlib_error(Z_BUF_ERROR);
- else
- wi_error_set_zlib_error(err);
-
- return -1;
- }
-
- if(enderr != Z_OK) {
- wi_error_set_zlib_error(err);
-
- return -1;
- }
-
- return bytes;
+ wi_integer_t bytes;
+ size_t length;
+ int err, enderr;
+
+ length = (in_size * 2) + 16;
+
+ if(!p7_socket->compression_buffer) {
+ p7_socket->compression_buffer = wi_malloc(length);
+ p7_socket->compression_buffer_length = length;
+ }
+ else if(p7_socket->compression_buffer_length < length) {
+ p7_socket->compression_buffer = wi_realloc(p7_socket->compression_buffer, length);
+ p7_socket->compression_buffer_length = length;
+ }
+
+ p7_socket->deflate_stream.next_in = (unsigned char *) in_buffer;
+ p7_socket->deflate_stream.avail_in = in_size;
+ p7_socket->deflate_stream.next_out = p7_socket->compression_buffer;
+ p7_socket->deflate_stream.avail_out = p7_socket->compression_buffer_length;
+
+ err = deflate(&p7_socket->deflate_stream, Z_FINISH);
+ bytes = p7_socket->deflate_stream.total_out;
+ enderr = deflateReset(&p7_socket->deflate_stream);
+
+ if(err != Z_STREAM_END) {
+ if(err == Z_OK)
+ wi_error_set_zlib_error(Z_BUF_ERROR);
+ else
+ wi_error_set_zlib_error(err);
+
+ return -1;
+ }
+
+ if(enderr != Z_OK) {
+ wi_error_set_zlib_error(err);
+
+ return -1;
+ }
+
+ return bytes;
}
static wi_integer_t _wi_p7_socket_inflate(wi_p7_socket_t *p7_socket, const void *in_buffer, uint32_t in_size) {
- wi_uinteger_t multiple, bytes;
- int err, enderr;
-
- for(multiple = 2; multiple < 16; multiple++) {
- p7_socket->compression_buffer_length = in_size * (1 << multiple);
-
- if(!p7_socket->compression_buffer)
- p7_socket->compression_buffer = wi_malloc(p7_socket->compression_buffer_length);
- else
- p7_socket->compression_buffer = wi_realloc(p7_socket->compression_buffer, p7_socket->compression_buffer_length);
-
- p7_socket->inflate_stream.next_in = (unsigned char *) in_buffer;
- p7_socket->inflate_stream.avail_in = in_size;
- p7_socket->inflate_stream.next_out = (unsigned char *) p7_socket->compression_buffer;
- p7_socket->inflate_stream.avail_out = p7_socket->compression_buffer_length;
-
- err = inflate(&p7_socket->inflate_stream, Z_FINISH);
- bytes = p7_socket->inflate_stream.total_out;
- enderr = inflateReset(&p7_socket->inflate_stream);
-
- if(err == Z_STREAM_END && enderr != Z_BUF_ERROR)
- break;
- }
-
- return bytes;
+ wi_uinteger_t multiple, bytes;
+ int err, enderr;
+
+ for(multiple = 2; multiple < 16; multiple++) {
+ p7_socket->compression_buffer_length = in_size * (1 << multiple);
+
+ if(!p7_socket->compression_buffer)
+ p7_socket->compression_buffer = wi_malloc(p7_socket->compression_buffer_length);
+ else
+ p7_socket->compression_buffer = wi_realloc(p7_socket->compression_buffer, p7_socket->compression_buffer_length);
+
+ p7_socket->inflate_stream.next_in = (unsigned char *) in_buffer;
+ p7_socket->inflate_stream.avail_in = in_size;
+ p7_socket->inflate_stream.next_out = (unsigned char *) p7_socket->compression_buffer;
+ p7_socket->inflate_stream.avail_out = p7_socket->compression_buffer_length;
+
+ err = inflate(&p7_socket->inflate_stream, Z_FINISH);
+ bytes = p7_socket->inflate_stream.total_out;
+ enderr = inflateReset(&p7_socket->inflate_stream);
+
+ if(err == Z_STREAM_END && enderr != Z_BUF_ERROR)
+ break;
+ }
+
+ return bytes;
}
#pragma mark -
-static void _wi_p7_socket_configure_checksum(wi_p7_socket_t *p7_socket) {
- if(p7_socket->options & WI_P7_CHECKSUM_SHA1) {
- p7_socket->checksum_length = WI_SHA1_DIGEST_LENGTH;
-
- p7_socket->checksum_enabled = true;
- }
- else if(p7_socket->options & WI_P7_CHECKSUM_SHA256) {
- p7_socket->checksum_length = WI_SHA256_DIGEST_LENGTH;
-
- p7_socket->checksum_enabled = true;
- }
+static void _wi_p7_socket_configure_checksum(wi_p7_socket_t *p7_socket) {
+ if(p7_socket->options & WI_P7_CHECKSUM_SHA1)
+ p7_socket->checksum_length = WI_SHA1_DIGEST_LENGTH;
+
+ else if(p7_socket->options & WI_P7_CHECKSUM_SHA256)
+ p7_socket->checksum_length = WI_SHA256_DIGEST_LENGTH;
+
+ else if(p7_socket->options & WI_P7_CHECKSUM_SHA512)
+ p7_socket->checksum_length = WI_SHA512_DIGEST_LENGTH;
+
+ p7_socket->checksum_enabled = true;
}
static void _wi_p7_socket_checksum_binary_message(wi_p7_socket_t *p7_socket, wi_p7_message_t *p7_message, void *out_buffer) {
- _wi_p7_socket_checksum_buffer(p7_socket, p7_message->binary_buffer, p7_message->binary_size, out_buffer);
+ _wi_p7_socket_checksum_buffer(p7_socket, p7_message->binary_buffer, p7_message->binary_size, out_buffer);
}
static void _wi_p7_socket_checksum_buffer(wi_p7_socket_t *p7_socket, const void *buffer, uint32_t size, void *out_buffer) {
- if(p7_socket->options & WI_P7_CHECKSUM_SHA1)
- wi_sha1_digest(buffer, size, out_buffer);
-
- else if(p7_socket->options & WI_P7_CHECKSUM_SHA256)
- wi_sha256_digest(buffer, size, out_buffer);
-}
-
-
-
-static wi_string_t * _wi_p7_socket_string_checksum(wi_p7_socket_t *p7_socket, wi_string_t *string) {
- if(p7_socket->options & WI_P7_CHECKSUM_SHA1)
- return wi_string_sha1(string);
-
- else if(p7_socket->options & WI_P7_CHECKSUM_SHA256)
- return wi_string_sha256(string);
-
- return wi_string_sha1(string);
-}
-
-
-
-static wi_string_t * _wi_p7_socket_data_checksum(wi_p7_socket_t *p7_socket, wi_data_t *data) {
- if(p7_socket->options & WI_P7_CHECKSUM_SHA1)
- return wi_data_sha1(data);
-
- else if(p7_socket->options & WI_P7_CHECKSUM_SHA256)
- return wi_data_sha256(data);
-
- return wi_data_sha1(data);
+ if(p7_socket->options & WI_P7_CHECKSUM_SHA1)
+ wi_sha1_digest(buffer, size, out_buffer);
+ else if(p7_socket->options & WI_P7_CHECKSUM_SHA256)
+ wi_sha256_digest(buffer, size, out_buffer);
+ else if(p7_socket->options & WI_P7_CHECKSUM_SHA512)
+ wi_sha512_digest(buffer, size, out_buffer);
}
@@ -1552,7 +1658,7 @@ static wi_string_t * _wi_p7_socket_data_checksum(wi_p7_socket_t *p7_socket, wi_d
#pragma mark -
wi_boolean_t wi_p7_socket_verify_message(wi_p7_socket_t *p7_socket, wi_p7_message_t *p7_message) {
- return wi_p7_spec_verify_message(p7_socket->merged_spec ? p7_socket->merged_spec : p7_socket->spec, p7_message);
+ return wi_p7_spec_verify_message(p7_socket->merged_spec ? p7_socket->merged_spec : p7_socket->spec, p7_message);
}
@@ -1560,72 +1666,71 @@ wi_boolean_t wi_p7_socket_verify_message(wi_p7_socket_t *p7_socket, wi_p7_messag
#pragma mark -
wi_boolean_t wi_p7_socket_connect(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout, wi_uinteger_t options, wi_p7_serialization_t serialization, wi_string_t *username, wi_string_t *password) {
- p7_socket->serialization = serialization;
-
- if(!_wi_p7_socket_connect_handshake(p7_socket, timeout, options))
- return false;
-
- if(WI_P7_COMPRESSION_ENABLED(p7_socket->options)) {
- if(!_wi_p7_socket_configure_compression(p7_socket))
- return false;
- }
-
- if(WI_P7_CHECKSUM_ENABLED(p7_socket->options))
- _wi_p7_socket_configure_checksum(p7_socket);
-
-
+ p7_socket->serialization = serialization;
+
+ if(!_wi_p7_socket_connect_handshake(p7_socket, timeout, options))
+ return false;
+
+ if(WI_P7_COMPRESSION_ENABLED(p7_socket->options)) {
+ if(!_wi_p7_socket_configure_compression(p7_socket))
+ return false;
+ }
+
+ if(WI_P7_CHECKSUM_ENABLED(p7_socket->options))
+ _wi_p7_socket_configure_checksum(p7_socket);
+
#ifdef WI_RSA
- if(WI_P7_ENCRYPTION_ENABLED(p7_socket->options)) {
- if(!_wi_p7_socket_connect_key_exchange(p7_socket, timeout, username, password))
- return false;
- }
+ if(WI_P7_ENCRYPTION_ENABLED(p7_socket->options)) {
+ if(!_wi_p7_socket_connect_key_exchange(p7_socket, timeout, username, password))
+ return false;
+ }
#endif
- if(p7_socket->remote_compatibility_check) {
- if(!_wi_p7_socket_send_compatibility_check(p7_socket, timeout))
- return false;
- }
-
- if(p7_socket->local_compatibility_check) {
- if(!_wi_p7_socket_receive_compatibility_check(p7_socket, timeout))
- return false;
- }
-
- return true;
+ if(p7_socket->remote_compatibility_check) {
+ if(!_wi_p7_socket_send_compatibility_check(p7_socket, timeout))
+ return false;
+ }
+
+ if(p7_socket->local_compatibility_check) {
+ if(!_wi_p7_socket_receive_compatibility_check(p7_socket, timeout))
+ return false;
+ }
+
+ return true;
}
wi_boolean_t wi_p7_socket_accept(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout, wi_uinteger_t options) {
- if(!_wi_p7_socket_accept_handshake(p7_socket, timeout, options))
- return false;
-
- if(WI_P7_COMPRESSION_ENABLED(p7_socket->options)) {
- if(!_wi_p7_socket_configure_compression(p7_socket))
- return false;
- }
-
- if(WI_P7_CHECKSUM_ENABLED(p7_socket->options))
- _wi_p7_socket_configure_checksum(p7_socket);
-
+ if(!_wi_p7_socket_accept_handshake(p7_socket, timeout, options))
+ return false;
+
+ if(WI_P7_COMPRESSION_ENABLED(p7_socket->options)) {
+ if(!_wi_p7_socket_configure_compression(p7_socket))
+ return false;
+ }
+
+ if(WI_P7_CHECKSUM_ENABLED(p7_socket->options))
+ _wi_p7_socket_configure_checksum(p7_socket);
+
#ifdef WI_RSA
- if(WI_P7_ENCRYPTION_ENABLED(p7_socket->options)) {
- if(!_wi_p7_socket_accept_key_exchange(p7_socket, timeout))
- return false;
- }
+ if(WI_P7_ENCRYPTION_ENABLED(p7_socket->options)) {
+ if(!_wi_p7_socket_accept_key_exchange(p7_socket, timeout))
+ return false;
+ }
#endif
-
- if(p7_socket->local_compatibility_check) {
- if(!_wi_p7_socket_receive_compatibility_check(p7_socket, timeout))
- return false;
- }
-
- if(p7_socket->remote_compatibility_check) {
- if(!_wi_p7_socket_send_compatibility_check(p7_socket, timeout))
- return false;
- }
-
- return true;
+
+ if(p7_socket->local_compatibility_check) {
+ if(!_wi_p7_socket_receive_compatibility_check(p7_socket, timeout))
+ return false;
+ }
+
+ if(p7_socket->remote_compatibility_check) {
+ if(!_wi_p7_socket_send_compatibility_check(p7_socket, timeout))
+ return false;
+ }
+
+ return true;
}
@@ -1638,267 +1743,267 @@ void wi_p7_socket_close(wi_p7_socket_t *p7_socket) {
#pragma mark -
wi_boolean_t wi_p7_socket_write_message(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout, wi_p7_message_t *p7_message) {
- wi_boolean_t result;
-
- wi_p7_message_serialize(p7_message, wi_p7_socket_serialization(p7_socket));
-
- if(wi_p7_socket_debug)
- wi_log_debug(WI_STR("Sending %@"), p7_message);
-
- if(p7_socket->serialization == WI_P7_BINARY)
- result = _wi_p7_socket_write_binary_message(p7_socket, timeout, p7_message);
- else
- result = _wi_p7_socket_write_xml_message(p7_socket, timeout, p7_message);
-
- if(!result)
- return false;
-
- if(wi_p7_socket_debug) {
- wi_log_debug(WI_STR("Sent %llu processed bytes, %llu raw bytes, compressed to %.2f%%"),
- p7_socket->sent_processed_bytes,
- p7_socket->sent_raw_bytes,
- ((double) p7_socket->sent_processed_bytes / (double) p7_socket->sent_raw_bytes) * 100.0);
- }
-
- if(p7_socket->wrote_message_callback)
- (*p7_socket->wrote_message_callback)(p7_socket, p7_message, p7_socket->wrote_message_context);
-
- return true;
+ wi_boolean_t result;
+
+ wi_p7_message_serialize(p7_message, wi_p7_socket_serialization(p7_socket));
+
+ if(wi_p7_socket_debug)
+ wi_log_debug(WI_STR("Sending %@"), p7_message);
+
+ if(p7_socket->serialization == WI_P7_BINARY)
+ result = _wi_p7_socket_write_binary_message(p7_socket, timeout, p7_message);
+ else
+ result = _wi_p7_socket_write_xml_message(p7_socket, timeout, p7_message);
+
+ if(!result)
+ return false;
+
+ if(wi_p7_socket_debug) {
+ wi_log_debug(WI_STR("Sent %llu processed bytes, %llu raw bytes, compressed to %.2f%%"),
+ p7_socket->sent_processed_bytes,
+ p7_socket->sent_raw_bytes,
+ ((double) p7_socket->sent_processed_bytes / (double) p7_socket->sent_raw_bytes) * 100.0);
+ }
+
+ if(p7_socket->wrote_message_callback)
+ (*p7_socket->wrote_message_callback)(p7_socket, p7_message, p7_socket->wrote_message_context);
+
+ return true;
}
wi_p7_message_t * wi_p7_socket_read_message(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout) {
- wi_p7_message_t *p7_message;
- wi_string_t *prefix = NULL;
- char length_buffer[_WI_P7_SOCKET_LENGTH_SIZE];
-
- if(p7_socket->serialization == WI_P7_UNKNOWN || p7_socket->serialization == WI_P7_BINARY) {
- if(p7_socket->message_binary_size == 0) {
- if(wi_socket_read_buffer(p7_socket->socket, timeout, length_buffer, sizeof(length_buffer)) <= 0)
- return NULL;
-
- p7_socket->message_binary_size = wi_read_swap_big_to_host_int32(length_buffer, 0);
- }
-
- if(p7_socket->serialization == WI_P7_UNKNOWN) {
- if(p7_socket->message_binary_size == _WI_P7_SOCKET_XML_MAGIC) {
- p7_socket->serialization = WI_P7_XML;
- prefix = WI_STR("message_binary_size < _WI_P7_SOCKET_MAX_BINARY_SIZE) {
- p7_socket->serialization = WI_P7_BINARY;
- }
- }
- }
-
- if(p7_socket->serialization == WI_P7_BINARY)
- p7_message = _wi_p7_socket_read_binary_message(p7_socket, timeout, p7_socket->message_binary_size);
- else if(p7_socket->serialization == WI_P7_XML)
- p7_message = _wi_p7_socket_read_xml_message(p7_socket, timeout, prefix);
- else {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
- WI_STR("Invalid data from remote host (%u doesn't look like a header)"),
- p7_socket->message_binary_size);
-
- return NULL;
- }
-
- if(!p7_message)
- return NULL;
-
- if(p7_socket->serialization == WI_P7_BINARY && p7_message->binary_size == 0) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDMESSAGE,
- WI_STR("Invalid data from remote host (%u doesn't look like a header)"),
- p7_socket->message_binary_size);
-
- return NULL;
- }
-
- wi_p7_message_deserialize(p7_message, p7_socket->serialization);
-
- if(wi_p7_socket_debug) {
- wi_log_debug(WI_STR("Received %@"), p7_message);
-
- wi_log_debug(WI_STR("Received %llu raw bytes, %llu processed bytes, compressed to %.2f%%"),
- p7_socket->read_raw_bytes,
- p7_socket->read_processed_bytes,
- ((double) p7_socket->read_raw_bytes / (double) p7_socket->read_processed_bytes) * 100.0);
- }
-
- if(p7_socket->read_message_callback)
- (*p7_socket->read_message_callback)(p7_socket, p7_message, p7_socket->read_message_context);
-
- return p7_message;
+ wi_p7_message_t *p7_message;
+ wi_string_t *prefix = NULL;
+ char length_buffer[_WI_P7_SOCKET_LENGTH_SIZE];
+
+ if(p7_socket->serialization == WI_P7_UNKNOWN || p7_socket->serialization == WI_P7_BINARY) {
+ if(p7_socket->message_binary_size == 0) {
+ if(wi_socket_read_buffer(p7_socket->socket, timeout, length_buffer, sizeof(length_buffer)) <= 0)
+ return NULL;
+
+ p7_socket->message_binary_size = wi_read_swap_big_to_host_int32(length_buffer, 0);
+ }
+
+ if(p7_socket->serialization == WI_P7_UNKNOWN) {
+ if(p7_socket->message_binary_size == _WI_P7_SOCKET_XML_MAGIC) {
+ p7_socket->serialization = WI_P7_XML;
+ prefix = WI_STR("message_binary_size < _WI_P7_SOCKET_MAX_BINARY_SIZE) {
+ p7_socket->serialization = WI_P7_BINARY;
+ }
+ }
+ }
+
+ if(p7_socket->serialization == WI_P7_BINARY)
+ p7_message = _wi_p7_socket_read_binary_message(p7_socket, timeout, p7_socket->message_binary_size);
+ else if(p7_socket->serialization == WI_P7_XML)
+ p7_message = _wi_p7_socket_read_xml_message(p7_socket, timeout, prefix);
+ else {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_HANDSHAKEFAILED,
+ WI_STR("Invalid data from remote host (%u doesn't look like a header)"),
+ p7_socket->message_binary_size);
+
+ return NULL;
+ }
+
+ if(!p7_message)
+ return NULL;
+
+ if(p7_socket->serialization == WI_P7_BINARY && p7_message->binary_size == 0) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDMESSAGE,
+ WI_STR("Invalid data from remote host (%u doesn't look like a header)"),
+ p7_socket->message_binary_size);
+
+ return NULL;
+ }
+
+ wi_p7_message_deserialize(p7_message, p7_socket->serialization);
+
+ if(wi_p7_socket_debug) {
+ wi_log_debug(WI_STR("Received %@"), p7_message);
+
+ wi_log_debug(WI_STR("Received %llu raw bytes, %llu processed bytes, compressed to %.2f%%"),
+ p7_socket->read_raw_bytes,
+ p7_socket->read_processed_bytes,
+ ((double) p7_socket->read_raw_bytes / (double) p7_socket->read_processed_bytes) * 100.0);
+ }
+
+ if(p7_socket->read_message_callback)
+ (*p7_socket->read_message_callback)(p7_socket, p7_message, p7_socket->read_message_context);
+
+ return p7_message;
}
wi_boolean_t wi_p7_socket_write_oobdata(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout, const void *buffer, uint32_t size) {
- const void *send_buffer;
- char length_buffer[_WI_P7_SOCKET_LENGTH_SIZE];
- unsigned char checksum_buffer[_WI_P7_CHECKSUM_OPTIONS_TO_LENGTH(p7_socket->options)];
- wi_integer_t compressed_size;
+ const void *send_buffer;
+ char length_buffer[_WI_P7_SOCKET_LENGTH_SIZE];
+ unsigned char checksum_buffer[_WI_P7_CHECKSUM_OPTIONS_TO_LENGTH(p7_socket->options)];
+ wi_integer_t compressed_size;
#ifdef WI_RSA
- wi_integer_t encrypted_size;
+ wi_integer_t encrypted_size;
#endif
- uint32_t send_size;
-
- send_size = size;
- send_buffer = buffer;
-
- if(p7_socket->checksum_enabled)
- _wi_p7_socket_checksum_buffer(p7_socket, send_buffer, send_size, checksum_buffer);
-
- if(p7_socket->compression_enabled) {
- compressed_size = _wi_p7_socket_deflate(p7_socket, send_buffer, send_size);
-
- if(compressed_size < 0)
- return false;
-
- send_size = compressed_size;
- send_buffer = p7_socket->compression_buffer;
- }
-
+ uint32_t send_size;
+
+ send_size = size;
+ send_buffer = buffer;
+
+ if(p7_socket->checksum_enabled)
+ _wi_p7_socket_checksum_buffer(p7_socket, send_buffer, send_size, checksum_buffer);
+
+ if(p7_socket->compression_enabled) {
+ compressed_size = _wi_p7_socket_deflate(p7_socket, send_buffer, send_size);
+
+ if(compressed_size < 0)
+ return false;
+
+ send_size = compressed_size;
+ send_buffer = p7_socket->compression_buffer;
+ }
+
#ifdef WI_RSA
- if(p7_socket->encryption_enabled) {
- encrypted_size = send_size + wi_cipher_block_size(p7_socket->cipher);
-
- if(!p7_socket->encryption_buffer) {
- p7_socket->encryption_buffer_length = encrypted_size;
- p7_socket->encryption_buffer = wi_malloc(p7_socket->encryption_buffer_length);
- }
- else if((wi_uinteger_t) encrypted_size > p7_socket->encryption_buffer_length) {
- p7_socket->encryption_buffer_length = encrypted_size * 2;
- p7_socket->encryption_buffer = wi_realloc(p7_socket->encryption_buffer, p7_socket->encryption_buffer_length);
- }
-
- encrypted_size = wi_cipher_encrypt_bytes(p7_socket->cipher,
- send_buffer,
- send_size,
- p7_socket->encryption_buffer);
-
- if(encrypted_size < 0)
- return false;
-
- send_size = encrypted_size;
- send_buffer = p7_socket->encryption_buffer;
- }
+ if(p7_socket->encryption_enabled) {
+ encrypted_size = send_size + wi_cipher_block_size(p7_socket->cipher);
+
+ if(!p7_socket->encryption_buffer) {
+ p7_socket->encryption_buffer_length = encrypted_size;
+ p7_socket->encryption_buffer = wi_malloc(p7_socket->encryption_buffer_length);
+ }
+ else if((wi_uinteger_t) encrypted_size > p7_socket->encryption_buffer_length) {
+ p7_socket->encryption_buffer_length = encrypted_size * 2;
+ p7_socket->encryption_buffer = wi_realloc(p7_socket->encryption_buffer, p7_socket->encryption_buffer_length);
+ }
+
+ encrypted_size = wi_cipher_encrypt_bytes(p7_socket->cipher,
+ send_buffer,
+ send_size,
+ p7_socket->encryption_buffer);
+
+ if(encrypted_size < 0)
+ return false;
+
+ send_size = encrypted_size;
+ send_buffer = p7_socket->encryption_buffer;
+ }
#endif
- wi_write_swap_host_to_big_int32(length_buffer, 0, send_size);
+ wi_write_swap_host_to_big_int32(length_buffer, 0, send_size);
- if(wi_socket_write_buffer(p7_socket->socket, timeout, length_buffer, sizeof(length_buffer)) < 0)
- return false;
+ if(wi_socket_write_buffer(p7_socket->socket, timeout, length_buffer, sizeof(length_buffer)) < 0)
+ return false;
- if(wi_socket_write_buffer(p7_socket->socket, timeout, send_buffer, send_size) < 0)
- return false;
+ if(wi_socket_write_buffer(p7_socket->socket, timeout, send_buffer, send_size) < 0)
+ return false;
- if(p7_socket->checksum_enabled) {
- if(wi_socket_write_buffer(p7_socket->socket, timeout, checksum_buffer, p7_socket->checksum_length) < 0)
- return false;
- }
-
- return true;
+ if(p7_socket->checksum_enabled) {
+ if(wi_socket_write_buffer(p7_socket->socket, timeout, checksum_buffer, p7_socket->checksum_length) < 0)
+ return false;
+ }
+
+ return true;
}
wi_integer_t wi_p7_socket_read_oobdata(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout, void **out_buffer) {
- void *receive_buffer;
- char length_buffer[_WI_P7_SOCKET_LENGTH_SIZE];
- unsigned char local_checksum_buffer[_WI_P7_CHECKSUM_OPTIONS_TO_LENGTH(p7_socket->options)];
- unsigned char remote_checksum_buffer[_WI_P7_CHECKSUM_OPTIONS_TO_LENGTH(p7_socket->options)];
- wi_integer_t result, decompressed_size;
+ void *receive_buffer;
+ char length_buffer[_WI_P7_SOCKET_LENGTH_SIZE];
+ unsigned char local_checksum_buffer[_WI_P7_CHECKSUM_OPTIONS_TO_LENGTH(p7_socket->options)];
+ unsigned char remote_checksum_buffer[_WI_P7_CHECKSUM_OPTIONS_TO_LENGTH(p7_socket->options)];
+ wi_integer_t result, decompressed_size;
#ifdef WI_RSA
- wi_integer_t decrypted_size;
+ wi_integer_t decrypted_size;
#endif
- uint32_t receive_size;
-
- result = wi_socket_read_buffer(p7_socket->socket, timeout, length_buffer, sizeof(length_buffer));
-
- if(result <= 0)
- return result;
-
- receive_size = wi_read_swap_big_to_host_int32(length_buffer, 0);
-
- if(receive_size > _WI_P7_SOCKET_MAX_BINARY_SIZE) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_MESSAGETOOLARGE,
- WI_STR("%u bytes"), receive_size);
-
- return -1;
- }
-
- if(!p7_socket->oobdata_read_buffer) {
- p7_socket->oobdata_read_buffer_length = receive_size * 2;
- p7_socket->oobdata_read_buffer = wi_malloc(p7_socket->oobdata_read_buffer_length);
- }
- else if(receive_size > p7_socket->oobdata_read_buffer_length) {
- p7_socket->oobdata_read_buffer_length = receive_size * 2;
- p7_socket->oobdata_read_buffer = wi_realloc(p7_socket->oobdata_read_buffer, p7_socket->oobdata_read_buffer_length);
- }
-
- receive_buffer = p7_socket->oobdata_read_buffer;
-
- result = wi_socket_read_buffer(p7_socket->socket, timeout, receive_buffer, receive_size);
-
- if(result <= 0)
- return false;
-
+ uint32_t receive_size;
+
+ result = wi_socket_read_buffer(p7_socket->socket, timeout, length_buffer, sizeof(length_buffer));
+
+ if(result <= 0)
+ return result;
+
+ receive_size = wi_read_swap_big_to_host_int32(length_buffer, 0);
+
+ if(receive_size > _WI_P7_SOCKET_MAX_BINARY_SIZE) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_MESSAGETOOLARGE,
+ WI_STR("%u bytes"), receive_size);
+
+ return -1;
+ }
+
+ if(!p7_socket->oobdata_read_buffer) {
+ p7_socket->oobdata_read_buffer_length = receive_size * 2;
+ p7_socket->oobdata_read_buffer = wi_malloc(p7_socket->oobdata_read_buffer_length);
+ }
+ else if(receive_size > p7_socket->oobdata_read_buffer_length) {
+ p7_socket->oobdata_read_buffer_length = receive_size * 2;
+ p7_socket->oobdata_read_buffer = wi_realloc(p7_socket->oobdata_read_buffer, p7_socket->oobdata_read_buffer_length);
+ }
+
+ receive_buffer = p7_socket->oobdata_read_buffer;
+
+ result = wi_socket_read_buffer(p7_socket->socket, timeout, receive_buffer, receive_size);
+
+ if(result <= 0)
+ return false;
+
#ifdef WI_RSA
- if(p7_socket->encryption_enabled) {
- decrypted_size = receive_size + wi_cipher_block_size(p7_socket->cipher);
-
- if(!p7_socket->decryption_buffer) {
- p7_socket->decryption_buffer_length = decrypted_size;
- p7_socket->decryption_buffer = wi_malloc(p7_socket->decryption_buffer_length);
- }
- else if((wi_uinteger_t) decrypted_size > p7_socket->decryption_buffer_length) {
- p7_socket->decryption_buffer_length = decrypted_size * 2;
- p7_socket->decryption_buffer = wi_realloc(p7_socket->decryption_buffer, p7_socket->decryption_buffer_length);
- }
-
- decrypted_size = wi_cipher_decrypt_bytes(p7_socket->cipher,
- receive_buffer,
- receive_size,
- p7_socket->decryption_buffer);
-
- if(decrypted_size < 0)
- return -1;
-
- receive_size = decrypted_size;
- receive_buffer = p7_socket->decryption_buffer;
- }
+ if(p7_socket->encryption_enabled) {
+ decrypted_size = receive_size + wi_cipher_block_size(p7_socket->cipher);
+
+ if(!p7_socket->decryption_buffer) {
+ p7_socket->decryption_buffer_length = decrypted_size;
+ p7_socket->decryption_buffer = wi_malloc(p7_socket->decryption_buffer_length);
+ }
+ else if((wi_uinteger_t) decrypted_size > p7_socket->decryption_buffer_length) {
+ p7_socket->decryption_buffer_length = decrypted_size * 2;
+ p7_socket->decryption_buffer = wi_realloc(p7_socket->decryption_buffer, p7_socket->decryption_buffer_length);
+ }
+
+ decrypted_size = wi_cipher_decrypt_bytes(p7_socket->cipher,
+ receive_buffer,
+ receive_size,
+ p7_socket->decryption_buffer);
+
+ if(decrypted_size < 0)
+ return -1;
+
+ receive_size = decrypted_size;
+ receive_buffer = p7_socket->decryption_buffer;
+ }
#endif
-
- if(p7_socket->compression_enabled) {
- decompressed_size = _wi_p7_socket_inflate(p7_socket, receive_buffer, receive_size);
-
- if(decompressed_size < 0)
- return -1;
-
- receive_size = decompressed_size;
- receive_buffer = p7_socket->compression_buffer;
- }
-
- if(p7_socket->checksum_enabled) {
- result = wi_socket_read_buffer(p7_socket->socket, timeout, remote_checksum_buffer, p7_socket->checksum_length);
-
- if(result <= 0)
- return result;
-
- _wi_p7_socket_checksum_buffer(p7_socket, receive_buffer, receive_size, local_checksum_buffer);
-
- if(memcmp(remote_checksum_buffer, local_checksum_buffer, p7_socket->checksum_length) != 0) {
- wi_error_set_libwired_error(WI_ERROR_P7_CHECKSUMMISMATCH);
-
- return -1;
- }
- }
-
- *out_buffer = receive_buffer;
-
- return receive_size;
+
+ if(p7_socket->compression_enabled) {
+ decompressed_size = _wi_p7_socket_inflate(p7_socket, receive_buffer, receive_size);
+
+ if(decompressed_size < 0)
+ return -1;
+
+ receive_size = decompressed_size;
+ receive_buffer = p7_socket->compression_buffer;
+ }
+
+ if(p7_socket->checksum_enabled) {
+ result = wi_socket_read_buffer(p7_socket->socket, timeout, remote_checksum_buffer, p7_socket->checksum_length);
+
+ if(result <= 0)
+ return result;
+
+ _wi_p7_socket_checksum_buffer(p7_socket, receive_buffer, receive_size, local_checksum_buffer);
+
+ if(memcmp(remote_checksum_buffer, local_checksum_buffer, p7_socket->checksum_length) != 0) {
+ wi_error_set_libwired_error(WI_ERROR_P7_CHECKSUMMISMATCH);
+
+ return -1;
+ }
+ }
+
+ *out_buffer = receive_buffer;
+
+ return receive_size;
}
#endif
diff --git a/vendor/WiredFrameworks/libwired/libwired/p7/wi-p7-socket.h b/vendor/WiredFrameworks/libwired/libwired/p7/wi-p7-socket.h
index b35f6880..12a184b0 100644
--- a/vendor/WiredFrameworks/libwired/libwired/p7/wi-p7-socket.h
+++ b/vendor/WiredFrameworks/libwired/libwired/p7/wi-p7-socket.h
@@ -42,13 +42,23 @@
(((options) & WI_P7_ENCRYPTION_RSA_AES128_SHA1) || \
((options) & WI_P7_ENCRYPTION_RSA_AES192_SHA1) || \
((options) & WI_P7_ENCRYPTION_RSA_AES256_SHA1) || \
- ((options) & WI_P7_ENCRYPTION_RSA_BF128_SHA1) || \
- ((options) & WI_P7_ENCRYPTION_RSA_3DES192_SHA1) || \
- ((options) & WI_P7_ENCRYPTION_RSA_AES256_SHA256))
+ ((options) & WI_P7_ENCRYPTION_RSA_BF128_SHA1) || \
+ ((options) & WI_P7_ENCRYPTION_RSA_3DES192_SHA1) || \
+ ((options) & WI_P7_ENCRYPTION_RSA_AES128_SHA256) || \
+ ((options) & WI_P7_ENCRYPTION_RSA_AES192_SHA256) || \
+ ((options) & WI_P7_ENCRYPTION_RSA_AES256_SHA256) || \
+ ((options) & WI_P7_ENCRYPTION_RSA_BF128_SHA256) || \
+ ((options) & WI_P7_ENCRYPTION_RSA_3DES192_SHA256) || \
+ ((options) & WI_P7_ENCRYPTION_RSA_AES128_SHA512) || \
+ ((options) & WI_P7_ENCRYPTION_RSA_AES192_SHA512) || \
+ ((options) & WI_P7_ENCRYPTION_RSA_AES256_SHA512) || \
+ ((options) & WI_P7_ENCRYPTION_RSA_BF128_SHA512) || \
+ ((options) & WI_P7_ENCRYPTION_RSA_3DES192_SHA512))
#define WI_P7_CHECKSUM_ENABLED(options) \
- (((options) & WI_P7_CHECKSUM_SHA1) || \
- ((options) & WI_P7_CHECKSUM_SHA256))
+ (((options) & WI_P7_CHECKSUM_SHA1) || \
+ ((options) & WI_P7_CHECKSUM_SHA256) || \
+ ((options) & WI_P7_CHECKSUM_SHA512))
enum _wi_p7_options {
@@ -58,18 +68,38 @@ enum _wi_p7_options {
WI_P7_ENCRYPTION_RSA_AES256_SHA1 = (1 << 3),
WI_P7_ENCRYPTION_RSA_BF128_SHA1 = (1 << 4),
WI_P7_ENCRYPTION_RSA_3DES192_SHA1 = (1 << 5),
- WI_P7_ENCRYPTION_RSA_AES256_SHA256 = (1 << 6),
- WI_P7_CHECKSUM_SHA1 = (1 << 7),
- WI_P7_CHECKSUM_SHA256 = (1 << 8),
+ WI_P7_ENCRYPTION_RSA_AES128_SHA256 = (1 << 6),
+ WI_P7_ENCRYPTION_RSA_AES192_SHA256 = (1 << 7),
+ WI_P7_ENCRYPTION_RSA_AES256_SHA256 = (1 << 8),
+ WI_P7_ENCRYPTION_RSA_BF128_SHA256 = (1 << 9),
+ WI_P7_ENCRYPTION_RSA_3DES192_SHA256 = (1 << 10),
+ WI_P7_ENCRYPTION_RSA_AES128_SHA512 = (1 << 11),
+ WI_P7_ENCRYPTION_RSA_AES192_SHA512 = (1 << 12),
+ WI_P7_ENCRYPTION_RSA_AES256_SHA512 = (1 << 13),
+ WI_P7_ENCRYPTION_RSA_BF128_SHA512 = (1 << 14),
+ WI_P7_ENCRYPTION_RSA_3DES192_SHA512 = (1 << 15),
+ WI_P7_CHECKSUM_SHA1 = (1 << 16),
+ WI_P7_CHECKSUM_SHA256 = (1 << 17),
+ WI_P7_CHECKSUM_SHA512 = (1 << 18),
WI_P7_ALL = (WI_P7_COMPRESSION_DEFLATE |
WI_P7_ENCRYPTION_RSA_AES128_SHA1 |
WI_P7_ENCRYPTION_RSA_AES192_SHA1 |
WI_P7_ENCRYPTION_RSA_AES256_SHA1 |
WI_P7_ENCRYPTION_RSA_BF128_SHA1 |
WI_P7_ENCRYPTION_RSA_3DES192_SHA1 |
- WI_P7_ENCRYPTION_RSA_AES256_SHA256 |
- WI_P7_CHECKSUM_SHA1 |
- WI_P7_CHECKSUM_SHA256)
+ WI_P7_ENCRYPTION_RSA_AES128_SHA256 |
+ WI_P7_ENCRYPTION_RSA_AES192_SHA256 |
+ WI_P7_ENCRYPTION_RSA_AES256_SHA256 |
+ WI_P7_ENCRYPTION_RSA_BF128_SHA256 |
+ WI_P7_ENCRYPTION_RSA_3DES192_SHA256 |
+ WI_P7_ENCRYPTION_RSA_AES128_SHA512 |
+ WI_P7_ENCRYPTION_RSA_AES192_SHA512 |
+ WI_P7_ENCRYPTION_RSA_AES256_SHA512 |
+ WI_P7_ENCRYPTION_RSA_BF128_SHA512 |
+ WI_P7_ENCRYPTION_RSA_3DES192_SHA512 |
+ WI_P7_CHECKSUM_SHA1 |
+ WI_P7_CHECKSUM_SHA256 |
+ WI_P7_CHECKSUM_SHA512)
};
typedef enum _wi_p7_options wi_p7_options_t;
diff --git a/vendor/WiredFrameworks/libwired/libwired/p7/wi-p7-spec.c b/vendor/WiredFrameworks/libwired/libwired/p7/wi-p7-spec.c
index 3b7e2815..c617daa1 100644
--- a/vendor/WiredFrameworks/libwired/libwired/p7/wi-p7-spec.c
+++ b/vendor/WiredFrameworks/libwired/libwired/p7/wi-p7-spec.c
@@ -52,27 +52,27 @@ int wi_p7_spec_dummy = 0;
#include
#include
-typedef struct _wi_p7_spec_collection _wi_p7_spec_collection_t;
-typedef struct _wi_p7_spec_transaction _wi_p7_spec_transaction_t;
-typedef struct _wi_p7_spec_broadcast _wi_p7_spec_broadcast_t;
-typedef struct _wi_p7_spec_andor _wi_p7_spec_andor_t;
-typedef struct _wi_p7_spec_reply _wi_p7_spec_reply_t;
+typedef struct _wi_p7_spec_collection _wi_p7_spec_collection_t;
+typedef struct _wi_p7_spec_transaction _wi_p7_spec_transaction_t;
+typedef struct _wi_p7_spec_broadcast _wi_p7_spec_broadcast_t;
+typedef struct _wi_p7_spec_andor _wi_p7_spec_andor_t;
+typedef struct _wi_p7_spec_reply _wi_p7_spec_reply_t;
struct _wi_p7_spec_type {
- wi_runtime_base_t base;
-
- wi_string_t *name;
- wi_uinteger_t size;
- wi_uinteger_t id;
+ wi_runtime_base_t base;
+
+ wi_string_t *name;
+ wi_uinteger_t size;
+ wi_uinteger_t id;
};
-static wi_p7_spec_type_t * _wi_p7_spec_type_with_node(wi_p7_spec_t *, xmlNodePtr);
-static void _wi_p7_spec_type_dealloc(wi_runtime_instance_t *);
-static wi_string_t * _wi_p7_spec_type_description(wi_runtime_instance_t *);
+static wi_p7_spec_type_t * _wi_p7_spec_type_with_node(wi_p7_spec_t *, xmlNodePtr);
+static void _wi_p7_spec_type_dealloc(wi_runtime_instance_t *);
+static wi_string_t * _wi_p7_spec_type_description(wi_runtime_instance_t *);
-static wi_runtime_id_t _wi_p7_spec_type_runtime_id = WI_RUNTIME_ID_NULL;
-static wi_runtime_class_t _wi_p7_spec_type_runtime_class = {
+static wi_runtime_id_t _wi_p7_spec_type_runtime_id = WI_RUNTIME_ID_NULL;
+static wi_runtime_class_t _wi_p7_spec_type_runtime_class = {
"wi_p7_spec_type_t",
_wi_p7_spec_type_dealloc,
NULL,
@@ -84,22 +84,22 @@ static wi_runtime_class_t _wi_p7_spec_type_runtime_class = {
struct _wi_p7_spec_field {
- wi_runtime_base_t base;
-
- wi_string_t *name;
- wi_uinteger_t id;
- wi_p7_spec_type_t *type;
- wi_p7_spec_type_t *listtype;
- wi_mutable_dictionary_t *enums_name;
- wi_mutable_dictionary_t *enums_value;
+ wi_runtime_base_t base;
+
+ wi_string_t *name;
+ wi_uinteger_t id;
+ wi_p7_spec_type_t *type;
+ wi_p7_spec_type_t *listtype;
+ wi_mutable_dictionary_t *enums_name;
+ wi_mutable_dictionary_t *enums_value;
};
-static wi_p7_spec_field_t * _wi_p7_spec_field_with_node(wi_p7_spec_t *, xmlNodePtr);
-static void _wi_p7_spec_field_dealloc(wi_runtime_instance_t *);
-static wi_string_t * _wi_p7_spec_field_description(wi_runtime_instance_t *);
+static wi_p7_spec_field_t * _wi_p7_spec_field_with_node(wi_p7_spec_t *, xmlNodePtr);
+static void _wi_p7_spec_field_dealloc(wi_runtime_instance_t *);
+static wi_string_t * _wi_p7_spec_field_description(wi_runtime_instance_t *);
-static wi_runtime_id_t _wi_p7_spec_field_runtime_id = WI_RUNTIME_ID_NULL;
-static wi_runtime_class_t _wi_p7_spec_field_runtime_class = {
+static wi_runtime_id_t _wi_p7_spec_field_runtime_id = WI_RUNTIME_ID_NULL;
+static wi_runtime_class_t _wi_p7_spec_field_runtime_class = {
"wi_p7_spec_field_t",
_wi_p7_spec_field_dealloc,
NULL,
@@ -111,18 +111,18 @@ static wi_runtime_class_t _wi_p7_spec_field_runtime_class = {
struct _wi_p7_spec_collection {
- wi_runtime_base_t base;
-
- wi_string_t *name;
- wi_mutable_array_t *fields;
+ wi_runtime_base_t base;
+
+ wi_string_t *name;
+ wi_mutable_array_t *fields;
};
-static _wi_p7_spec_collection_t * _wi_p7_spec_collection_with_node(wi_p7_spec_t *, xmlNodePtr);
-static void _wi_p7_spec_collection_dealloc(wi_runtime_instance_t *);
-static wi_string_t * _wi_p7_spec_collection_description(wi_runtime_instance_t *);
+static _wi_p7_spec_collection_t * _wi_p7_spec_collection_with_node(wi_p7_spec_t *, xmlNodePtr);
+static void _wi_p7_spec_collection_dealloc(wi_runtime_instance_t *);
+static wi_string_t * _wi_p7_spec_collection_description(wi_runtime_instance_t *);
-static wi_runtime_id_t _wi_p7_spec_collection_runtime_id = WI_RUNTIME_ID_NULL;
-static wi_runtime_class_t _wi_p7_spec_collection_runtime_class = {
+static wi_runtime_id_t _wi_p7_spec_collection_runtime_id = WI_RUNTIME_ID_NULL;
+static wi_runtime_class_t _wi_p7_spec_collection_runtime_class = {
"_wi_p7_spec_collection_t",
_wi_p7_spec_collection_dealloc,
NULL,
@@ -134,22 +134,22 @@ static wi_runtime_class_t _wi_p7_spec_collection_runtime_class = {
struct _wi_p7_spec_message {
- wi_runtime_base_t base;
-
- wi_string_t *name;
- wi_uinteger_t id;
- wi_array_t *parameters;
- wi_mutable_dictionary_t *parameters_name;
- wi_mutable_dictionary_t *parameters_id;
- wi_uinteger_t required_parameters;
+ wi_runtime_base_t base;
+
+ wi_string_t *name;
+ wi_uinteger_t id;
+ wi_array_t *parameters;
+ wi_mutable_dictionary_t *parameters_name;
+ wi_mutable_dictionary_t *parameters_id;
+ wi_uinteger_t required_parameters;
};
-static wi_p7_spec_message_t * _wi_p7_spec_message_with_node(wi_p7_spec_t *, xmlNodePtr);
-static void _wi_p7_spec_message_dealloc(wi_runtime_instance_t *);
-static wi_string_t * _wi_p7_spec_message_description(wi_runtime_instance_t *);
+static wi_p7_spec_message_t * _wi_p7_spec_message_with_node(wi_p7_spec_t *, xmlNodePtr);
+static void _wi_p7_spec_message_dealloc(wi_runtime_instance_t *);
+static wi_string_t * _wi_p7_spec_message_description(wi_runtime_instance_t *);
-static wi_runtime_id_t _wi_p7_spec_message_runtime_id = WI_RUNTIME_ID_NULL;
-static wi_runtime_class_t _wi_p7_spec_message_runtime_class = {
+static wi_runtime_id_t _wi_p7_spec_message_runtime_id = WI_RUNTIME_ID_NULL;
+static wi_runtime_class_t _wi_p7_spec_message_runtime_class = {
"wi_p7_spec_message_t",
_wi_p7_spec_message_dealloc,
NULL,
@@ -161,19 +161,19 @@ static wi_runtime_class_t _wi_p7_spec_message_runtime_class = {
struct _wi_p7_spec_parameter {
- wi_runtime_base_t base;
-
- wi_p7_spec_field_t *field;
- wi_boolean_t required;
+ wi_runtime_base_t base;
+
+ wi_p7_spec_field_t *field;
+ wi_boolean_t required;
};
-static wi_p7_spec_parameter_t * _wi_p7_spec_parameter_with_node(wi_p7_spec_t *, xmlNodePtr, wi_p7_spec_message_t *);
-static wi_p7_spec_parameter_t * _wi_p7_spec_parameter_with_field(wi_p7_spec_t *, wi_p7_spec_message_t *, wi_p7_spec_field_t *);
-static void _wi_p7_spec_parameter_dealloc(wi_runtime_instance_t *);
-static wi_string_t * _wi_p7_spec_parameter_description(wi_runtime_instance_t *);
+static wi_p7_spec_parameter_t * _wi_p7_spec_parameter_with_node(wi_p7_spec_t *, xmlNodePtr, wi_p7_spec_message_t *);
+static wi_p7_spec_parameter_t * _wi_p7_spec_parameter_with_field(wi_p7_spec_t *, wi_p7_spec_message_t *, wi_p7_spec_field_t *);
+static void _wi_p7_spec_parameter_dealloc(wi_runtime_instance_t *);
+static wi_string_t * _wi_p7_spec_parameter_description(wi_runtime_instance_t *);
-static wi_runtime_id_t _wi_p7_spec_parameter_runtime_id = WI_RUNTIME_ID_NULL;
-static wi_runtime_class_t _wi_p7_spec_parameter_runtime_class = {
+static wi_runtime_id_t _wi_p7_spec_parameter_runtime_id = WI_RUNTIME_ID_NULL;
+static wi_runtime_class_t _wi_p7_spec_parameter_runtime_class = {
"wi_p7_spec_parameter_t",
_wi_p7_spec_parameter_dealloc,
NULL,
@@ -185,20 +185,20 @@ static wi_runtime_class_t _wi_p7_spec_parameter_runtime_class = {
struct _wi_p7_spec_transaction {
- wi_runtime_base_t base;
+ wi_runtime_base_t base;
- wi_p7_spec_message_t *message;
- wi_p7_originator_t originator;
- wi_boolean_t required;
- _wi_p7_spec_andor_t *andor;
+ wi_p7_spec_message_t *message;
+ wi_p7_originator_t originator;
+ wi_boolean_t required;
+ _wi_p7_spec_andor_t *andor;
};
-static _wi_p7_spec_transaction_t * _wi_p7_spec_transaction_with_node(wi_p7_spec_t *, xmlNodePtr);
-static void _wi_p7_spec_transaction_dealloc(wi_runtime_instance_t *);
-static wi_string_t * _wi_p7_spec_transaction_description(wi_runtime_instance_t *);
+static _wi_p7_spec_transaction_t * _wi_p7_spec_transaction_with_node(wi_p7_spec_t *, xmlNodePtr);
+static void _wi_p7_spec_transaction_dealloc(wi_runtime_instance_t *);
+static wi_string_t * _wi_p7_spec_transaction_description(wi_runtime_instance_t *);
-static wi_runtime_id_t _wi_p7_spec_transaction_runtime_id = WI_RUNTIME_ID_NULL;
-static wi_runtime_class_t _wi_p7_spec_transaction_runtime_class = {
+static wi_runtime_id_t _wi_p7_spec_transaction_runtime_id = WI_RUNTIME_ID_NULL;
+static wi_runtime_class_t _wi_p7_spec_transaction_runtime_class = {
"_wi_p7_spec_transaction_t",
_wi_p7_spec_transaction_dealloc,
NULL,
@@ -210,18 +210,18 @@ static wi_runtime_class_t _wi_p7_spec_transaction_runtime_class = {
struct _wi_p7_spec_broadcast {
- wi_runtime_base_t base;
+ wi_runtime_base_t base;
- wi_p7_spec_message_t *message;
- wi_boolean_t required;
+ wi_p7_spec_message_t *message;
+ wi_boolean_t required;
};
-static _wi_p7_spec_broadcast_t * _wi_p7_spec_broadcast_with_node(wi_p7_spec_t *, xmlNodePtr);
-static void _wi_p7_spec_broadcast_dealloc(wi_runtime_instance_t *);
-static wi_string_t * _wi_p7_spec_broadcast_description(wi_runtime_instance_t *);
+static _wi_p7_spec_broadcast_t * _wi_p7_spec_broadcast_with_node(wi_p7_spec_t *, xmlNodePtr);
+static void _wi_p7_spec_broadcast_dealloc(wi_runtime_instance_t *);
+static wi_string_t * _wi_p7_spec_broadcast_description(wi_runtime_instance_t *);
-static wi_runtime_id_t _wi_p7_spec_broadcast_runtime_id = WI_RUNTIME_ID_NULL;
-static wi_runtime_class_t _wi_p7_spec_broadcast_runtime_class = {
+static wi_runtime_id_t _wi_p7_spec_broadcast_runtime_id = WI_RUNTIME_ID_NULL;
+static wi_runtime_class_t _wi_p7_spec_broadcast_runtime_class = {
"_wi_p7_spec_broadcast_t",
_wi_p7_spec_broadcast_dealloc,
NULL,
@@ -233,26 +233,26 @@ static wi_runtime_class_t _wi_p7_spec_broadcast_runtime_class = {
enum _wi_p7_spec_andor_type {
- _WI_P7_SPEC_AND,
- _WI_P7_SPEC_OR
+ _WI_P7_SPEC_AND,
+ _WI_P7_SPEC_OR
};
-typedef enum _wi_p7_spec_andor_type _wi_p7_spec_andor_type_t;
+typedef enum _wi_p7_spec_andor_type _wi_p7_spec_andor_type_t;
struct _wi_p7_spec_andor {
- wi_runtime_base_t base;
+ wi_runtime_base_t base;
- _wi_p7_spec_andor_type_t type;
- wi_mutable_array_t *children;
- wi_mutable_array_t *replies_array;
- wi_mutable_dictionary_t *replies_dictionary;
+ _wi_p7_spec_andor_type_t type;
+ wi_mutable_array_t *children;
+ wi_mutable_array_t *replies_array;
+ wi_mutable_dictionary_t *replies_dictionary;
};
-static _wi_p7_spec_andor_t * _wi_p7_spec_andor(_wi_p7_spec_andor_type_t, wi_p7_spec_t *, xmlNodePtr, _wi_p7_spec_transaction_t *);
-static void _wi_p7_spec_andor_dealloc(wi_runtime_instance_t *);
-static wi_string_t * _wi_p7_spec_andor_description(wi_runtime_instance_t *);
+static _wi_p7_spec_andor_t * _wi_p7_spec_andor(_wi_p7_spec_andor_type_t, wi_p7_spec_t *, xmlNodePtr, _wi_p7_spec_transaction_t *);
+static void _wi_p7_spec_andor_dealloc(wi_runtime_instance_t *);
+static wi_string_t * _wi_p7_spec_andor_description(wi_runtime_instance_t *);
-static wi_runtime_id_t _wi_p7_spec_andor_runtime_id = WI_RUNTIME_ID_NULL;
-static wi_runtime_class_t _wi_p7_spec_andor_runtime_class = {
+static wi_runtime_id_t _wi_p7_spec_andor_runtime_id = WI_RUNTIME_ID_NULL;
+static wi_runtime_class_t _wi_p7_spec_andor_runtime_class = {
"_wi_p7_spec_andor_t",
_wi_p7_spec_andor_dealloc,
NULL,
@@ -263,25 +263,25 @@ static wi_runtime_class_t _wi_p7_spec_andor_runtime_class = {
-#define _WI_P7_SPEC_REPLY_ONE_OR_ZERO -1
-#define _WI_P7_SPEC_REPLY_ZERO_OR_MORE -2
-#define _WI_P7_SPEC_REPLY_ONE_OR_MORE -3
+#define _WI_P7_SPEC_REPLY_ONE_OR_ZERO -1
+#define _WI_P7_SPEC_REPLY_ZERO_OR_MORE -2
+#define _WI_P7_SPEC_REPLY_ONE_OR_MORE -3
struct _wi_p7_spec_reply {
- wi_runtime_base_t base;
+ wi_runtime_base_t base;
- wi_p7_spec_message_t *message;
- wi_integer_t count;
- wi_boolean_t required;
+ wi_p7_spec_message_t *message;
+ wi_integer_t count;
+ wi_boolean_t required;
};
-static _wi_p7_spec_reply_t * _wi_p7_spec_reply_with_node(wi_p7_spec_t *, xmlNodePtr, _wi_p7_spec_transaction_t *);
-static wi_string_t * _wi_p7_spec_reply_count(_wi_p7_spec_reply_t *);
-static void _wi_p7_spec_reply_dealloc(wi_runtime_instance_t *);
-static wi_string_t * _wi_p7_spec_reply_description(wi_runtime_instance_t *);
+static _wi_p7_spec_reply_t * _wi_p7_spec_reply_with_node(wi_p7_spec_t *, xmlNodePtr, _wi_p7_spec_transaction_t *);
+static wi_string_t * _wi_p7_spec_reply_count(_wi_p7_spec_reply_t *);
+static void _wi_p7_spec_reply_dealloc(wi_runtime_instance_t *);
+static wi_string_t * _wi_p7_spec_reply_description(wi_runtime_instance_t *);
-static wi_runtime_id_t _wi_p7_spec_reply_runtime_id = WI_RUNTIME_ID_NULL;
-static wi_runtime_class_t _wi_p7_spec_reply_runtime_class = {
+static wi_runtime_id_t _wi_p7_spec_reply_runtime_id = WI_RUNTIME_ID_NULL;
+static wi_runtime_class_t _wi_p7_spec_reply_runtime_class = {
"_wi_p7_spec_reply_t",
_wi_p7_spec_reply_dealloc,
NULL,
@@ -293,186 +293,195 @@ static wi_runtime_class_t _wi_p7_spec_reply_runtime_class = {
struct _wi_p7_spec {
- wi_runtime_base_t base;
-
- wi_string_t *xml;
-
- wi_string_t *filename;
- wi_string_t *name;
- wi_string_t *version;
- wi_p7_originator_t originator;
-
- wi_array_t *messages;
- wi_mutable_dictionary_t *messages_name, *messages_id;
- wi_array_t *fields;
- wi_mutable_dictionary_t *fields_name, *fields_id;
- wi_mutable_dictionary_t *collections_name;
- wi_mutable_dictionary_t *types_name, *types_id;
- wi_mutable_dictionary_t *transactions_name;
- wi_mutable_dictionary_t *broadcasts_name;
+ wi_runtime_base_t base;
+
+ wi_string_t *xml;
+
+ wi_string_t *filename;
+ wi_string_t *name;
+ wi_string_t *version;
+ wi_p7_originator_t originator;
+
+ wi_array_t *messages;
+ wi_mutable_dictionary_t *messages_name, *messages_id;
+ wi_array_t *fields;
+ wi_mutable_dictionary_t *fields_name, *fields_id;
+ wi_mutable_dictionary_t *collections_name;
+ wi_mutable_dictionary_t *types_name, *types_id;
+ wi_mutable_dictionary_t *transactions_name;
+ wi_mutable_dictionary_t *broadcasts_name;
};
-static wi_string_t * _wi_p7_spec_originator(wi_p7_originator_t);
-
-static wi_p7_spec_t * _wi_p7_spec_init(wi_p7_spec_t *, wi_p7_originator_t);
-static wi_p7_spec_t * _wi_p7_spec_init_builtin_spec(wi_p7_spec_t *);
-
-static void _wi_p7_spec_dealloc(wi_runtime_instance_t *);
-static wi_runtime_instance_t * _wi_p7_spec_copy(wi_runtime_instance_t *);
-static wi_string_t * _wi_p7_spec_description(wi_runtime_instance_t *);
-
-static wi_boolean_t _wi_p7_spec_load_builtin(wi_p7_spec_t *);
-static wi_boolean_t _wi_p7_spec_load_file(wi_p7_spec_t *, wi_string_t *);
-static wi_boolean_t _wi_p7_spec_load_string(wi_p7_spec_t *, wi_string_t *);
-static wi_boolean_t _wi_p7_spec_load_spec(wi_p7_spec_t *, xmlDocPtr);
-static wi_boolean_t _wi_p7_spec_load_types(wi_p7_spec_t *, xmlNodePtr);
-static wi_boolean_t _wi_p7_spec_load_fields(wi_p7_spec_t *, xmlNodePtr);
-static wi_boolean_t _wi_p7_spec_load_collections(wi_p7_spec_t *, xmlNodePtr);
-static wi_boolean_t _wi_p7_spec_load_messages(wi_p7_spec_t *, xmlNodePtr);
-static wi_boolean_t _wi_p7_spec_load_transactions(wi_p7_spec_t *, xmlNodePtr);
-static wi_boolean_t _wi_p7_spec_load_broadcasts(wi_p7_spec_t *, xmlNodePtr);
-
-static wi_boolean_t _wi_p7_spec_transaction_is_compatible(wi_p7_spec_t *, _wi_p7_spec_transaction_t *, _wi_p7_spec_transaction_t *);
-static wi_boolean_t _wi_p7_spec_broadcast_is_compatible(wi_p7_spec_t *, _wi_p7_spec_broadcast_t *, _wi_p7_spec_broadcast_t *);
-static wi_boolean_t _wi_p7_spec_andor_is_compatible(wi_p7_spec_t *, _wi_p7_spec_transaction_t *, _wi_p7_spec_andor_t *, _wi_p7_spec_andor_t *);
-static wi_boolean_t _wi_p7_spec_replies_are_compatible(wi_p7_spec_t *, _wi_p7_spec_transaction_t *, _wi_p7_spec_andor_t *, _wi_p7_spec_andor_t *, wi_boolean_t);
-static wi_boolean_t _wi_p7_spec_reply_is_compatible(wi_p7_spec_t *, _wi_p7_spec_transaction_t *, _wi_p7_spec_reply_t *, _wi_p7_spec_reply_t *, wi_boolean_t);
-static wi_boolean_t _wi_p7_spec_message_is_compatible(wi_p7_spec_t *, wi_p7_spec_message_t *, wi_p7_spec_message_t *);
-
-static wi_p7_spec_t *_wi_p7_spec_builtin_spec;
-
-static xmlChar _wi_p7_spec_builtin[] =
- ""
- ""
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- ""
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- ""
- " "
- " "
- " "
- " "
- " "
- " "
- ""
- " "
- " "
- " "
- ""
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- ""
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- ""
- " "
- " "
- " "
- ""
- " "
- " "
- " "
- ""
- " "
- " "
- " "
- " "
- " "
- " "
- ""
- " "
- " "
- " "
- ""
- " "
- ""
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- " "
- ""
- " "
- " "
- " "
- " "
- ""
- " "
- " "
- " "
- ""
- " "
- " "
- " "
- ""
- " "
- " "
- " "
- " "
- " "
- " "
- ""
- " "
- " "
- " "
- " "
- "";
-
-static wi_runtime_id_t _wi_p7_spec_runtime_id = WI_RUNTIME_ID_NULL;
-static wi_runtime_class_t _wi_p7_spec_runtime_class = {
+static wi_string_t * _wi_p7_spec_originator(wi_p7_originator_t);
+
+static wi_p7_spec_t * _wi_p7_spec_init(wi_p7_spec_t *, wi_p7_originator_t);
+static wi_p7_spec_t * _wi_p7_spec_init_builtin_spec(wi_p7_spec_t *);
+
+static void _wi_p7_spec_dealloc(wi_runtime_instance_t *);
+static wi_runtime_instance_t * _wi_p7_spec_copy(wi_runtime_instance_t *);
+static wi_string_t * _wi_p7_spec_description(wi_runtime_instance_t *);
+
+static wi_boolean_t _wi_p7_spec_load_builtin(wi_p7_spec_t *);
+static wi_boolean_t _wi_p7_spec_load_file(wi_p7_spec_t *, wi_string_t *);
+static wi_boolean_t _wi_p7_spec_load_string(wi_p7_spec_t *, wi_string_t *);
+static wi_boolean_t _wi_p7_spec_load_spec(wi_p7_spec_t *, xmlDocPtr);
+static wi_boolean_t _wi_p7_spec_load_types(wi_p7_spec_t *, xmlNodePtr);
+static wi_boolean_t _wi_p7_spec_load_fields(wi_p7_spec_t *, xmlNodePtr);
+static wi_boolean_t _wi_p7_spec_load_collections(wi_p7_spec_t *, xmlNodePtr);
+static wi_boolean_t _wi_p7_spec_load_messages(wi_p7_spec_t *, xmlNodePtr);
+static wi_boolean_t _wi_p7_spec_load_transactions(wi_p7_spec_t *, xmlNodePtr);
+static wi_boolean_t _wi_p7_spec_load_broadcasts(wi_p7_spec_t *, xmlNodePtr);
+
+static wi_boolean_t _wi_p7_spec_transaction_is_compatible(wi_p7_spec_t *, _wi_p7_spec_transaction_t *, _wi_p7_spec_transaction_t *);
+static wi_boolean_t _wi_p7_spec_broadcast_is_compatible(wi_p7_spec_t *, _wi_p7_spec_broadcast_t *, _wi_p7_spec_broadcast_t *);
+static wi_boolean_t _wi_p7_spec_andor_is_compatible(wi_p7_spec_t *, _wi_p7_spec_transaction_t *, _wi_p7_spec_andor_t *, _wi_p7_spec_andor_t *);
+static wi_boolean_t _wi_p7_spec_replies_are_compatible(wi_p7_spec_t *, _wi_p7_spec_transaction_t *, _wi_p7_spec_andor_t *, _wi_p7_spec_andor_t *, wi_boolean_t);
+static wi_boolean_t _wi_p7_spec_reply_is_compatible(wi_p7_spec_t *, _wi_p7_spec_transaction_t *, _wi_p7_spec_reply_t *, _wi_p7_spec_reply_t *, wi_boolean_t);
+static wi_boolean_t _wi_p7_spec_message_is_compatible(wi_p7_spec_t *, wi_p7_spec_message_t *, wi_p7_spec_message_t *);
+
+static wi_p7_spec_t *_wi_p7_spec_builtin_spec;
+
+static xmlChar _wi_p7_spec_builtin[] =
+ ""
+ ""
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ ""
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ ""
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ ""
+ " "
+ " "
+ " "
+ ""
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ ""
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ ""
+ " "
+ " "
+ " "
+ ""
+ " "
+ " "
+ " "
+ ""
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ ""
+ " "
+ " "
+ " "
+ ""
+ " "
+ ""
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ ""
+ " "
+ " "
+ " "
+ " "
+ ""
+ " "
+ " "
+ " "
+ ""
+ " "
+ " "
+ " "
+ ""
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ ""
+ " "
+ " "
+ " "
+ " "
+ "";
+
+static wi_runtime_id_t _wi_p7_spec_runtime_id = WI_RUNTIME_ID_NULL;
+static wi_runtime_class_t _wi_p7_spec_runtime_class = {
"wi_p7_spec_t",
_wi_p7_spec_dealloc,
_wi_p7_spec_copy,
@@ -499,7 +508,7 @@ void wi_p7_spec_register(void) {
void wi_p7_spec_initialize(void) {
- xmlInitParser();
+ xmlInitParser();
}
@@ -515,38 +524,38 @@ wi_runtime_id_t wi_p7_spec_runtime_id(void) {
#pragma mark -
wi_p7_spec_t * wi_p7_spec_builtin_spec(void) {
- if(!_wi_p7_spec_builtin_spec) {
- _wi_p7_spec_builtin_spec = _wi_p7_spec_init_builtin_spec(wi_p7_spec_alloc());
-
- if(!_wi_p7_spec_builtin_spec)
- wi_log_fatal(WI_STR("Could not load builtin P7 spec: %m"));
- }
-
- return _wi_p7_spec_builtin_spec;
+ if(!_wi_p7_spec_builtin_spec) {
+ _wi_p7_spec_builtin_spec = _wi_p7_spec_init_builtin_spec(wi_p7_spec_alloc());
+
+ if(!_wi_p7_spec_builtin_spec)
+ wi_log_fatal(WI_STR("Could not load builtin P7 spec: %m"));
+ }
+
+ return _wi_p7_spec_builtin_spec;
}
wi_p7_originator_t wi_p7_spec_opposite_originator(wi_p7_originator_t originator) {
- switch(originator) {
- case WI_P7_SERVER: return WI_P7_BOTH; break;
- case WI_P7_CLIENT: return WI_P7_SERVER; break;
- case WI_P7_BOTH: return WI_P7_BOTH; break;
- }
-
- return WI_P7_BOTH;
+ switch(originator) {
+ case WI_P7_SERVER: return WI_P7_BOTH; break;
+ case WI_P7_CLIENT: return WI_P7_SERVER; break;
+ case WI_P7_BOTH: return WI_P7_BOTH; break;
+ }
+
+ return WI_P7_BOTH;
}
static wi_string_t * _wi_p7_spec_originator(wi_p7_originator_t originator) {
- switch(originator) {
- case WI_P7_CLIENT: return WI_STR("client"); break;
- case WI_P7_SERVER: return WI_STR("server"); break;
- case WI_P7_BOTH: return WI_STR("both"); break;
- }
-
- return NULL;
+ switch(originator) {
+ case WI_P7_CLIENT: return WI_STR("client"); break;
+ case WI_P7_SERVER: return WI_STR("server"); break;
+ case WI_P7_BOTH: return WI_STR("both"); break;
+ }
+
+ return NULL;
}
@@ -560,147 +569,147 @@ wi_p7_spec_t * wi_p7_spec_alloc(void) {
static wi_p7_spec_t * _wi_p7_spec_init(wi_p7_spec_t *p7_spec, wi_p7_originator_t originator) {
- p7_spec->originator = originator;
+ p7_spec->originator = originator;
- p7_spec->messages_name = wi_dictionary_init_with_capacity(wi_mutable_dictionary_alloc(), 500);
- p7_spec->messages_id = wi_dictionary_init_with_capacity_and_callbacks(wi_mutable_dictionary_alloc(),
- 500, wi_dictionary_null_key_callbacks, wi_dictionary_default_value_callbacks);
+ p7_spec->messages_name = wi_dictionary_init_with_capacity(wi_mutable_dictionary_alloc(), 500);
+ p7_spec->messages_id = wi_dictionary_init_with_capacity_and_callbacks(wi_mutable_dictionary_alloc(),
+ 500, wi_dictionary_null_key_callbacks, wi_dictionary_default_value_callbacks);
- p7_spec->fields_name = wi_dictionary_init_with_capacity(wi_mutable_dictionary_alloc(), 500);
- p7_spec->fields_id = wi_dictionary_init_with_capacity_and_callbacks(wi_mutable_dictionary_alloc(),
- 500, wi_dictionary_null_key_callbacks, wi_dictionary_default_value_callbacks);
+ p7_spec->fields_name = wi_dictionary_init_with_capacity(wi_mutable_dictionary_alloc(), 500);
+ p7_spec->fields_id = wi_dictionary_init_with_capacity_and_callbacks(wi_mutable_dictionary_alloc(),
+ 500, wi_dictionary_null_key_callbacks, wi_dictionary_default_value_callbacks);
- p7_spec->collections_name = wi_dictionary_init_with_capacity(wi_mutable_dictionary_alloc(), 20);
+ p7_spec->collections_name = wi_dictionary_init_with_capacity(wi_mutable_dictionary_alloc(), 20);
- p7_spec->types_name = wi_dictionary_init_with_capacity(wi_mutable_dictionary_alloc(), 20);
- p7_spec->types_id = wi_dictionary_init_with_capacity_and_callbacks(wi_mutable_dictionary_alloc(),
- 20, wi_dictionary_null_key_callbacks, wi_dictionary_default_value_callbacks);
+ p7_spec->types_name = wi_dictionary_init_with_capacity(wi_mutable_dictionary_alloc(), 20);
+ p7_spec->types_id = wi_dictionary_init_with_capacity_and_callbacks(wi_mutable_dictionary_alloc(),
+ 20, wi_dictionary_null_key_callbacks, wi_dictionary_default_value_callbacks);
- p7_spec->transactions_name = wi_dictionary_init_with_capacity(wi_mutable_dictionary_alloc(), 20);
- p7_spec->broadcasts_name = wi_dictionary_init_with_capacity(wi_mutable_dictionary_alloc(), 20);
+ p7_spec->transactions_name = wi_dictionary_init_with_capacity(wi_mutable_dictionary_alloc(), 20);
+ p7_spec->broadcasts_name = wi_dictionary_init_with_capacity(wi_mutable_dictionary_alloc(), 20);
- return p7_spec;
+ return p7_spec;
}
static wi_p7_spec_t * _wi_p7_spec_init_builtin_spec(wi_p7_spec_t *p7_spec) {
- p7_spec = _wi_p7_spec_init(p7_spec, WI_P7_BOTH);
- p7_spec->filename = wi_retain(WI_STR("(builtin)"));
+ p7_spec = _wi_p7_spec_init(p7_spec, WI_P7_BOTH);
+ p7_spec->filename = wi_retain(WI_STR("(builtin)"));
- if(!_wi_p7_spec_load_builtin(p7_spec)) {
- wi_release(p7_spec);
-
- return NULL;
- }
-
- return p7_spec;
+ if(!_wi_p7_spec_load_builtin(p7_spec)) {
+ wi_release(p7_spec);
+
+ return NULL;
+ }
+
+ return p7_spec;
}
wi_p7_spec_t * wi_p7_spec_init_with_file(wi_p7_spec_t *p7_spec, wi_string_t *path, wi_p7_originator_t originator) {
-
- (void) wi_p7_spec_builtin_spec();
-
- p7_spec = _wi_p7_spec_init(p7_spec, originator);
- p7_spec->filename = wi_retain(wi_string_last_path_component(path));
-
- if(!_wi_p7_spec_load_file(p7_spec, path)) {
- wi_release(p7_spec);
-
- return NULL;
- }
+
+ (void) wi_p7_spec_builtin_spec();
+
+ p7_spec = _wi_p7_spec_init(p7_spec, originator);
+ p7_spec->filename = wi_retain(wi_string_last_path_component(path));
+
+ if(!_wi_p7_spec_load_file(p7_spec, path)) {
+ wi_release(p7_spec);
+
+ return NULL;
+ }
- return p7_spec;
+ return p7_spec;
}
wi_p7_spec_t * wi_p7_spec_init_with_string(wi_p7_spec_t *p7_spec, wi_string_t *string, wi_p7_originator_t originator) {
-
- (void) wi_p7_spec_builtin_spec();
-
- p7_spec = _wi_p7_spec_init(p7_spec, originator);
-
- if(!_wi_p7_spec_load_string(p7_spec, string)) {
- wi_release(p7_spec);
-
- return NULL;
- }
+
+ (void) wi_p7_spec_builtin_spec();
+
+ p7_spec = _wi_p7_spec_init(p7_spec, originator);
+
+ if(!_wi_p7_spec_load_string(p7_spec, string)) {
+ wi_release(p7_spec);
+
+ return NULL;
+ }
- return p7_spec;
+ return p7_spec;
}
static void _wi_p7_spec_dealloc(wi_runtime_instance_t *instance) {
- wi_p7_spec_t *p7_spec = instance;
-
- wi_release(p7_spec->xml);
+ wi_p7_spec_t *p7_spec = instance;
+
+ wi_release(p7_spec->xml);
- wi_release(p7_spec->filename);
- wi_release(p7_spec->name);
- wi_release(p7_spec->version);
-
- wi_release(p7_spec->messages);
- wi_release(p7_spec->messages_name);
- wi_release(p7_spec->messages_id);
-
- wi_release(p7_spec->fields);
- wi_release(p7_spec->fields_name);
- wi_release(p7_spec->fields_id);
-
- wi_release(p7_spec->collections_name);
-
- wi_release(p7_spec->types_name);
- wi_release(p7_spec->types_id);
+ wi_release(p7_spec->filename);
+ wi_release(p7_spec->name);
+ wi_release(p7_spec->version);
+
+ wi_release(p7_spec->messages);
+ wi_release(p7_spec->messages_name);
+ wi_release(p7_spec->messages_id);
+
+ wi_release(p7_spec->fields);
+ wi_release(p7_spec->fields_name);
+ wi_release(p7_spec->fields_id);
+
+ wi_release(p7_spec->collections_name);
+
+ wi_release(p7_spec->types_name);
+ wi_release(p7_spec->types_id);
- wi_release(p7_spec->transactions_name);
- wi_release(p7_spec->broadcasts_name);
+ wi_release(p7_spec->transactions_name);
+ wi_release(p7_spec->broadcasts_name);
}
static wi_runtime_instance_t * _wi_p7_spec_copy(wi_runtime_instance_t *instance) {
- wi_p7_spec_t *p7_spec = instance, *p7_spec_copy;
-
- p7_spec_copy = _wi_p7_spec_init(wi_p7_spec_alloc(), p7_spec->originator);
-
- p7_spec_copy->xml = wi_copy(p7_spec->xml);
-
- p7_spec_copy->filename = wi_copy(p7_spec->filename);
- p7_spec_copy->name = wi_copy(p7_spec->name);
- p7_spec_copy->version = wi_copy(p7_spec->version);
+ wi_p7_spec_t *p7_spec = instance, *p7_spec_copy;
+
+ p7_spec_copy = _wi_p7_spec_init(wi_p7_spec_alloc(), p7_spec->originator);
+
+ p7_spec_copy->xml = wi_copy(p7_spec->xml);
+
+ p7_spec_copy->filename = wi_copy(p7_spec->filename);
+ p7_spec_copy->name = wi_copy(p7_spec->name);
+ p7_spec_copy->version = wi_copy(p7_spec->version);
- p7_spec_copy->messages = wi_copy(p7_spec->messages);
- p7_spec_copy->messages_name = wi_mutable_copy(p7_spec->messages_name);
- p7_spec_copy->messages_id = wi_mutable_copy(p7_spec->messages_id);
- p7_spec_copy->fields = wi_copy(p7_spec->fields);
- p7_spec_copy->fields_name = wi_mutable_copy(p7_spec->fields_name);
- p7_spec_copy->fields_id = wi_mutable_copy(p7_spec->fields_id);
- p7_spec_copy->collections_name = wi_mutable_copy(p7_spec->collections_name);
- p7_spec_copy->types_name = wi_mutable_copy(p7_spec->types_name);
- p7_spec_copy->types_id = wi_mutable_copy(p7_spec->types_id);
- p7_spec_copy->transactions_name = wi_mutable_copy(p7_spec->transactions_name);
- p7_spec_copy->broadcasts_name = wi_mutable_copy(p7_spec->broadcasts_name);
+ p7_spec_copy->messages = wi_copy(p7_spec->messages);
+ p7_spec_copy->messages_name = wi_mutable_copy(p7_spec->messages_name);
+ p7_spec_copy->messages_id = wi_mutable_copy(p7_spec->messages_id);
+ p7_spec_copy->fields = wi_copy(p7_spec->fields);
+ p7_spec_copy->fields_name = wi_mutable_copy(p7_spec->fields_name);
+ p7_spec_copy->fields_id = wi_mutable_copy(p7_spec->fields_id);
+ p7_spec_copy->collections_name = wi_mutable_copy(p7_spec->collections_name);
+ p7_spec_copy->types_name = wi_mutable_copy(p7_spec->types_name);
+ p7_spec_copy->types_id = wi_mutable_copy(p7_spec->types_id);
+ p7_spec_copy->transactions_name = wi_mutable_copy(p7_spec->transactions_name);
+ p7_spec_copy->broadcasts_name = wi_mutable_copy(p7_spec->broadcasts_name);
- return p7_spec_copy;
+ return p7_spec_copy;
}
static wi_string_t * _wi_p7_spec_description(wi_runtime_instance_t *instance) {
- wi_p7_spec_t *p7_spec = instance;
-
- return wi_string_with_format(WI_STR("<%@ %p>{name = %@, version = %@, types = %@, fields = %@, messages = %@}"),
- wi_runtime_class_name(p7_spec),
- p7_spec,
- p7_spec->name,
- p7_spec->version,
- p7_spec->types_name,
- p7_spec->fields_name,
- p7_spec->messages_name);
+ wi_p7_spec_t *p7_spec = instance;
+
+ return wi_string_with_format(WI_STR("<%@ %p>{name = %@, version = %@, types = %@, fields = %@, messages = %@}"),
+ wi_runtime_class_name(p7_spec),
+ p7_spec,
+ p7_spec->name,
+ p7_spec->version,
+ p7_spec->types_name,
+ p7_spec->fields_name,
+ p7_spec->messages_name);
}
@@ -708,461 +717,461 @@ static wi_string_t * _wi_p7_spec_description(wi_runtime_instance_t *instance) {
#pragma mark -
static wi_boolean_t _wi_p7_spec_load_builtin(wi_p7_spec_t *p7_spec) {
- xmlDocPtr doc;
-
- doc = xmlParseDoc(_wi_p7_spec_builtin);
-
- if(!doc) {
- wi_error_set_libxml2_error();
-
- return false;
- }
-
- if(!_wi_p7_spec_load_spec(p7_spec, doc)) {
- wi_log_info(WI_STR("no spec loaded"));
-
- xmlFreeDoc(doc);
-
- return false;
- }
-
- xmlFreeDoc(doc);
-
- return true;
+ xmlDocPtr doc;
+
+ doc = xmlParseDoc(_wi_p7_spec_builtin);
+
+ if(!doc) {
+ wi_error_set_libxml2_error();
+
+ return false;
+ }
+
+ if(!_wi_p7_spec_load_spec(p7_spec, doc)) {
+ wi_log_info(WI_STR("no spec loaded"));
+
+ xmlFreeDoc(doc);
+
+ return false;
+ }
+
+ xmlFreeDoc(doc);
+
+ return true;
}
static wi_boolean_t _wi_p7_spec_load_file(wi_p7_spec_t *p7_spec, wi_string_t *path) {
- xmlDocPtr doc;
- xmlChar *buffer;
- int length;
-
- doc = xmlReadFile(wi_string_cstring(path), NULL, 0);
-
- if(!doc) {
- wi_error_set_libxml2_error();
-
- return false;
- }
-
- if(!_wi_p7_spec_load_spec(p7_spec, doc)) {
- xmlFreeDoc(doc);
-
- return false;
- }
-
- xmlDocDumpMemory(doc, &buffer, &length);
-
- p7_spec->xml = wi_string_init_with_bytes(wi_string_alloc(), (const char *) buffer, length);
-
- xmlFreeDoc(doc);
- xmlFree(buffer);
-
- return true;
+ xmlDocPtr doc;
+ xmlChar *buffer;
+ int length;
+
+ doc = xmlReadFile(wi_string_cstring(path), NULL, 0);
+
+ if(!doc) {
+ wi_error_set_libxml2_error();
+
+ return false;
+ }
+
+ if(!_wi_p7_spec_load_spec(p7_spec, doc)) {
+ xmlFreeDoc(doc);
+
+ return false;
+ }
+
+ xmlDocDumpMemory(doc, &buffer, &length);
+
+ p7_spec->xml = wi_string_init_with_bytes(wi_string_alloc(), (const char *) buffer, length);
+
+ xmlFreeDoc(doc);
+ xmlFree(buffer);
+
+ return true;
}
static wi_boolean_t _wi_p7_spec_load_string(wi_p7_spec_t *p7_spec, wi_string_t *string) {
- xmlDocPtr doc;
- xmlChar *buffer;
- int length;
-
- doc = xmlReadMemory(wi_string_cstring(string), wi_string_length(string), NULL, NULL, 0);
-
- if(!doc) {
- wi_error_set_libxml2_error();
+ xmlDocPtr doc;
+ xmlChar *buffer;
+ int length;
+
+ doc = xmlReadMemory(wi_string_cstring(string), wi_string_length(string), NULL, NULL, 0);
+
+ if(!doc) {
+ wi_error_set_libxml2_error();
- return false;
- }
-
- if(!_wi_p7_spec_load_spec(p7_spec, doc)) {
- xmlFreeDoc(doc);
+ return false;
+ }
+
+ if(!_wi_p7_spec_load_spec(p7_spec, doc)) {
+ xmlFreeDoc(doc);
- return false;
- }
-
- xmlDocDumpMemory(doc, &buffer, &length);
-
- p7_spec->xml = wi_string_init_with_bytes(wi_string_alloc(), (const char *) buffer, length);
-
- xmlFree(buffer);
- xmlFreeDoc(doc);
+ return false;
+ }
+
+ xmlDocDumpMemory(doc, &buffer, &length);
+
+ p7_spec->xml = wi_string_init_with_bytes(wi_string_alloc(), (const char *) buffer, length);
+
+ xmlFree(buffer);
+ xmlFreeDoc(doc);
- return true;
+ return true;
}
static wi_boolean_t _wi_p7_spec_load_spec(wi_p7_spec_t *p7_spec, xmlDocPtr doc) {
- xmlNodePtr root_node, node, next_node;
-
- root_node = xmlDocGetRootElement(doc);
-
- if(strcmp((const char *) root_node->name, "protocol") != 0) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Expected \"protocol\" node but got \"%s\""),
- root_node->name);
-
- return false;
- }
-
- p7_spec->name = wi_retain(wi_xml_node_attribute_with_name(root_node, WI_STR("name")));
-
- if(!p7_spec->name) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Protocol has no \"name\""));
-
- return false;
- }
-
- p7_spec->version = wi_retain(wi_xml_node_attribute_with_name(root_node, WI_STR("version")));
-
- if(!p7_spec->version) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Protocol has no \"version\""));
-
- return false;
- }
-
- for(node = root_node->children; node != NULL; node = next_node) {
- next_node = node->next;
-
- if(node->type == XML_ELEMENT_NODE) {
- if(strcmp((const char *) node->name, "documentation") == 0) {
- xmlUnlinkNode(node);
- xmlFreeNode(node);
-
- continue;
- }
-
- if(strcmp((const char *) node->name, "types") == 0) {
- if(!_wi_p7_spec_load_types(p7_spec, node))
- return false;
- }
- else if(strcmp((const char *) node->name, "fields") == 0) {
- if(!_wi_p7_spec_load_fields(p7_spec, node))
- return false;
- }
- else if(strcmp((const char *) node->name, "collections") == 0) {
- if(!_wi_p7_spec_load_collections(p7_spec, node))
- return false;
- }
- else if(strcmp((const char *) node->name, "messages") == 0) {
- if(!_wi_p7_spec_load_messages(p7_spec, node))
- return false;
- }
- else if(strcmp((const char *) node->name, "transactions") == 0) {
- if(!_wi_p7_spec_load_transactions(p7_spec, node))
- return false;
- }
- else if(strcmp((const char *) node->name, "broadcasts") == 0) {
- if(!_wi_p7_spec_load_broadcasts(p7_spec, node))
- return false;
- }
- else {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Expected \"types\", \"fields\", \"collections\", \"messages\", \"transactions\" or \"broadcasts\" node but got \"%s\""),
- node->name);
-
- return false;
- }
- }
- }
-
- return true;
+ xmlNodePtr root_node, node, next_node;
+
+ root_node = xmlDocGetRootElement(doc);
+
+ if(strcmp((const char *) root_node->name, "protocol") != 0) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Expected \"protocol\" node but got \"%s\""),
+ root_node->name);
+
+ return false;
+ }
+
+ p7_spec->name = wi_retain(wi_xml_node_attribute_with_name(root_node, WI_STR("name")));
+
+ if(!p7_spec->name) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Protocol has no \"name\""));
+
+ return false;
+ }
+
+ p7_spec->version = wi_retain(wi_xml_node_attribute_with_name(root_node, WI_STR("version")));
+
+ if(!p7_spec->version) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Protocol has no \"version\""));
+
+ return false;
+ }
+
+ for(node = root_node->children; node != NULL; node = next_node) {
+ next_node = node->next;
+
+ if(node->type == XML_ELEMENT_NODE) {
+ if(strcmp((const char *) node->name, "documentation") == 0) {
+ xmlUnlinkNode(node);
+ xmlFreeNode(node);
+
+ continue;
+ }
+
+ if(strcmp((const char *) node->name, "types") == 0) {
+ if(!_wi_p7_spec_load_types(p7_spec, node))
+ return false;
+ }
+ else if(strcmp((const char *) node->name, "fields") == 0) {
+ if(!_wi_p7_spec_load_fields(p7_spec, node))
+ return false;
+ }
+ else if(strcmp((const char *) node->name, "collections") == 0) {
+ if(!_wi_p7_spec_load_collections(p7_spec, node))
+ return false;
+ }
+ else if(strcmp((const char *) node->name, "messages") == 0) {
+ if(!_wi_p7_spec_load_messages(p7_spec, node))
+ return false;
+ }
+ else if(strcmp((const char *) node->name, "transactions") == 0) {
+ if(!_wi_p7_spec_load_transactions(p7_spec, node))
+ return false;
+ }
+ else if(strcmp((const char *) node->name, "broadcasts") == 0) {
+ if(!_wi_p7_spec_load_broadcasts(p7_spec, node))
+ return false;
+ }
+ else {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Expected \"types\", \"fields\", \"collections\", \"messages\", \"transactions\" or \"broadcasts\" node but got \"%s\""),
+ node->name);
+
+ return false;
+ }
+ }
+ }
+
+ return true;
}
static wi_boolean_t _wi_p7_spec_load_types(wi_p7_spec_t *p7_spec, xmlNodePtr node) {
- wi_p7_spec_type_t *type;
- xmlNodePtr type_node, next_node;
-
- for(type_node = node->children; type_node != NULL; type_node = next_node) {
- next_node = type_node->next;
-
- if(type_node->type == XML_ELEMENT_NODE) {
- if(strcmp((const char *) type_node->name, "type") != 0) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Expected \"type\" node but got \"%s\""),
- type_node->name);
-
- return false;
- }
-
- type = _wi_p7_spec_type_with_node(p7_spec, type_node);
-
- if(!type)
- return false;
-
- if(wi_dictionary_data_for_key(p7_spec->types_name, type->name)) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Type with name \"%@\" already exists"),
- type->name);
-
- return false;
- }
-
- if(wi_dictionary_data_for_key(p7_spec->types_id, (void *) type->id)) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Type with id %lu (name \"%@\") already exists"),
- type->name, type->id);
-
- return false;
- }
-
- wi_mutable_dictionary_set_data_for_key(p7_spec->types_name, type, type->name);
- wi_mutable_dictionary_set_data_for_key(p7_spec->types_id, type, (void *) type->id);
- }
- }
-
- return true;
+ wi_p7_spec_type_t *type;
+ xmlNodePtr type_node, next_node;
+
+ for(type_node = node->children; type_node != NULL; type_node = next_node) {
+ next_node = type_node->next;
+
+ if(type_node->type == XML_ELEMENT_NODE) {
+ if(strcmp((const char *) type_node->name, "type") != 0) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Expected \"type\" node but got \"%s\""),
+ type_node->name);
+
+ return false;
+ }
+
+ type = _wi_p7_spec_type_with_node(p7_spec, type_node);
+
+ if(!type)
+ return false;
+
+ if(wi_dictionary_data_for_key(p7_spec->types_name, type->name)) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Type with name \"%@\" already exists"),
+ type->name);
+
+ return false;
+ }
+
+ if(wi_dictionary_data_for_key(p7_spec->types_id, (void *) type->id)) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Type with id %lu (name \"%@\") already exists"),
+ type->name, type->id);
+
+ return false;
+ }
+
+ wi_mutable_dictionary_set_data_for_key(p7_spec->types_name, type, type->name);
+ wi_mutable_dictionary_set_data_for_key(p7_spec->types_id, type, (void *) type->id);
+ }
+ }
+
+ return true;
}
static wi_boolean_t _wi_p7_spec_load_fields(wi_p7_spec_t *p7_spec, xmlNodePtr node) {
- wi_p7_spec_field_t *field;
- xmlNodePtr field_node, next_node;
-
- for(field_node = node->children; field_node != NULL; field_node = next_node) {
- next_node = field_node->next;
-
- if(field_node->type == XML_ELEMENT_NODE) {
- if(strcmp((const char *) field_node->name, "field") != 0) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Expected \"field\" node but got \"%s\""),
- field_node->name);
-
- return false;
- }
-
- field = _wi_p7_spec_field_with_node(p7_spec, field_node);
-
- if(!field)
- return false;
-
- if(wi_dictionary_data_for_key(p7_spec->fields_name, field->name)) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Field with name \"%@\" already exists"),
- field->name);
-
- return false;
- }
-
- if(wi_dictionary_data_for_key(p7_spec->fields_id, (void *) field->id)) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Field with id %lu (name \"%@\") already exists"),
- field->id, field->name);
-
- return false;
- }
-
- if(_wi_p7_spec_builtin_spec) {
- if(wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->fields_name, field->name)) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Field with name \"%@\" already exists"),
- field->name);
-
- return false;
- }
-
- if(wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->fields_id, (void *) field->id)) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Field with id %lu (name \"%@\") already exists"),
- field->id, field->name);
-
- return false;
- }
- }
-
- wi_mutable_dictionary_set_data_for_key(p7_spec->fields_name, field, field->name);
- wi_mutable_dictionary_set_data_for_key(p7_spec->fields_id, field, (void *) field->id);
- }
- }
-
- return true;
+ wi_p7_spec_field_t *field;
+ xmlNodePtr field_node, next_node;
+
+ for(field_node = node->children; field_node != NULL; field_node = next_node) {
+ next_node = field_node->next;
+
+ if(field_node->type == XML_ELEMENT_NODE) {
+ if(strcmp((const char *) field_node->name, "field") != 0) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Expected \"field\" node but got \"%s\""),
+ field_node->name);
+
+ return false;
+ }
+
+ field = _wi_p7_spec_field_with_node(p7_spec, field_node);
+
+ if(!field)
+ return false;
+
+ if(wi_dictionary_data_for_key(p7_spec->fields_name, field->name)) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Field with name \"%@\" already exists"),
+ field->name);
+
+ return false;
+ }
+
+ if(wi_dictionary_data_for_key(p7_spec->fields_id, (void *) field->id)) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Field with id %lu (name \"%@\") already exists"),
+ field->id, field->name);
+
+ return false;
+ }
+
+ if(_wi_p7_spec_builtin_spec) {
+ if(wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->fields_name, field->name)) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Field with name \"%@\" already exists"),
+ field->name);
+
+ return false;
+ }
+
+ if(wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->fields_id, (void *) field->id)) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Field with id %lu (name \"%@\") already exists"),
+ field->id, field->name);
+
+ return false;
+ }
+ }
+
+ wi_mutable_dictionary_set_data_for_key(p7_spec->fields_name, field, field->name);
+ wi_mutable_dictionary_set_data_for_key(p7_spec->fields_id, field, (void *) field->id);
+ }
+ }
+
+ return true;
}
static wi_boolean_t _wi_p7_spec_load_collections(wi_p7_spec_t *p7_spec, xmlNodePtr node) {
- _wi_p7_spec_collection_t *collection;
- xmlNodePtr collection_node, next_node;
-
- for(collection_node = node->children; collection_node != NULL; collection_node = next_node) {
- next_node = collection_node->next;
-
- if(collection_node->type == XML_ELEMENT_NODE) {
- if(strcmp((const char *) collection_node->name, "collection") != 0) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Expected \"collection\" node but got \"%s\""),
- collection_node->name);
-
- return false;
- }
-
- collection = _wi_p7_spec_collection_with_node(p7_spec, collection_node);
-
- if(!collection)
- return false;
-
- if(wi_dictionary_data_for_key(p7_spec->collections_name, collection->name)) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Collection with name \"%@\" already exists"),
- collection->name);
-
- return false;
- }
-
- wi_mutable_dictionary_set_data_for_key(p7_spec->collections_name, collection, collection->name);
- }
- }
-
- return true;
+ _wi_p7_spec_collection_t *collection;
+ xmlNodePtr collection_node, next_node;
+
+ for(collection_node = node->children; collection_node != NULL; collection_node = next_node) {
+ next_node = collection_node->next;
+
+ if(collection_node->type == XML_ELEMENT_NODE) {
+ if(strcmp((const char *) collection_node->name, "collection") != 0) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Expected \"collection\" node but got \"%s\""),
+ collection_node->name);
+
+ return false;
+ }
+
+ collection = _wi_p7_spec_collection_with_node(p7_spec, collection_node);
+
+ if(!collection)
+ return false;
+
+ if(wi_dictionary_data_for_key(p7_spec->collections_name, collection->name)) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Collection with name \"%@\" already exists"),
+ collection->name);
+
+ return false;
+ }
+
+ wi_mutable_dictionary_set_data_for_key(p7_spec->collections_name, collection, collection->name);
+ }
+ }
+
+ return true;
}
static wi_boolean_t _wi_p7_spec_load_messages(wi_p7_spec_t *p7_spec, xmlNodePtr node) {
- wi_p7_spec_message_t *message;
- xmlNodePtr message_node, next_node;
-
- for(message_node = node->children; message_node != NULL; message_node = next_node) {
- next_node = message_node->next;
-
- if(message_node->type == XML_ELEMENT_NODE) {
- if(strcmp((const char *) message_node->name, "message") != 0) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Expected \"message\" node but got \"%s\""),
- message_node->name);
-
- return false;
- }
-
- message = _wi_p7_spec_message_with_node(p7_spec, message_node);
-
- if(!message)
- return false;
-
- if(wi_dictionary_data_for_key(p7_spec->messages_name, message->name)) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Message with name \"%@\" already exists"),
- message->name);
-
- return false;
- }
-
- if(wi_dictionary_data_for_key(p7_spec->messages_id, (void *) message->id)) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Message with id %lu (name \"%@\") already exists"),
- message->id, message->name);
-
- return false;
- }
-
- if(_wi_p7_spec_builtin_spec) {
- if(wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->messages_name, message->name)) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Message with name \"%@\" already exists"),
- message->name);
-
- return false;
- }
-
- if(wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->messages_id, (void *) message->id)) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Message with id %lu (name \"%@\") already exists"),
- message->id, message->name);
-
- return false;
- }
- }
-
- wi_mutable_dictionary_set_data_for_key(p7_spec->messages_name, message, message->name);
- wi_mutable_dictionary_set_data_for_key(p7_spec->messages_id, message, (void *) message->id);
- }
- }
-
- return true;
+ wi_p7_spec_message_t *message;
+ xmlNodePtr message_node, next_node;
+
+ for(message_node = node->children; message_node != NULL; message_node = next_node) {
+ next_node = message_node->next;
+
+ if(message_node->type == XML_ELEMENT_NODE) {
+ if(strcmp((const char *) message_node->name, "message") != 0) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Expected \"message\" node but got \"%s\""),
+ message_node->name);
+
+ return false;
+ }
+
+ message = _wi_p7_spec_message_with_node(p7_spec, message_node);
+
+ if(!message)
+ return false;
+
+ if(wi_dictionary_data_for_key(p7_spec->messages_name, message->name)) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Message with name \"%@\" already exists"),
+ message->name);
+
+ return false;
+ }
+
+ if(wi_dictionary_data_for_key(p7_spec->messages_id, (void *) message->id)) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Message with id %lu (name \"%@\") already exists"),
+ message->id, message->name);
+
+ return false;
+ }
+
+ if(_wi_p7_spec_builtin_spec) {
+ if(wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->messages_name, message->name)) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Message with name \"%@\" already exists"),
+ message->name);
+
+ return false;
+ }
+
+ if(wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->messages_id, (void *) message->id)) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Message with id %lu (name \"%@\") already exists"),
+ message->id, message->name);
+
+ return false;
+ }
+ }
+
+ wi_mutable_dictionary_set_data_for_key(p7_spec->messages_name, message, message->name);
+ wi_mutable_dictionary_set_data_for_key(p7_spec->messages_id, message, (void *) message->id);
+ }
+ }
+
+ return true;
}
static wi_boolean_t _wi_p7_spec_load_transactions(wi_p7_spec_t *p7_spec, xmlNodePtr node) {
- _wi_p7_spec_transaction_t *transaction;
- xmlNodePtr transaction_node, next_node;
-
- for(transaction_node = node->children; transaction_node != NULL; transaction_node = next_node) {
- next_node = transaction_node->next;
-
- if(transaction_node->type == XML_ELEMENT_NODE) {
- if(strcmp((const char *) transaction_node->name, "transaction") != 0) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Expected \"transaction\" node but got \"%s\""),
- transaction_node->name);
-
- return false;
- }
-
- transaction = _wi_p7_spec_transaction_with_node(p7_spec, transaction_node);
-
- if(!transaction)
- return false;
-
- if(wi_dictionary_data_for_key(p7_spec->transactions_name, transaction->message->name)) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Transaction with message \"%@\" already exists"),
- transaction->message->name);
-
- return false;
- }
-
- wi_mutable_dictionary_set_data_for_key(p7_spec->transactions_name, transaction, transaction->message->name);
- }
- }
-
- return true;
+ _wi_p7_spec_transaction_t *transaction;
+ xmlNodePtr transaction_node, next_node;
+
+ for(transaction_node = node->children; transaction_node != NULL; transaction_node = next_node) {
+ next_node = transaction_node->next;
+
+ if(transaction_node->type == XML_ELEMENT_NODE) {
+ if(strcmp((const char *) transaction_node->name, "transaction") != 0) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Expected \"transaction\" node but got \"%s\""),
+ transaction_node->name);
+
+ return false;
+ }
+
+ transaction = _wi_p7_spec_transaction_with_node(p7_spec, transaction_node);
+
+ if(!transaction)
+ return false;
+
+ if(wi_dictionary_data_for_key(p7_spec->transactions_name, transaction->message->name)) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Transaction with message \"%@\" already exists"),
+ transaction->message->name);
+
+ return false;
+ }
+
+ wi_mutable_dictionary_set_data_for_key(p7_spec->transactions_name, transaction, transaction->message->name);
+ }
+ }
+
+ return true;
}
static wi_boolean_t _wi_p7_spec_load_broadcasts(wi_p7_spec_t *p7_spec, xmlNodePtr node) {
- _wi_p7_spec_broadcast_t *broadcast;
- xmlNodePtr broadcast_node, next_node;
-
- for(broadcast_node = node->children; broadcast_node != NULL; broadcast_node = next_node) {
- next_node = broadcast_node->next;
-
- if(broadcast_node->type == XML_ELEMENT_NODE) {
- if(strcmp((const char *) broadcast_node->name, "broadcast") != 0) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Expected \"broadcast\" node but got \"%s\""),
- broadcast_node->name);
-
- return false;
- }
-
- broadcast = _wi_p7_spec_broadcast_with_node(p7_spec, broadcast_node);
-
- if(!broadcast)
- return false;
-
- if(wi_dictionary_data_for_key(p7_spec->broadcasts_name, broadcast->message->name)) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Broadcast with message \"%@\" already exists"),
- broadcast->message->name);
-
- return false;
- }
-
- wi_mutable_dictionary_set_data_for_key(p7_spec->broadcasts_name, broadcast, broadcast->message->name);
- }
- }
-
- return true;
+ _wi_p7_spec_broadcast_t *broadcast;
+ xmlNodePtr broadcast_node, next_node;
+
+ for(broadcast_node = node->children; broadcast_node != NULL; broadcast_node = next_node) {
+ next_node = broadcast_node->next;
+
+ if(broadcast_node->type == XML_ELEMENT_NODE) {
+ if(strcmp((const char *) broadcast_node->name, "broadcast") != 0) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Expected \"broadcast\" node but got \"%s\""),
+ broadcast_node->name);
+
+ return false;
+ }
+
+ broadcast = _wi_p7_spec_broadcast_with_node(p7_spec, broadcast_node);
+
+ if(!broadcast)
+ return false;
+
+ if(wi_dictionary_data_for_key(p7_spec->broadcasts_name, broadcast->message->name)) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Broadcast with message \"%@\" already exists"),
+ broadcast->message->name);
+
+ return false;
+ }
+
+ wi_mutable_dictionary_set_data_for_key(p7_spec->broadcasts_name, broadcast, broadcast->message->name);
+ }
+ }
+
+ return true;
}
@@ -1170,382 +1179,382 @@ static wi_boolean_t _wi_p7_spec_load_broadcasts(wi_p7_spec_t *p7_spec, xmlNodePt
#pragma mark -
wi_boolean_t wi_p7_spec_is_compatible_with_protocol(wi_p7_spec_t *p7_spec, wi_string_t *name, wi_string_t *version) {
- return (wi_is_equal(p7_spec->name, name) && wi_is_equal(p7_spec->version, version));
+ return (wi_is_equal(p7_spec->name, name) && wi_is_equal(p7_spec->version, version));
}
wi_boolean_t wi_p7_spec_is_compatible_with_spec(wi_p7_spec_t *p7_spec, wi_p7_spec_t *other_p7_spec) {
- wi_enumerator_t *enumerator;
- wi_string_t *key;
- _wi_p7_spec_transaction_t *transaction, *other_transaction;
- _wi_p7_spec_broadcast_t *broadcast, *other_broadcast;
-
- enumerator = wi_dictionary_key_enumerator(p7_spec->transactions_name);
-
- while((key = wi_enumerator_next_data(enumerator))) {
- transaction = wi_dictionary_data_for_key(p7_spec->transactions_name, key);
- other_transaction = wi_dictionary_data_for_key(other_p7_spec->transactions_name, key);
-
- if(!_wi_p7_spec_transaction_is_compatible(p7_spec, transaction, other_transaction))
- return false;
- }
-
- enumerator = wi_dictionary_key_enumerator(p7_spec->broadcasts_name);
-
- while((key = wi_enumerator_next_data(enumerator))) {
- broadcast = wi_dictionary_data_for_key(p7_spec->broadcasts_name, key);
- other_broadcast = wi_dictionary_data_for_key(other_p7_spec->broadcasts_name, key);
-
- if(!_wi_p7_spec_broadcast_is_compatible(p7_spec, broadcast, other_broadcast))
- return false;
- }
-
- return true;
+ wi_enumerator_t *enumerator;
+ wi_string_t *key;
+ _wi_p7_spec_transaction_t *transaction, *other_transaction;
+ _wi_p7_spec_broadcast_t *broadcast, *other_broadcast;
+
+ enumerator = wi_dictionary_key_enumerator(p7_spec->transactions_name);
+
+ while((key = wi_enumerator_next_data(enumerator))) {
+ transaction = wi_dictionary_data_for_key(p7_spec->transactions_name, key);
+ other_transaction = wi_dictionary_data_for_key(other_p7_spec->transactions_name, key);
+
+ if(!_wi_p7_spec_transaction_is_compatible(p7_spec, transaction, other_transaction))
+ return false;
+ }
+
+ enumerator = wi_dictionary_key_enumerator(p7_spec->broadcasts_name);
+
+ while((key = wi_enumerator_next_data(enumerator))) {
+ broadcast = wi_dictionary_data_for_key(p7_spec->broadcasts_name, key);
+ other_broadcast = wi_dictionary_data_for_key(other_p7_spec->broadcasts_name, key);
+
+ if(!_wi_p7_spec_broadcast_is_compatible(p7_spec, broadcast, other_broadcast))
+ return false;
+ }
+
+ return true;
}
static wi_boolean_t _wi_p7_spec_transaction_is_compatible(wi_p7_spec_t *p7_spec, _wi_p7_spec_transaction_t *transaction, _wi_p7_spec_transaction_t *other_transaction) {
- if(transaction->required) {
- if(!other_transaction || !other_transaction->required) {
- if(!other_transaction) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
- WI_STR("Transaction \"%@\" is required, but peer lacks it"),
- transaction->message->name);
- } else {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
- WI_STR("Transaction \"%@\" is required, but peer has it optional"),
- transaction->message->name);
- }
-
- return false;
- }
- }
-
- if(other_transaction) {
- if(transaction->originator != other_transaction->originator) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
- WI_STR("Transaction \"%@\" should be sent by %@, but peer sends it by %@"),
- transaction->message->name,
- _wi_p7_spec_originator(transaction->originator),
- _wi_p7_spec_originator(other_transaction->originator));
-
- return false;
- }
-
- if(!_wi_p7_spec_message_is_compatible(p7_spec, transaction->message, other_transaction->message))
- return false;
-
- if(!_wi_p7_spec_andor_is_compatible(p7_spec, transaction, transaction->andor, other_transaction->andor))
- return false;
- }
-
- return true;
+ if(transaction->required) {
+ if(!other_transaction || !other_transaction->required) {
+ if(!other_transaction) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
+ WI_STR("Transaction \"%@\" is required, but peer lacks it"),
+ transaction->message->name);
+ } else {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
+ WI_STR("Transaction \"%@\" is required, but peer has it optional"),
+ transaction->message->name);
+ }
+
+ return false;
+ }
+ }
+
+ if(other_transaction) {
+ if(transaction->originator != other_transaction->originator) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
+ WI_STR("Transaction \"%@\" should be sent by %@, but peer sends it by %@"),
+ transaction->message->name,
+ _wi_p7_spec_originator(transaction->originator),
+ _wi_p7_spec_originator(other_transaction->originator));
+
+ return false;
+ }
+
+ if(!_wi_p7_spec_message_is_compatible(p7_spec, transaction->message, other_transaction->message))
+ return false;
+
+ if(!_wi_p7_spec_andor_is_compatible(p7_spec, transaction, transaction->andor, other_transaction->andor))
+ return false;
+ }
+
+ return true;
}
static wi_boolean_t _wi_p7_spec_broadcast_is_compatible(wi_p7_spec_t *p7_spec, _wi_p7_spec_broadcast_t *broadcast, _wi_p7_spec_broadcast_t *other_broadcast) {
- if(broadcast->required) {
- if(!other_broadcast || !other_broadcast->required) {
- if(!other_broadcast) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
- WI_STR("Broadcast \"%@\" is required, but peer lacks it"),
- broadcast->message->name);
- } else {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
- WI_STR("Broadcast \"%@\" is required, but peer has it optional"),
- broadcast->message->name);
- }
-
- return false;
- }
- }
-
- if(other_broadcast) {
- if(!_wi_p7_spec_message_is_compatible(p7_spec, broadcast->message, other_broadcast->message))
- return false;
- }
-
- return true;
+ if(broadcast->required) {
+ if(!other_broadcast || !other_broadcast->required) {
+ if(!other_broadcast) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
+ WI_STR("Broadcast \"%@\" is required, but peer lacks it"),
+ broadcast->message->name);
+ } else {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
+ WI_STR("Broadcast \"%@\" is required, but peer has it optional"),
+ broadcast->message->name);
+ }
+
+ return false;
+ }
+ }
+
+ if(other_broadcast) {
+ if(!_wi_p7_spec_message_is_compatible(p7_spec, broadcast->message, other_broadcast->message))
+ return false;
+ }
+
+ return true;
}
static wi_boolean_t _wi_p7_spec_andor_is_compatible(wi_p7_spec_t *p7_spec, _wi_p7_spec_transaction_t *transaction, _wi_p7_spec_andor_t *andor, _wi_p7_spec_andor_t *other_andor) {
- wi_uinteger_t i, count, other_count;
-
- if(andor->type != other_andor->type)
- return false;
-
- if(!_wi_p7_spec_replies_are_compatible(p7_spec, transaction, andor, other_andor, false) ||
- !_wi_p7_spec_replies_are_compatible(p7_spec, transaction, other_andor, andor, true))
- return false;
-
- count = wi_array_count(andor->children);
- other_count = wi_array_count(other_andor->children);
-
- if(count != other_count) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
- WI_STR("Transaction \"%@\" should have %lu %@, but peer has %lu"),
- transaction->message->name,
- count,
- count == 1
- ? WI_STR("child")
- : WI_STR("children"),
- other_count);
-
- return false;
- }
-
- for(i = 0; i < count; i++) {
- if(!_wi_p7_spec_andor_is_compatible(p7_spec, transaction, WI_ARRAY(andor->children, i), WI_ARRAY(other_andor->children, i)))
- return false;
- }
-
- return true;
+ wi_uinteger_t i, count, other_count;
+
+ if(andor->type != other_andor->type)
+ return false;
+
+ if(!_wi_p7_spec_replies_are_compatible(p7_spec, transaction, andor, other_andor, false) ||
+ !_wi_p7_spec_replies_are_compatible(p7_spec, transaction, other_andor, andor, true))
+ return false;
+
+ count = wi_array_count(andor->children);
+ other_count = wi_array_count(other_andor->children);
+
+ if(count != other_count) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
+ WI_STR("Transaction \"%@\" should have %lu %@, but peer has %lu"),
+ transaction->message->name,
+ count,
+ count == 1
+ ? WI_STR("child")
+ : WI_STR("children"),
+ other_count);
+
+ return false;
+ }
+
+ for(i = 0; i < count; i++) {
+ if(!_wi_p7_spec_andor_is_compatible(p7_spec, transaction, WI_ARRAY(andor->children, i), WI_ARRAY(other_andor->children, i)))
+ return false;
+ }
+
+ return true;
}
static wi_boolean_t _wi_p7_spec_replies_are_compatible(wi_p7_spec_t *p7_spec, _wi_p7_spec_transaction_t *transaction, _wi_p7_spec_andor_t *andor, _wi_p7_spec_andor_t *other_andor, wi_boolean_t commutativity) {
- wi_enumerator_t *enumerator;
- _wi_p7_spec_reply_t *reply, *other_reply, *each_reply;
- wi_uinteger_t i, count, index;
-
- if(andor->type != other_andor->type)
- return false;
-
- enumerator = wi_array_data_enumerator(andor->replies_array);
- count = wi_array_count(other_andor->replies_array);
- index = 0;
-
- while((reply = wi_enumerator_next_data(enumerator))) {
- if(reply->required) {
- other_reply = NULL;
-
- for(i = index; i < count; i++) {
- each_reply = WI_ARRAY(other_andor->replies_array, i);
-
- if(each_reply->required) {
- other_reply = each_reply;
-
- break;
- }
- }
-
- index = i + 1;
-
- if(!_wi_p7_spec_reply_is_compatible(p7_spec, transaction, reply, other_reply, commutativity))
- return false;
- } else {
- other_reply = wi_dictionary_data_for_key(other_andor->replies_dictionary, reply->message->name);
-
- if(!_wi_p7_spec_reply_is_compatible(p7_spec, transaction, reply, other_reply, commutativity))
- return false;
- }
- }
-
- return true;
+ wi_enumerator_t *enumerator;
+ _wi_p7_spec_reply_t *reply, *other_reply, *each_reply;
+ wi_uinteger_t i, count, index;
+
+ if(andor->type != other_andor->type)
+ return false;
+
+ enumerator = wi_array_data_enumerator(andor->replies_array);
+ count = wi_array_count(other_andor->replies_array);
+ index = 0;
+
+ while((reply = wi_enumerator_next_data(enumerator))) {
+ if(reply->required) {
+ other_reply = NULL;
+
+ for(i = index; i < count; i++) {
+ each_reply = WI_ARRAY(other_andor->replies_array, i);
+
+ if(each_reply->required) {
+ other_reply = each_reply;
+
+ break;
+ }
+ }
+
+ index = i + 1;
+
+ if(!_wi_p7_spec_reply_is_compatible(p7_spec, transaction, reply, other_reply, commutativity))
+ return false;
+ } else {
+ other_reply = wi_dictionary_data_for_key(other_andor->replies_dictionary, reply->message->name);
+
+ if(!_wi_p7_spec_reply_is_compatible(p7_spec, transaction, reply, other_reply, commutativity))
+ return false;
+ }
+ }
+
+ return true;
}
static wi_boolean_t _wi_p7_spec_reply_is_compatible(wi_p7_spec_t *p7_spec, _wi_p7_spec_transaction_t *transaction, _wi_p7_spec_reply_t *reply, _wi_p7_spec_reply_t *other_reply, wi_boolean_t commutativity) {
- wi_boolean_t compatible;
-
- if(reply->required) {
- if(!other_reply || !other_reply->required) {
- if(!other_reply) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
- WI_STR("Reply \"%@\" in transaction \"%@\" is required, but peer lacks it"),
- reply->message->name, transaction->message->name);
- } else {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
- WI_STR("Reply \"%@\" in transaction \"%@\" is required, but peer has it optional"),
- reply->message->name, transaction->message->name);
- }
-
- return false;
- }
- }
-
- if(!commutativity) {
- if(other_reply) {
- if(reply->count == _WI_P7_SPEC_REPLY_ONE_OR_ZERO)
- compatible = (other_reply->count == _WI_P7_SPEC_REPLY_ONE_OR_ZERO);
- else if(reply->count == _WI_P7_SPEC_REPLY_ZERO_OR_MORE)
- compatible = (other_reply->count == _WI_P7_SPEC_REPLY_ONE_OR_ZERO || other_reply->count == _WI_P7_SPEC_REPLY_ZERO_OR_MORE);
- else if(reply->count == _WI_P7_SPEC_REPLY_ONE_OR_MORE)
- compatible = (other_reply->count == _WI_P7_SPEC_REPLY_ONE_OR_MORE || other_reply->count > 0);
- else
- compatible = (reply->count == other_reply->count);
-
- if(!compatible) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
- WI_STR("Reply \"%@\" in transaction \"%@\" should be sent %@, but peer sends it %@"),
- reply->message->name,
- transaction->message->name,
- _wi_p7_spec_reply_count(reply),
- _wi_p7_spec_reply_count(other_reply));
-
- return false;
- }
-
- if(!_wi_p7_spec_message_is_compatible(p7_spec, reply->message, other_reply->message))
- return false;
- }
- }
-
- return true;
-}
-
-
-
+ wi_boolean_t compatible;
+
+ if(reply->required) {
+ if(!other_reply || !other_reply->required) {
+ if(!other_reply) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
+ WI_STR("Reply \"%@\" in transaction \"%@\" is required, but peer lacks it"),
+ reply->message->name, transaction->message->name);
+ } else {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
+ WI_STR("Reply \"%@\" in transaction \"%@\" is required, but peer has it optional"),
+ reply->message->name, transaction->message->name);
+ }
+
+ return false;
+ }
+ }
+
+ if(!commutativity) {
+ if(other_reply) {
+ if(reply->count == _WI_P7_SPEC_REPLY_ONE_OR_ZERO)
+ compatible = (other_reply->count == _WI_P7_SPEC_REPLY_ONE_OR_ZERO);
+ else if(reply->count == _WI_P7_SPEC_REPLY_ZERO_OR_MORE)
+ compatible = (other_reply->count == _WI_P7_SPEC_REPLY_ONE_OR_ZERO || other_reply->count == _WI_P7_SPEC_REPLY_ZERO_OR_MORE);
+ else if(reply->count == _WI_P7_SPEC_REPLY_ONE_OR_MORE)
+ compatible = (other_reply->count == _WI_P7_SPEC_REPLY_ONE_OR_MORE || other_reply->count > 0);
+ else
+ compatible = (reply->count == other_reply->count);
+
+ if(!compatible) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
+ WI_STR("Reply \"%@\" in transaction \"%@\" should be sent %@, but peer sends it %@"),
+ reply->message->name,
+ transaction->message->name,
+ _wi_p7_spec_reply_count(reply),
+ _wi_p7_spec_reply_count(other_reply));
+
+ return false;
+ }
+
+ if(!_wi_p7_spec_message_is_compatible(p7_spec, reply->message, other_reply->message))
+ return false;
+ }
+ }
+
+ return true;
+}
+
+
+
static wi_boolean_t _wi_p7_spec_message_is_compatible(wi_p7_spec_t *p7_spec, wi_p7_spec_message_t *message, wi_p7_spec_message_t *other_message) {
- wi_enumerator_t *enumerator, *enum_enumerator;
- wi_string_t *key, *name;
- wi_p7_spec_parameter_t *parameter, *other_parameter;
- wi_p7_spec_field_t *field, *other_field;
- wi_uinteger_t value, other_value;
-
- if(!wi_is_equal(message->name, other_message->name)) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
- WI_STR("Message should be \"%@\", but peer has \"%@\""),
- message->name, other_message->name);
-
- return false;
- }
-
- if(message->id != other_message->id) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
- WI_STR("Message should have id %lu, but peer has id %lu"),
- message->id, other_message->id);
-
- return false;
- }
-
- enumerator = wi_dictionary_key_enumerator(message->parameters_name);
-
- while((key = wi_enumerator_next_data(enumerator))) {
- parameter = wi_dictionary_data_for_key(message->parameters_name, key);
- other_parameter = wi_dictionary_data_for_key(other_message->parameters_name, key);
-
- if(parameter->required) {
- if(!other_parameter || !other_parameter->required) {
- if(!other_parameter) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
- WI_STR("Parameter \"%@\" in message \"%@\" is required, but peer lacks it"),
- parameter->field->name, message->name);
- } else {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
- WI_STR("Parameter \"%@\" in message \"%@\" is required, but peer has it optional"),
- parameter->field->name, message->name);
- }
-
- return false;
- }
- }
-
- if(other_parameter) {
- field = parameter->field;
- other_field = other_parameter->field;
-
- if(field->id != other_field->id) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
- WI_STR("Field in parameter \"%@\" in message \"%@\" should have id %lu, but peer has id %lu"),
- parameter->field->name, message->name, field->id, other_field->id);
-
- return false;
- }
-
- if(field->type->id != other_field->type->id) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
- WI_STR("Parameter \"%@\" in message \"%@\" should be of type \"%@\", but peer has it as \"%@\""),
- parameter->field->name, message->name, field->type->name, other_field->type->name);
-
- return false;
- }
-
- if(field->type->id == WI_P7_ENUM) {
- enum_enumerator = wi_dictionary_key_enumerator(field->enums_name);
-
- while((name = wi_enumerator_next_data(enum_enumerator))) {
- value = (wi_uinteger_t) wi_dictionary_data_for_key(field->enums_name, name);
- other_value = (wi_uinteger_t) wi_dictionary_data_for_key(other_field->enums_name, name);
-
- if(value != other_value) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
- WI_STR("Enumeration \"%@\" in parameter \"%@\" in message \"%@\" should have value %lu, but peer has value %lu"),
- name, parameter->field->name, message->name, value, other_value);
-
- return false;
- }
- }
- }
- }
- }
-
- return true;
+ wi_enumerator_t *enumerator, *enum_enumerator;
+ wi_string_t *key, *name;
+ wi_p7_spec_parameter_t *parameter, *other_parameter;
+ wi_p7_spec_field_t *field, *other_field;
+ wi_uinteger_t value, other_value;
+
+ if(!wi_is_equal(message->name, other_message->name)) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
+ WI_STR("Message should be \"%@\", but peer has \"%@\""),
+ message->name, other_message->name);
+
+ return false;
+ }
+
+ if(message->id != other_message->id) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
+ WI_STR("Message should have id %lu, but peer has id %lu"),
+ message->id, other_message->id);
+
+ return false;
+ }
+
+ enumerator = wi_dictionary_key_enumerator(message->parameters_name);
+
+ while((key = wi_enumerator_next_data(enumerator))) {
+ parameter = wi_dictionary_data_for_key(message->parameters_name, key);
+ other_parameter = wi_dictionary_data_for_key(other_message->parameters_name, key);
+
+ if(parameter->required) {
+ if(!other_parameter || !other_parameter->required) {
+ if(!other_parameter) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
+ WI_STR("Parameter \"%@\" in message \"%@\" is required, but peer lacks it"),
+ parameter->field->name, message->name);
+ } else {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
+ WI_STR("Parameter \"%@\" in message \"%@\" is required, but peer has it optional"),
+ parameter->field->name, message->name);
+ }
+
+ return false;
+ }
+ }
+
+ if(other_parameter) {
+ field = parameter->field;
+ other_field = other_parameter->field;
+
+ if(field->id != other_field->id) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
+ WI_STR("Field in parameter \"%@\" in message \"%@\" should have id %lu, but peer has id %lu"),
+ parameter->field->name, message->name, field->id, other_field->id);
+
+ return false;
+ }
+
+ if(field->type->id != other_field->type->id) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
+ WI_STR("Parameter \"%@\" in message \"%@\" should be of type \"%@\", but peer has it as \"%@\""),
+ parameter->field->name, message->name, field->type->name, other_field->type->name);
+
+ return false;
+ }
+
+ if(field->type->id == WI_P7_ENUM) {
+ enum_enumerator = wi_dictionary_key_enumerator(field->enums_name);
+
+ while((name = wi_enumerator_next_data(enum_enumerator))) {
+ value = (wi_uinteger_t) wi_dictionary_data_for_key(field->enums_name, name);
+ other_value = (wi_uinteger_t) wi_dictionary_data_for_key(other_field->enums_name, name);
+
+ if(value != other_value) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INCOMPATIBLESPEC,
+ WI_STR("Enumeration \"%@\" in parameter \"%@\" in message \"%@\" should have value %lu, but peer has value %lu"),
+ name, parameter->field->name, message->name, value, other_value);
+
+ return false;
+ }
+ }
+ }
+ }
+ }
+
+ return true;
}
void wi_p7_spec_merge_with_spec(wi_p7_spec_t *p7_spec, wi_p7_spec_t *other_p7_spec) {
- wi_enumerator_t *enumerator;
- wi_p7_spec_message_t *message;
- wi_p7_spec_field_t *field, *other_field;
- wi_uinteger_t id;
- wi_boolean_t modified;
-
- modified = false;
- enumerator = wi_dictionary_key_enumerator(other_p7_spec->messages_id);
-
- while((id = (wi_uinteger_t) wi_enumerator_next_data(enumerator))) {
- if(!wi_dictionary_data_for_key(p7_spec->messages_id, (void *) id)) {
- message = wi_dictionary_data_for_key(other_p7_spec->messages_id, (void *) id);
-
- wi_mutable_dictionary_set_data_for_key(p7_spec->messages_id, message, (void *) message->id);
- wi_mutable_dictionary_set_data_for_key(p7_spec->messages_name, message, message->name);
-
- modified = true;
- }
- }
-
- if(modified) {
- wi_release(p7_spec->messages);
- p7_spec->messages = NULL;
- }
-
- modified = false;
- enumerator = wi_dictionary_key_enumerator(other_p7_spec->fields_id);
-
- while((id = (wi_uinteger_t) wi_enumerator_next_data(enumerator))) {
- field = wi_dictionary_data_for_key(p7_spec->fields_id, (void *) id);
- other_field = wi_dictionary_data_for_key(other_p7_spec->fields_id, (void *) id);
-
- if(field) {
- if(field->type->id == WI_P7_ENUM) {
- if(!wi_is_equal(field->enums_name, other_field->enums_name)) {
- wi_mutable_dictionary_set_dictionary(field->enums_name, other_field->enums_name);
- wi_mutable_dictionary_set_dictionary(field->enums_value, other_field->enums_value);
-
- modified = true;
- }
- }
- } else {
- wi_mutable_dictionary_set_data_for_key(p7_spec->fields_id, other_field, (void *) other_field->id);
- wi_mutable_dictionary_set_data_for_key(p7_spec->fields_name, other_field, other_field->name);
-
- modified = true;
- }
- }
-
- if(modified) {
- wi_release(p7_spec->fields);
- p7_spec->fields = NULL;
- }
+ wi_enumerator_t *enumerator;
+ wi_p7_spec_message_t *message;
+ wi_p7_spec_field_t *field, *other_field;
+ wi_uinteger_t id;
+ wi_boolean_t modified;
+
+ modified = false;
+ enumerator = wi_dictionary_key_enumerator(other_p7_spec->messages_id);
+
+ while((id = (wi_uinteger_t) wi_enumerator_next_data(enumerator))) {
+ if(!wi_dictionary_data_for_key(p7_spec->messages_id, (void *) id)) {
+ message = wi_dictionary_data_for_key(other_p7_spec->messages_id, (void *) id);
+
+ wi_mutable_dictionary_set_data_for_key(p7_spec->messages_id, message, (void *) message->id);
+ wi_mutable_dictionary_set_data_for_key(p7_spec->messages_name, message, message->name);
+
+ modified = true;
+ }
+ }
+
+ if(modified) {
+ wi_release(p7_spec->messages);
+ p7_spec->messages = NULL;
+ }
+
+ modified = false;
+ enumerator = wi_dictionary_key_enumerator(other_p7_spec->fields_id);
+
+ while((id = (wi_uinteger_t) wi_enumerator_next_data(enumerator))) {
+ field = wi_dictionary_data_for_key(p7_spec->fields_id, (void *) id);
+ other_field = wi_dictionary_data_for_key(other_p7_spec->fields_id, (void *) id);
+
+ if(field) {
+ if(field->type->id == WI_P7_ENUM) {
+ if(!wi_is_equal(field->enums_name, other_field->enums_name)) {
+ wi_mutable_dictionary_set_dictionary(field->enums_name, other_field->enums_name);
+ wi_mutable_dictionary_set_dictionary(field->enums_value, other_field->enums_value);
+
+ modified = true;
+ }
+ }
+ } else {
+ wi_mutable_dictionary_set_data_for_key(p7_spec->fields_id, other_field, (void *) other_field->id);
+ wi_mutable_dictionary_set_data_for_key(p7_spec->fields_name, other_field, other_field->name);
+
+ modified = true;
+ }
+ }
+
+ if(modified) {
+ wi_release(p7_spec->fields);
+ p7_spec->fields = NULL;
+ }
}
@@ -1553,121 +1562,121 @@ void wi_p7_spec_merge_with_spec(wi_p7_spec_t *p7_spec, wi_p7_spec_t *other_p7_sp
#pragma mark -
wi_string_t * wi_p7_spec_name(wi_p7_spec_t *p7_spec) {
- return p7_spec->name;
+ return p7_spec->name;
}
wi_string_t * wi_p7_spec_version(wi_p7_spec_t *p7_spec) {
- return p7_spec->version;
+ return p7_spec->version;
}
wi_p7_originator_t wi_p7_spec_originator(wi_p7_spec_t *p7_spec) {
- return p7_spec->originator;
+ return p7_spec->originator;
}
wi_string_t * wi_p7_spec_xml(wi_p7_spec_t *p7_spec) {
- return p7_spec->xml;
+ return p7_spec->xml;
}
wi_p7_spec_type_t * wi_p7_spec_type_with_name(wi_p7_spec_t *p7_spec, wi_string_t *type_name) {
- wi_p7_spec_type_t *type;
-
- type = wi_dictionary_data_for_key(p7_spec->types_name, type_name);
-
- if(!type && _wi_p7_spec_builtin_spec)
- type = wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->types_name, type_name);
-
- return type;
+ wi_p7_spec_type_t *type;
+
+ type = wi_dictionary_data_for_key(p7_spec->types_name, type_name);
+
+ if(!type && _wi_p7_spec_builtin_spec)
+ type = wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->types_name, type_name);
+
+ return type;
}
wi_p7_spec_type_t * wi_p7_spec_type_with_id(wi_p7_spec_t *p7_spec, wi_uinteger_t type_id) {
- wi_p7_spec_type_t *type;
-
- type = wi_dictionary_data_for_key(p7_spec->types_id, (void *) type_id);
-
- if(!type && _wi_p7_spec_builtin_spec)
- type = wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->types_id, (void *) type_id);
-
- return type;
+ wi_p7_spec_type_t *type;
+
+ type = wi_dictionary_data_for_key(p7_spec->types_id, (void *) type_id);
+
+ if(!type && _wi_p7_spec_builtin_spec)
+ type = wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->types_id, (void *) type_id);
+
+ return type;
}
wi_array_t * wi_p7_spec_fields(wi_p7_spec_t *p7_spec) {
- if(!p7_spec->fields)
- p7_spec->fields = wi_retain(wi_dictionary_all_values(p7_spec->fields_id));
-
- return p7_spec->fields;
+ if(!p7_spec->fields)
+ p7_spec->fields = wi_retain(wi_dictionary_all_values(p7_spec->fields_id));
+
+ return p7_spec->fields;
}
wi_p7_spec_field_t * wi_p7_spec_field_with_name(wi_p7_spec_t *p7_spec, wi_string_t *field_name) {
- wi_p7_spec_field_t *field;
-
- field = wi_dictionary_data_for_key(p7_spec->fields_name, field_name);
-
- if(!field && _wi_p7_spec_builtin_spec)
- field = wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->fields_name, field_name);
-
- return field;
+ wi_p7_spec_field_t *field;
+
+ field = wi_dictionary_data_for_key(p7_spec->fields_name, field_name);
+
+ if(!field && _wi_p7_spec_builtin_spec)
+ field = wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->fields_name, field_name);
+
+ return field;
}
wi_p7_spec_field_t * wi_p7_spec_field_with_id(wi_p7_spec_t *p7_spec, wi_uinteger_t field_id) {
- wi_p7_spec_field_t *field;
-
- field = wi_dictionary_data_for_key(p7_spec->fields_id, (void *) field_id);
-
- if(!field && _wi_p7_spec_builtin_spec)
- field = wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->fields_id, (void *) field_id);
-
- return field;
+ wi_p7_spec_field_t *field;
+
+ field = wi_dictionary_data_for_key(p7_spec->fields_id, (void *) field_id);
+
+ if(!field && _wi_p7_spec_builtin_spec)
+ field = wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->fields_id, (void *) field_id);
+
+ return field;
}
wi_array_t * wi_p7_spec_messages(wi_p7_spec_t *p7_spec) {
- if(!p7_spec->messages)
- p7_spec->messages = wi_retain(wi_dictionary_all_values(p7_spec->messages_id));
-
- return p7_spec->messages;
+ if(!p7_spec->messages)
+ p7_spec->messages = wi_retain(wi_dictionary_all_values(p7_spec->messages_id));
+
+ return p7_spec->messages;
}
wi_p7_spec_message_t * wi_p7_spec_message_with_name(wi_p7_spec_t *p7_spec, wi_string_t *message_name) {
- wi_p7_spec_message_t *message;
-
- message = wi_dictionary_data_for_key(p7_spec->messages_name, message_name);
-
- if(!message && _wi_p7_spec_builtin_spec)
- message = wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->messages_name, message_name);
-
- return message;
+ wi_p7_spec_message_t *message;
+
+ message = wi_dictionary_data_for_key(p7_spec->messages_name, message_name);
+
+ if(!message && _wi_p7_spec_builtin_spec)
+ message = wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->messages_name, message_name);
+
+ return message;
}
wi_p7_spec_message_t * wi_p7_spec_message_with_id(wi_p7_spec_t *p7_spec, wi_uinteger_t message_id) {
- wi_p7_spec_message_t *message;
-
- message = wi_dictionary_data_for_key(p7_spec->messages_id, (void *) message_id);
-
- if(!message && _wi_p7_spec_builtin_spec)
- message = wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->messages_id, (void *) message_id);
-
- return message;
+ wi_p7_spec_message_t *message;
+
+ message = wi_dictionary_data_for_key(p7_spec->messages_id, (void *) message_id);
+
+ if(!message && _wi_p7_spec_builtin_spec)
+ message = wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->messages_id, (void *) message_id);
+
+ return message;
}
@@ -1675,59 +1684,59 @@ wi_p7_spec_message_t * wi_p7_spec_message_with_id(wi_p7_spec_t *p7_spec, wi_uint
#pragma mark -
wi_boolean_t wi_p7_spec_verify_message(wi_p7_spec_t *p7_spec, wi_p7_message_t *p7_message) {
- wi_p7_spec_message_t *message;
- wi_p7_spec_field_t *field;
- wi_p7_spec_parameter_t *parameter;
- unsigned char *buffer, *start;
- wi_uinteger_t required_parameters = 0;
- uint32_t message_size, field_id, field_size;
-
- message = wi_dictionary_data_for_key(p7_spec->messages_id, (void *) (intptr_t) p7_message->binary_id);
-
- if(!message) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_UNKNOWNMESSAGE,
- WI_STR("Message with id %u not recognized"),
- p7_message->binary_id);
-
- return false;
- }
-
- message_size = p7_message->binary_size - WI_P7_MESSAGE_BINARY_HEADER_SIZE;
- buffer = start = p7_message->binary_buffer + WI_P7_MESSAGE_BINARY_HEADER_SIZE;
-
- while((uint32_t) (buffer - start) < message_size) {
- field_id = wi_read_swap_big_to_host_int32(buffer, 0);
- buffer += sizeof(field_id);
- field = wi_p7_spec_field_with_id(p7_spec, field_id);
-
- if(!field)
- continue;
-
- field_size = wi_p7_spec_field_size(field);
-
- if(field_size == 0) {
- field_size = wi_read_swap_big_to_host_int32(buffer, 0);
-
- buffer += sizeof(field_size);
- }
-
- parameter = wi_dictionary_data_for_key(message->parameters_id, (void *) (intptr_t) field_id);
-
- if(parameter && parameter->required)
- required_parameters++;
-
- buffer += field_size;
- }
-
- if(required_parameters != message->required_parameters) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDMESSAGE,
- WI_STR("%u out of %u required parameters in message \"%@\""),
- required_parameters, message->required_parameters, message->name);
-
- return false;
- }
-
- return true;
+ wi_p7_spec_message_t *message;
+ wi_p7_spec_field_t *field;
+ wi_p7_spec_parameter_t *parameter;
+ unsigned char *buffer, *start;
+ wi_uinteger_t required_parameters = 0;
+ uint32_t message_size, field_id, field_size;
+
+ message = wi_dictionary_data_for_key(p7_spec->messages_id, (void *) (intptr_t) p7_message->binary_id);
+
+ if(!message) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_UNKNOWNMESSAGE,
+ WI_STR("Message with id %u not recognized"),
+ p7_message->binary_id);
+
+ return false;
+ }
+
+ message_size = p7_message->binary_size - WI_P7_MESSAGE_BINARY_HEADER_SIZE;
+ buffer = start = p7_message->binary_buffer + WI_P7_MESSAGE_BINARY_HEADER_SIZE;
+
+ while((uint32_t) (buffer - start) < message_size) {
+ field_id = wi_read_swap_big_to_host_int32(buffer, 0);
+ buffer += sizeof(field_id);
+ field = wi_p7_spec_field_with_id(p7_spec, field_id);
+
+ if(!field)
+ continue;
+
+ field_size = wi_p7_spec_field_size(field);
+
+ if(field_size == 0) {
+ field_size = wi_read_swap_big_to_host_int32(buffer, 0);
+
+ buffer += sizeof(field_size);
+ }
+
+ parameter = wi_dictionary_data_for_key(message->parameters_id, (void *) (intptr_t) field_id);
+
+ if(parameter && parameter->required)
+ required_parameters++;
+
+ buffer += field_size;
+ }
+
+ if(required_parameters != message->required_parameters) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDMESSAGE,
+ WI_STR("%u out of %u required parameters in message \"%@\""),
+ required_parameters, message->required_parameters, message->name);
+
+ return false;
+ }
+
+ return true;
}
@@ -1735,7 +1744,7 @@ wi_boolean_t wi_p7_spec_verify_message(wi_p7_spec_t *p7_spec, wi_p7_message_t *p
#pragma mark -
wi_runtime_id_t wi_p7_spec_type_runtime_id(void) {
- return _wi_p7_spec_type_runtime_id;
+ return _wi_p7_spec_type_runtime_id;
}
@@ -1743,52 +1752,52 @@ wi_runtime_id_t wi_p7_spec_type_runtime_id(void) {
#pragma mark -
static wi_p7_spec_type_t * _wi_p7_spec_type_with_node(wi_p7_spec_t *p7_spec, xmlNodePtr type_node) {
- wi_p7_spec_type_t *type;
-
+ wi_p7_spec_type_t *type;
+
type = wi_autorelease(wi_runtime_create_instance(_wi_p7_spec_type_runtime_id, sizeof(wi_p7_spec_type_t)));
- type->name = wi_retain(wi_xml_node_attribute_with_name(type_node, WI_STR("name")));
-
- if(!type->name) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Type has no \"name\""));
-
- return NULL;
- }
-
- type->id = wi_xml_node_integer_attribute_with_name(type_node, WI_STR("id"));
-
- if(type->id == 0) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Type \"%@\" has no \"id\""),
- type->name);
-
- return NULL;
- }
-
- type->size = wi_xml_node_integer_attribute_with_name(type_node, WI_STR("size"));
-
- return type;
+ type->name = wi_retain(wi_xml_node_attribute_with_name(type_node, WI_STR("name")));
+
+ if(!type->name) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Type has no \"name\""));
+
+ return NULL;
+ }
+
+ type->id = wi_xml_node_integer_attribute_with_name(type_node, WI_STR("id"));
+
+ if(type->id == 0) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Type \"%@\" has no \"id\""),
+ type->name);
+
+ return NULL;
+ }
+
+ type->size = wi_xml_node_integer_attribute_with_name(type_node, WI_STR("size"));
+
+ return type;
}
static void _wi_p7_spec_type_dealloc(wi_runtime_instance_t *instance) {
- wi_p7_spec_type_t *type = instance;
-
- wi_release(type->name);
+ wi_p7_spec_type_t *type = instance;
+
+ wi_release(type->name);
}
static wi_string_t * _wi_p7_spec_type_description(wi_runtime_instance_t *instance) {
- wi_p7_spec_type_t *type = instance;
-
- return wi_string_with_format(WI_STR("<%@ %p>{name = %@, id = %lu, size = %lu}"),
+ wi_p7_spec_type_t *type = instance;
+
+ return wi_string_with_format(WI_STR("<%@ %p>{name = %@, id = %lu, size = %lu}"),
wi_runtime_class_name(type),
- type,
- type->name,
- type->id,
- type->size);
+ type,
+ type->name,
+ type->id,
+ type->size);
}
@@ -1796,19 +1805,19 @@ static wi_string_t * _wi_p7_spec_type_description(wi_runtime_instance_t *instanc
#pragma mark -
wi_string_t * wi_p7_spec_type_name(wi_p7_spec_type_t *type) {
- return type->name;
+ return type->name;
}
wi_uinteger_t wi_p7_spec_type_id(wi_p7_spec_type_t *type) {
- return type->id;
+ return type->id;
}
wi_uinteger_t wi_p7_spec_type_size(wi_p7_spec_type_t *type) {
- return type->size;
+ return type->size;
}
@@ -1816,7 +1825,7 @@ wi_uinteger_t wi_p7_spec_type_size(wi_p7_spec_type_t *type) {
#pragma mark -
wi_runtime_id_t wi_p7_spec_field_runtime_id(void) {
- return _wi_p7_spec_field_runtime_id;
+ return _wi_p7_spec_field_runtime_id;
}
@@ -1824,163 +1833,163 @@ wi_runtime_id_t wi_p7_spec_field_runtime_id(void) {
#pragma mark -
static wi_p7_spec_field_t * _wi_p7_spec_field_with_node(wi_p7_spec_t *p7_spec, xmlNodePtr node) {
- xmlNodePtr enum_node, next_node;
- wi_p7_spec_field_t *field;
- wi_string_t *type, *listtype, *name;
- wi_integer_t value;
-
+ xmlNodePtr enum_node, next_node;
+ wi_p7_spec_field_t *field;
+ wi_string_t *type, *listtype, *name;
+ wi_integer_t value;
+
field = wi_autorelease(wi_runtime_create_instance(_wi_p7_spec_field_runtime_id, sizeof(wi_p7_spec_field_t)));
- field->name = wi_retain(wi_xml_node_attribute_with_name(node, WI_STR("name")));
-
- if(!field->name) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Field has no \"name\""));
-
- return NULL;
- }
-
- type = wi_xml_node_attribute_with_name(node, WI_STR("type"));
-
- if(!type) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Field \"%@\" has no \"type\""),
- field->name);
-
- return NULL;
- }
-
- field->type = wi_retain(wi_dictionary_data_for_key(p7_spec->types_name, type));
-
- if(!field->type && _wi_p7_spec_builtin_spec)
- field->type = wi_retain(wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->types_name, type));
-
- if(!field->type) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Field \"%@\" has an invalid \"type\" (\"%@\")"),
- field->name, type);
-
- return NULL;
- }
-
- listtype = wi_xml_node_attribute_with_name(node, WI_STR("listtype"));
-
- if(listtype) {
- field->listtype = wi_retain(wi_dictionary_data_for_key(p7_spec->types_name, listtype));
-
- if(!field->listtype && _wi_p7_spec_builtin_spec)
- field->listtype = wi_retain(wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->types_name, listtype));
-
- if(!field->listtype) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Field \"%@\" has an invalid \"listtype\" (\"%@\")"),
- field->name, listtype);
-
- return NULL;
- }
- }
-
- field->id = wi_xml_node_integer_attribute_with_name(node, WI_STR("id"));
-
- if(field->id == 0) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Field \"%@\" has no \"id\""),
- field->name);
-
- return NULL;
- }
-
- if(field->type->id == WI_P7_ENUM) {
- field->enums_name = wi_dictionary_init_with_capacity_and_callbacks(wi_mutable_dictionary_alloc(),
- 20, wi_dictionary_default_key_callbacks, wi_dictionary_null_value_callbacks);
- field->enums_value = wi_dictionary_init_with_capacity_and_callbacks(wi_mutable_dictionary_alloc(),
- 20, wi_dictionary_null_key_callbacks, wi_dictionary_default_value_callbacks);
- }
-
- for(enum_node = node->children; enum_node != NULL; enum_node = next_node) {
- next_node = enum_node->next;
-
- if(enum_node->type == XML_ELEMENT_NODE) {
- if(strcmp((const char *) enum_node->name, "documentation") == 0) {
- xmlUnlinkNode(enum_node);
- xmlFreeNode(enum_node);
-
- continue;
- }
-
- if(field->type->id != WI_P7_ENUM) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Expected no more nodes but got \"%s\""),
- enum_node->name);
-
- return NULL;
- }
-
- if(strcmp((const char *) enum_node->name, "enum") != 0) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Expected \"enum\" node but got \"%s\""),
- enum_node->name);
-
- return NULL;
- }
-
- name = wi_xml_node_attribute_with_name(enum_node, WI_STR("name"));
-
- if(!name) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Field \"%@\" enum has no \"name\""),
- field->name);
-
- return NULL;
- }
-
- value = wi_xml_node_integer_attribute_with_name(enum_node, WI_STR("value"));
-
- if(wi_dictionary_data_for_key(field->enums_name, name)) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Enum with name \"%@\" in field \"%@\" already exists"),
- name, field->name);
-
- return NULL;
- }
-
- if(wi_dictionary_data_for_key(field->enums_value, (void *) value)) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Enum with value %lu (name \"%@\") in field \"%@\" already exists"),
- value, name, field->name);
-
- return NULL;
- }
-
- wi_mutable_dictionary_set_data_for_key(field->enums_name, (void *) value, name);
- wi_mutable_dictionary_set_data_for_key(field->enums_value, name, (void *) value);
- }
- }
-
- return field;
+ field->name = wi_retain(wi_xml_node_attribute_with_name(node, WI_STR("name")));
+
+ if(!field->name) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Field has no \"name\""));
+
+ return NULL;
+ }
+
+ type = wi_xml_node_attribute_with_name(node, WI_STR("type"));
+
+ if(!type) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Field \"%@\" has no \"type\""),
+ field->name);
+
+ return NULL;
+ }
+
+ field->type = wi_retain(wi_dictionary_data_for_key(p7_spec->types_name, type));
+
+ if(!field->type && _wi_p7_spec_builtin_spec)
+ field->type = wi_retain(wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->types_name, type));
+
+ if(!field->type) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Field \"%@\" has an invalid \"type\" (\"%@\")"),
+ field->name, type);
+
+ return NULL;
+ }
+
+ listtype = wi_xml_node_attribute_with_name(node, WI_STR("listtype"));
+
+ if(listtype) {
+ field->listtype = wi_retain(wi_dictionary_data_for_key(p7_spec->types_name, listtype));
+
+ if(!field->listtype && _wi_p7_spec_builtin_spec)
+ field->listtype = wi_retain(wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->types_name, listtype));
+
+ if(!field->listtype) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Field \"%@\" has an invalid \"listtype\" (\"%@\")"),
+ field->name, listtype);
+
+ return NULL;
+ }
+ }
+
+ field->id = wi_xml_node_integer_attribute_with_name(node, WI_STR("id"));
+
+ if(field->id == 0) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Field \"%@\" has no \"id\""),
+ field->name);
+
+ return NULL;
+ }
+
+ if(field->type->id == WI_P7_ENUM) {
+ field->enums_name = wi_dictionary_init_with_capacity_and_callbacks(wi_mutable_dictionary_alloc(),
+ 20, wi_dictionary_default_key_callbacks, wi_dictionary_null_value_callbacks);
+ field->enums_value = wi_dictionary_init_with_capacity_and_callbacks(wi_mutable_dictionary_alloc(),
+ 20, wi_dictionary_null_key_callbacks, wi_dictionary_default_value_callbacks);
+ }
+
+ for(enum_node = node->children; enum_node != NULL; enum_node = next_node) {
+ next_node = enum_node->next;
+
+ if(enum_node->type == XML_ELEMENT_NODE) {
+ if(strcmp((const char *) enum_node->name, "documentation") == 0) {
+ xmlUnlinkNode(enum_node);
+ xmlFreeNode(enum_node);
+
+ continue;
+ }
+
+ if(field->type->id != WI_P7_ENUM) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Expected no more nodes but got \"%s\""),
+ enum_node->name);
+
+ return NULL;
+ }
+
+ if(strcmp((const char *) enum_node->name, "enum") != 0) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Expected \"enum\" node but got \"%s\""),
+ enum_node->name);
+
+ return NULL;
+ }
+
+ name = wi_xml_node_attribute_with_name(enum_node, WI_STR("name"));
+
+ if(!name) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Field \"%@\" enum has no \"name\""),
+ field->name);
+
+ return NULL;
+ }
+
+ value = wi_xml_node_integer_attribute_with_name(enum_node, WI_STR("value"));
+
+ if(wi_dictionary_data_for_key(field->enums_name, name)) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Enum with name \"%@\" in field \"%@\" already exists"),
+ name, field->name);
+
+ return NULL;
+ }
+
+ if(wi_dictionary_data_for_key(field->enums_value, (void *) value)) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Enum with value %lu (name \"%@\") in field \"%@\" already exists"),
+ value, name, field->name);
+
+ return NULL;
+ }
+
+ wi_mutable_dictionary_set_data_for_key(field->enums_name, (void *) value, name);
+ wi_mutable_dictionary_set_data_for_key(field->enums_value, name, (void *) value);
+ }
+ }
+
+ return field;
}
static void _wi_p7_spec_field_dealloc(wi_runtime_instance_t *instance) {
- wi_p7_spec_field_t *field = instance;
+ wi_p7_spec_field_t *field = instance;
- wi_release(field->name);
- wi_release(field->type);
- wi_release(field->enums_name);
- wi_release(field->enums_value);
+ wi_release(field->name);
+ wi_release(field->type);
+ wi_release(field->enums_name);
+ wi_release(field->enums_value);
}
static wi_string_t * _wi_p7_spec_field_description(wi_runtime_instance_t *instance) {
- wi_p7_spec_field_t *field = instance;
-
- return wi_string_with_format(WI_STR("<%@ %p>{name = %@, id = %lu, type = %@}"),
+ wi_p7_spec_field_t *field = instance;
+
+ return wi_string_with_format(WI_STR("<%@ %p>{name = %@, id = %lu, type = %@}"),
wi_runtime_class_name(field),
- field,
- field->name,
- field->id,
- field->type);
+ field,
+ field->name,
+ field->id,
+ field->type);
}
@@ -1988,43 +1997,43 @@ static wi_string_t * _wi_p7_spec_field_description(wi_runtime_instance_t *instan
#pragma mark -
wi_string_t * wi_p7_spec_field_name(wi_p7_spec_field_t *field) {
- return field->name;
+ return field->name;
}
wi_uinteger_t wi_p7_spec_field_id(wi_p7_spec_field_t *field) {
- return field->id;
+ return field->id;
}
wi_uinteger_t wi_p7_spec_field_size(wi_p7_spec_field_t *field) {
- return field->type->size;
+ return field->type->size;
}
wi_p7_spec_type_t * wi_p7_spec_field_type(wi_p7_spec_field_t *field) {
- return field->type;
+ return field->type;
}
wi_p7_spec_type_t * wi_p7_spec_field_listtype(wi_p7_spec_field_t *field) {
- return field->listtype;
+ return field->listtype;
}
wi_dictionary_t * wi_p7_spec_field_enums_by_name(wi_p7_spec_field_t *field) {
- return field->enums_name;
+ return field->enums_name;
}
wi_dictionary_t * wi_p7_spec_field_enums_by_value(wi_p7_spec_field_t *field) {
- return field->enums_value;
+ return field->enums_value;
}
@@ -2032,91 +2041,91 @@ wi_dictionary_t * wi_p7_spec_field_enums_by_value(wi_p7_spec_field_t *field) {
#pragma mark -
static _wi_p7_spec_collection_t * _wi_p7_spec_collection_with_node(wi_p7_spec_t *p7_spec, xmlNodePtr node) {
- xmlNodePtr member_node, next_node;
- _wi_p7_spec_collection_t *collection;
- wi_p7_spec_field_t *field;
- wi_string_t *field_name;
-
+ xmlNodePtr member_node, next_node;
+ _wi_p7_spec_collection_t *collection;
+ wi_p7_spec_field_t *field;
+ wi_string_t *field_name;
+
collection = wi_autorelease(wi_runtime_create_instance(_wi_p7_spec_collection_runtime_id, sizeof(_wi_p7_spec_collection_t)));
- collection->name = wi_retain(wi_xml_node_attribute_with_name(node, WI_STR("name")));
-
- if(!collection->name) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Collection has no \"name\""));
-
- return NULL;
- }
-
- collection->fields = wi_array_init(wi_mutable_array_alloc());
-
- for(member_node = node->children; member_node != NULL; member_node = next_node) {
- next_node = member_node->next;
-
- if(member_node->type == XML_ELEMENT_NODE) {
- if(strcmp((const char *) member_node->name, "documentation") == 0) {
- xmlUnlinkNode(member_node);
- xmlFreeNode(member_node);
-
- continue;
- }
-
- if(strcmp((const char *) member_node->name, "member") != 0) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Expected \"member\" node but got \"%s\""),
- member_node->name);
-
- return false;
- }
-
- field_name = wi_xml_node_attribute_with_name(member_node, WI_STR("field"));
-
- if(!field_name) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Member in collection \"%@\" has no \"field\""),
- collection->name);
-
- return NULL;
- }
-
- field = wi_dictionary_data_for_key(p7_spec->fields_name, field_name);
-
- if(!field && _wi_p7_spec_builtin_spec)
- field = wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->fields_name, field_name);
-
- if(!field) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Member in collection \"%@\" has an invalid \"field\" (\"%@\")"),
- collection->name, field_name);
-
- return NULL;
- }
-
- wi_mutable_array_add_data(collection->fields, field);
- }
- }
-
- return collection;
+ collection->name = wi_retain(wi_xml_node_attribute_with_name(node, WI_STR("name")));
+
+ if(!collection->name) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Collection has no \"name\""));
+
+ return NULL;
+ }
+
+ collection->fields = wi_array_init(wi_mutable_array_alloc());
+
+ for(member_node = node->children; member_node != NULL; member_node = next_node) {
+ next_node = member_node->next;
+
+ if(member_node->type == XML_ELEMENT_NODE) {
+ if(strcmp((const char *) member_node->name, "documentation") == 0) {
+ xmlUnlinkNode(member_node);
+ xmlFreeNode(member_node);
+
+ continue;
+ }
+
+ if(strcmp((const char *) member_node->name, "member") != 0) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Expected \"member\" node but got \"%s\""),
+ member_node->name);
+
+ return false;
+ }
+
+ field_name = wi_xml_node_attribute_with_name(member_node, WI_STR("field"));
+
+ if(!field_name) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Member in collection \"%@\" has no \"field\""),
+ collection->name);
+
+ return NULL;
+ }
+
+ field = wi_dictionary_data_for_key(p7_spec->fields_name, field_name);
+
+ if(!field && _wi_p7_spec_builtin_spec)
+ field = wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->fields_name, field_name);
+
+ if(!field) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Member in collection \"%@\" has an invalid \"field\" (\"%@\")"),
+ collection->name, field_name);
+
+ return NULL;
+ }
+
+ wi_mutable_array_add_data(collection->fields, field);
+ }
+ }
+
+ return collection;
}
static void _wi_p7_spec_collection_dealloc(wi_runtime_instance_t *instance) {
- _wi_p7_spec_collection_t *collection = instance;
+ _wi_p7_spec_collection_t *collection = instance;
- wi_release(collection->name);
- wi_release(collection->fields);
+ wi_release(collection->name);
+ wi_release(collection->fields);
}
static wi_string_t * _wi_p7_spec_collection_description(wi_runtime_instance_t *instance) {
- _wi_p7_spec_collection_t *collection = instance;
-
- return wi_string_with_format(WI_STR("<%@ %p>{name = %@, fields = %@}"),
+ _wi_p7_spec_collection_t *collection = instance;
+
+ return wi_string_with_format(WI_STR("<%@ %p>{name = %@, fields = %@}"),
wi_runtime_class_name(collection),
- collection,
- collection->name,
- collection->fields);
+ collection,
+ collection->name,
+ collection->fields);
}
@@ -2124,7 +2133,7 @@ static wi_string_t * _wi_p7_spec_collection_description(wi_runtime_instance_t *i
#pragma mark -
wi_runtime_id_t wi_p7_spec_message_runtime_id(void) {
- return _wi_p7_spec_message_runtime_id;
+ return _wi_p7_spec_message_runtime_id;
}
@@ -2132,168 +2141,168 @@ wi_runtime_id_t wi_p7_spec_message_runtime_id(void) {
#pragma mark -
static wi_p7_spec_message_t * _wi_p7_spec_message_with_node(wi_p7_spec_t *p7_spec, xmlNodePtr node) {
- wi_enumerator_t *enumerator;
- wi_string_t *field_name, *collection_name, *use;
- xmlNodePtr parameter_node, next_node;
- wi_p7_spec_message_t *message;
- wi_p7_spec_parameter_t *parameter;
- _wi_p7_spec_collection_t *collection;
- wi_p7_spec_field_t *field;
- wi_boolean_t required;
+ wi_enumerator_t *enumerator;
+ wi_string_t *field_name, *collection_name, *use;
+ xmlNodePtr parameter_node, next_node;
+ wi_p7_spec_message_t *message;
+ wi_p7_spec_parameter_t *parameter;
+ _wi_p7_spec_collection_t *collection;
+ wi_p7_spec_field_t *field;
+ wi_boolean_t required;
message = wi_autorelease(wi_runtime_create_instance(_wi_p7_spec_message_runtime_id, sizeof(wi_p7_spec_message_t)));
- message->name = wi_retain(wi_xml_node_attribute_with_name(node, WI_STR("name")));
-
- if(!message->name) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Message has no name"));
-
- return NULL;
- }
-
- message->id = wi_xml_node_integer_attribute_with_name(node, WI_STR("id"));
-
- if(message->id == 0) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Message \"%@\" has no \"id\""),
- message->name);
-
- return NULL;
- }
-
- message->parameters_name = wi_dictionary_init_with_capacity(wi_mutable_dictionary_alloc(), 20);
- message->parameters_id = wi_dictionary_init_with_capacity_and_callbacks(wi_mutable_dictionary_alloc(),
- 20, wi_dictionary_null_key_callbacks, wi_dictionary_default_value_callbacks);
-
- for(parameter_node = node->children; parameter_node != NULL; parameter_node = next_node) {
- next_node = parameter_node->next;
-
- if(parameter_node->type == XML_ELEMENT_NODE) {
- if(strcmp((const char *) parameter_node->name, "documentation") == 0) {
- xmlUnlinkNode(parameter_node);
- xmlFreeNode(parameter_node);
-
- continue;
- }
-
- if(strcmp((const char *) parameter_node->name, "parameter") != 0) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Expected \"parameter\" node but got \"%s\""),
- parameter_node->name);
-
- return false;
- }
-
- field_name = wi_xml_node_attribute_with_name(parameter_node, WI_STR("field"));
- collection_name = wi_xml_node_attribute_with_name(parameter_node, WI_STR("collection"));
-
- if(field_name) {
- parameter = _wi_p7_spec_parameter_with_node(p7_spec, parameter_node, message);
-
- if(!parameter)
- return NULL;
-
- if(wi_dictionary_data_for_key(message->parameters_name, parameter->field->name)) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Message \"%@\" has a duplicate field \"%@\""),
- message->name, parameter->field->name);
-
- return NULL;
- }
-
- wi_mutable_dictionary_set_data_for_key(message->parameters_name, parameter, parameter->field->name);
- wi_mutable_dictionary_set_data_for_key(message->parameters_id, parameter, (void *) parameter->field->id);
-
- if(parameter->required)
- message->required_parameters++;
- }
- else if(collection_name) {
- collection = wi_dictionary_data_for_key(p7_spec->collections_name, collection_name);
-
- if(!collection) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Parameter in message \"%@\" has an invalid \"collection\" (\"%@\")"),
- message->name, collection_name);
-
- return NULL;
- }
-
- required = false;
- use = wi_xml_node_attribute_with_name(parameter_node, WI_STR("use"));
-
- if(use) {
- if(wi_string_case_insensitive_compare(use, WI_STR("required")) != 0 &&
- wi_string_case_insensitive_compare(use, WI_STR("optional")) != 0) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Parameter \"%@\" in message \"%@\" has an invalid \"use\" (\"%@\")"),
- collection_name, message->name, use);
-
- return NULL;
- }
-
- required = (wi_string_case_insensitive_compare(use, WI_STR("required")) == 0);
- }
-
- enumerator = wi_array_data_enumerator(collection->fields);
-
- while((field = wi_enumerator_next_data(enumerator))) {
- parameter = _wi_p7_spec_parameter_with_field(p7_spec, message, field);
-
- if(!parameter)
- return NULL;
-
- if(wi_dictionary_data_for_key(message->parameters_name, parameter->field->name)) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Message \"%@\" has a duplicate field \"%@\""),
- message->name, parameter->field->name);
-
- return NULL;
- }
-
- wi_mutable_dictionary_set_data_for_key(message->parameters_name, parameter, parameter->field->name);
- wi_mutable_dictionary_set_data_for_key(message->parameters_id, parameter, (void *) parameter->field->id);
-
- parameter->required = required;
-
- if(parameter->required)
- message->required_parameters++;
- }
- }
- else {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Parameter in message \"%@\" has no \"field\" or \"collection\""),
- message->name);
-
- return NULL;
- }
- }
- }
-
- return message;
+ message->name = wi_retain(wi_xml_node_attribute_with_name(node, WI_STR("name")));
+
+ if(!message->name) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Message has no name"));
+
+ return NULL;
+ }
+
+ message->id = wi_xml_node_integer_attribute_with_name(node, WI_STR("id"));
+
+ if(message->id == 0) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Message \"%@\" has no \"id\""),
+ message->name);
+
+ return NULL;
+ }
+
+ message->parameters_name = wi_dictionary_init_with_capacity(wi_mutable_dictionary_alloc(), 20);
+ message->parameters_id = wi_dictionary_init_with_capacity_and_callbacks(wi_mutable_dictionary_alloc(),
+ 20, wi_dictionary_null_key_callbacks, wi_dictionary_default_value_callbacks);
+
+ for(parameter_node = node->children; parameter_node != NULL; parameter_node = next_node) {
+ next_node = parameter_node->next;
+
+ if(parameter_node->type == XML_ELEMENT_NODE) {
+ if(strcmp((const char *) parameter_node->name, "documentation") == 0) {
+ xmlUnlinkNode(parameter_node);
+ xmlFreeNode(parameter_node);
+
+ continue;
+ }
+
+ if(strcmp((const char *) parameter_node->name, "parameter") != 0) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Expected \"parameter\" node but got \"%s\""),
+ parameter_node->name);
+
+ return false;
+ }
+
+ field_name = wi_xml_node_attribute_with_name(parameter_node, WI_STR("field"));
+ collection_name = wi_xml_node_attribute_with_name(parameter_node, WI_STR("collection"));
+
+ if(field_name) {
+ parameter = _wi_p7_spec_parameter_with_node(p7_spec, parameter_node, message);
+
+ if(!parameter)
+ return NULL;
+
+ if(wi_dictionary_data_for_key(message->parameters_name, parameter->field->name)) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Message \"%@\" has a duplicate field \"%@\""),
+ message->name, parameter->field->name);
+
+ return NULL;
+ }
+
+ wi_mutable_dictionary_set_data_for_key(message->parameters_name, parameter, parameter->field->name);
+ wi_mutable_dictionary_set_data_for_key(message->parameters_id, parameter, (void *) parameter->field->id);
+
+ if(parameter->required)
+ message->required_parameters++;
+ }
+ else if(collection_name) {
+ collection = wi_dictionary_data_for_key(p7_spec->collections_name, collection_name);
+
+ if(!collection) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Parameter in message \"%@\" has an invalid \"collection\" (\"%@\")"),
+ message->name, collection_name);
+
+ return NULL;
+ }
+
+ required = false;
+ use = wi_xml_node_attribute_with_name(parameter_node, WI_STR("use"));
+
+ if(use) {
+ if(wi_string_case_insensitive_compare(use, WI_STR("required")) != 0 &&
+ wi_string_case_insensitive_compare(use, WI_STR("optional")) != 0) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Parameter \"%@\" in message \"%@\" has an invalid \"use\" (\"%@\")"),
+ collection_name, message->name, use);
+
+ return NULL;
+ }
+
+ required = (wi_string_case_insensitive_compare(use, WI_STR("required")) == 0);
+ }
+
+ enumerator = wi_array_data_enumerator(collection->fields);
+
+ while((field = wi_enumerator_next_data(enumerator))) {
+ parameter = _wi_p7_spec_parameter_with_field(p7_spec, message, field);
+
+ if(!parameter)
+ return NULL;
+
+ if(wi_dictionary_data_for_key(message->parameters_name, parameter->field->name)) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Message \"%@\" has a duplicate field \"%@\""),
+ message->name, parameter->field->name);
+
+ return NULL;
+ }
+
+ wi_mutable_dictionary_set_data_for_key(message->parameters_name, parameter, parameter->field->name);
+ wi_mutable_dictionary_set_data_for_key(message->parameters_id, parameter, (void *) parameter->field->id);
+
+ parameter->required = required;
+
+ if(parameter->required)
+ message->required_parameters++;
+ }
+ }
+ else {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Parameter in message \"%@\" has no \"field\" or \"collection\""),
+ message->name);
+
+ return NULL;
+ }
+ }
+ }
+
+ return message;
}
static void _wi_p7_spec_message_dealloc(wi_runtime_instance_t *instance) {
- wi_p7_spec_message_t *message = instance;
-
- wi_release(message->name);
- wi_release(message->parameters);
- wi_release(message->parameters_name);
- wi_release(message->parameters_id);
+ wi_p7_spec_message_t *message = instance;
+
+ wi_release(message->name);
+ wi_release(message->parameters);
+ wi_release(message->parameters_name);
+ wi_release(message->parameters_id);
}
static wi_string_t * _wi_p7_spec_message_description(wi_runtime_instance_t *instance) {
- wi_p7_spec_message_t *message = instance;
-
- return wi_string_with_format(WI_STR("<%@ %p>{name = %@, id = %lu, parameters = %@}"),
+ wi_p7_spec_message_t *message = instance;
+
+ return wi_string_with_format(WI_STR("<%@ %p>{name = %@, id = %lu, parameters = %@}"),
wi_runtime_class_name(message),
- message,
- message->name,
- message->id,
- message->parameters_name);
+ message,
+ message->name,
+ message->id,
+ message->parameters_name);
}
@@ -2301,7 +2310,7 @@ static wi_string_t * _wi_p7_spec_message_description(wi_runtime_instance_t *inst
#pragma mark -
wi_runtime_id_t wi_p7_spec_parameter_runtime_id(void) {
- return _wi_p7_spec_parameter_runtime_id;
+ return _wi_p7_spec_parameter_runtime_id;
}
@@ -2309,22 +2318,22 @@ wi_runtime_id_t wi_p7_spec_parameter_runtime_id(void) {
#pragma mark -
wi_string_t * wi_p7_spec_message_name(wi_p7_spec_message_t *message) {
- return message->name;
+ return message->name;
}
wi_uinteger_t wi_p7_spec_message_id(wi_p7_spec_message_t *message) {
- return message->id;
+ return message->id;
}
wi_array_t * wi_p7_spec_message_parameters(wi_p7_spec_message_t *message) {
- if(!message->parameters)
- message->parameters = wi_retain(wi_dictionary_all_values(message->parameters_id));
-
- return message->parameters;
+ if(!message->parameters)
+ message->parameters = wi_retain(wi_dictionary_all_values(message->parameters_id));
+
+ return message->parameters;
}
@@ -2332,80 +2341,80 @@ wi_array_t * wi_p7_spec_message_parameters(wi_p7_spec_message_t *message) {
#pragma mark -
static wi_p7_spec_parameter_t * _wi_p7_spec_parameter_with_node(wi_p7_spec_t *p7_spec, xmlNodePtr node, wi_p7_spec_message_t *message) {
- wi_p7_spec_parameter_t *parameter;
- wi_string_t *field, *use;
+ wi_p7_spec_parameter_t *parameter;
+ wi_string_t *field, *use;
parameter = wi_autorelease(wi_runtime_create_instance(_wi_p7_spec_parameter_runtime_id, sizeof(wi_p7_spec_parameter_t)));
- field = wi_xml_node_attribute_with_name(node, WI_STR("field"));
-
- if(!field) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Parameter in message \"%@\" has no \"field\""),
- message->name);
-
- return NULL;
- }
-
- parameter->field = wi_retain(wi_dictionary_data_for_key(p7_spec->fields_name, field));
-
- if(!parameter->field && _wi_p7_spec_builtin_spec)
- parameter->field = wi_retain(wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->fields_name, field));
-
- if(!parameter->field) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Parameter in message \"%@\" has an invalid \"field\" (\"%@\")"),
- message->name, field);
-
- return NULL;
- }
-
- use = wi_xml_node_attribute_with_name(node, WI_STR("use"));
-
- if(use) {
- if(wi_string_case_insensitive_compare(use, WI_STR("required")) != 0 &&
- wi_string_case_insensitive_compare(use, WI_STR("optional")) != 0) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Parameter \"%@\" in message \"%@\" has an invalid \"use\" (\"%@\")"),
- parameter->field->name, message->name, use);
-
- return NULL;
- }
-
- parameter->required = (wi_string_case_insensitive_compare(use, WI_STR("required")) == 0);
- }
-
- return parameter;
+ field = wi_xml_node_attribute_with_name(node, WI_STR("field"));
+
+ if(!field) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Parameter in message \"%@\" has no \"field\""),
+ message->name);
+
+ return NULL;
+ }
+
+ parameter->field = wi_retain(wi_dictionary_data_for_key(p7_spec->fields_name, field));
+
+ if(!parameter->field && _wi_p7_spec_builtin_spec)
+ parameter->field = wi_retain(wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->fields_name, field));
+
+ if(!parameter->field) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Parameter in message \"%@\" has an invalid \"field\" (\"%@\")"),
+ message->name, field);
+
+ return NULL;
+ }
+
+ use = wi_xml_node_attribute_with_name(node, WI_STR("use"));
+
+ if(use) {
+ if(wi_string_case_insensitive_compare(use, WI_STR("required")) != 0 &&
+ wi_string_case_insensitive_compare(use, WI_STR("optional")) != 0) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Parameter \"%@\" in message \"%@\" has an invalid \"use\" (\"%@\")"),
+ parameter->field->name, message->name, use);
+
+ return NULL;
+ }
+
+ parameter->required = (wi_string_case_insensitive_compare(use, WI_STR("required")) == 0);
+ }
+
+ return parameter;
}
static wi_p7_spec_parameter_t * _wi_p7_spec_parameter_with_field(wi_p7_spec_t *p7_spec, wi_p7_spec_message_t *message, wi_p7_spec_field_t *field) {
- wi_p7_spec_parameter_t *parameter;
+ wi_p7_spec_parameter_t *parameter;
parameter = wi_autorelease(wi_runtime_create_instance(_wi_p7_spec_parameter_runtime_id, sizeof(wi_p7_spec_parameter_t)));
- parameter->field = wi_retain(field);
+ parameter->field = wi_retain(field);
- return parameter;
+ return parameter;
}
static void _wi_p7_spec_parameter_dealloc(wi_runtime_instance_t *instance) {
- wi_p7_spec_parameter_t *parameter = instance;
-
- wi_release(parameter->field);
+ wi_p7_spec_parameter_t *parameter = instance;
+
+ wi_release(parameter->field);
}
static wi_string_t * _wi_p7_spec_parameter_description(wi_runtime_instance_t *instance) {
- wi_p7_spec_parameter_t *parameter = instance;
-
- return wi_string_with_format(WI_STR("<%@ %p>{field = %@, required = %@}"),
+ wi_p7_spec_parameter_t *parameter = instance;
+
+ return wi_string_with_format(WI_STR("<%@ %p>{field = %@, required = %@}"),
wi_runtime_class_name(parameter),
- parameter,
- parameter->field,
- parameter->required ? WI_STR("true") : WI_STR("false"));
+ parameter,
+ parameter->field,
+ parameter->required ? WI_STR("true") : WI_STR("false"));
}
@@ -2413,13 +2422,13 @@ static wi_string_t * _wi_p7_spec_parameter_description(wi_runtime_instance_t *in
#pragma mark -
wi_p7_spec_field_t * wi_p7_spec_parameter_field(wi_p7_spec_parameter_t *parameter) {
- return parameter->field;
+ return parameter->field;
}
wi_boolean_t wi_p7_spec_parameter_required(wi_p7_spec_parameter_t *parameter) {
- return parameter->required;
+ return parameter->required;
}
@@ -2427,102 +2436,102 @@ wi_boolean_t wi_p7_spec_parameter_required(wi_p7_spec_parameter_t *parameter) {
#pragma mark -
static _wi_p7_spec_transaction_t * _wi_p7_spec_transaction_with_node(wi_p7_spec_t *p7_spec, xmlNodePtr node) {
- wi_string_t *message, *originator, *use;
- _wi_p7_spec_transaction_t *transaction;
+ wi_string_t *message, *originator, *use;
+ _wi_p7_spec_transaction_t *transaction;
transaction = wi_autorelease(wi_runtime_create_instance(_wi_p7_spec_transaction_runtime_id, sizeof(_wi_p7_spec_transaction_t)));
- message = wi_xml_node_attribute_with_name(node, WI_STR("message"));
-
- if(!message) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Transaction has no \"message\""));
-
- return NULL;
- }
-
- transaction->message = wi_retain(wi_dictionary_data_for_key(p7_spec->messages_name, message));
-
- if(!transaction->message && _wi_p7_spec_builtin_spec)
- transaction->message = wi_retain(wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->messages_name, message));
-
- if(!transaction->message) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Transaction has an invalid \"message\" (\"%@\")"),
- message);
-
- return NULL;
- }
-
- originator = wi_xml_node_attribute_with_name(node, WI_STR("originator"));
-
- if(!originator) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Transaction \"%@\" has no \"originator\""),
- transaction->message->name);
-
- return NULL;
- }
-
- if(wi_string_case_insensitive_compare(originator, WI_STR("client")) != 0 &&
- wi_string_case_insensitive_compare(originator, WI_STR("server")) != 0 &&
- wi_string_case_insensitive_compare(originator, WI_STR("both")) != 0) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Transaction \"%@\" has an invalid \"originator\" (\"%@\")"),
- transaction->message->name, originator);
-
- return NULL;
- }
-
- if(wi_string_case_insensitive_compare(originator, WI_STR("client")) == 0)
- transaction->originator = WI_P7_CLIENT;
- else if(wi_string_case_insensitive_compare(originator, WI_STR("server")) == 0)
- transaction->originator = WI_P7_SERVER;
- else
- transaction->originator = WI_P7_BOTH;
-
- use = wi_xml_node_attribute_with_name(node, WI_STR("use"));
-
- if(use) {
- if(wi_string_case_insensitive_compare(use, WI_STR("required")) != 0 &&
- wi_string_case_insensitive_compare(use, WI_STR("optional"))) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Transaction \"%@\" has an invalid \"use\" (\"%@\")"),
- transaction->message->name, use);
-
- return NULL;
- }
-
- transaction->required = (wi_string_case_insensitive_compare(use, WI_STR("required")) == 0);
- }
-
- transaction->andor = wi_retain(_wi_p7_spec_andor(_WI_P7_SPEC_AND, p7_spec, node, transaction));
-
- if(!transaction->andor)
- return NULL;
-
- return transaction;
+ message = wi_xml_node_attribute_with_name(node, WI_STR("message"));
+
+ if(!message) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Transaction has no \"message\""));
+
+ return NULL;
+ }
+
+ transaction->message = wi_retain(wi_dictionary_data_for_key(p7_spec->messages_name, message));
+
+ if(!transaction->message && _wi_p7_spec_builtin_spec)
+ transaction->message = wi_retain(wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->messages_name, message));
+
+ if(!transaction->message) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Transaction has an invalid \"message\" (\"%@\")"),
+ message);
+
+ return NULL;
+ }
+
+ originator = wi_xml_node_attribute_with_name(node, WI_STR("originator"));
+
+ if(!originator) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Transaction \"%@\" has no \"originator\""),
+ transaction->message->name);
+
+ return NULL;
+ }
+
+ if(wi_string_case_insensitive_compare(originator, WI_STR("client")) != 0 &&
+ wi_string_case_insensitive_compare(originator, WI_STR("server")) != 0 &&
+ wi_string_case_insensitive_compare(originator, WI_STR("both")) != 0) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Transaction \"%@\" has an invalid \"originator\" (\"%@\")"),
+ transaction->message->name, originator);
+
+ return NULL;
+ }
+
+ if(wi_string_case_insensitive_compare(originator, WI_STR("client")) == 0)
+ transaction->originator = WI_P7_CLIENT;
+ else if(wi_string_case_insensitive_compare(originator, WI_STR("server")) == 0)
+ transaction->originator = WI_P7_SERVER;
+ else
+ transaction->originator = WI_P7_BOTH;
+
+ use = wi_xml_node_attribute_with_name(node, WI_STR("use"));
+
+ if(use) {
+ if(wi_string_case_insensitive_compare(use, WI_STR("required")) != 0 &&
+ wi_string_case_insensitive_compare(use, WI_STR("optional"))) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Transaction \"%@\" has an invalid \"use\" (\"%@\")"),
+ transaction->message->name, use);
+
+ return NULL;
+ }
+
+ transaction->required = (wi_string_case_insensitive_compare(use, WI_STR("required")) == 0);
+ }
+
+ transaction->andor = wi_retain(_wi_p7_spec_andor(_WI_P7_SPEC_AND, p7_spec, node, transaction));
+
+ if(!transaction->andor)
+ return NULL;
+
+ return transaction;
}
static void _wi_p7_spec_transaction_dealloc(wi_runtime_instance_t *instance) {
- _wi_p7_spec_transaction_t *transaction = instance;
-
- wi_release(transaction->message);
- wi_release(transaction->andor);
+ _wi_p7_spec_transaction_t *transaction = instance;
+
+ wi_release(transaction->message);
+ wi_release(transaction->andor);
}
static wi_string_t * _wi_p7_spec_transaction_description(wi_runtime_instance_t *instance) {
- _wi_p7_spec_transaction_t *transaction = instance;
-
- return wi_string_with_format(WI_STR("<%@ %p>{message = %@, required = %@, andor = %@}"),
+ _wi_p7_spec_transaction_t *transaction = instance;
+
+ return wi_string_with_format(WI_STR("<%@ %p>{message = %@, required = %@, andor = %@}"),
wi_runtime_class_name(transaction),
- transaction,
- transaction->message ? transaction->message->name : NULL,
- transaction->required ? WI_STR("true") : WI_STR("false"),
- transaction->andor);
+ transaction,
+ transaction->message ? transaction->message->name : NULL,
+ transaction->required ? WI_STR("true") : WI_STR("false"),
+ transaction->andor);
}
@@ -2530,66 +2539,66 @@ static wi_string_t * _wi_p7_spec_transaction_description(wi_runtime_instance_t *
#pragma mark -
static _wi_p7_spec_broadcast_t * _wi_p7_spec_broadcast_with_node(wi_p7_spec_t *p7_spec, xmlNodePtr node) {
- xmlNodePtr broadcast_node, next_node;
- wi_string_t *message;
- _wi_p7_spec_broadcast_t *broadcast;
+ xmlNodePtr broadcast_node, next_node;
+ wi_string_t *message;
+ _wi_p7_spec_broadcast_t *broadcast;
broadcast = wi_autorelease(wi_runtime_create_instance(_wi_p7_spec_broadcast_runtime_id, sizeof(_wi_p7_spec_broadcast_t)));
- message = wi_xml_node_attribute_with_name(node, WI_STR("message"));
-
- if(!message) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Broadcast has no \"message\""));
-
- return NULL;
- }
-
- broadcast->message = wi_retain(wi_dictionary_data_for_key(p7_spec->messages_name, message));
-
- if(!broadcast->message && _wi_p7_spec_builtin_spec)
- broadcast->message = wi_retain(wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->messages_name, message));
-
- if(!broadcast->message) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Broadcast has an invalid \"message\" (\"%@\")"),
- message);
-
- return NULL;
- }
-
- for(broadcast_node = node->children; broadcast_node != NULL; broadcast_node = next_node) {
- next_node = broadcast_node->next;
-
- if(broadcast_node->type == XML_ELEMENT_NODE) {
- if(strcmp((const char *) broadcast_node->name, "documentation") == 0) {
- xmlUnlinkNode(broadcast_node);
- xmlFreeNode(broadcast_node);
-
- continue;
- }
- }
- }
-
- return broadcast;
+ message = wi_xml_node_attribute_with_name(node, WI_STR("message"));
+
+ if(!message) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Broadcast has no \"message\""));
+
+ return NULL;
+ }
+
+ broadcast->message = wi_retain(wi_dictionary_data_for_key(p7_spec->messages_name, message));
+
+ if(!broadcast->message && _wi_p7_spec_builtin_spec)
+ broadcast->message = wi_retain(wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->messages_name, message));
+
+ if(!broadcast->message) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Broadcast has an invalid \"message\" (\"%@\")"),
+ message);
+
+ return NULL;
+ }
+
+ for(broadcast_node = node->children; broadcast_node != NULL; broadcast_node = next_node) {
+ next_node = broadcast_node->next;
+
+ if(broadcast_node->type == XML_ELEMENT_NODE) {
+ if(strcmp((const char *) broadcast_node->name, "documentation") == 0) {
+ xmlUnlinkNode(broadcast_node);
+ xmlFreeNode(broadcast_node);
+
+ continue;
+ }
+ }
+ }
+
+ return broadcast;
}
static void _wi_p7_spec_broadcast_dealloc(wi_runtime_instance_t *instance) {
- _wi_p7_spec_broadcast_t *broadcast = instance;
-
- wi_release(broadcast->message);
+ _wi_p7_spec_broadcast_t *broadcast = instance;
+
+ wi_release(broadcast->message);
}
static wi_string_t * _wi_p7_spec_broadcast_description(wi_runtime_instance_t *instance) {
- _wi_p7_spec_broadcast_t *broadcast = instance;
-
- return wi_string_with_format(WI_STR("<%@ %p>{message = %@}"),
+ _wi_p7_spec_broadcast_t *broadcast = instance;
+
+ return wi_string_with_format(WI_STR("<%@ %p>{message = %@}"),
wi_runtime_class_name(broadcast),
- broadcast,
- broadcast->message ? broadcast->message->name : NULL);
+ broadcast,
+ broadcast->message ? broadcast->message->name : NULL);
}
@@ -2597,90 +2606,90 @@ static wi_string_t * _wi_p7_spec_broadcast_description(wi_runtime_instance_t *in
#pragma mark -
static _wi_p7_spec_andor_t * _wi_p7_spec_andor(_wi_p7_spec_andor_type_t type, wi_p7_spec_t *p7_spec, xmlNodePtr node, _wi_p7_spec_transaction_t *transaction) {
- xmlNodePtr andor_node, next_node;
- _wi_p7_spec_andor_t *andor, *child_andor;
- _wi_p7_spec_reply_t *reply;
-
- andor = wi_autorelease(wi_runtime_create_instance(_wi_p7_spec_andor_runtime_id, sizeof(_wi_p7_spec_andor_t)));
- andor->type = type;
- andor->children = wi_array_init_with_capacity(wi_mutable_array_alloc(), 10);
- andor->replies_array = wi_array_init_with_capacity(wi_mutable_array_alloc(), 10);
- andor->replies_dictionary = wi_dictionary_init_with_capacity(wi_mutable_dictionary_alloc(), 10);
-
- for(andor_node = node->children; andor_node != NULL; andor_node = next_node) {
- next_node = andor_node->next;
-
- if(andor_node->type == XML_ELEMENT_NODE) {
- if(strcmp((const char *) andor_node->name, "documentation") == 0) {
- xmlUnlinkNode(andor_node);
- xmlFreeNode(andor_node);
-
- continue;
- }
-
- if(strcmp((const char *) andor_node->name, "reply") == 0) {
- reply = _wi_p7_spec_reply_with_node(p7_spec, andor_node, transaction);
-
- if(!reply)
- return NULL;
-
- if(wi_dictionary_data_for_key(andor->replies_dictionary, reply->message->name)) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Transaction \"%@\" has a duplicate reply \"%@\""),
- transaction->message->name, reply->message->name);
-
- return NULL;
- }
-
- wi_mutable_array_add_data(andor->replies_array, reply);
- wi_mutable_dictionary_set_data_for_key(andor->replies_dictionary, reply, reply->message->name);
- } else {
- if(strcmp((const char *) andor_node->name, "and") == 0) {
- child_andor = _wi_p7_spec_andor(_WI_P7_SPEC_AND, p7_spec, andor_node, transaction);
- }
- else if(strcmp((const char *) andor_node->name, "or") == 0) {
- child_andor = _wi_p7_spec_andor(_WI_P7_SPEC_OR, p7_spec, andor_node, transaction);
- }
- else {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Expected \"and\" or \"or\" node but got \"%s\""),
- andor_node->name);
-
- return false;
- }
-
- if(!child_andor)
- return NULL;
-
- wi_mutable_array_add_data(andor->children, child_andor);
- }
- }
- }
-
- return andor;
+ xmlNodePtr andor_node, next_node;
+ _wi_p7_spec_andor_t *andor, *child_andor;
+ _wi_p7_spec_reply_t *reply;
+
+ andor = wi_autorelease(wi_runtime_create_instance(_wi_p7_spec_andor_runtime_id, sizeof(_wi_p7_spec_andor_t)));
+ andor->type = type;
+ andor->children = wi_array_init_with_capacity(wi_mutable_array_alloc(), 10);
+ andor->replies_array = wi_array_init_with_capacity(wi_mutable_array_alloc(), 10);
+ andor->replies_dictionary = wi_dictionary_init_with_capacity(wi_mutable_dictionary_alloc(), 10);
+
+ for(andor_node = node->children; andor_node != NULL; andor_node = next_node) {
+ next_node = andor_node->next;
+
+ if(andor_node->type == XML_ELEMENT_NODE) {
+ if(strcmp((const char *) andor_node->name, "documentation") == 0) {
+ xmlUnlinkNode(andor_node);
+ xmlFreeNode(andor_node);
+
+ continue;
+ }
+
+ if(strcmp((const char *) andor_node->name, "reply") == 0) {
+ reply = _wi_p7_spec_reply_with_node(p7_spec, andor_node, transaction);
+
+ if(!reply)
+ return NULL;
+
+ if(wi_dictionary_data_for_key(andor->replies_dictionary, reply->message->name)) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Transaction \"%@\" has a duplicate reply \"%@\""),
+ transaction->message->name, reply->message->name);
+
+ return NULL;
+ }
+
+ wi_mutable_array_add_data(andor->replies_array, reply);
+ wi_mutable_dictionary_set_data_for_key(andor->replies_dictionary, reply, reply->message->name);
+ } else {
+ if(strcmp((const char *) andor_node->name, "and") == 0) {
+ child_andor = _wi_p7_spec_andor(_WI_P7_SPEC_AND, p7_spec, andor_node, transaction);
+ }
+ else if(strcmp((const char *) andor_node->name, "or") == 0) {
+ child_andor = _wi_p7_spec_andor(_WI_P7_SPEC_OR, p7_spec, andor_node, transaction);
+ }
+ else {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Expected \"and\" or \"or\" node but got \"%s\""),
+ andor_node->name);
+
+ return false;
+ }
+
+ if(!child_andor)
+ return NULL;
+
+ wi_mutable_array_add_data(andor->children, child_andor);
+ }
+ }
+ }
+
+ return andor;
}
static void _wi_p7_spec_andor_dealloc(wi_runtime_instance_t *instance) {
- _wi_p7_spec_andor_t *andor = instance;
-
- wi_release(andor->children);
- wi_release(andor->replies_dictionary);
- wi_release(andor->replies_array);
+ _wi_p7_spec_andor_t *andor = instance;
+
+ wi_release(andor->children);
+ wi_release(andor->replies_dictionary);
+ wi_release(andor->replies_array);
}
static wi_string_t * _wi_p7_spec_andor_description(wi_runtime_instance_t *instance) {
- _wi_p7_spec_andor_t *andor = instance;
-
- return wi_string_with_format(WI_STR("<%@ %p>{type = %@, replies = %@, children = %@}"),
+ _wi_p7_spec_andor_t *andor = instance;
+
+ return wi_string_with_format(WI_STR("<%@ %p>{type = %@, replies = %@, children = %@}"),
wi_runtime_class_name(andor),
- andor,
- andor->type == _WI_P7_SPEC_AND ? WI_STR("and") : WI_STR("or"),
- andor->replies_array,
- andor->children);
+ andor,
+ andor->type == _WI_P7_SPEC_AND ? WI_STR("and") : WI_STR("or"),
+ andor->replies_array,
+ andor->children);
}
@@ -2688,110 +2697,110 @@ static wi_string_t * _wi_p7_spec_andor_description(wi_runtime_instance_t *instan
#pragma mark -
static _wi_p7_spec_reply_t * _wi_p7_spec_reply_with_node(wi_p7_spec_t *p7_spec, xmlNodePtr node, _wi_p7_spec_transaction_t *transaction) {
- _wi_p7_spec_reply_t *reply;
- wi_string_t *message, *use, *count;
+ _wi_p7_spec_reply_t *reply;
+ wi_string_t *message, *use, *count;
reply = wi_autorelease(wi_runtime_create_instance(_wi_p7_spec_reply_runtime_id, sizeof(_wi_p7_spec_reply_t)));
- message = wi_xml_node_attribute_with_name(node, WI_STR("message"));
-
- if(!message) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Reply in transaction \"%@\" has no \"message\""),
- transaction->message->name);
-
- return NULL;
- }
-
- reply->message = wi_retain(wi_dictionary_data_for_key(p7_spec->messages_name, message));
-
- if(!reply->message && _wi_p7_spec_builtin_spec)
- reply->message = wi_retain(wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->messages_name, message));
-
- if(!reply->message) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Reply in transaction \"%@\" has an invalid \"message\" (\"%@\")"),
- transaction->message->name, message);
-
- return NULL;
- }
-
- use = wi_xml_node_attribute_with_name(node, WI_STR("use"));
-
- if(use) {
- if(wi_string_case_insensitive_compare(use, WI_STR("required")) != 0 &&
- wi_string_case_insensitive_compare(use, WI_STR("optional"))) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Reply \"%@\" in transaction \"%@\" has an invalid \"use\" (\"%@\")"),
- reply->message->name, transaction->message->name, use);
-
- return NULL;
- }
-
- reply->required = (wi_string_case_insensitive_compare(use, WI_STR("required")) == 0);
- }
-
- count = wi_xml_node_attribute_with_name(node, WI_STR("count"));
-
- if(!count) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Reply in transaction \"%@\" has no \"count\""),
- transaction->message->name);
-
- return NULL;
- }
-
- if(wi_string_compare(count, WI_STR("?")) == 0)
- reply->count = _WI_P7_SPEC_REPLY_ONE_OR_ZERO;
- else if(wi_string_compare(count, WI_STR("*")) == 0)
- reply->count = _WI_P7_SPEC_REPLY_ZERO_OR_MORE;
- else if(wi_string_compare(count, WI_STR("+")) == 0)
- reply->count = _WI_P7_SPEC_REPLY_ONE_OR_MORE;
- else
- reply->count = wi_string_integer(count);
-
- if(reply->count == 0) {
- wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
- WI_STR("Reply in transaction \"%@\" has an invalid \"count\" (\"%@\")"),
- transaction->message->name, count);
-
- return NULL;
- }
-
- return reply;
+ message = wi_xml_node_attribute_with_name(node, WI_STR("message"));
+
+ if(!message) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Reply in transaction \"%@\" has no \"message\""),
+ transaction->message->name);
+
+ return NULL;
+ }
+
+ reply->message = wi_retain(wi_dictionary_data_for_key(p7_spec->messages_name, message));
+
+ if(!reply->message && _wi_p7_spec_builtin_spec)
+ reply->message = wi_retain(wi_dictionary_data_for_key(_wi_p7_spec_builtin_spec->messages_name, message));
+
+ if(!reply->message) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Reply in transaction \"%@\" has an invalid \"message\" (\"%@\")"),
+ transaction->message->name, message);
+
+ return NULL;
+ }
+
+ use = wi_xml_node_attribute_with_name(node, WI_STR("use"));
+
+ if(use) {
+ if(wi_string_case_insensitive_compare(use, WI_STR("required")) != 0 &&
+ wi_string_case_insensitive_compare(use, WI_STR("optional"))) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Reply \"%@\" in transaction \"%@\" has an invalid \"use\" (\"%@\")"),
+ reply->message->name, transaction->message->name, use);
+
+ return NULL;
+ }
+
+ reply->required = (wi_string_case_insensitive_compare(use, WI_STR("required")) == 0);
+ }
+
+ count = wi_xml_node_attribute_with_name(node, WI_STR("count"));
+
+ if(!count) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Reply in transaction \"%@\" has no \"count\""),
+ transaction->message->name);
+
+ return NULL;
+ }
+
+ if(wi_string_compare(count, WI_STR("?")) == 0)
+ reply->count = _WI_P7_SPEC_REPLY_ONE_OR_ZERO;
+ else if(wi_string_compare(count, WI_STR("*")) == 0)
+ reply->count = _WI_P7_SPEC_REPLY_ZERO_OR_MORE;
+ else if(wi_string_compare(count, WI_STR("+")) == 0)
+ reply->count = _WI_P7_SPEC_REPLY_ONE_OR_MORE;
+ else
+ reply->count = wi_string_integer(count);
+
+ if(reply->count == 0) {
+ wi_error_set_libwired_error_with_format(WI_ERROR_P7_INVALIDSPEC,
+ WI_STR("Reply in transaction \"%@\" has an invalid \"count\" (\"%@\")"),
+ transaction->message->name, count);
+
+ return NULL;
+ }
+
+ return reply;
}
static wi_string_t * _wi_p7_spec_reply_count(_wi_p7_spec_reply_t *reply) {
- if(reply->count == _WI_P7_SPEC_REPLY_ONE_OR_ZERO)
- return WI_STR("one or zero times");
- if(reply->count == _WI_P7_SPEC_REPLY_ZERO_OR_MORE)
- return WI_STR("zero or more times");
- else if(reply->count == _WI_P7_SPEC_REPLY_ONE_OR_MORE)
- return WI_STR("one or more times");
+ if(reply->count == _WI_P7_SPEC_REPLY_ONE_OR_ZERO)
+ return WI_STR("one or zero times");
+ if(reply->count == _WI_P7_SPEC_REPLY_ZERO_OR_MORE)
+ return WI_STR("zero or more times");
+ else if(reply->count == _WI_P7_SPEC_REPLY_ONE_OR_MORE)
+ return WI_STR("one or more times");
- return wi_string_with_format(WI_STR("%lu %@"), reply->count, (reply->count == 1) ? WI_STR("time") : WI_STR("times"));
+ return wi_string_with_format(WI_STR("%lu %@"), reply->count, (reply->count == 1) ? WI_STR("time") : WI_STR("times"));
}
static void _wi_p7_spec_reply_dealloc(wi_runtime_instance_t *instance) {
- _wi_p7_spec_reply_t *reply = instance;
-
- wi_release(reply->message);
+ _wi_p7_spec_reply_t *reply = instance;
+
+ wi_release(reply->message);
}
static wi_string_t * _wi_p7_spec_reply_description(wi_runtime_instance_t *instance) {
- _wi_p7_spec_reply_t *reply = instance;
-
- return wi_string_with_format(WI_STR("<%@ %p>{message = %@, count = %lu, required = %@}"),
+ _wi_p7_spec_reply_t *reply = instance;
+
+ return wi_string_with_format(WI_STR("<%@ %p>{message = %@, count = %lu, required = %@}"),
wi_runtime_class_name(reply),
- reply,
- reply->message ? reply->message->name : NULL,
- reply->count,
- reply->required ? WI_STR("true") : WI_STR("false"));
+ reply,
+ reply->message ? reply->message->name : NULL,
+ reply->count,
+ reply->required ? WI_STR("true") : WI_STR("false"));
}
#endif
diff --git a/vendor/WiredFrameworks/libwired/libwired/system/wi-system.c b/vendor/WiredFrameworks/libwired/libwired/system/wi-system.c
index ad63f4a2..ae6436f4 100644
--- a/vendor/WiredFrameworks/libwired/libwired/system/wi-system.c
+++ b/vendor/WiredFrameworks/libwired/libwired/system/wi-system.c
@@ -217,7 +217,7 @@ void * wi_malloc(size_t size) {
pointer = calloc(1, size);
if(pointer == NULL)
- __builtin_trap();
+ wi_crash();
return pointer;
}
@@ -230,7 +230,7 @@ void * wi_realloc(void *pointer, size_t size) {
newpointer = realloc(pointer, size);
if(newpointer == NULL)
- __builtin_trap();
+ wi_crash();
return newpointer;
}
diff --git a/vendor/WiredFrameworks/libwired/libwired/thread/wi-timer.c b/vendor/WiredFrameworks/libwired/libwired/thread/wi-timer.c
index 40b97a6b..e9c0b800 100644
--- a/vendor/WiredFrameworks/libwired/libwired/thread/wi-timer.c
+++ b/vendor/WiredFrameworks/libwired/libwired/thread/wi-timer.c
@@ -132,7 +132,7 @@ static void _wi_timer_thread(wi_runtime_instance_t *argument) {
pool = wi_pool_init(wi_pool_alloc());
- while(true) {
+ while(true) {//always true
fire_timer = NULL;
locked = true;
interval = wi_time_interval();