+- (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, *buffer2, buffer3[16];
+ EVP_MD_CTX ctx;
+ int i;
+
+ buffer = malloc(EVP_MD_size(EVP_md5()));
+ //buffer3 = malloc(EVP_MD_size(EVP_md5()));
+
+ EVP_DigestInit(&ctx, EVP_md5());
+ EVP_DigestUpdate(&ctx, pass, strlen(pass));
+ EVP_DigestUpdate(&ctx, [_md5Challenge UTF8String], strlen([_md5Challenge UTF8String]));
+ EVP_DigestFinal(&ctx, buffer, NULL);
+
+ for (i = 0; i < 16; i++) {
+ char hex1, hex2;
+ hex1 = toascii(48+ (buffer[i] / 16));
+ if (hex1 > 57) {
+ hex1 = hex1 + 39;
+ }
+ hex2 = toascii(48 + (buffer[i] % 16));
+ if (hex2 > 57) {
+ hex2 = hex2 + 39;
+ }
+
+ buffer3[i] = hex1;
+ buffer3[i + 1] = hex2;
+ }
+
+ NSLog(@"%s", buffer3);
+
+ /*unsigned char *cat = strcat(buffer3, [[_md5Challenge lowercaseString] UTF8String]);
+
+ EVP_DigestInit(&ctx, EVP_md5());
+ EVP_DigestUpdate(&ctx, cat, strlen(cat));
+ EVP_DigestFinal(&ctx, buffer2, NULL);
+
+ for (i = 0; i < 16; i++) {
+ char hex1, hex2;
+ hex1 = toascii(48+ (buffer2[i] / 16));
+ if (hex1 > 57) {
+ hex1 = hex1 + 39;
+ }
+ hex2 = toascii(48 + (buffer2[i] % 16));
+ if (hex2 > 57) {
+ hex2 = hex2 + 39;
+ }
+ buffer3[i] = hex1;
+ buffer3[i + 1] = hex2;
+ }
+ NSLog(@"%s", buffer3);*/
+
+ if ([NSString respondsToSelector:@selector(stringWithCString:encoding:)]) {
+ responseHash = [NSString stringWithCString:buffer3 encoding:NSASCIIStringEncoding];
+ } else {
+ responseHash = [NSString stringWithCString:buffer3 length:strlen(buffer)];
+ }
+
+ requestBody = [NSString stringWithFormat:@"u=%@&s=%@&a[0]=%@&t[0]=%@&b[0]=%@&m[0]=&l[0]=%i&i[0]=%@", @"Tristrex", @"rawr", responseHash, title, album, length, [[NSDate date] descriptionWithCalendarFormat:@"%Y-%m-%d %H:%M:%S" timeZone:nil locale:nil]];
+ [request setHTTPMethod:@"POST"];
+ [request setHTTPBody:[requestBody dataUsingEncoding:NSUTF8StringEncoding]];
+
+ _currentStatus = AudioscrobblerSubmittingTrackStatus;
+ _responseData = [[NSMutableData alloc] init];
+ [NSURLConnection connectionWithRequest:request delegate:self];
+ [request release];
+}
+
+- (void)handleAudioscrobblerNotification:(NSNotification *)note
+{
+ if ([[note name] isEqualToString:@"AudioscrobblerHandshakeComplete"]) {
+ [[AudioscrobblerController sharedController] submitTrack:@"Stairway To Heaven" artist:@"Led Zeppelin" album:@"Led Zeppelin IV" length:483];
+ }
+}
+