Adding mini changes

This commit is contained in:
2025-09-25 11:24:14 +10:00
parent d8df1b739a
commit 6bd1fc943e
3 changed files with 15 additions and 14 deletions

View File

@@ -1,4 +1,4 @@
egcc main.c \ gcc main.c \
configHandler.c \ configHandler.c \
libopensubsonic/httpclient.c \ libopensubsonic/httpclient.c \
external/cJSON.c \ external/cJSON.c \
@@ -17,4 +17,4 @@ egcc main.c \
libopensubsonic/endpoint_getAlbumList.c \ libopensubsonic/endpoint_getAlbumList.c \
libopensubsonic/endpoint_getStarred.c \ libopensubsonic/endpoint_getStarred.c \
libopensubsonic/endpoint_scrobble.c \ libopensubsonic/endpoint_scrobble.c \
-o main -I/usr/local/include -L/usr/local/lib -lcurl -o main -lcurl

View File

@@ -180,8 +180,9 @@ char* opensubsonic_authenticate_lastFm(void) {
* Sends a scrobble to LastFM * Sends a scrobble to LastFM
* If 'finalize' is true, it sends to the track.scrobble endpoint * If 'finalize' is true, it sends to the track.scrobble endpoint
* If 'finalize' is false, it sends to the track.updateNowPlaying endpoint * If 'finalize' is false, it sends to the track.updateNowPlaying endpoint
* Returns 1 if error, else 0
*/ */
void opensubsonic_scrobble_lastFm(bool finalize, opensubsonic_getSong_struct* songStruct) { int opensubsonic_scrobble_lastFm(bool finalize, opensubsonic_getSong_struct* songStruct) {
if (finalize) { if (finalize) {
logger_log_general(__func__, "Performing final scrobble to LastFM."); logger_log_general(__func__, "Performing final scrobble to LastFM.");
} else { } else {
@@ -194,8 +195,8 @@ void opensubsonic_scrobble_lastFm(bool finalize, opensubsonic_getSong_struct* so
currentTime = time(NULL); currentTime = time(NULL);
rc = asprintf(&currentTime_string, "%ld", currentTime); rc = asprintf(&currentTime_string, "%ld", currentTime);
if (rc == -1) { if (rc == -1) {
logger_log_error(__func__, "asprintf() failed."); logger_log_error(__func__, "asprintf() failed (Could not make char* of UNIX timestamp).");
return; // TODO return error return 1;
} }
// Assemble the signature // Assemble the signature
@@ -210,8 +211,8 @@ void opensubsonic_scrobble_lastFm(bool finalize, opensubsonic_getSong_struct* so
configObj->lastfm_api_session_key, currentTime_string, songStruct->title, configObj->lastfm_api_secret); configObj->lastfm_api_session_key, currentTime_string, songStruct->title, configObj->lastfm_api_secret);
} }
if (rc == -1) { if (rc == -1) {
logger_log_error(__func__, "asprintf() failed."); logger_log_error(__func__, "asprintf() failed (Could not assemble plaintext signature).");
return; // TODO handle error return 1;
} }
uint8_t sig_md5_bytes[16]; uint8_t sig_md5_bytes[16];
@@ -224,8 +225,8 @@ void opensubsonic_scrobble_lastFm(bool finalize, opensubsonic_getSong_struct* so
sig_md5_bytes[8], sig_md5_bytes[9], sig_md5_bytes[10], sig_md5_bytes[11], sig_md5_bytes[8], sig_md5_bytes[9], sig_md5_bytes[10], sig_md5_bytes[11],
sig_md5_bytes[12], sig_md5_bytes[13], sig_md5_bytes[14], sig_md5_bytes[15]); sig_md5_bytes[12], sig_md5_bytes[13], sig_md5_bytes[14], sig_md5_bytes[15]);
if (rc == -1) { if (rc == -1) {
logger_log_error(__func__, "asprintf() failed."); logger_log_error(__func__, "asprintf() failed (Could not assemble md5 signature).");
return; // TODO handle error return 1;
} }
// URI encode strings // URI encode strings
@@ -233,13 +234,13 @@ void opensubsonic_scrobble_lastFm(bool finalize, opensubsonic_getSong_struct* so
char* uri_songArtist = lcue_uriescape(songStruct->artist, (unsigned int)strlen(songStruct->artist)); char* uri_songArtist = lcue_uriescape(songStruct->artist, (unsigned int)strlen(songStruct->artist));
char* uri_songAlbum = lcue_uriescape(songStruct->album, (unsigned int)strlen(songStruct->album)); char* uri_songAlbum = lcue_uriescape(songStruct->album, (unsigned int)strlen(songStruct->album));
if (uri_songTitle == NULL || uri_songArtist == NULL || uri_songAlbum == NULL) { if (uri_songTitle == NULL || uri_songArtist == NULL || uri_songAlbum == NULL) {
logger_log_error(__func__, "lcue_uriescape() error."); logger_log_error(__func__, "lcue_uriescape() error (Could not URI escape required strings).");
free(currentTime_string); free(currentTime_string);
free(sig_md5_text); free(sig_md5_text);
if (uri_songTitle != NULL) { free(uri_songTitle); } if (uri_songTitle != NULL) { free(uri_songTitle); }
if (uri_songArtist != NULL) { free(uri_songArtist); } if (uri_songArtist != NULL) { free(uri_songArtist); }
if (uri_songAlbum != NULL) { free(uri_songAlbum); } if (uri_songAlbum != NULL) { free(uri_songAlbum); }
return; // TODO return error return 1;
} }
// Assemble the payload // Assemble the payload
@@ -263,8 +264,8 @@ void opensubsonic_scrobble_lastFm(bool finalize, opensubsonic_getSong_struct* so
free(uri_songAlbum); free(uri_songAlbum);
free(uri_songArtist); free(uri_songArtist);
if (rc == -1) { if (rc == -1) {
logger_log_error(__func__, "asprintf() failed."); logger_log_error(__func__, "asprintf() failed (Could not assemble payload).");
return; // TODO return error return 1;
} }
// Send scrobble and receive response // Send scrobble and receive response

View File

@@ -4,6 +4,6 @@
#include "endpoint_getSong.h" #include "endpoint_getSong.h"
char* opensubsonic_authenticate_lastFm(void); char* opensubsonic_authenticate_lastFm(void);
void opensubsonic_scrobble_lastFm(bool finalize, opensubsonic_getSong_struct* songStruct); int opensubsonic_scrobble_lastFm(bool finalize, opensubsonic_getSong_struct* songStruct);
#endif #endif