Skip to content

Commit

Permalink
Support for Draft-IETF-HYBI-00 and Draft-IETF-HYBI-06 protocols.
Browse files Browse the repository at this point in the history
  • Loading branch information
mirek committed May 3, 2011
1 parent 982bc06 commit 0d52c13
Show file tree
Hide file tree
Showing 8 changed files with 826 additions and 246 deletions.
9 changes: 9 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,12 @@ Link your target with:
</script>
</head>
</html>

## License

Unless otherwise stated, the code is released under Open Source MIT License, (c) Copyright Mirek Rusin <mirek [at] me [dot] com>

Parts of the source code (particularly Base64 encoding functions) have been copied from http://opensource.apple.com which are released
under Apple Public Source License 2.0 http://www.opensource.apple.com/apsl.

Portions of the copied source code could be modified.
27 changes: 20 additions & 7 deletions WebSocketCore/WebSocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,32 @@ WebSocketRef WebSocketCreate(CFAllocatorRef allocator, CFStringRef host, UInt16
} else {

// Set the host based on provided string. TODO: hostname resolution?
__WebSocketString hostASCII = __WebSocketStringMake(NULL, host, kCFStringEncodingASCII);
inet_aton((const char *)__WebSocketStringGetCString(hostASCII), &webSocket->addr.sin_addr);
__WebSocketStringDestroy(hostASCII);
CFIndex hostCStringLength = CFStringGetMaximumSizeForEncoding(CFStringGetLength(host), kCFStringEncodingASCII) + 1;
char *hostCString = CFAllocatorAllocate(webSocket->allocator, hostCStringLength, 0);
if (hostCString) {
if (CFStringGetCString(host, hostCString, hostCStringLength, kCFStringEncodingASCII)) {
inet_aton(hostCString, &webSocket->addr.sin_addr);
} else {
// TODO: Couldn't get CString
}
CFAllocatorDeallocate(webSocket->allocator, hostCString);
} else {
// TODO: Couldn't allocate buffer
}
}

webSocket->addr.sin_port = htons(port);

CFDataRef address = CFDataCreate(webSocket->allocator, (const void *)&webSocket->addr, sizeof(webSocket->addr));
if (CFSocketSetAddress(webSocket->socket, (CFDataRef)address) != kCFSocketSuccess) {
webSocket = WebSocketRelease(webSocket);
goto fin;
if (address) {
if (CFSocketSetAddress(webSocket->socket, (CFDataRef)address) != kCFSocketSuccess) {
webSocket = WebSocketRelease(webSocket);
// CFRelease(address); // TODO: is it retained by the function?
goto fin;
} else {
// CFRelease(address); // TODO: is it retained bby the function
}
}
//CFRelease(address);

// Create run loop source and add it to the current run loop
CFRunLoopSourceRef source = CFSocketCreateRunLoopSource(webSocket->allocator, webSocket->socket, 0);
Expand Down
4 changes: 2 additions & 2 deletions WebSocketCore/WebSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
#include <unistd.h>
#include <netdb.h>

#import <CommonCrypto/CommonDigest.h>

#if (TARGET_OS_IPHONE)
#include <CFNetwork/CFNetwork.h>
#include <CommonCrypto/CommonDigest.h>
#else
#include <CoreServices/CoreServices.h>
#include <openssl/evp.h>
Expand All @@ -27,7 +28,6 @@
#include <netinet/in.h>

#include "WebSocketTypes.h"
#include "WebSocketString.h"
#include "WebSocketClient.h"

#define __WebSocketMaxHeaderKeyLength 4096
Expand Down
Loading

0 comments on commit 0d52c13

Please sign in to comment.