-
Notifications
You must be signed in to change notification settings - Fork 0
/
receiver.c
580 lines (515 loc) · 18 KB
/
receiver.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
/*
* receiver.c - Onkyo receiver interaction code
*
* Copyright (c) 2008-2010 Dan McGee <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE 1 /* memmem */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "onkyo.h"
extern const char * const rcvr_err;
/** A mapping of receiver status value to returned message */
struct status {
unsigned long hash;
const char *key;
const char *value;
};
/** A mapping of receiver power status value to returned message as well as
* helping to internally track power on/off state */
struct power_status {
unsigned long hash;
const char *key;
const char *value;
int zone;
int power;
};
/**
* Get the next receiver command that should be sent. This implementation has
* logic to discard non-power commands if the receiver is not powered up.
* @param rcvr the receiver to pull a command out of the queue for
* @return the command to send (must be freed), NULL if none available
*/
static struct cmdqueue *next_rcvr_command(struct receiver *rcvr)
{
/* Determine whether we should send the command. This depends on two
* factors:
* 1. If the power is on, always send the command.
* 2. If the power is off, send only power commands through.
*/
while(rcvr->queue) {
/* dequeue the next cmd queue item */
struct cmdqueue *ptr = rcvr->queue;
rcvr->queue = rcvr->queue->next;
if(rcvr->power || is_power_command(ptr->cmd)) {
return ptr;
} else {
printf("skipping command as receiver power appears to be off\n");
free(ptr);
}
}
return NULL;
}
/**
* Send a command to the receiver. This should be used when a write() to the
* given file descriptor is known to be non-blocking; e.g. after a select()
* call on the descriptor.
* @param rcvr the receiver to send a command to from the attached queue
* @return 0 on success or no action taken, -1 on failure
*/
int rcvr_send_command(struct receiver *rcvr)
{
struct cmdqueue *ptr;
if(!rcvr->queue)
return -1;
ptr = next_rcvr_command(rcvr);
if(ptr) {
ssize_t retval;
size_t cmdsize;
char fullcmd[BUF_SIZE * 2];
cmdsize = strlen(START_SEND) + strlen(ptr->cmd) + strlen(END_SEND);
if(cmdsize >= BUF_SIZE * 2) {
fprintf(stderr, "send_command, command too large: %zd\n", cmdsize);
return -1;
}
sprintf(fullcmd, START_SEND "%s" END_SEND, ptr->cmd);
/* write the command */
retval = xwrite(rcvr->fd, fullcmd, cmdsize);
/* set our last sent time */
gettimeofday(&(rcvr->last_cmd), NULL);
/* print command to console; newline is already in command */
printf("command: %s", fullcmd);
free(ptr);
if(retval < 0 || ((size_t)retval) != cmdsize) {
fprintf(stderr, "send_command, write returned %zd\n", retval);
printf("%s", rcvr_err);
return -1;
}
rcvr->cmds_sent++;
}
return 0;
}
/**
* Handle a pending status message coming from the receiver. This is most
* likely called after a select() on the serial fd returned that a read will
* not block. It may also be used to get the status message that is returned
* after sending a command.
* @param serialfd the file descriptor the receiver is accessible on
* @param status the status string returned by the receiver
* @return the read size on success, -1 on failure
*/
static ssize_t rcvr_handle_status(int serialfd, char **status)
{
ssize_t retval;
char buf[BUF_SIZE];
memset(buf, 0, BUF_SIZE);
/* read the status message that should be present */
retval = xread(serialfd, &buf, BUF_SIZE - 1);
/* if we had a returned status, we are good to go */
if(retval > 0) {
buf[retval] = '\0';
/* return the status message if asked for */
if(status) {
size_t alloc_size = (size_t)retval + 1;
*status = malloc(alloc_size * sizeof(char));
if(*status)
memcpy(*status, buf, alloc_size);
}
return retval;
}
fprintf(stderr, "handle_status, read value was empty\n");
return -1;
}
/**
* Array to hold all status messages that can easily be transposed into
* one of our own status messages. We can't handle all of them this way,
* but for those we can this is a code and time saver.
*/
static struct status statuses[] = {
{ 0, "AMT00", "OK:mute:off\n" },
{ 0, "AMT01", "OK:mute:on\n" },
{ 0, "SLI00", "OK:input:DVR\n" },
{ 0, "SLI01", "OK:input:Cable\n" },
{ 0, "SLI02", "OK:input:TV\n" },
{ 0, "SLI03", "OK:input:AUX\n" },
{ 0, "SLI04", "OK:input:AUX2\n" },
{ 0, "SLI05", "OK:input:PC\n" },
{ 0, "SLI10", "OK:input:DVD\n" },
{ 0, "SLI20", "OK:input:Tape\n" },
{ 0, "SLI22", "OK:input:Phono\n" },
{ 0, "SLI23", "OK:input:CD\n" },
{ 0, "SLI24", "OK:input:FM Tuner\n" },
{ 0, "SLI25", "OK:input:AM Tuner\n" },
{ 0, "SLI26", "OK:input:Tuner\n" },
{ 0, "SLI27", "OK:input:Music Server\n" },
{ 0, "SLI28", "OK:input:Internet Radio\n" },
{ 0, "SLI29", "OK:input:USB\n" },
{ 0, "SLI2A", "OK:input:USB Rear\n" },
{ 0, "SLI40", "OK:input:Port\n" },
{ 0, "SLI30", "OK:input:Multichannel\n" },
{ 0, "SLI31", "OK:input:XM Radio\n" },
{ 0, "SLI32", "OK:input:Sirius Radio\n" },
{ 0, "SLIFF", "OK:input:Audyssey Speaker Setup\n" },
{ 0, "LMD00", "OK:mode:Stereo\n" },
{ 0, "LMD01", "OK:mode:Direct\n" },
{ 0, "LMD07", "OK:mode:Mono Movie\n" },
{ 0, "LMD08", "OK:mode:Orchestra\n" },
{ 0, "LMD09", "OK:mode:Unplugged\n" },
{ 0, "LMD0A", "OK:mode:Studio-Mix\n" },
{ 0, "LMD0B", "OK:mode:TV Logic\n" },
{ 0, "LMD0C", "OK:mode:All Channel Stereo\n" },
{ 0, "LMD0D", "OK:mode:Theater-Dimensional\n" },
{ 0, "LMD0F", "OK:mode:Mono\n" },
{ 0, "LMD10", "OK:mode:Test Tone\n" },
{ 0, "LMD11", "OK:mode:Pure Audio\n" },
{ 0, "LMD13", "OK:mode:Full Mono\n" },
{ 0, "LMD15", "OK:mode:DTS Surround Sensation\n" },
{ 0, "LMD16", "OK:mode:Audyssey DSX\n" },
{ 0, "LMD40", "OK:mode:Straight Decode\n" },
{ 0, "LMD41", "OK:mode:Dolby EX/DTS ES\n" },
{ 0, "LMD42", "OK:mode:THX Cinema\n" },
{ 0, "LMD43", "OK:mode:THX Surround EX\n" },
{ 0, "LMD44", "OK:mode:THX Music\n" },
{ 0, "LMD45", "OK:mode:THX Games\n" },
{ 0, "LMD80", "OK:mode:Pro Logic IIx Movie\n" },
{ 0, "LMD81", "OK:mode:Pro Logic IIx Music\n" },
{ 0, "LMD82", "OK:mode:Neo:6 Cinema\n" },
{ 0, "LMD83", "OK:mode:Neo:6 Music\n" },
{ 0, "LMD84", "OK:mode:PLIIx THX Cinema\n" },
{ 0, "LMD85", "OK:mode:Neo:6 THX Cinema\n" },
{ 0, "LMD86", "OK:mode:Pro Logic IIx Game\n" },
{ 0, "LMD88", "OK:mode:Neural THX\n" },
{ 0, "LMDN/A", "ERROR:mode:N/A\n" },
{ 0, "MEMLOCK", "OK:memory:locked\n" },
{ 0, "MEMUNLK", "OK:memory:unlocked\n" },
{ 0, "MEMN/A", "ERROR:memory:N/A\n" },
{ 0, "ZMT00", "OK:zone2mute:off\n" },
{ 0, "ZMT01", "OK:zone2mute:on\n" },
{ 0, "ZVLN/A", "ERROR:zone2volume:N/A\n" },
{ 0, "SLZ00", "OK:zone2input:DVR\n" },
{ 0, "SLZ01", "OK:zone2input:Cable\n" },
{ 0, "SLZ02", "OK:zone2input:TV\n" },
{ 0, "SLZ03", "OK:zone2input:AUX\n" },
{ 0, "SLZ04", "OK:zone2input:AUX2\n" },
{ 0, "SLZ10", "OK:zone2input:DVD\n" },
{ 0, "SLZ20", "OK:zone2input:Tape\n" },
{ 0, "SLZ22", "OK:zone2input:Phono\n" },
{ 0, "SLZ23", "OK:zone2input:CD\n" },
{ 0, "SLZ24", "OK:zone2input:FM Tuner\n" },
{ 0, "SLZ25", "OK:zone2input:AM Tuner\n" },
{ 0, "SLZ26", "OK:zone2input:Tuner\n" },
{ 0, "SLZ30", "OK:zone2input:Multichannel\n" },
{ 0, "SLZ31", "OK:zone2input:XM Radio\n" },
{ 0, "SLZ32", "OK:zone2input:Sirius Radio\n" },
{ 0, "SLZ7F", "OK:zone2input:Off\n" },
{ 0, "SLZ80", "OK:zone2input:Source\n" },
{ 0, "MT300", "OK:zone3mute:off\n" },
{ 0, "MT301", "OK:zone3mute:on\n" },
{ 0, "VL3N/A", "ERROR:zone3volume:N/A\n" },
{ 0, "SL300", "OK:zone3input:DVR\n" },
{ 0, "SL301", "OK:zone3input:Cable\n" },
{ 0, "SL302", "OK:zone3input:TV\n" },
{ 0, "SL303", "OK:zone3input:AUX\n" },
{ 0, "SL304", "OK:zone3input:AUX2\n" },
{ 0, "SL310", "OK:zone3input:DVD\n" },
{ 0, "SL320", "OK:zone3input:Tape\n" },
{ 0, "SL322", "OK:zone3input:Phono\n" },
{ 0, "SL323", "OK:zone3input:CD\n" },
{ 0, "SL324", "OK:zone3input:FM Tuner\n" },
{ 0, "SL325", "OK:zone3input:AM Tuner\n" },
{ 0, "SL326", "OK:zone3input:Tuner\n" },
{ 0, "SL330", "OK:zone3input:Multichannel\n" },
{ 0, "SL331", "OK:zone3input:XM Radio\n" },
{ 0, "SL332", "OK:zone3input:Sirius Radio\n" },
{ 0, "SL37F", "OK:zone3input:Off\n" },
{ 0, "SL380", "OK:zone3input:Source\n" },
{ 0, "DIF00", "OK:display:Volume\n" },
{ 0, "DIF01", "OK:display:Mode\n" },
{ 0, "DIF02", "OK:display:Digital Format\n" },
{ 0, "DIFN/A", "ERROR:display:N/A\n" },
{ 0, "DIM00", "OK:dimmer:Bright\n" },
{ 0, "DIM01", "OK:dimmer:Dim\n" },
{ 0, "DIM02", "OK:dimmer:Dark\n" },
{ 0, "DIM03", "OK:dimmer:Shut-off\n" },
{ 0, "DIM08", "OK:dimmer:Bright (LED off)\n" },
{ 0, "DIMN/A", "ERROR:dimmer:N/A\n" },
{ 0, "LTN00", "OK:latenight:off\n" },
{ 0, "LTN01", "OK:latenight:low\n" },
{ 0, "LTN02", "OK:latenight:high\n" },
{ 0, "RAS00", "OK:re-eq:off\n" },
{ 0, "RAS01", "OK:re-eq:on\n" },
{ 0, "ADY00", "OK:audyssey:off\n" },
{ 0, "ADY01", "OK:audyssey:on\n" },
{ 0, "ADQ00", "OK:dynamiceq:off\n" },
{ 0, "ADQ01", "OK:dynamiceq:on\n" },
{ 0, "HDO00", "OK:hdmiout:off\n" },
{ 0, "HDO01", "OK:hdmiout:on\n" },
{ 0, "RES00", "OK:resolution:Through\n" },
{ 0, "RES01", "OK:resolution:Auto\n" },
{ 0, "RES02", "OK:resolution:480p\n" },
{ 0, "RES03", "OK:resolution:720p\n" },
{ 0, "RES04", "OK:resolution:1080i\n" },
{ 0, "RES05", "OK:resolution:1080p\n" },
{ 0, "SLA00", "OK:audioselector:Auto\n" },
{ 0, "SLA01", "OK:audioselector:Multichannel\n" },
{ 0, "SLA02", "OK:audioselector:Analog\n" },
{ 0, "SLA03", "OK:audioselector:iLink\n" },
{ 0, "SLA04", "OK:audioselector:HDMI\n" },
{ 0, "TGA00", "OK:triggera:off\n" },
{ 0, "TGA01", "OK:triggera:on\n" },
{ 0, "TGAN/A", "ERROR:triggera:N/A\n" },
{ 0, "TGB00", "OK:triggerb:off\n" },
{ 0, "TGB01", "OK:triggerb:on\n" },
{ 0, "TGBN/A", "ERROR:triggerb:N/A\n" },
{ 0, "TGC00", "OK:triggerc:off\n" },
{ 0, "TGC01", "OK:triggerc:on\n" },
{ 0, "TGCN/A", "ERROR:triggerc:N/A\n" },
/* Do not remove! */
{ 0, NULL, NULL },
};
static struct power_status power_statuses[] = {
{ 0, "PWR00", "OK:power:off\n", 1, 0 },
{ 0, "PWR01", "OK:power:on\n", 1, 1 },
{ 0, "ZPW00", "OK:zone2power:off\n", 2, 0 },
{ 0, "ZPW01", "OK:zone2power:on\n", 2, 1 },
{ 0, "PW300", "OK:zone3power:off\n", 3, 0 },
{ 0, "PW301", "OK:zone3power:on\n", 3, 1 },
/* Do not remove! */
{ 0, NULL, NULL, -1,-1 },
};
/**
* Initialize our list of static statuses. This must be called before the first
* call to process_incoming_message(). This initialization gives us a slight
* performance gain by pre-hashing our status values to unsigned longs,
* allowing the status lookups to be relatively low-cost.
*/
void init_statuses(void)
{
unsigned int status_count = 0;
struct status *status;
struct power_status *pwr_status;
for(status = statuses; status->key; status++) {
status->hash = hash_sdbm(status->key);
status_count++;
}
for(pwr_status = power_statuses; pwr_status->key; pwr_status++) {
pwr_status->hash = hash_sdbm(pwr_status->key);
status_count++;
}
printf("%u status messages prehashed in status list.\n", status_count);
}
static void update_power_status(struct receiver *rcvr, int zone, int value);
/**
* Form the human readable status message from the receiver return value.
* Note that the status parameter is freely modified as necessary and
* should not be expected to be readable after this method has completed.
* @param rcvr the receiver the message was received from
* @param size the length of the status message as it might contain null
* bytes
* @param status the receiver status message to make human readable
* @return 0 on normal status, -1 on parse errors
*/
static int parse_status(struct receiver *rcvr, size_t size, char *status)
{
unsigned long hashval;
char buf[BUF_SIZE];
char *sptr, *eptr;
struct status *st;
struct power_status *pwr_st;
/* Trim the start and end portions off. We want to strip any leading
* garbage, including null bytes, and just start where we find the
* START_RECV characters. */
sptr = memmem(status, size, START_RECV, strlen(START_RECV));
if(sptr) {
sptr += strlen(START_RECV);
eptr = strstr(sptr, END_RECV);
if(eptr)
*eptr = '\0';
} else {
/* Hmm, we couldn't find the start chars. WTF? */
write_to_connections(rcvr_err);
return -1;
}
hashval = hash_sdbm(sptr);
/* this depends on the {NULL} entry at the end of the list */
st = statuses;
while(st->hash != 0) {
if(st->hash == hashval) {
write_to_connections(st->value);
return 0;
}
st++;
}
pwr_st = power_statuses;
while(pwr_st->hash != 0) {
if(pwr_st->hash == hashval) {
update_power_status(rcvr, pwr_st->zone, pwr_st->power);
write_to_connections(pwr_st->value);
return 0;
}
pwr_st++;
}
/* We couldn't use our easy method of matching statuses to messages,
* so handle the special cases. */
if(strncmp(sptr, "MVL", 3) == 0 || strncmp(sptr, "ZVL", 3) == 0
|| strncmp(sptr, "VL3", 3) == 0) {
char buf2[BUF_SIZE];
/* parse the volume number out */
char *pos;
/* read volume level in as a base 16 (hex) number */
long level = strtol(sptr + 3, &pos, 16);
if(*sptr == 'M') {
/* main volume level */
snprintf(buf, BUF_SIZE, "OK:volume:%ld\n", level);
snprintf(buf2, BUF_SIZE, "OK:dbvolume:%ld\n", level - 82);
} else if(*sptr == 'Z') {
/* zone 2 volume level */
snprintf(buf, BUF_SIZE, "OK:zone2volume:%ld\n", level);
snprintf(buf2, BUF_SIZE, "OK:zone2dbvolume:%ld\n", level - 82);
} else if(*sptr == 'V') {
/* zone 3 volume level */
snprintf(buf, BUF_SIZE, "OK:zone3volume:%ld\n", level);
snprintf(buf2, BUF_SIZE, "OK:zone3dbvolume:%ld\n", level - 82);
}
/* this block is special compared to the rest; we write out buf2 here
* but let the normal write at the end handle buf as usual */
write_to_connections(buf2);
}
/* TUN, TUZ, TU3 */
else if(strncmp(sptr, "TU", 2) == 0) {
/* parse the frequency number out */
char *pos, *tunemsg;
/* read frequency in as a base 10 number */
long freq = strtol(sptr + 3, &pos, 10);
/* decide whether we are main or zones */
tunemsg = "OK:tune:";
if(sptr[2] == 'Z') {
tunemsg = "OK:zone2tune:";
} else if(sptr[2] == '3') {
tunemsg = "OK:zone3tune:";
}
if(freq > 8000) {
/* FM frequency, something like 09790 was read */
/* Use some awesome integer math to format the output */
snprintf(buf, BUF_SIZE, "%s%ld.%ld FM\n", tunemsg,
freq / 100, (freq / 10) % 10);
} else {
/* AM frequency, something like 00780 was read */
snprintf(buf, BUF_SIZE, "%s%ld AM\n", tunemsg, freq);
}
}
else if(strncmp(sptr, "PRS", 3) == 0 || strncmp(sptr, "PRZ", 3) == 0
|| strncmp(sptr, "PR3", 3) == 0) {
/* parse the preset number out */
char *pos, *prsmsg;
/* read value in as a base 16 (hex) number */
long value = strtol(sptr + 3, &pos, 16);
/* decide whether we are main or zones */
prsmsg = "OK:preset:";
if(sptr[2] == 'Z') {
prsmsg = "OK:zone2preset:";
} else if(sptr[2] == '3') {
prsmsg = "OK:zone3preset:";
}
snprintf(buf, BUF_SIZE, "%s%ld\n", prsmsg, value);
}
else if(strncmp(sptr, "SLP", 3) == 0) {
/* parse the minutes out */
char *pos;
/* read sleep timer in as a base 16 (hex) number */
long mins = strtol(sptr + 3, &pos, 16);
snprintf(buf, BUF_SIZE, "OK:sleep:%ld\n", mins);
}
else if(strncmp(sptr, "SWL", 3) == 0) {
/* parse the level out */
char *pos;
/* read volume level in as a base 16 (hex) number */
long level = strtol(sptr + 3, &pos, 16);
snprintf(buf, BUF_SIZE, "OK:swlevel:%+ld\n", level);
}
else if(strncmp(sptr, "AVS", 3) == 0) {
/* parse the time value out */
char *pos;
/* read time value in as a base 10 number */
long level = strtol(sptr + 3, &pos, 10);
/* AVS1000 -> 100 ms delay */
level /= 10;
snprintf(buf, BUF_SIZE, "OK:avsync:%ld\n", level);
}
else {
snprintf(buf, BUF_SIZE, "OK:todo:%s\n", sptr);
}
write_to_connections(buf);
return 0;
}
/**
* Update the power status for the given zone to the given value. This
* message may or may not be related to power; if it is not then the status
* will not be updated. If it is, perform some bitmask-foo to update the power
* status depending on what zone was turned on or off.
* @param rcvr the receiver the message was received from
* @param zone the value 1, 2, or 3 corresponding to the zone
* @param value 1 for on, 0 for off
*/
static void update_power_status(struct receiver *rcvr, int zone, int value)
{
/* var is a bitmask, manage power/zone2power separately */
if(zone == 1 && value == 0) {
rcvr->power &= ~MAIN_POWER;
} else if(zone == 1 && value == 1) {
rcvr->power |= MAIN_POWER;
} else if(zone == 2 && value == 0) {
rcvr->power &= ~ZONE2_POWER;
timeval_clear(rcvr->zone2_sleep);
} else if(zone == 2 && value == 1) {
rcvr->power |= ZONE2_POWER;
} else if(zone == 3 && value == 0) {
rcvr->power &= ~ZONE3_POWER;
timeval_clear(rcvr->zone3_sleep);
} else if(zone == 3 && value == 1) {
rcvr->power |= ZONE3_POWER;
}
}
/**
* Process a status message to be read from the receiver (one that the
* receiver initiated). Return a human-readable status message.
* @param rcvr the receiver to process the command for
* @param logfd the fd used for logging raw status messages
* @return 0 on successful processing, -1 on failure
*/
int process_incoming_message(struct receiver *rcvr, int logfd)
{
int ret;
ssize_t size;
char *status = NULL;
/* get the output from the receiver */
size = rcvr_handle_status(rcvr->fd, &status);
if(size >= 0) {
/* log the message if we have a logfd */
if(logfd > 0)
xwrite(logfd, status, (size_t)size + 1);
/* parse the return and output a status message */
ret = parse_status(rcvr, (size_t)size, status);
if(!ret)
rcvr->msgs_received++;
} else {
write_to_connections(rcvr_err);
ret = -1;
}
free(status);
return ret;
}
/* vim: set ts=4 sw=4 noet: */