~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbms/src/metadata_ms.h

  • Committer: Brian Aker
  • Date: 2009-11-12 16:13:04 UTC
  • mfrom: (1211.1.7 staging)
  • Revision ID: brian@gaz-20091112161304-opamiauv36fg0n6u
Rollup of Brian, Padraig, and Stewart patches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2009 PrimeBase Technologies GmbH, Germany
2
 
 *
3
 
 * PrimeBase Media Stream for MySQL
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License as published by
7
 
 * the Free Software Foundation; either version 2 of the License, or
8
 
 * (at your option) any later version.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
 
 *
19
 
 * Barry Leslie
20
 
 *
21
 
 * 2009-01-09
22
 
 *
23
 
 * H&G2JCtL
24
 
 *
25
 
 * PBMS Meta Data utilities.
26
 
 *
27
 
 */
28
 
#ifndef __METADATA_MS_H__
29
 
#define __METADATA_MS_H__
30
 
 
31
 
#ifdef DRIZZLED
32
 
#include <drizzled/internal/m_string.h>
33
 
#include <drizzled/charset_info.h>
34
 
#else
35
 
#include "m_ctype.h"
36
 
#endif
37
 
 
38
 
#include "pbmslib.h"
39
 
 
40
 
class MetaData
41
 
{
42
 
private:
43
 
        char *data;
44
 
        char *eod;
45
 
        char *position;
46
 
        
47
 
public:
48
 
        MetaData(): data(NULL), eod(NULL), position(NULL){}
49
 
        MetaData(char *meta_data, size_t meta_data_size): data(meta_data), eod(meta_data + meta_data_size), position(meta_data){}
50
 
        
51
 
        char *getBuffer() { return data;}
52
 
                
53
 
        void use_data(char *meta_data, size_t meta_data_size) 
54
 
        {
55
 
                data = meta_data;
56
 
                position = data;
57
 
                eod = data + meta_data_size;
58
 
        }
59
 
        
60
 
        void reset() 
61
 
        {
62
 
                position = data;
63
 
        }
64
 
        
65
 
        char *findNext(char **value)
66
 
        {
67
 
                char *name = position;
68
 
                if (position >= eod)
69
 
                        return NULL;
70
 
                        
71
 
                position += strlen(position) +1;
72
 
                if (position >= eod)
73
 
                        return NULL;
74
 
                        
75
 
                *value = position;
76
 
                position += strlen(position) +1;
77
 
                
78
 
                return name;
79
 
        }
80
 
        
81
 
        char *findName(const char *name)
82
 
        {
83
 
                char  *metadata = data;
84
 
                
85
 
                while (metadata < eod && my_strcasecmp(&my_charset_utf8_general_ci, metadata, name)) {
86
 
                        metadata += strlen(metadata) +1;
87
 
                        metadata += strlen(metadata) +1;
88
 
                }
89
 
                
90
 
                if (metadata < eod)
91
 
                        return metadata + strlen(metadata) +1;
92
 
                        
93
 
                return NULL;
94
 
        }
95
 
        
96
 
        char *findNamePosition(const char *name)
97
 
        {
98
 
                char  *metadata = data;
99
 
                
100
 
                while (metadata < eod && my_strcasecmp(&my_charset_utf8_general_ci, metadata, name)) {
101
 
                        metadata += strlen(metadata) +1;
102
 
                        metadata += strlen(metadata) +1;
103
 
                }
104
 
                
105
 
                if (metadata < eod)
106
 
                        return metadata;
107
 
                        
108
 
                return NULL;
109
 
        }
110
 
        
111
 
#ifdef HAVE_ALIAS_SUPPORT
112
 
        char *findAlias() {return findName(MS_ALIAS_TAG);}
113
 
#endif
114
 
        
115
 
        static uint32_t recSize(const char *rec) 
116
 
        { 
117
 
                uint32_t len = strlen(rec) + 1;
118
 
                
119
 
                rec += len;
120
 
                return (len + strlen(rec) + 1);
121
 
        }
122
 
        
123
 
};
124
 
#endif //__METADATA_MS_H__