Example #1
0
void
CAudioScrobbler::Handshake()
{
	std::string username="";
	for(unsigned int i = 0; i < Config->getLUsername().length(); i++) {
		username.append(1, tolower(Config->getLUsername().c_str()[i]));
	}
	std::string authtoken(md5sum((char*)"%s%s", username.c_str(), Config->getLPassword().c_str()));

	std::ostringstream query, sig;
	query << "method=auth.getMobileSession&username="******"&authToken=" << authtoken << "&api_key=" << APIKEY;

	sig << "api_key" << APIKEY << "authToken" << authtoken << "methodauth.getMobileSessionusername" << Config->getLUsername() << SECRET;
	std::string sighash(md5sum((char*)"%s", sig.str().c_str()));

	query << "&api_sig=" << sighash;

	OpenURL(ROOTURL, query.str().c_str());

	if(_response.find("<lfm status=\"ok\">") != std::string::npos) {
		size_t start, end;
		start = _response.find("<key>") + 5;
		end = _response.find("</key>");
		_sessionid = _response.substr(start, end-start);
		iprintf("%s%s", "Last.fm handshake successful. SessionID: ", _sessionid.c_str());
		_authed = true;
	}
	else if(_response.find("<lfm status=\"failed\">") != std::string::npos) {
		CheckFailure(_response);
		exit(EXIT_FAILURE);
	}

	CLEANUP();
}
Example #2
0
bool
CAudioScrobbler::SendNowPlaying(mpd_Song* song)
{
	bool retval = false;
	if(!song || !song->artist || !song->title) return retval;

	char* artist = curl_easy_escape(_handle, song->artist, 0);
	char* title = curl_easy_escape(_handle, song->title, 0);
	char* album = 0;
	if(song->album)
		album = curl_easy_escape(_handle, song->album, 0);

	std::ostringstream query, sig;
	query << "method=track.updateNowPlaying&track=" << title << "&artist=" << artist << "&duration=" << song->time << "&api_key=" << APIKEY << "&sk=" << _sessionid;
	if(album) {
		query << "&album=" << album;
		sig << "album" << song->album;
	}

    curl_free(artist);
    curl_free(title);
    curl_free(album);

	sig << "api_key" << APIKEY << "artist" << song->artist << "duration" << song->time << "methodtrack.updateNowPlaying" << "sk" << _sessionid << "track" << song->title << SECRET;

	std::string sighash(md5sum((char*)"%s", sig.str().c_str()));

	query << "&api_sig=" << sighash;

	OpenURL(ROOTURL, query.str().c_str());

	if(_response.find("<lfm status=\"ok\">") != std::string::npos) {
		iprintf("%s", "Updated \"Now Playing\" status successfully.");
		retval = true;
	}
	else if(_response.find("<lfm status=\"failed\">") != std::string::npos) {
		eprintf("%s%s", "Last.fm returned an error while updating the currently playing track:\n", _response.c_str());
		if(CheckFailure(_response))
			Failure();
	}

	CLEANUP();
	return retval;
}
Example #3
0
std::string
CAudioScrobbler::CreateScrobbleMessage(int index, centry_t* entry)
{
	std::ostringstream msg, sigmsg ;
	std::string artist, title, album, array = "=";

	char* temp = 0;
	temp = curl_easy_escape(_handle, entry->artist.c_str(), entry->artist.length());
	artist = temp;
	curl_free(temp);
	temp = curl_easy_escape(_handle, entry->title.c_str(), entry->title.length());
	title = temp;
	curl_free(temp);
	temp = curl_easy_escape(_handle, entry->album.c_str(), entry->album.length());
	album = temp;
	curl_free(temp);

	msg << "&album" << array << album;
	msg << "&api_key=" << APIKEY;
	msg << "&artist" << array << artist;
	msg << "&duration" << array << entry->time;
	msg << "&method=track.Scrobble";
	msg << "&timestamp" << array << entry->starttime;
	msg << "&track" << array << title;
	msg << "&sk=" << _sessionid;

	array = "";

	sigmsg << "album" << array << entry->album;
	sigmsg << "api_key" << APIKEY;
	sigmsg << "artist" << array << entry->artist;
	sigmsg << "duration" << array << entry->time;
	sigmsg << "methodtrack.Scrobble";
	sigmsg << "sk" << _sessionid;
	sigmsg << "timestamp" << array << entry->starttime;
	sigmsg << "track" << array << entry->title;
	sigmsg << SECRET;

	std::string sighash(md5sum((char*)"%s", sigmsg.str().c_str()));
	msg << "&api_sig=" << sighash;

	return msg.str();
}
Example #4
0
static PGPError
Annotate (PGPPipeline *myself, PGPPipeline *origin, int type,
	  PGPByte const *string, size_t size)
{
	ReadAnnContext *context;
	PGPError	error = kPGPError_NoErr;
	int i;
	PgpUICbArg msgarg1;
	PGPContextRef	cdkContext;
	
	pgpAssertAddrValid( myself, PGPPipeline );
	cdkContext	= myself->cdkContext;

	pgpAssert (myself);
	pgpAssert (myself->magic == READANNOTATIONMAGIC);

	context = (ReadAnnContext *)myself->priv;
	pgpAssert (context);

	if (PGP_IS_SCOPE_MARKER (type)) {
		if (PGP_IS_BEGIN_SCOPE (type)) {
			context->stack[context->sp++] = type;
		} else {
			pgpAssert(PGP_IS_END_SCOPE (type));

			if (context->stack[context->sp - 1] != type - 1)
				context->ui->message (context->ui_arg,
						      kPGPError_UnbalancedScope,
						      PGPMSG_UNBALANCED_SCOPE,
						      0);
			else {
				context->stack[--context->sp] = 0;
				context->sepsig[context->sp] = 0;
			}

		}
		/*
		 * For clearsigned messages, preserve type.  See comments
		 * re PGPANN_CLEARSIG_BEGIN/END below.  Otherwise go back
		 * to type of next annotation on the stack.
		 */
		if (!(type==PGPANN_ARMOR_BEGIN &&
					      context->type==PGP_LITERAL_TEXT))
			if (context->sp)
				context->type = context->stack[context->sp-1];
	}

	if (context->ui->annotate) {
		error = (PGPError)context->ui->annotate (context->ui_arg, origin,
					       type, string, size);
		if (error)
			return error;
	}

	switch (type) {
	case PGPANN_COMMIT:
		do {
			i = context->ui->doCommit 
				(context->ui_arg,
				 context->stack[context->sp - 1]);

			/* Allow commit function to abort us */
			if (i < 0) {
				return i;
			}

			if (i != PGPANN_PARSER_PASSTHROUGH &&
			    i != PGPANN_PARSER_EATIT &&
			    i != PGPANN_PARSER_PROCESS &&
			    i != PGPANN_PARSER_RECURSE) {
				msgarg1.type = PGP_UI_ARG_INT;
				msgarg1.val.i = i;
				context->ui->message (context->ui_arg,
						      kPGPError_InvalidCommit,
						      PGPMSG_COMMIT_INVALID,
						      1,
						      &msgarg1);
				continue;
			}

			if (i < PGPANN_PARSER_PROCESS) {
				error = origin->annotate (origin, myself, i,
				                          0, 0);
				if (error) 
					context->ui->message
						(context->ui_arg, error,
						 PGPMSG_ANNOTATE_ERROR, 0);
			} else if (context->stack[context->sp-1] ==
			                          PGPANN_CIPHER_BEGIN) {
				error = (PGPError)eskdecrypt(myself, origin, i);
				if (error) {
					context->ui->message
						(context->ui_arg, error,
						 PGPMSG_ESK_NODECRYPT, 0);
					break;
				}
			} else if (context->stack[context->sp-1] ==
			                          PGPANN_SIGNED_BEGIN) {
				if (context->sepsig[context->sp-1]) {
					error = (PGPError)sepsighash(context);
					if (error) {
						context->ui->message
						   (context->ui_arg, error,
						    PGPMSG_SEPSIG_NOVERIFY, 0);
						break;
					}
				} else {
					error = (PGPError)sighash(myself, origin, i);
					if (error) {
						context->ui->message
						   (context->ui_arg, error,
						    PGPMSG_SIG_NOVERIFY, 0);
						break;
					}
				}
			} else {
				error = origin->annotate (origin, myself, i,
				                          0, 0);
				if (error)
					context->ui->message
						(context->ui_arg, error,
						 PGPMSG_ANNOTATE_ERROR, 0);
			}
			/* The idea of looping until the error goes away does not seem
			 * practical.  If it failed once, it will almost always fail
			 * again.
			 */
			if (error)
				return error;
		} while (error);
		break;
	case PGPANN_PKCIPHER_ESK:
	case PGPANN_SKCIPHER_ESK:
		i = pgpEskAdd( cdkContext, &context->esklist, type, string, size);
		if (i != 0) {
			context->ui->message (context->ui_arg, i,
					      PGPMSG_ESK_ADD_ERROR, 0);
		}
		break;

	case PGPANN_SIGNED_SIG:
	case PGPANN_SIGNED_SIG2:
		/* Add signature for */
		i = pgpSigAdd ( cdkContext, &context->siglist[context->sp-1], type,
			       string, size);
		if (i != 0) {
			context->ui->message (context->ui_arg, i,
					      PGPMSG_SIG_ADD_ERROR, 0);
		}
		break;

	case PGPANN_SIGNED_SEP:
		/* This signature context is for a separate signature */
		context->sepsig[context->sp-1] = 1;
		break;
	case PGPANN_SIGNED_END:
		error = (PGPError)sigtry(myself, origin);
		break;
	case PGPANN_HASH_VALUE:
		error = (PGPError)sigverify(myself, string, size);
		break;
	case PGPANN_LITERAL_TYPE:
		if (size)
			context->type = string[0];
		break;
	case PGPANN_LITERAL_NAME:
		if (size) {
			if (context->name)
				pgpContextMemFree( cdkContext, context->name);
			context->name = (char *)pgpContextMemAlloc( cdkContext,
				size+1, kPGPMemoryMgrFlags_Clear);
			if (context->name)
			{
				memcpy (context->name, string, size);
				context->name[size] = 0;
			}
			else
				error = kPGPError_OutOfMemory;
		}
		break;
	/*
	 * The actual sequence is: PGPANN_CLEARSIG_BEGIN, PGPANN_CLEARSIG_END,
	 * PGPANN_ARMOR_BEGIN, and then we do a Write when we want our type
	 * to be PGP_LITERAL_TEXT.  So it takes some careful work here and
	 * above.
	 */
	case PGPANN_CLEARSIG_BEGIN:
	case PGPANN_CLEARSIG_END:
		/* Clearsigned messages are always text! */
		context->type = PGP_LITERAL_TEXT;
		break;
	default:
		; /* Do nothing */
	}

	/* At end of scope, shut down output */
	if (!error && PGP_IS_END_SCOPE (type) && context-> sp < context->file_sp)
	{
		/* We are now closing tail during the annotation callback */
		if (context->tail)
			error = context->tail->sizeAdvise (context->tail, 0);
		if (!error) {
			if (context->name) {
				pgpContextMemFree( cdkContext, context->name);
				context->name = NULL;
			}
			context->type = -1;
			context->newoutput = 1;
		}
	}

	return error;
}