glitch in the license text detected by hyazinthe, thank you!
[oweals/gnunet.git] / src / auction / gnunet-service-auction.c
1 /*
2    This file is part of GNUnet.
3    Copyright (C) 2009 GNUnet e.V.
4
5    GNUnet is free software: you can redistribute it and/or modify it
6    under the terms of the GNU Affero General Public License as published
7    by the Free Software Foundation, either version 3 of the License,
8    or (at your 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    Affero General Public License for more details.
14    */
15
16 /**
17  * @file auction/gnunet-service-auction.c
18  * @brief service for executing auctions
19  * @author Markus Teich
20  */
21 #include "platform.h"
22 #include "gnunet_util_lib.h"
23
24 #include "auction.h"
25
26 /**
27  * Check AUCTION CREATE messages from the client.
28  *
29  * @param cls the client we received this message from
30  * @param msg the actual message received
31  * @return #GNUNET_OK (always)
32  */
33 static int
34 check_create (void *cls, const struct GNUNET_AUCTION_ClientCreateMessage *msg)
35 {
36         /* always well-formed due to arbitrary length description */
37         return GNUNET_OK;
38 }
39
40
41 /**
42  * Handler for CREATE messages.
43  *
44  * @param cls the client we received this message from
45  * @param msg the actual message received
46  */
47 static void
48 handle_create (void *cls, const struct GNUNET_AUCTION_ClientCreateMessage *msg)
49 {
50         struct GNUNET_SERVICE_Client *client = cls;
51 //      struct GNUNET_MQ_Handle *mq;
52 //      struct GNUNET_MQ_Envelope *env;
53 //      struct GNUNET_AUCTION_blabla em;
54         uint16_t size;
55
56         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
57                     "Received CREATE message from client\n");
58
59         size = ntohs (msg->header.size);
60
61         /**TODO: create auction and return auction object */
62 //      mq = GNUNET_SERVICE_client_get_mq (client);
63 //      setup_info_message (&em);
64 //      env = GNUNET_MQ_msg_copy (&em.header);
65 //      GNUNET_MQ_send (mq, env);
66
67         GNUNET_SERVICE_client_continue (client);
68 }
69
70
71 /**
72  * Task run during shutdown.
73  *
74  * @param cls unused
75  */
76 static void
77 cleanup_task (void *cls)
78 {
79         /* FIXME: do clean up here */
80 }
81
82
83 /**
84  * Callback called when a client connects to the service.
85  *
86  * @param cls closure for the service
87  * @param c the new client that connected to the service
88  * @param mq the message queue used to send messages to the client
89  * @return @a c
90  */
91 static void *
92 client_connect_cb (void *cls,
93                    struct GNUNET_SERVICE_Client *c,
94                    struct GNUNET_MQ_Handle *mq)
95 {
96         return c;
97 }
98
99
100 /**
101  * Callback called when a client disconnected from the service
102  *
103  * @param cls closure for the service
104  * @param c the client that disconnected
105  * @param internal_cls should be equal to @a c
106  */
107 static void
108 client_disconnect_cb (void *cls,
109                       struct GNUNET_SERVICE_Client *c,
110                       void *internal_cls)
111 {
112         GNUNET_assert (c == internal_cls);
113 }
114
115
116 /**
117  * Process auction requests.
118  *
119  * @param cls closure
120  * @param cfg configuration to use
121  * @param service the initialized service
122  */
123 static void
124 run (void *cls,
125      const struct GNUNET_CONFIGURATION_Handle *cfg,
126      struct GNUNET_SERVICE_Handle *service)
127 {
128         /* FIXME: do setup here */
129         GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL);
130 }
131
132
133 /**
134  * Define "main" method using service macro.
135  */
136 GNUNET_SERVICE_MAIN
137 ("auction",
138  GNUNET_SERVICE_OPTION_NONE,
139  &run,
140  &client_connect_cb,
141  &client_disconnect_cb,
142  NULL,
143  GNUNET_MQ_hd_var_size (create,
144                         GNUNET_MESSAGE_TYPE_AUCTION_CLIENT_CREATE,
145                         struct GNUNET_AUCTION_ClientCreateMessage,
146                         NULL),
147  GNUNET_MQ_handler_end ())
148
149
150 /* end of gnunet-service-auction.c */