* Add proxy username/password support
[oweals/opkg-lede.git] / conffile.c
1 /* conffile.c - the itsy package management system
2
3    Carl D. Worth
4
5    Copyright (C) 2001 University of Southern California
6
7    This program is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License as
9    published by the Free Software Foundation; either version 2, or (at
10    your option) any later version.
11
12    This program is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16 */
17
18 #include <string.h>
19 #include <stdlib.h>
20
21 #include "opkg.h"
22 #include "opkg_message.h"
23
24 #include "conffile.h"
25 #include "file_util.h"
26 #include "sprintf_alloc.h"
27
28 int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum)
29 {
30     return nv_pair_init(conffile, file_name, md5sum);
31 }
32
33 void conffile_deinit(conffile_t *conffile)
34 {
35     nv_pair_deinit(conffile);
36 }
37
38 int conffile_has_been_modified(opkg_conf_t *conf, conffile_t *conffile)
39 {
40     char *md5sum;
41     char *filename = conffile->name;
42     char *root_filename;
43     int ret;
44
45     if (conffile->value == NULL) {
46          opkg_message(conf, OPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
47          return 1;
48     }
49
50     root_filename = root_filename_alloc(conf, filename);
51
52     md5sum = file_md5sum_alloc(root_filename);
53
54     ret = strcmp(md5sum, conffile->value);
55     if (ret) {
56       opkg_message(conf, OPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
57               conffile->name, md5sum, conffile->value);
58     }
59
60     free(root_filename);
61     free(md5sum);
62
63     return ret;
64 }