331
329
void parse_status_answer(MpdObj *mo, void* unused_param)
334
char key[15], value[200];
336
while (strcmp(mo->buffer,"OK\n"))
331
gchar **lines, **tokens;
334
lines = g_strsplit(mo->buffer, "\n", 0);
335
for (i = 0 ; lines[i] && strcmp(lines[i], "OK") ; i++)
339
ptr = strstr(mo->buffer, ":");
340
eol = strstr(mo->buffer, "\n");
341
strncpy(key, mo->buffer, ptr - mo->buffer);
342
key[ptr - mo->buffer]='\0';
343
strncpy(value,ptr + 2 , eol - ptr - 2);
344
value[eol - ptr - 2]='\0';
346
DBG("key=\"%s\",value=\"%s\"", key, value);
347
if (0 == strcmp("volume",key)) mo->curvol = atoi(value);
348
else if (0 == strcmp("repeat",key)) mo->repeat = atoi(value);
349
else if (0 == strcmp("random",key)) mo->random = atoi(value);
350
else if (0 == strcmp("playlistlength",key)) mo->playlistlength = atoi(value);
351
else if (0 == strcmp("state", key))
337
tokens = g_strsplit(lines[i], ":", 2);
338
/* remove leading whitespace */
339
tokens[1] = g_strchug(tokens[1]);
340
DBG("key=\"%s\",value=\"%s\"", tokens[0], tokens[1]);
341
if (0 == strcmp("volume",tokens[0])) mo->curvol = atoi(tokens[1]);
342
else if (0 == strcmp("repeat",tokens[0])) mo->repeat = atoi(tokens[1]);
343
else if (0 == strcmp("random",tokens[0])) mo->random = atoi(tokens[1]);
344
else if (0 == strcmp("playlistlength",tokens[0])) mo->playlistlength = atoi(tokens[1]);
345
else if (0 == strcmp("state", tokens[0]))
353
if (0 == strcmp("play", value)) mo->status = MPD_PLAYER_PLAY;
354
else if (0 == strcmp("pause",value)) mo->status = MPD_PLAYER_PAUSE;
355
else if (0 == strcmp("stop", value)) mo->status = MPD_PLAYER_STOP;
347
if (0 == strcmp("play", tokens[1])) mo->status = MPD_PLAYER_PLAY;
348
else if (0 == strcmp("pause",tokens[1])) mo->status = MPD_PLAYER_PAUSE;
349
else if (0 == strcmp("stop", tokens[1])) mo->status = MPD_PLAYER_STOP;
357
else if (0 == strcmp("song",key)) mo->song = atoi(value);
358
else if (0 == strcmp("songid",key)) mo->songid = atoi(value);
361
strcpy(mo->buffer, eol+1); /*overlap ! */
362
mo->buflen = strlen(mo->buffer);
351
else if (0 == strcmp("song",tokens[0])) mo->song = atoi(tokens[1]);
352
else if (0 == strcmp("songid",tokens[0])) mo->songid = atoi(tokens[1]);
366
358
int mpd_status_update(MpdObj* mo)
375
367
void parse_one_song(MpdObj *mo, void* param)
377
369
mpd_Song* ms = (mpd_Song*) param;
379
char key[15], value[200];
370
gchar **lines, **tokens;
380
372
ms->artist = ms->album = ms->title = ms->track = NULL;
381
ms->id = ms->pos = 0;
373
ms->id = ms->pos = -1;
375
lines = g_strsplit(mo->buffer, "\n", 0);
376
for (i = 0 ; lines[i] && strcmp(lines[i], "OK") ; i++)
386
ptr = strstr(mo->buffer, ":");
387
eol = strstr(mo->buffer, "\n");
388
strncpy(key, mo->buffer, ptr - mo->buffer);
389
key[ptr - mo->buffer]='\0';
390
strncpy(value,ptr + 2 , eol - ptr - 2);
391
value[eol - ptr - 2]='\0';
393
DBG("key=\"%s\",value=\"%s\"", key, value);
394
if (!ms->artist && 0 == strcmp("Artist",key)) ms->artist= strdup(value);
395
else if (!ms->album && 0 == strcmp("Album", key)) ms->album = strdup(value);
396
else if (!ms->title && 0 == strcmp("Title", key)) ms->title = strdup(value);
397
else if (!ms->track && 0 == strcmp("Track", key)) ms->track = strdup(value);
398
else if (!ms->pos && 0 == strcmp("Pos", key)) ms->pos = atoi(value);
399
else if (!ms->id && 0 == strcmp("Id", key)) ms->id = atoi(value);
401
strcpy(mo->buffer, eol+1); /* overlap ! */
402
mo->buflen = strlen(mo->buffer);
378
tokens = g_strsplit(lines[i], ":", 2);
379
/* remove leading whitespace */
380
tokens[1] = g_strchug(tokens[1]);
381
DBG("key=\"%s\",value=\"%s\"", tokens[0], tokens[1]);
382
if (!ms->artist && 0 == strcmp("Artist",tokens[0])) ms->artist= g_strdup(tokens[1]);
383
else if (!ms->album && 0 == strcmp("Album", tokens[0])) ms->album = g_strdup(tokens[1]);
384
else if (!ms->title && 0 == strcmp("Title", tokens[0])) ms->title = g_strdup(tokens[1]);
385
else if (!ms->track && 0 == strcmp("Track", tokens[0])) ms->track = g_strdup(tokens[1]);
386
else if (ms->pos < 0 && 0 == strcmp("Pos", tokens[0])) ms->pos = atoi(tokens[1]);
387
else if (ms->id < 0 && 0 == strcmp("Id", tokens[0])) ms->id = atoi(tokens[1]);
391
mo->error = MPD_FAILED;
406
395
void parse_playlistinfo_answer(MpdObj *mo, void *param)
408
397
MpdData* md = (MpdData*) param;
409
while (strcmp(mo->buffer,"OK\n"))
399
gchar **lines, **tokens;
402
lines = g_strsplit(mo->buffer, "\n", 0);
403
while(lines[i] && strcmp(lines[i],"OK"))
405
ms = &md->allsongs[md->nb];
406
ms->artist = ms->album = ms->title = ms->track = NULL;
407
ms->id = ms->pos = -1;
411
408
DBG("Going to parse song #%d", md->nb);
412
parse_one_song(mo, (void*) &(md->allsongs[md->nb]));
410
while(lines[i] && ms->id < 0)
412
tokens = g_strsplit(lines[i], ":", 2);
413
/* remove leading whitespace */
414
tokens[1] = g_strchug(tokens[1]);
415
DBG("key=\"%s\",value=\"%s\"", tokens[0], tokens[1]);
416
if (!ms->artist && 0 == strcmp("Artist",tokens[0])) ms->artist= g_strdup(tokens[1]);
417
else if (!ms->album && 0 == strcmp("Album", tokens[0])) ms->album = g_strdup(tokens[1]);
418
else if (!ms->title && 0 == strcmp("Title", tokens[0])) ms->title = g_strdup(tokens[1]);
419
else if (!ms->track && 0 == strcmp("Track", tokens[0])) ms->track = g_strdup(tokens[1]);
420
else if (ms->pos < 0 && 0 == strcmp("Pos", tokens[0])) ms->pos = atoi(tokens[1]);
421
else if (ms->id < 0 && 0 == strcmp("Id", tokens[0])) ms->id = atoi(tokens[1]);
415
428
DBG("Got 'OK', md->nb = %d", md->nb);