diff options
-rwxr-xr-x | watrack_mpd/globals.h | 1 | ||||
-rwxr-xr-x | watrack_mpd/main.c | 130 |
2 files changed, 108 insertions, 23 deletions
diff --git a/watrack_mpd/globals.h b/watrack_mpd/globals.h index 20beab9..400781f 100755 --- a/watrack_mpd/globals.h +++ b/watrack_mpd/globals.h @@ -8,4 +8,5 @@ BOOL bWatrackService; TCHAR *gbHost, *gbPassword;
WORD gbPort;
BOOL Connected;
+int gbState;
#endif
diff --git a/watrack_mpd/main.c b/watrack_mpd/main.c index 637580d..87fd2e5 100755 --- a/watrack_mpd/main.c +++ b/watrack_mpd/main.c @@ -34,23 +34,43 @@ LPDEINITPROC DeInit() }
LPCHECKPROC CheckPlayer(HWND wnd, int flags)
{
+ if(!ghConnection)
+ {
+ Start();
+ return 0;
+ }
if(Connected)
return (LPCHECKPROC)1;
return 0;
}
LPGETSTATUSPROC GetStatus()
{
- return 0;
+ if(!ghConnection)
+ {
+ Start();
+ return 0;
+ }
+ return (LPGETSTATUSPROC)gbState;
}
LPNAMEPROC GetFileName(HWND wnd, int flags)
{
+ if(!ghConnection)
+ {
+ Start();
+ return 0;
+ }
return 0;
}
SONGINFO SongInfo = {0};
LPINFOPROC GetPlayerInfo(LPSONGINFO info, int flags)
{
+ if(!ghConnection)
+ {
+ Start();
+ return 0;
+ }
/* info->album = SongInfo.album;
- info->artist = SongInfo.artist;
+
info->channels = SongInfo.channels;
info->codec = SongInfo.codec;
info->comment = SongInfo.comment;
@@ -58,7 +78,7 @@ LPINFOPROC GetPlayerInfo(LPSONGINFO info, int flags) info->date = SongInfo.date;
info->fps = SongInfo.fps;
info->fsize = SongInfo.fsize;
- info->genre = SongInfo.genre;
+
info->icon = SongInfo.icon;
info->kbps = SongInfo.kbps;
info->khz = SongInfo.khz;
@@ -71,18 +91,17 @@ LPINFOPROC GetPlayerInfo(LPSONGINFO info, int flags) info->title = SongInfo.title;
info->total = SongInfo.total;
info->track = SongInfo.track;*/
+ info->total = SongInfo.total;
info->time = SongInfo.time;
info->mfile = SongInfo.mfile;
info->txtver = SongInfo.txtver;
info->title = SongInfo.title;
+ info->artist = SongInfo.artist;
+ info->genre = SongInfo.genre;
/* info->url = SongInfo.url; //??
info->vbr = SongInfo.vbr;
info->volume = SongInfo.volume;
info->year = SongInfo.year;*/
-// free(SongInfo.txtver);
-// free(SongInfo.mfile);
-// free(SongInfo.title);
-
return 0;
}
LPCOMMANDPROC SendCommand(HWND wnd, int command, int value)
@@ -113,7 +132,7 @@ void RegisterPlayer() }
}
-int Parser(unsigned char *buf, int len)
+int Parser(unsigned char *buf)
{
char *ptr;
char tmp[128];
@@ -122,37 +141,91 @@ int Parser(unsigned char *buf, int len) {
Connected = TRUE;
ptr = &ptr[4];
- for(i = 0; ptr[i] != '\n'; i++)
+ for(i = 0; ((ptr[i] != '\n') && (ptr[i] != '\0')); i++)
tmp[i] = ptr[i];
tmp[i+1] = '\0';
- SongInfo.txtver = (TCHAR*)mir_a2t(tmp);
+// SongInfo.txtver = (TCHAR*)mir_a2t(tmp);
+ SongInfo.txtver = (TCHAR*)mir_strdup(tmp);
}
+ else if (!SongInfo.txtver)
+ SongInfo.txtver = _T("");
if(ptr = strstr(buf, "file:"))
{
ptr = &ptr[6];
- for(i = 0; ptr[i] != '\n'; i++)
+ for(i = 0; ((ptr[i] != '\n') && (ptr[i] != '\0')); i++)
tmp[i] = ptr[i];
tmp[i+1] = '\0';
- SongInfo.mfile = (TCHAR*)mir_a2t(tmp);
+
+ SongInfo.mfile = (TCHAR*)mir_strdup(tmp);
}
+ else if(!SongInfo.mfile)
+ SongInfo.mfile = _T("");
if(ptr = strstr(buf, "Time:"))
{
ptr = &ptr[6];
- for(i = 0; ptr[i] != '\n'; i++)
+ for(i = 0; ((ptr[i] != '\n') && (ptr[i] != '\0')); i++)
+ tmp[i] = ptr[i];
+ tmp[i+1] = '\0';
+ SongInfo.total = atoi(tmp);
+ }
+ else if(!SongInfo.total)
+ SongInfo.total = 0;
+ if(ptr = strstr(buf, "time:"))
+ {
+ ptr = &ptr[6];
+ for(i = 0; ((ptr[i] != '\n') && (ptr[i] != '\0')); i++)
tmp[i] = ptr[i];
tmp[i+1] = '\0';
SongInfo.time = atoi(tmp);
}
+ else if(!SongInfo.time)
+ SongInfo.time = 0;
if(ptr = strstr(buf, "Title:"))
{
ptr = &ptr[7];
- for(i = 0; ptr[i] != '\n'; i++)
+ for(i = 0; ((ptr[i] != '\n') && (ptr[i] != '\0')); i++)
tmp[i] = ptr[i];
tmp[i+1] = '\0';
- SongInfo.title = (TCHAR*)mir_a2t(tmp);
+ SongInfo.title = (TCHAR*)mir_strdup(tmp);
}
-
- return len;
+ else if(!SongInfo.title)
+ SongInfo.title = _T("");
+ if(ptr = strstr(buf, "Artist:"))
+ {
+ ptr = &ptr[8];
+ for(i = 0; ((ptr[i] != '\n') && (ptr[i] != '\0')); i++)
+ tmp[i] = ptr[i];
+ tmp[i+1] = '\0';
+ SongInfo.artist = (TCHAR*)mir_strdup(tmp);
+ }
+ else if(!SongInfo.artist)
+ SongInfo.artist = _T("");
+ if(ptr = strstr(buf, "Genre:"))
+ {
+ ptr = &ptr[7];
+ for(i = 0; ((ptr[i] != '\n') && (ptr[i] != '\0')); i++)
+ tmp[i] = ptr[i];
+ tmp[i+1] = '\0';
+ SongInfo.genre = (TCHAR*)mir_strdup(tmp);
+ }
+ else if(!SongInfo.genre)
+ SongInfo.genre = _T("");
+ if(ptr = strstr(buf, "state:"))
+ {
+ ptr = &ptr[7];
+ for(i = 0; ((ptr[i] != '\n') && (ptr[i] != '\0')); i++)
+ tmp[i] = ptr[i];
+ tmp[i+1] = '\0';
+ if(strstr(tmp, "play"))
+ gbState = WAT_MES_PLAYING;
+ if(strstr(tmp, "pause"))
+ gbState = WAT_MES_PAUSED;
+ if(strstr(tmp, "stop"))
+ gbState = WAT_MES_STOPPED;
+ }
+ else if(!gbState)
+ gbState = WAT_MES_UNKNOWN;
+ return 0;
}
DWORD __stdcall Reciever(LPVOID lp)
@@ -166,21 +239,32 @@ DWORD __stdcall Reciever(LPVOID lp) nloc.timeout = 5;
nloc.wPort = gbPort;
ghConnection = NetLib_CreateConnection(ghNetlibUser, &nloc);
- free(tmp);
+// free(tmp);
nlpr.cbSize = sizeof(nlpr);
nlpr.dwTimeout = INFINITE;
- ghPacketReciever = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER,(WPARAM)ghConnection,0x2400);
+ ghPacketReciever = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER,(WPARAM)ghConnection,2048);
while(ghConnection)
{
- Netlib_Send(ghConnection, "currentsong\n", strlen("currentsong\n") + 1, 0);
- Netlib_Send(ghConnection, "status\n", strlen("status\n") + 1, 0);
recvResult = CallService(MS_NETLIB_GETMOREPACKETS,(WPARAM)ghPacketReciever, (LPARAM)&nlpr);
if(recvResult == 0)
break;
if (recvResult == SOCKET_ERROR)
break;
- nlpr.bytesUsed = Parser(nlpr.buffer, nlpr.bytesAvailable);
- Sleep(1000);
+ Netlib_Send(ghConnection, "status\n", strlen("status\n"), 0);
+ recvResult = CallService(MS_NETLIB_GETMOREPACKETS,(WPARAM)ghPacketReciever, (LPARAM)&nlpr);
+ if(recvResult == 0)
+ break;
+ if (recvResult == SOCKET_ERROR)
+ break;
+ Netlib_Send(ghConnection, "currentsong\n", strlen("currentsong\n"), 0);
+ recvResult = CallService(MS_NETLIB_GETMOREPACKETS,(WPARAM)ghPacketReciever, (LPARAM)&nlpr);
+ if(recvResult == 0)
+ break;
+ if (recvResult == SOCKET_ERROR)
+ break;
+ Parser(nlpr.buffer);
+ nlpr.bytesUsed = nlpr.bytesAvailable;
+ Sleep(1000); //do not flood daemon
}
return 0;
}
|