1 /* Copyright (C) 2018 Thomas Balzer */
3 /* This file is part of tomd. */
5 /* tomd is free software: you can redistribute it and/or modify */
6 /* it under the terms of the GNU General Public License as published by */
7 /* the Free Software Foundation, either version 3 of the License, or */
8 /* (at your option) any later version. */
10 /* tomd is distributed in the hope that it will be useful, */
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
13 /* GNU General Public License for more details. */
15 /* You should have received a copy of the GNU General Public License */
16 /* along with tomd. If not, see <http://www.gnu.org/licenses/>. */
23 #include <sys/socket.h>
38 void setup_socket(int sfd
)
41 options
.buf
= malloc(sizeof(char) * MAX_LEN
);
44 static struct line
*find_lines(void)
46 /* printf("entering find_lines\n"); */
47 struct line
*lines
= malloc(sizeof(struct line
));
48 struct line
*cur_line
= lines
;
49 struct line
*old_line
= lines
;
50 char *ptr
= options
.buf
;
51 lines
->buf
= options
.buf
;
54 /* printf("starting loop.\n"); */
56 if(*ptr
== '\n' || *ptr
== '\0'){
57 /* printf("----\n"); */
58 /* printf("found a new line.\n"); */
59 /* printf("'%c' -> \\0\n", *ptr); */
60 /* printf("'next \%c': %c\n", *(ptr+1)); */
63 /* printf("found the end. (1)\n"); */
72 /* printf("empty\n"); */
79 /* printf("found the end. (2)\n"); */
83 /* printf("hallo there.\n"); */
84 cur_line
= malloc(sizeof(struct line
));
85 old_line
->next
= cur_line
;
89 printf("________|%c|\n", *ptr
);
94 void socket_read(void (*func
)(char *line
))
96 if(options
.lines
!= NULL
){
97 printf("|||| already got some input. |||\n");
103 printf("||||| doing read. ||||\n");
104 size
= read(options
.sfd
, options
.buf
, MAX_LEN
);
105 printf("||||| got read. ||||\n");
107 printf("||||| reading again. ||||\n");
110 printf("||||| done read. ||||\n");
111 options
.lines
= find_lines();
113 struct line
*cur_line
= options
.lines
;
117 printf("[%d] '%s'\n", count
++, cur_line
->buf
);
118 if(cur_line
->next
== NULL
){
119 printf("found the end.\n");
122 cur_line
= cur_line
->next
;
127 printf("calling function with %s\n", options
.lines
->buf
);
128 func(options
.lines
->buf
);
129 options
.lines
= options
.lines
->next
;