Page Menu
Home
ClusterLabs Projects
Search
Configure Global Search
Log In
Files
F3153159
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/conf.c b/conf.c
index 9618090d..419a78e6 100644
--- a/conf.c
+++ b/conf.c
@@ -1,45 +1,89 @@
-#include "conf.h"
-
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
+#include <limits.h>
+
+#include "conf.h"
static int parse_config(FILE *fp, struct peer **head)
{
-
+ char *line = NULL;
+ size_t len = 0;
+ ssize_t read;
+ struct peer *new = NULL;
+ struct peer *tmp = NULL;
+
+ while ((read = getline(&line, &len, fp)) != -1) {
+ /* clear newline */
+ if ((read) && (line[read - 1] == '\n')) {
+ line[read - 1] = '\0';
+ read--;
+ }
+ if ((read) && (line[read - 1] == '\r')) {
+ line[read - 1] = '\0';
+ read--;
+ }
+
+ if ((!read) || ((read) && (line[0] == '#')))
+ continue;
+
+ new = malloc(sizeof(struct peer));
+ if (!new) {
+ fprintf(stderr, "Unable to allocate memory for peer list!!\n");
+ return -1;
+ }
+
+ new->line=strdup(line);
+ if(new->line == NULL) {
+ fprintf(stderr, "Unable to allocate memory for peer line entry\n");
+ return -1;
+ }
+
+ if (tmp == NULL)
+ tmp = new;
+ else
+ tmp->tail->next = new;
+
+ tmp->tail = new;
+ }
+
+ if (line)
+ free(line);
+
+ *head = tmp;
return 0;
}
int readconf(const char *conffile, struct peer **head)
{
FILE *fp;
int res = 0;
fp = fopen (conffile, "r");
if (fp == NULL) {
fprintf(stderr, "Unable to open config file [%s] reason [%s]\n",
conffile, strerror(errno));
return -1;
}
res = parse_config(fp, head);
fclose(fp);
return res;
}
void freeconf(struct peer *head)
{
struct peer *next;
while(head) {
next = head->next;
free(head);
head = next;
}
return;
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Feb 25, 11:59 AM (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1464816
Default Alt Text
(1 KB)
Attached To
Mode
rK kronosnet
Attached
Detach File
Event Timeline
Log In to Comment