summaryrefslogtreecommitdiffstats
path: root/csv.c
blob: bf8e80070638e42e19ba67c2bb8a7184d4153e7f (plain)
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
/* Asterisk Manager Proxy
   Copyright (c) 2005 David C. Troy <dave@popvox.com>

   This program is free software, distributed under the terms of
   the GNU General Public License.

   CSV I/O Handler
*/

#include "astmanproxy.h"

/* TODO: catch and expand/handle commas in output */

int _write(struct mansession *s, struct message *m) {
    int i;
    char outstring[MAX_LEN];

    pthread_mutex_lock(&s->lock);
    for (i=0; i<m->hdrcount; i++) {
        sprintf(outstring, "\"%s\"", m->headers[i]);
        if (i<m->hdrcount-1)
            strcat(outstring, ", ");
        write(s->fd, outstring, strlen(outstring));
    }
    write(s->fd, "\r\n\r\n", 4);
    pthread_mutex_unlock(&s->lock);

    return 0;
}

int _autodisconnect() {
    return 0;
}