File: mrss_search.c

package info (click to toggle)
feedreader 2.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,868 kB
  • sloc: ansic: 11,829; xml: 879; php: 170; sh: 32; makefile: 16; python: 14
file content (122 lines) | stat: -rw-r--r-- 2,751 bytes parent folder | download | duplicates (2)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* mRss - Copyright (C) 2005-2007 bakunin - Andrea Marchesini 
 *                                    <bakunin@autistici.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "mrss.h"
#include "mrss_internal.h"

static mrss_error_t __mrss_search_tag_real (mrss_tag_t * tag, char *name,
					    char *ns, mrss_tag_t ** ret);

mrss_error_t
mrss_search_tag (mrss_generic_t data, char *name, char *ns, mrss_tag_t ** tag)
{
  mrss_t *tmp;
  mrss_error_t err;

  if (!data || !name)
    return MRSS_ERR_DATA;


  tmp = (mrss_t *) data;
  switch (tmp->element)
    {
    case MRSS_ELEMENT_CHANNEL:
      err =
	__mrss_search_tag_real (((mrss_t *) data)->other_tags, name, ns, tag);
      break;

    case MRSS_ELEMENT_ITEM:
      err =
	__mrss_search_tag_real (((mrss_item_t *) data)->other_tags, name, ns,
				tag);
      break;

    case MRSS_ELEMENT_TAG:
      err =
	__mrss_search_tag_real (((mrss_tag_t *) data)->children, name, ns,
				tag);
      break;

    default:
      err = MRSS_ERR_DATA;
      break;
    }

  return err;
}

static mrss_error_t
__mrss_search_tag_real (mrss_tag_t * tag, char *name, char *ns,
			mrss_tag_t ** ret)
{
  int i;

  for (*ret = NULL; tag; tag = tag->next)
    {
      i = 0;
      if (tag->ns)
	i++;
      if (ns)
	i++;

      if ((!i || (i == 2 && !strcmp (tag->ns, ns)))
	  && !strcmp (name, tag->name))
	{
	  *ret = tag;
	  return MRSS_OK;
	}
    }

  return MRSS_OK;
}

mrss_error_t
mrss_search_attribute (mrss_generic_t data, char *name, char *ns,
		       mrss_attribute_t ** attribute)
{
  mrss_tag_t *tag;
  mrss_attribute_t *attr;
  int i;

  if (!data || !name)
    return MRSS_ERR_DATA;

  tag = (mrss_tag_t *) data;
  if (tag->element != MRSS_ELEMENT_TAG)
    return MRSS_ERR_DATA;

  for (*attribute = NULL, attr = tag->attributes; attr; attr = attr->next)
    {
      i = 0;
      if (attr->ns)
	i++;
      if (ns)
	i++;

      if ((!i || (i == 2 && !strcmp (attr->ns, ns)))
	  && !strcmp (name, attr->name))
	{
	  *attribute = attr;
	  return MRSS_OK;
	}
    }

  return MRSS_OK;
}

/* EOF */