示例#1
0
文件: ui.c 项目: groomba/pianobar
/*	fetch http resource (post request)
 *	@param waitress handle
 *	@param piano request (initialized by PianoRequest())
 */
static WaitressReturn_t BarPianoHttpRequest (WaitressHandle_t *waith,
		PianoRequest_t *req) {
	waith->extraHeaders = "Content-Type: text/xml\r\n";
	waith->postData = req->postData;
	waith->method = WAITRESS_METHOD_POST;
	strncpy (waith->path, req->urlPath, sizeof (waith->path)-1);

	return WaitressFetchBuf (waith, &req->responseData);
}
示例#2
0
/*	fetch http resource (post request)
 *	@param waitress handle
 *	@param piano request (initialized by PianoRequest())
 */
static WaitressReturn_t BarPianoHttpRequest (WaitressHandle_t *waith,
		PianoRequest_t *req) {
	waith->extraHeaders = "Content-Type: text/plain\r\n";
	waith->postData = req->postData;
	waith->method = WAITRESS_METHOD_POST;
	waith->url.path = req->urlPath;
	waith->url.tls = req->secure;

	return WaitressFetchBuf (waith, &req->responseData);
}
示例#3
0
WaitressReturn_t
MythPianoService::PianoHttpRequest(WaitressHandle_t *waith,
				   PianoRequest_t *req) {
  waith->extraHeaders = "Content-Type: text/xml\r\n";
  waith->postData = req->postData;
  waith->method = WAITRESS_METHOD_POST;
  waith->url.path = req->urlPath;

  return WaitressFetchBuf (waith, &req->responseData);
}
示例#4
0
/*	authenticate user
 */
static bool BarMainLoginUser (BarApp_t *app) {
	PianoReturn_t pRet;
	WaitressReturn_t wRet;
	PianoRequestDataLogin_t reqData;
	bool ret;
#if 0
	WaitressHandle_t waithSync;
	char *syncTime;
	unsigned long int syncTimeInt;

	/* skip sync step by fetching time from somewhere else */
	WaitressInit (&waithSync);
	WaitressSetUrl (&waithSync, "http://ridetheclown.com/s2/synctime.php");
	if (app->settings.proxy != NULL && strlen (app->settings.proxy) > 0) {
		WaitressSetProxy (&waithSync, app->settings.proxy);
	}
	wRet = WaitressFetchBuf (&waithSync, &syncTime);
	WaitressFree (&waithSync);
	if (wRet != WAITRESS_RET_OK) {
		BarUiMsg (&app->settings, MSG_ERR, "Unable to sync: %s\n",
				WaitressErrorToStr (wRet));
		return false;
	}

	syncTimeInt = strtoul (syncTime, NULL, 0);
	app->ph.timeOffset = time (NULL) - syncTimeInt;
	free (syncTime);
#endif
	app->ph.timeOffset = -30239998; /* woo! magic number */

	reqData.user = app->settings.username;
	reqData.password = app->settings.password;
	reqData.step = 0;

	BarUiMsg (&app->settings, MSG_INFO, "Login... ");
	ret = BarUiPianoCall (app, PIANO_REQUEST_LOGIN, &reqData, &pRet, &wRet);
	BarUiStartEventCmd (&app->settings, "userlogin", NULL, NULL, &app->player,
			NULL, pRet, wRet);
	return ret;
}
示例#5
0
/*	_really_ submit song to last.fm
 *	@param wardrobe handle
 *	@param song
 *	@return _OK or error
 */
