eve: convert to generic object payload
authorPhil Sutter <phil@nwl.cc>
Sun, 4 Oct 2009 16:53:17 +0000 (18:53 +0200)
committerPhil Sutter <phil@nwl.cc>
Tue, 3 Nov 2009 22:23:22 +0000 (23:23 +0100)
src/core.c
src/eve.c
src/eve.h
src/text_object.h

index 495cfb5..2177355 100644 (file)
@@ -1544,6 +1544,7 @@ void free_text_objects(struct text_object *root, int internal)
 #endif
 #ifdef EVE
                        case OBJ_eve:
+                               free_eve(obj);
                                break;
 #endif
 #ifdef HAVE_CURL
index 16446bf..2c81a2a 100644 (file)
--- a/src/eve.c
+++ b/src/eve.c
@@ -22,7 +22,6 @@
  *
  */
 
-#include "eve.h"
 #include "config.h"
 #include "text_object.h"
 #include <stdio.h>
@@ -66,6 +65,12 @@ struct xmlData {
        size_t size;
 };
 
+struct eve_data {
+       char apikey[64];
+       char charid[20];
+       char userid[20];
+};
+
 int num_chars = 0;
 Character eveCharacters[MAXCHARS];
 
@@ -406,21 +411,31 @@ static char *eve(char *userid, char *apikey, char *charid)
 void scan_eve(struct text_object *obj, const char *arg)
 {
        int argc;
-       char *userid = (char *) malloc(20 * sizeof(char));
-       char *apikey = (char *) malloc(64 * sizeof(char));
-       char *charid = (char *) malloc(20 * sizeof(char));
+       struct eve_data *ed;
+
+       ed = malloc(sizeof(struct eve_data));
+       memset(ed, 0, sizeof(struct eve_data));
 
-       argc = sscanf(arg, "%20s %64s %20s", userid, apikey, charid);
-       obj->data.eve.charid = charid;
-       obj->data.eve.userid = userid;
-       obj->data.eve.apikey = apikey;
+       argc = sscanf(arg, "%20s %64s %20s", ed->userid, ed->apikey, ed->charid);
 
        init_eve();
+       obj->data.opaque = ed;
 }
 
 void print_eve(struct text_object *obj, char *p, int p_max_size)
 {
-       snprintf(p, p_max_size, "%s",
-                       eve(obj->data.eve.userid,
-                               obj->data.eve.apikey, obj->data.eve.charid));
+       struct eve_data *ed = obj->data.opaque;
+
+       if (!ed)
+               return;
+
+       snprintf(p, p_max_size, "%s", eve(ed->userid, ed->apikey, ed->charid));
+}
+
+void free_eve(struct text_object *obj)
+{
+       if (obj->data.opaque) {
+               free(obj->data.opaque);
+               obj->data.opaque = NULL;
+       }
 }
index 1c5bbd2..9382117 100644 (file)
--- a/src/eve.h
+++ b/src/eve.h
@@ -26,5 +26,6 @@
 
 void scan_eve(struct text_object *, const char *);
 void print_eve(struct text_object *, char *, int);
+void free_eve(struct text_object *);
 
 #endif /* _EVE_H */
index a97b355..4ba6278 100644 (file)
@@ -487,13 +487,6 @@ struct text_object {
                struct {
                        int a, b;
                } pair;                 /* 2 */
-#ifdef EVE
-               struct {
-                       char *apikey;
-                       char *charid;
-                       char *userid;
-               } eve;
-#endif
 #ifdef HAVE_CURL
                struct {
                        char *uri;