Subversion Repositories tpanel

Rev

Rev 8 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8 Rev 21
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (C) 2020 by Andreas Theofilu <andreas@theosys.at>
2
 * Copyright (C) 2020, 2021 by Andreas Theofilu <andreas@theosys.at>
3
 *
3
 *
4
 * This program is free software; you can redistribute it and/or modify
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
7
 * (at your option) any later version.
Line 46... Line 46...
46
    }
46
    }
47
 
47
 
48
    return RESOURCE_LIST_T();
48
    return RESOURCE_LIST_T();
49
}
49
}
50
 
50
 
-
 
51
RESOURCE_T TPrjResources::findResource(int idx, const std::string& name)
-
 
52
{
-
 
53
    DECL_TRACER("TPrjResources::findResource(int idx, const std::string& name)");
-
 
54
 
-
 
55
    if (idx < 1 || mResources.size() < (size_t)idx)
-
 
56
    {
-
 
57
        MSG_ERROR("Invalid index " << idx << "!");
-
 
58
        return RESOURCE_T();
-
 
59
    }
-
 
60
 
-
 
61
    RESOURCE_LIST_T list = mResources[idx-1];
-
 
62
 
-
 
63
    if (list.type.empty())
-
 
64
    {
-
 
65
        MSG_ERROR("Resource list " << idx << " is empty!");
-
 
66
        return RESOURCE_T();
-
 
67
    }
-
 
68
 
-
 
69
    vector<RESOURCE_T>::iterator iter;
-
 
70
 
-
 
71
    for (iter = list.ressource.begin(); iter != list.ressource.end(); iter++)
-
 
72
    {
-
 
73
        MSG_DEBUG("Resource: " << iter->name);
-
 
74
        if (iter->name.compare(name) == 0)
-
 
75
            return *iter;
-
 
76
    }
-
 
77
 
-
 
78
    MSG_WARNING("Resource " << name << " not found!");
-
 
79
    return RESOURCE_T();
-
 
80
}
-
 
81
 
51
RESOURCE_T TPrjResources::findResource(const std::string& type, const std::string& name)
82
RESOURCE_T TPrjResources::findResource(const std::string& type, const std::string& name)
52
{
83
{
53
    DECL_TRACER("TPrjResources::findResource(const std::string& type, const std::string& name)");
84
    DECL_TRACER("TPrjResources::findResource(const std::string& type, const std::string& name)");
54
 
85
 
55
    RESOURCE_LIST_T list = findResourceType(type);
86
    RESOURCE_LIST_T list = findResourceType(type);
Line 84... Line 115...
84
            return *iter;
115
            return *iter;
85
    }
116
    }
86
 
117
 
87
    return RESOURCE_T();
118
    return RESOURCE_T();
88
}
119
}
-
 
120
 
-
 
121
bool TPrjResources::setResource(const string& name, const string& scheme, const string& host, const string& path, const string& file, const string& user, const string& pw, int refresh)
-
 
122
{
-
 
123
    DECL_TRACER("TPrjResources::setResource(const string& name, const string& scheme, const string& host, const string& path, const string& file, const string& user, const string& pw, int refresh)");
-
 
124
 
-
 
125
    if (mResources.size() == 0 || mResources[0].ressource.size() == 0)
-
 
126
        return false;
-
 
127
 
-
 
128
    vector<RESOURCE_T> list = mResources[0].ressource;
-
 
129
    vector<RESOURCE_T>::iterator iter;
-
 
130
 
-
 
131
    for (iter = list.begin(); iter != list.end(); iter++)
-
 
132
    {
-
 
133
        if (iter->name.compare(name) == 0)
-
 
134
        {
-
 
135
            RESOURCE_T res = *iter;
-
 
136
 
-
 
137
            if (!scheme.empty())
-
 
138
                res.protocol = scheme;
-
 
139
 
-
 
140
            if (!host.empty())
-
 
141
                res.host = host;
-
 
142
 
-
 
143
            if (!path.empty())
-
 
144
                res.path = path;
-
 
145
 
-
 
146
            if (!file.empty())
-
 
147
                res.file = file;
-
 
148
 
-
 
149
            if (!user.empty())
-
 
150
                res.user = user;
-
 
151
 
-
 
152
            if (!pw.empty())
-
 
153
                res.password = pw;
-
 
154
 
-
 
155
            if (refresh >= 0)
-
 
156
                res.refresh = refresh;
-
 
157
 
-
 
158
            list.erase(iter);
-
 
159
            list.push_back(res);
-
 
160
            RESOURCE_LIST_T rlist = mResources[0];
-
 
161
            rlist.ressource.clear();
-
 
162
            rlist.ressource = list;
-
 
163
            mResources.erase(mResources.begin());
-
 
164
            mResources.push_back(rlist);
-
 
165
            return true;
-
 
166
        }
-
 
167
    }
-
 
168
 
-
 
169
    return false;
-
 
170
}