Project

General

Profile

Revision 15928a3d

ID15928a3da0f711d39edf122bcf596e81402a76f6
Parent 880dc54f
Child 38df0012

Added by Thomas Mullins about 11 years ago

Added username/password to add_event query

View differences:

mainbox/query.c
1 1
#include "query.h"
2 2
#include "event.h"
3
#include "util.h"
4
#include <stdlib.h>
3 5
#include <stdio.h>
6
#include <string.h>
4 7
#include <curl/curl.h>
5 8

  
6 9
const char *server;
10
char *tooltron_password;
7 11

  
8 12
int query_init(const char *server_name) {
9 13
  CURLcode error_code;
14
  int len;
10 15

  
11 16
  server = server_name;
12 17

  
13 18
  error_code = curl_global_init(CURL_GLOBAL_SSL);
14
  if (error_code)
19
  if (error_code) {
15 20
    fprintf(stderr, "curl_global_init: %s\n", curl_easy_strerror(error_code));
21
    return error_code;
22
  }
16 23

  
17
  return error_code;
24
  tooltron_password = read_file("tooltron_password");
25
  if (!tooltron_password)
26
    return 1;
27
  len = strlen(tooltron_password);
28
  while (len > 0 && tooltron_password[len-1] == '\n')
29
    tooltron_password[--len] = '\0';
30

  
31
  return 0;
18 32
}
19 33

  
20 34
void query_cleanup() {
21 35
  curl_global_cleanup();
36
  if (tooltron_password)
37
    free(tooltron_password);
22 38
}
23 39

  
24 40
static size_t write_bool(void *buffer, size_t size, size_t nmemb, void *userp) {
......
110 126
    return 1;
111 127

  
112 128
  curl_formadd(&formpost, &lastptr,
129
      CURLFORM_COPYNAME, "username",
130
      CURLFORM_COPYCONTENTS, "tooltron",
131
      CURLFORM_END);
132

  
133
  curl_formadd(&formpost, &lastptr,
134
      CURLFORM_COPYNAME, "password",
135
      CURLFORM_COPYCONTENTS, tooltron_password,
136
      CURLFORM_END);
137

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

Also available in: Unified diff