static WardrobeReturn_t WardrobeSendSong (WardrobeHandle_t *wh,
		const WardrobeSong_t *ws) {
	char postContent[WARDROBE_HTTP_SEND_SIZE];
	char *urlencArtist, *urlencTitle, *urlencAlbum, *ret;
	WardrobeReturn_t fRet = WARDROBE_RET_ERR;

	urlencArtist = WaitressUrlEncode (ws->artist);
	urlencTitle = WaitressUrlEncode (ws->title);
	urlencAlbum = WaitressUrlEncode (ws->album);

	snprintf (postContent, sizeof (postContent), "s=%s&a[0]=%s&t[0]=%s&"
			"i[0]=%li&o[0]=E&r[0]=&l[0]=%li&b[0]=%s&n[0]=&m[0]=",
			wh->authToken, urlencArtist, urlencTitle, ws->started,
			ws->length, urlencAlbum);

	WaitressSetHPP (&wh->waith, wh->postHost, wh->postPort, wh->postPath);
	wh->waith.method = WAITRESS_METHOD_POST;
	wh->waith.postData = postContent;
	wh->waith.extraHeaders = "Content-Type: application/x-www-form-urlencoded\r\n";
	if (WaitressFetchBuf (&wh->waith, &ret) != WAITRESS_RET_OK) {
		return WARDROBE_RET_CONNECT_ERR;
	}

	if (memcmp (ret, "OK", 2) == 0) {
		fRet = WARDROBE_RET_OK;
	} else if (memcmp (ret, "BADSESSION", 10) == 0) {
		fRet = WARDROBE_RET_BADSESSION;
	}

	WardrobeFree (urlencArtist, 0);
	WardrobeFree (urlencTitle, 0);
	WardrobeFree (urlencAlbum, 0);
	WardrobeFree (ret, 0);

	return fRet;
}
示例#6
0
/*	get session id from last.fm; you don't have to call this manually
 *	@param wardrobe handle
 *	@return _OK or error
 */
static WardrobeReturn_t WardrobeHandshake (WardrobeHandle_t *wh) {
	/* md5 hash length + long integer max + NULL */
	char url[WARDROBE_URL_SIZE], tmp[32+55+1], *tmpDigest, *pwDigest,
			*ret, postUrl[1024];
	WardrobeReturn_t fRet = WARDROBE_RET_ERR;
	time_t currTStamp = time (NULL);

	tmpDigest = WardrobeMd5Calc (wh->password);
	snprintf (tmp, sizeof (tmp), "%s%li", tmpDigest, currTStamp);
	pwDigest = WardrobeMd5Calc (tmp);
	snprintf (url, sizeof (url), "/?hs=true&p=1.2&c=pia&v=1.0&u=%s&t=%li&a=%s",
			wh->user, currTStamp, pwDigest);
	
	WaitressSetHPP (&wh->waith, "post.audioscrobbler.com", "80", url);
	wh->waith.method = WAITRESS_METHOD_GET;
	wh->waith.postData = NULL;
	wh->waith.extraHeaders = NULL;
	if (WaitressFetchBuf (&wh->waith, &ret) != WAITRESS_RET_OK) {
		return WARDROBE_RET_CONNECT_ERR;
	}

	/* parse answer */
	if (memcmp (ret, "OK", 2) == 0) {
		char *newlines[5];
		size_t i;
		newlines[0] = ret;
		/* split string */
		for (i = 1; i < sizeof (newlines) / sizeof (*newlines); i++) {
			newlines[i] = strchr (newlines[i-1]+1, '\n');
		}
		/* copy needed values (auth token and post url) */
		if (newlines[2] - newlines[1]-1 < sizeof (wh->authToken)) {
			memcpy (wh->authToken, newlines[1]+1, newlines[2] -
					newlines[1]-1);
		} else {
			printf ("buffer overflow!\n");
		}
		if (newlines[4] - newlines[3]-1 < sizeof (postUrl)) {
			memset (postUrl, 0, sizeof (postUrl));
			memcpy (postUrl, newlines[3]+1, newlines[4] -
					newlines[3]-1);
			WaitressSplitUrl (postUrl, wh->postHost, sizeof (wh->postHost),
					wh->postPort, sizeof (wh->postPort), wh->postPath,
					sizeof (wh->postPath));
		} else {
			printf ("buffer overflow!\n");
		}
		fRet = WARDROBE_RET_OK;
	} else if (memcmp (ret, "BADAUTH", 7) == 0) {
		fRet = WARDROBE_RET_BADAUTH;
	} else if (memcmp (ret, "BADTIME", 7) == 0) {
		fRet = WARDROBE_RET_BADTIME;
	} else if (memcmp (ret, "BANNED", 6) == 0) {
		fRet = WARDROBE_RET_CLIENT_BANNED;
	}

	WardrobeFree (tmpDigest, WARDROBE_MD5_DIGEST_LEN);
	WardrobeFree (pwDigest, WARDROBE_MD5_DIGEST_LEN);
	WardrobeFree (ret, 0);

	return fRet;
}