fae9c13aef5a35949602c057c55f024ea35c85d7
[oweals/gnunet.git] / src / auction / gnunet-auction-create.c
1 /*
2    This file is part of GNUnet.
3    Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 GNUnet e.V.
4
5    GNUnet is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published
7    by the Free Software Foundation; either version 3, or (at your
8    option) any later version.
9
10    GNUnet is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with GNUnet; see the file COPYING.  If not, write to the
17    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18    Boston, MA 02110-1301, USA.
19    */
20
21 /**
22  * @file auction/gnunet-auction-create.c
23  * @brief tool to create a new auction
24  * @author Markus Teich
25  */
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 /* #include "gnunet_auction_service.h" */
29
30 #define FIRST_PRICE 0
31 #define OUTCOME_PRIVATE 0
32 #define OUTCOME_PUBLIC 1
33
34 static int ret; /** Final status code. */
35 static char *fndesc; /** filename of the item description */
36 static char *fnprices; /** filename of the price map */
37 static struct GNUNET_TIME_Relative dround; /** max round duration */
38 static struct GNUNET_TIME_Relative dstart; /** time until auction starts */
39 static unsigned int m = FIRST_PRICE; /** auction parameter m */
40 static int outcome = OUTCOME_PRIVATE; /** outcome */
41 static int interactive; /** keep running in foreground */
42
43
44 /**
45  * Main function that will be run by the scheduler.
46  *
47  * @param cls closure
48  * @param args remaining command-line arguments
49  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
50  * @param cfg configuration
51  */
52 static void
53 run (void *cls,
54          char *const *args,
55          const char *cfgfile,
56          const struct GNUNET_CONFIGURATION_Handle *cfg)
57 {
58         /* cmdline parsing */
59         if (GNUNET_TIME_UNIT_ZERO.rel_value_us == dstart.rel_value_us)
60         {
61                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
62                             "required argument --regtime missing or invalid (zero)\n");
63                 goto fail;
64         }
65         if (GNUNET_TIME_UNIT_ZERO.rel_value_us == dround.rel_value_us)
66         {
67                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
68                             "required argument --roundtime missing or invalid (zero)\n");
69                 goto fail;
70         }
71         if (!fndesc)
72         {
73                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
74                             "required argument --description missing\n");
75                 goto fail;
76         }
77         if (!fnprices)
78         {
79                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
80                             "required argument --pricemap missing\n");
81                 goto fail;
82         }
83
84 fail:
85         ret = 1;
86         return;
87 }
88
89
90 /**
91  * The main function.
92  *
93  * @param argc number of arguments from the command line
94  * @param argv command line arguments
95  * @return 0 ok, 1 on error
96  */
97 int
98 main (int argc, char *const *argv)
99 {
100         static const struct GNUNET_GETOPT_CommandLineOption options[] = {
101                 {'d', "description", "FILE",
102                         gettext_noop ("description of the item to be sold"),
103                         1, &GNUNET_GETOPT_set_filename, &fndesc},
104                 {'p', "pricemap", "FILE",
105                         gettext_noop ("mapping of possible prices"),
106                         1, &GNUNET_GETOPT_set_filename, &fnprices},
107                 {'r', "roundtime", "DURATION",
108                         gettext_noop ("max duration per round"),
109                         1, &GNUNET_GETOPT_set_relative_time, &dround},
110                 {'s', "regtime", "DURATION",
111                         gettext_noop ("duration until auction starts"),
112                         1, &GNUNET_GETOPT_set_relative_time, &dstart},
113                 {'m', "m", "NUMBER",
114                         gettext_noop ("number of items to sell\n"
115                                       "0 for first price auction\n"
116                                       ">0 for vickrey/M+1st price auction"),
117                         1, &GNUNET_GETOPT_set_uint, &m},
118                 {'u', "public", NULL,
119                         gettext_noop ("public auction outcome"),
120                         0, &GNUNET_GETOPT_set_one, &outcome},
121                 {'i', "interactive", NULL,
122                         gettext_noop ("keep running in foreground until auction completes"),
123                         0, &GNUNET_GETOPT_set_one, &interactive},
124                 GNUNET_GETOPT_OPTION_END
125         };
126         if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
127                 return 2;
128
129         ret = (GNUNET_OK ==
130                    GNUNET_PROGRAM_run (argc, argv,
131                                                            "gnunet-auction-create",
132                                                            gettext_noop ("create a new auction and "
133                                                                          "start listening for bidders"),
134                                                            options,
135                                                            &run,
136                                                            NULL)) ? ret : 1;
137         GNUNET_free ((void*) argv);
138         return ret;
139 }