Revision 38df0012

View differences:

mainbox/event.h
6 6
struct event_t {
7 7
  unsigned int user;
8 8
  int tool_id;
9
  int succ;
9 10
  time_t tstart;
10 11
  time_t tend;
11 12
  struct event_t *next;
mainbox/query.c
135 135
      CURLFORM_COPYCONTENTS, tooltron_password,
136 136
      CURLFORM_END);
137 137

  
138
  curl_formadd(&formpost, &lastptr,
139
      CURLFORM_COPYNAME, "type",
140
      CURLFORM_COPYCONTENTS, "usage",
141
      CURLFORM_END);
142

  
143 138
  timeinfo = localtime(&event->tstart);
144 139
  strftime(buf, sizeof(buf), "%F %T", timeinfo);
145 140
  curl_formadd(&formpost, &lastptr,
......
156 151

  
157 152
  sprintf(buf, "%08x", event->user);
158 153
  curl_formadd(&formpost, &lastptr,
159
      CURLFORM_COPYNAME, "user",
154
      CURLFORM_COPYNAME, "user_id",
160 155
      CURLFORM_COPYCONTENTS, buf,
161 156
      CURLFORM_END);
162 157

  
163 158
  sprintf(buf, "%d", event->tool_id);
164 159
  curl_formadd(&formpost, &lastptr,
165
      CURLFORM_COPYNAME, "machine",
160
      CURLFORM_COPYNAME, "machine_id",
166 161
      CURLFORM_COPYCONTENTS, buf,
167 162
      CURLFORM_END);
168 163

  
169
  sprintf(buf, "https://%s/add_event/", server);
164
  curl_formadd(&formpost, &lastptr,
165
      CURLFORM_COPYNAME, "succ",
166
      CURLFORM_COPYCONTENTS, event->succ? "1" : "0",
167
      CURLFORM_END);
168

  
169
  sprintf(buf, "https://%s/add_card_event/", server);
170
  //sprintf(buf, "http://%s/add_card_event/", server);
170 171
  error_code = curl_easy_setopt(handle, CURLOPT_URL, buf);
171 172
  if (error_code) goto error;
172 173

  
173 174
  error_code = curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0L);
174 175
  if (error_code) goto error;
175 176

  
177
  /* TODO TEMPORARY */
178
  FILE *tmp = fopen("temp.html", "w");
179
  error_code = curl_easy_setopt(handle, CURLOPT_WRITEDATA, tmp);
180
  if (error_code) goto error;
181

  
182
  /*
176 183
  error_code = curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_ignore);
177 184
  if (error_code) goto error;
185
  */
178 186

  
179 187
  error_code = curl_easy_setopt(handle, CURLOPT_HTTPPOST, formpost);
180 188
  if (error_code) goto error;
......
191 199

  
192 200
  curl_easy_cleanup(handle);
193 201
  curl_formfree(formpost);
202
  fclose(tmp);
194 203
  return response >= 300;
195 204

  
196 205
error:
mainbox/tool.c
57 57
}
58 58

  
59 59
static void tool_grant_access(struct tool_t *tool) {
60

  
60 61
  printf("Granting access to %08x on %s (%d)\n", tool->user, tool->name,
61 62
      tool->address);
63

  
62 64
  tool_write_coil(MB_COIL_EN, 1);
63 65
  tool->state = TS_ON;
66

  
64 67
  tool->event = event_alloc();
65 68
  tool->event->user = tool->user;
66 69
  tool->event->tool_id = tool->address;
67 70
  tool->event->tstart = time(NULL);
71
  tool->event->succ = 1;
68 72
}
69 73

  
70 74
static void tool_deny_access(struct tool_t *tool) {
75
  struct event_t *event;
76

  
71 77
  printf("Denying access to %08x on %s (%d)\n", tool->user, tool->name,
72 78
      tool->address);
79

  
73 80
  tool_write_coil(MB_COIL_EN, 0);
74 81
  tool->state = TS_OFF;
82

  
83
  event = event_alloc();
84
  event->user = tool->user;
85
  event->tool_id = tool->address;
86
  event->tstart = time(NULL);
87
  event->tend = event->tstart;
88
  event->succ = 0;
89
  event_q_push(event);
75 90
}
76 91

  
77 92
static void tool_off(struct tool_t *tool) {

Also available in: Unified diff