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