summaryrefslogtreecommitdiff
path: root/src/libwebvi/link.c
blob: 501e70abe464acaa0b6a20db0e3b8891a7227172 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <stdlib.h>
#include <glib.h>
#include "link.h"

struct Link {
  gchar *href;
  gchar *title;
  LinkActionType type;
};

struct LinkAction {
  LinkActionType type;
  gchar *command;
};

struct Link *link_create(const char *href, const char *title, LinkActionType type) {
  struct Link *self = malloc(sizeof(struct Link));
  self->href = g_strdup(href ? href : "");
  self->title = g_strdup(title ? title : "");
  self->type = type;
  return self;
}

const char *link_get_href(const struct Link *self) {
  return self->href;
}

const char *link_get_title(const struct Link *self) {
  return self->title;
}

LinkActionType link_get_type(const struct Link *self) {
  return self->type;
}

void link_delete(struct Link *self) {
  g_free(self->href);
  g_free(self->title);
  free(self);
}

void g_free_link(gpointer data) {
  link_delete((struct Link *)data);
}

struct LinkAction *link_action_create(LinkActionType type, const char *command) {
  struct LinkAction *self = malloc(sizeof(struct LinkAction));
  self->type = type;
  self->command = g_strdup(command ? command : "");
  return self;
}

LinkActionType link_action_get_type(const struct LinkAction *self) {
  return self->type;
}

const char *link_action_get_command(const struct LinkAction *self) {
  return self->command;
}

void link_action_delete(struct LinkAction *self) {
  if (self) {
    g_free(self->command);
    free(self);
  }
}

struct ActionTypeMessage {
  LinkActionType type;
  const char *message;
};

const char *link_action_type_to_string(LinkActionType atype) {
  static struct ActionTypeMessage messages[] = 
    {{LINK_ACTION_PARSE, "regular link"},
     {LINK_ACTION_STREAM_LIBQUVI, "stream"},
     {LINK_ACTION_EXTERNAL_COMMAND, "external command"}};

  for (int i=0;  i<(sizeof(messages)/sizeof(messages[0])); i++) {
    if (atype == messages[i].type) {
      return messages[i].message;
    }
  }

  return "???";
}