gwenhywfar 5.14.1
rfi.c
Go to the documentation of this file.
1/***************************************************************************
2 begin : Mon Jun 27 2011
3 copyright : (C) 2011 by Martin Preuss
4 email : martin@libchipcard.de
5
6 ***************************************************************************
7 * Please see toplevel file COPYING for license details *
8 ***************************************************************************/
9
10#ifdef HAVE_CONFIG_H
11# include <config.h>
12#endif
13
14#include "globals.h"
15
16#include <gwenhywfar/debug.h>
17#include <gwenhywfar/db.h>
18
19
20
21
22int releaseFillIn(GWEN_DB_NODE *dbArgs, int argc, char **argv)
23{
24 GWEN_DB_NODE *db;
25 const char *name;
26 const char *arch;
27 const char *sys;
28 const char *inFile;
29 const char *clFile;
30 const char *outFile;
31 const char *url;
32 int vMajor;
33 int vMinor;
34 int vPatchLevel;
35 int vBuild;
36 int maturityLevel;
37 GWEN_DB_NODE *dbVersion;
38 int rv;
39 GWEN_BUFFER *cbuf;
40 char ubuf[512];
41 const GWEN_ARGS args[]= {
42 {
44 GWEN_ArgsType_Char, /* type */
45 "infile", /* name */
46 1, /* minnum */
47 1, /* maxnum */
48 "i", /* short option */
49 "infile", /* long option */
50 "Specify the input version file", /* short description */
51 "Specify the input version file" /* long description */
52 },
53 {
55 GWEN_ArgsType_Char, /* type */
56 "changeLogFile", /* name */
57 1, /* minnum */
58 1, /* maxnum */
59 "c", /* short option */
60 "changelog", /* long option */
61 "Specify the changelog file", /* short description */
62 "Specify the changelog file" /* long description */
63 },
64 {
66 GWEN_ArgsType_Char, /* type */
67 "url", /* name */
68 1, /* minnum */
69 1, /* maxnum */
70 "u", /* short option */
71 "url", /* long option */
72 "Specify the URL of the update server", /* short description */
73 "Specify the URL of the update server" /* long description */
74 },
75 {
77 GWEN_ArgsType_Char, /* type */
78 "outfile", /* name */
79 1, /* minnum */
80 1, /* maxnum */
81 "o", /* short option */
82 "outfile", /* long option */
83 "Specify the output version file", /* short description */
84 "Specify the output version file" /* long description */
85 },
86 {
88 GWEN_ArgsType_Int, /* type */
89 "help", /* name */
90 0, /* minnum */
91 0, /* maxnum */
92 "h", /* short option */
93 "help", /* long option */
94 "Show this help screen", /* short description */
95 "Show this help screen" /* long description */
96 }
97 };
98
99 db=GWEN_DB_GetGroup(dbArgs, GWEN_DB_FLAGS_DEFAULT, "local");
100 rv=GWEN_Args_Check(argc, argv, 1,
102 args,
103 db);
104 if (rv==GWEN_ARGS_RESULT_ERROR) {
105 fprintf(stderr, "ERROR: Could not parse arguments\n");
106 return 1;
107 }
108 else if (rv==GWEN_ARGS_RESULT_HELP) {
109 GWEN_BUFFER *ubuf;
110
111 ubuf=GWEN_Buffer_new(0, 1024, 0, 1);
112 if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) {
113 fprintf(stderr, "ERROR: Could not create help string\n");
114 return 1;
115 }
116 fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf));
117 GWEN_Buffer_free(ubuf);
118 return 0;
119 }
120
121 inFile=GWEN_DB_GetCharValue(db, "infile", 0, NULL);
122 assert(inFile);
123
124 clFile=GWEN_DB_GetCharValue(db, "changeLogFile", 0, NULL);
125 assert(clFile);
126
127 outFile=GWEN_DB_GetCharValue(db, "outfile", 0, NULL);
128 assert(outFile);
129
130 url=GWEN_DB_GetCharValue(db, "url", 0, NULL);
131 assert(url);
132
133 /* read changelog file */
134 cbuf=GWEN_Buffer_new(0, 256, 0, 1);
135 rv=readFile(clFile, cbuf);
136 if (rv<0) {
137 fprintf(stderr, "ERROR: Could not read changelog file [%s] (%d)\n", clFile, rv);
138 return 2;
139 }
140
141 /* read version file */
142 dbVersion=GWEN_DB_Group_new("version");
143 rv=GWEN_DB_ReadFile(dbVersion, inFile, GWEN_DB_FLAGS_DEFAULT);
144 if (rv<0) {
145 fprintf(stderr, "ERROR: Could not read file [%s] (%d)\n", inFile, rv);
146 return 2;
147 }
148
149 name=GWEN_DB_GetCharValue(dbVersion, "name", 0, NULL);
150 if (!(name && *name)) {
151 fprintf(stderr, "Missing name in version file.\n");
152 return 2;
153 }
154 arch=GWEN_DB_GetCharValue(dbVersion, "architecture", 0, NULL);
155 if (!(arch && *arch)) {
156 fprintf(stderr, "Missing architecture in version file.\n");
157 return 2;
158 }
159 sys=GWEN_DB_GetCharValue(dbVersion, "system", 0, NULL);
160 if (!(sys && *sys)) {
161 fprintf(stderr, "Missing system in version file.\n");
162 return 2;
163 }
164 vMajor=GWEN_DB_GetIntValue(dbVersion, "versionMajor", 0, 0);
165 vMinor=GWEN_DB_GetIntValue(dbVersion, "versionMinor", 0, 0);
166 vPatchLevel=GWEN_DB_GetIntValue(dbVersion, "versionPatchLevel", 0, 0);
167 vBuild=GWEN_DB_GetIntValue(dbVersion, "versionBuild", 0, 0);
168 maturityLevel=GWEN_DB_GetIntValue(dbVersion, "maturityLevel", 0, 0);
169
170 /* create URL entry */
171 snprintf(ubuf, sizeof(ubuf)-1, "%s/%s-%s-%s-%d.%d.%d.%d-%d.sar.gz",
172 url,
173 name, sys, arch,
174 vMajor, vMinor, vPatchLevel, vBuild,
175 maturityLevel);
176 ubuf[sizeof(ubuf)-1]=0;
177 GWEN_DB_SetCharValue(dbVersion, GWEN_DB_FLAGS_OVERWRITE_VARS, "url", ubuf);
178
179 /* create changelog entry */
181 GWEN_Buffer_free(cbuf);
182
183 /* write version file back */
184 rv=GWEN_DB_WriteFile(dbVersion, outFile, GWEN_DB_FLAGS_DEFAULT);
185 if (rv<0) {
186 fprintf(stderr, "ERROR: Could not write file [%s] (%d)\n", outFile, rv);
187 return 2;
188 }
189
190 return 0;
191}
192
193
194
#define NULL
Definition binreloc.c:300
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
Definition buffer.c:42
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition buffer.c:89
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition buffer.c:235
const char * GWEN_DB_GetCharValue(GWEN_DB_NODE *n, const char *path, int idx, const char *defVal)
Definition db.c:971
GWEN_DB_NODE * GWEN_DB_Group_new(const char *name)
Definition db.c:173
GWEN_DB_NODE * GWEN_DB_GetGroup(GWEN_DB_NODE *n, uint32_t flags, const char *path)
Definition db.c:1381
int GWEN_DB_SetCharValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, const char *val)
Definition db.c:997
int GWEN_DB_GetIntValue(GWEN_DB_NODE *n, const char *path, int idx, int defVal)
Definition db.c:1163
GWENHYWFAR_API int GWEN_DB_ReadFile(GWEN_DB_NODE *n, const char *fname, uint32_t dbflags)
Definition dbrw.c:1003
GWENHYWFAR_API int GWEN_DB_WriteFile(GWEN_DB_NODE *n, const char *fname, uint32_t dbflags)
Definition dbrw.c:535
#define GWEN_DB_FLAGS_DEFAULT
Definition db.h:168
#define GWEN_DB_FLAGS_OVERWRITE_VARS
Definition db.h:121
struct GWEN_DB_NODE GWEN_DB_NODE
Definition db.h:228
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition buffer.h:38
static int readFile(const char *fname, GWEN_BUFFER *dbuf)
Definition passwdstore.c:90
int releaseFillIn(GWEN_DB_NODE *dbArgs, int argc, char **argv)
Definition rfi.c:22
int GWEN_Args_Check(int argc, char **argv, int startAt, uint32_t mode, const GWEN_ARGS *args, GWEN_DB_NODE *db)
int GWEN_Args_Usage(const GWEN_ARGS *args, GWEN_BUFFER *ubuf, GWEN_ARGS_OUTTYPE ot)
#define GWEN_ARGS_FLAGS_HAS_ARGUMENT
#define GWEN_ARGS_RESULT_ERROR
#define GWEN_ARGS_MODE_ALLOW_FREEPARAM
#define GWEN_ARGS_FLAGS_HELP
#define GWEN_ARGS_FLAGS_LAST
@ GWEN_ArgsOutType_Txt
@ GWEN_ArgsType_Int
@ GWEN_ArgsType_Char
#define GWEN_ARGS_RESULT_HELP