+- (void)submitTrack:(NSString *)title artist:(NSString *)artist album:(NSString *)album length:(int)length
+{
+ if (!_handshakeCompleted) {
+ [self attemptHandshake];
+ return;
+ }
+
+ //What we eventually want is a submission list that sends backlogs also
+ NSMutableURLRequest *request = [[NSURLRequest requestWithURL:_postURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30] mutableCopy];
+ NSString *responseHash = @"", *requestBody;
+
+ char *pass = "waffles";
+ unsigned char *buffer;
+ EVP_MD_CTX ctx;
+ int i;
+
+ buffer = malloc(EVP_MD_size(EVP_md5()));
+
+ EVP_DigestInit(&ctx, EVP_md5());
+ EVP_DigestUpdate(&ctx, pass, strlen(pass));
+ EVP_DigestFinal(&ctx, buffer, NULL);
+
+ for (i = 0; i < 16; i++) {
+ responseHash = [responseHash stringByAppendingFormat:@"%0.2x", buffer[i]];
+ }
+
+ free(buffer);
+ buffer = malloc(EVP_MD_size(EVP_md5()));
+ char *cat = (char *)[[responseHash stringByAppendingString:_md5Challenge] UTF8String];
+ EVP_DigestInit(&ctx, EVP_md5());
+ EVP_DigestUpdate(&ctx, cat, strlen(cat));
+ EVP_DigestFinal(&ctx, buffer, NULL);
+
+ responseHash = @"";
+ for (i = 0; i < 16; i++) {
+ responseHash = [responseHash stringByAppendingFormat:@"%0.2x", buffer[i]];
+ }
+ free(buffer);
+
+ requestBody = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)[NSString stringWithFormat:@"u=%@&s=%@&a[0]=%@&t[0]=%@&b[0]=%@&m[0]=&l[0]=%i&i[0]=%@", @"Tristrex", responseHash, artist, title, album, length, [[NSDate date] descriptionWithCalendarFormat:@"%Y-%m-%d %H:%M:%S" timeZone:nil locale:nil]], NULL, NULL, kCFStringEncodingUTF8);
+ [request setHTTPMethod:@"POST"];
+ [request setHTTPBody:[requestBody dataUsingEncoding:NSUTF8StringEncoding]];
+ _currentStatus = AudioscrobblerSubmittingTrackStatus;
+ _responseData = [[NSMutableData alloc] init];
+ [NSURLConnection connectionWithRequest:request delegate:self];
+ CFRelease(requestBody);
+ [request release];
+}
+
+- (void)handleAudioscrobblerNotification:(NSNotification *)note
+{
+ if ([[note name] isEqualToString:@"AudioscrobblerHandshakeComplete"]) {
+ [[AudioscrobblerController sharedController] submitTrack:@"Good Times Bad Times" artist:@"Led Zeppelin" album:@"Led Zeppelin I" length:166];
+ }
+}
+