Project

General

Profile

Revision 8f961e44

ID8f961e44de90cc19ffc4374e0ca52626a9672185
Parent 9e764ac9
Child 828c5d29

Added by Thomas Mullins over 11 years ago

Added getopt for inputting serial device and CRM server

View differences:

mainbox/query.c
2 2
#include <stdio.h>
3 3
#include <curl/curl.h>
4 4

  
5
int query_init() {
5
const char *server;
6

  
7
int query_init(const char *server_name) {
6 8
  CURLcode error_code;
7 9

  
10
  server = server_name;
11

  
8 12
  error_code = curl_global_init(CURL_GLOBAL_NOTHING);
9 13
  if (error_code)
10 14
    fprintf(stderr, "curl_global_init: %s\n", curl_easy_strerror(error_code));
......
18 22

  
19 23
static size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp) {
20 24
  int *resultp = userp;
25
  char *str = buffer;
26

  
27
  if (size*nmemb > 0 && str[0] == '1')
28
    *resultp = 1;
29
  else
30
    *resultp = 0;
21 31

  
22
  return fwrite(buffer, size, nmemb, stdout);
32
  return nmemb;
23 33
}
24 34

  
25 35
int query_user_permission(int tool_id, int user_id) {
......
32 42
  if (handle == NULL)
33 43
    return 0;
34 44

  
35
  sprintf(url, "http://roboclub.org/tooltron/%08x/%d/", user_id, tool_id);
36
  /* TODO temporary */ sprintf(url, "http://www.google.com");
45
  sprintf(url, "http://%s/roboauth/%08x/%d/", server, user_id, tool_id);
37 46
  error_code = curl_easy_setopt(handle, CURLOPT_URL, url);
38 47
  if (error_code) goto error;
39 48

  
......
51 60

  
52 61
error:
53 62
  fprintf(stderr, "curl: %s\n", curl_easy_strerror(error_code));
54
  fprintf(stderr, "     when authenticating user %08x on tool %d\n",
63
  fprintf(stderr, "      when authenticating user %08x on tool %d\n",
55 64
      user_id, tool_id);
56 65
  curl_easy_cleanup(handle);
57 66
  return 0;

Also available in: Unified diff