]> git.zerfleddert.de Git - record-dvb/blame - common.c
record a stream (for example from getstream)
[record-dvb] / common.c
CommitLineData
5c2e3e44 1#include <strings.h>
2#include <string.h>
3#include <stdio.h>
4#include <stdlib.h>
5
6#include "common.h"
7
8struct dvb_host *parse(char *urlpart, char *defport)
9{
10 struct dvb_host *dvbhost;
11 char *pos;
12
13 if (!(dvbhost = malloc(sizeof(struct dvb_host)))) {
14 perror("malloc");
15 exit(EXIT_FAILURE);
16 }
17
18 bzero(dvbhost, sizeof(struct dvb_host));
19
20 if (!(dvbhost->hostname = strdup(urlpart))) {
21 perror("strdup");
22 exit(EXIT_FAILURE);
23 }
24
25 /* Unneded, but better readablity: */
26 dvbhost->location = NULL;
27 dvbhost->port = NULL;
28
29 pos = dvbhost->hostname;
30
31 while(*pos != '\0' && *pos != ':' && *pos != '/')
32 pos++;
33
34 if (*pos == '/')
35 dvbhost->location = pos + 1;
36
37 if (*pos == ':')
38 dvbhost->port = pos + 1;
39
40 *pos = 0;
41
42 if (dvbhost->port) {
43 pos++;
44
45 while(*pos != '\0' && *pos != '/')
46 pos ++;
47
48 if(*pos == '/')
49 dvbhost->location = pos + 1;
50
51 *pos = 0;
52 }
53
54 if (!dvbhost->port)
55 dvbhost->port = strdup(defport);
56
57 if (!dvbhost->location)
58 if(!(dvbhost->location = strdup(""))) {
59 perror("strdup");
60 exit(EXIT_FAILURE);
61 }
62
63 return dvbhost;
64}
Impressum, Datenschutz