Plugins/Bonjour/libezv/Private Classes/AWEzvContactManagerRendezvous.m
branchadium-1.5.10.3
changeset 5956 297f01718b75
parent 5019 89b86d3ffe84
child 6017 489d1e762237
equal deleted inserted replaced
5955:297d0d30e457 5956:297f01718b75
    38 #import "AWEzvContactPrivate.h"
    38 #import "AWEzvContactPrivate.h"
    39 #import "AWEzvRendezvousData.h"
    39 #import "AWEzvRendezvousData.h"
    40 #import "AWEzvSupportRoutines.h"
    40 #import "AWEzvSupportRoutines.h"
    41 
    41 
    42 #import <dns_sd.h>
    42 #import <dns_sd.h>
    43 #import <openssl/sha.h>
    43 #include <CommonCrypto/CommonDigest.h>
    44 
    44 
    45 /* One of the stupidest things I've ever met. Doing DNS lookups using the standard
    45 /* One of the stupidest things I've ever met. Doing DNS lookups using the standard
    46  * functions does not for mDNS records work unless you're in BIND 8 compatibility
    46  * functions does not for mDNS records work unless you're in BIND 8 compatibility
    47  * mode. And of course how do you get data from say a NULL record for iChat stuff?
    47  * mode. And of course how do you get data from say a NULL record for iChat stuff?
    48  * With the standard DNS functions. So we have to use BIND 8 mode. Which means we
    48  * With the standard DNS functions. So we have to use BIND 8 mode. Which means we
   329 }
   329 }
   330 
   330 
   331 - (void)setImageData:(NSData *)JPEGData
   331 - (void)setImageData:(NSData *)JPEGData
   332 {
   332 {
   333 	DNSServiceErrorType error;
   333 	DNSServiceErrorType error;
   334 	SHA_CTX ctx;
   334 	unsigned char digest[CC_SHA1_DIGEST_LENGTH];
   335 	unsigned char digest[20];
       
   336 
   335 
   337 	if (avDNSReference == NULL) {
   336 	if (avDNSReference == NULL) {
   338 		[[client client] reportError:@"Error setting image data" ofLevel:AWEzvWarning];
   337 		[[client client] reportError:@"Error setting image data" ofLevel:AWEzvWarning];
   339 		return;
   338 		return;
   340 	}
   339 	}
   380 	                             /* Data */ [JPEGData bytes], 
   379 	                             /* Data */ [JPEGData bytes], 
   381 	                             /* Time to live; 0 = default */ 0);
   380 	                             /* Time to live; 0 = default */ 0);
   382 
   381 
   383 	if (error == kDNSServiceErr_NoError) {
   382 	if (error == kDNSServiceErr_NoError) {
   384 		// Let's create the hash
   383 		// Let's create the hash
   385 		SHA1_Init(&ctx);
   384 		CC_SHA1([JPEGData bytes], (CC_LONG)[JPEGData length], digest);
   386 		SHA1_Update(&ctx, [JPEGData bytes], (unsigned long)[JPEGData length]);
       
   387 		SHA1_Final(digest, &ctx);
       
   388 		imagehash = [[NSData dataWithBytes:digest length:20] retain];
   385 		imagehash = [[NSData dataWithBytes:digest length:20] retain];
   389 		AILogWithSignature(@"Will update with hash %@; length is %u", imagehash, [JPEGData length]);
   386 		AILogWithSignature(@"Will update with hash %@; length is %u", imagehash, [JPEGData length]);
   390 		[self updatePHSH];
   387 		[self updatePHSH];
   391 	} else {
   388 	} else {
   392 		[[client client] reportError:@"Error adding image record" ofLevel:AWEzvWarning];
   389 		[[client client] reportError:@"Error adding image record" ofLevel:AWEzvWarning];