~ubuntu-branches/ubuntu/jaunty/pcsc-lite/jaunty-security

« back to all changes in this revision

Viewing changes to src/tokenparser.l

  • Committer: Bazaar Package Importer
  • Author(s): Ludovic Rousseau
  • Date: 2004-06-13 21:45:56 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040613214556-zio7hrzkz9wwtffx
Tags: 1.2.9-beta2-2
* debian/rules: add -lpthread to LDFLAGS so that pthread_* symbols are
  included in the library (problem only seen on mips and mipsel).
  Closes: #253629
* debian/control: make libpcsclite-dev and libpcsclite1 at Priority:
  optional so that other packages at Priority: optional can use them.
  Closes: #249374

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Reads lexical config files and updates database.
 
3
 *
 
4
 * MUSCLE SmartCard Development ( http://www.linuxnet.com )
 
5
 *
 
6
 * Copyright (C) 2001-2003
 
7
 *  David Corcoran <corcoran@linuxnet.com>
 
8
 *  Ludovic Rousseau <ludovic.rousseau@free.fr>
 
9
 *
 
10
 * $Id: tokenparser.l,v 1.9 2003/10/18 18:24:00 aet-guest Exp $
 
11
 */
 
12
 
 
13
%{
 
14
 
 
15
#include "config.h"
 
16
#include <stdio.h>
 
17
#include <string.h>
 
18
 
 
19
#include "debuglog.h"
 
20
#include "parser.h"
 
21
 
 
22
void tpevalToken(char *pcToken, int tokType);
 
23
 
 
24
static char *pcDesiredKey = 0;
 
25
static char pcKey[TOKEN_MAX_KEY_SIZE];
 
26
static char pcValue[TOKEN_MAX_VALUE_SIZE];
 
27
static char pcFinValue[TOKEN_MAX_VALUE_SIZE];
 
28
static int valueIndex = 0;
 
29
static int desiredIndex = 0;
 
30
 
 
31
void tperrorCheck (char *pcToken_error);
 
32
 
 
33
%}
 
34
 
 
35
%%
 
36
 
 
37
#.*                                             {}
 
38
"\n"                                            {}
 
39
\<key\>([A-Z]|[a-z]|[0-9]|[ \t])+\<\/key\>      { valueIndex = 0; tpevalToken(yytext, TOKEN_TYPE_KEY); }
 
40
[ \t]                                           {}
 
41
\<string\>([A-Z]|[a-z]|[0-9]|[ \t]|[!@#$%^&*()\-+/_\:?.,=~'"])+\<\/string\> {tpevalToken(yytext, TOKEN_TYPE_STRING); valueIndex += 1;}
 
42
.                                               { tperrorCheck( yytext ); }
 
43
%%
 
44
 
 
45
 
 
46
int yywrap()
 
47
{
 
48
        return 1;
 
49
}
 
50
 
 
51
 
 
52
void tpevalToken(char *pcToken, int tokType)
 
53
{
 
54
        int len;
 
55
        len = 0;
 
56
 
 
57
        if (tokType == TOKEN_TYPE_KEY)
 
58
        {
 
59
                for (len=5; pcToken[len] != '<'; len++)
 
60
                        ;
 
61
                if (len - 5 > TOKEN_MAX_KEY_SIZE)
 
62
                {
 
63
                        strncpy(pcKey, &pcToken[5], TOKEN_MAX_KEY_SIZE);
 
64
                        pcKey[TOKEN_MAX_KEY_SIZE - 1] = '\0';
 
65
                }
 
66
                else
 
67
                {
 
68
                        strncpy(pcKey, &pcToken[5], len - 5);
 
69
                        pcKey[len-5] = 0;
 
70
                }
 
71
        }
 
72
 
 
73
        if (tokType == TOKEN_TYPE_STRING)
 
74
        {
 
75
                for (len=8; pcToken[len] != '<'; len++)
 
76
                        ;
 
77
                if (len - 8 > TOKEN_MAX_VALUE_SIZE)
 
78
                {
 
79
                        strncpy(pcValue, &pcToken[8], TOKEN_MAX_VALUE_SIZE);
 
80
                        pcValue[TOKEN_MAX_VALUE_SIZE - 1] = '\0';
 
81
                }
 
82
                else
 
83
                {
 
84
                        strncpy(pcValue, &pcToken[8], len - 8);
 
85
                        pcValue[len-8] = 0;
 
86
                }
 
87
                if (strcmp(pcKey, pcDesiredKey) == 0)
 
88
                        if (desiredIndex == valueIndex)
 
89
                        {
 
90
                                strncpy(pcFinValue, pcValue, TOKEN_MAX_VALUE_SIZE);
 
91
                                pcFinValue[TOKEN_MAX_VALUE_SIZE - 1] = '\0';
 
92
                        }
 
93
        }
 
94
}
 
95
 
 
96
void tperrorCheck (char *token_error)
 
97
{
 
98
}
 
99
 
 
100
int LTPBundleFindValueWithKey(char *fileName, char *tokenKey,
 
101
                              char *tokenValue, int tokenIndice)
 
102
{
 
103
        FILE *file = NULL;
 
104
        int ret = 0;
 
105
 
 
106
        desiredIndex  = tokenIndice;
 
107
        pcDesiredKey  = tokenKey;
 
108
        pcFinValue[0] = '\0';
 
109
 
 
110
        file = fopen(fileName, "r");
 
111
 
 
112
        if (!file)
 
113
        {
 
114
                DebugLogB("Could not open bundle file : %s", fileName);
 
115
                return 1;
 
116
        }
 
117
 
 
118
        yyin = file;
 
119
 
 
120
        do
 
121
        {
 
122
                yylex();
 
123
        } while (!feof(file));
 
124
 
 
125
        if (pcFinValue[0] == 0)
 
126
        {
 
127
                if (tokenIndice == 0)
 
128
                {
 
129
                        /* Not defined at all */
 
130
                        DebugLogC("Value/Key not defined for: %s, indice: %d",
 
131
                                tokenKey, tokenIndice);
 
132
                }
 
133
                ret = -1;
 
134
        }
 
135
        else
 
136
        {
 
137
                strncpy(tokenValue, pcFinValue, TOKEN_MAX_VALUE_SIZE);
 
138
                tokenValue[TOKEN_MAX_VALUE_SIZE - 1] = '\0';
 
139
        }
 
140
 
 
141
        fclose(file);
 
142
        return ret;
 
143
}
 
144