~ubuntu-branches/ubuntu/edgy/gnome-pilot-conduits/edgy

« back to all changes in this revision

Viewing changes to mal-conduit/mal/client/unix/MAL31ServerConfig.c

  • Committer: Bazaar Package Importer
  • Author(s): Mike Markley
  • Date: 2005-01-17 01:08:21 UTC
  • Revision ID: james.westby@ubuntu.com-20050117010821-d8omp6psfwhzdmna
Tags: upstream-2.0.12
ImportĀ upstreamĀ versionĀ 2.0.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 
2
 
 
3
/* The contents of this file are subject to the Mozilla Public License
 
4
 * Version 1.0 (the "License"); you may not use this file except in
 
5
 * compliance with the License. You may obtain a copy of the License at
 
6
 * http://www.mozilla.org/MPL/
 
7
 *
 
8
 * Software distributed under the License is distributed on an "AS IS"
 
9
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 
10
 * License for the specific language governing rights and limitations
 
11
 * under the License.
 
12
 *
 
13
 * The Original Code is Mobile Application Link.
 
14
 *
 
15
 * The Initial Developer of the Original Code is AvantGo, Inc.
 
16
 * Portions created by AvantGo, Inc. are Copyright (C) 1997-1999
 
17
 * AvantGo, Inc. All Rights Reserved.
 
18
 *
 
19
 * Contributor(s):
 
20
 */
 
21
 
 
22
#include <MAL31ServerConfig.h>
 
23
#include <AGBufferReader.h>
 
24
#include <AGBufferWriter.h>
 
25
#include <AGUtil.h>
 
26
#include <AGDigest.h>
 
27
#include <AGBase64.h>
 
28
#include <AGMD5.h>
 
29
#include <MAL31DBConfig.h>
 
30
 
 
31
/* Version 0 - original creation */
 
32
#define RECORD_VERSION_0 (0)
 
33
 
 
34
/* Version 1 - added allowSecureConnection */
 
35
#define RECORD_VERSION_1 (1)
 
36
 
 
37
/* This is the version number that is written to new records */
 
38
#define CURRENT_RECORD_VERSION (RECORD_VERSION_1)
 
39
 
 
40
/*--------------------------------------------------------------------------*/
 
41
void
 
42
MAL31ServerConfigReadData(AGServerConfig *config, AGReader *r)
 
43
{
 
44
    int32 count, i;
 
45
    int16 recordVersion;
 
46
    AGDBConfig *dbconfig;
 
47
 
 
48
    recordVersion = AGReadInt16(r);
 
49
    config->uid = AGReadInt32(r);
 
50
    config->status = (AGRecordStatus)AGReadInt16(r);
 
51
    config->serverName = AGReadCString(r);
 
52
    config->serverPort = AGReadInt16(r);
 
53
 
 
54
    config->userName = AGReadCString(r);
 
55
    config->cleartextPassword = AGReadCString(r);
 
56
    if (AGReadInt8(r))
 
57
        AGReadBytes(r, config->password, 16);
 
58
 
 
59
    /* read in nonce */
 
60
    if (AGReadInt8(r))
 
61
        AGReadBytes(r, config->nonce, 16);
 
62
 
 
63
    if (AGReadInt8(r))
 
64
        config->disabled = TRUE;
 
65
    else
 
66
        config->disabled = FALSE;
 
67
 
 
68
    config->friendlyName = AGReadCString(r);
 
69
    config->userUrl = AGReadCString(r);
 
70
    config->description = AGReadCString(r);
 
71
    config->serverUri = AGReadCString(r);
 
72
 
 
73
    config->sequenceCookieLength = AGReadInt32(r);
 
74
    if (config->sequenceCookieLength > 0) {
 
75
        config->sequenceCookie =
 
76
            (uint8*)malloc(config->sequenceCookieLength);
 
77
        AGReadBytes(r, config->sequenceCookie, config->sequenceCookieLength);
 
78
    }
 
79
 
 
80
    count = AGReadInt32(r);
 
81
    config->dbconfigs = AGArrayNew(AGUnownedPointerElements, count);
 
82
    for (i = 0; i < count; i++) {
 
83
        dbconfig = AGDBConfigNew(NULL, AG_SENDALL_CFG, FALSE, 0, NULL, NULL);
 
84
        MAL31DBConfigReadData(dbconfig, r);
 
85
        AGArrayAppend(config->dbconfigs, dbconfig);
 
86
    }
 
87
    if (AGReadInt8(r))
 
88
        config->sendDeviceInfo = TRUE;
 
89
    else
 
90
        config->sendDeviceInfo = FALSE;
 
91
 
 
92
    config->hashPassword = AGReadBoolean(r);
 
93
    /* pending(miket):  leave in until cleartext password support is in. */
 
94
    config->hashPassword = TRUE;
 
95
    config->connectTimeout = AGReadCompactInt(r);
 
96
    config->writeTimeout = AGReadCompactInt(r);
 
97
    config->readTimeout = AGReadCompactInt(r);
 
98
 
 
99
    config->connectSecurely = AGReadBoolean(r);
 
100
 
 
101
    if (recordVersion >= RECORD_VERSION_1) {
 
102
        /* Record version 1:  added allowSecureConnection. */
 
103
        config->allowSecureConnection = AGReadBoolean(r);
 
104
    } else {
 
105
        config->allowSecureConnection = FALSE;
 
106
    }
 
107
}
 
108
 
 
109
/*---------------------------------------------------------------------------*/
 
110
static AGBool
 
111
digestIsNull(uint8 a[16])
 
112
{
 
113
    int i;
 
114
    for(i=0;i<16;i++)
 
115
        if(a[i])
 
116
            return 0;
 
117
    return 1;
 
118
}
 
119
/*---------------------------------------------------------------------------*/
 
120
void
 
121
MAL31ServerConfigWriteData(AGServerConfig *config, AGWriter *w)
 
122
{
 
123
    int32 i, count;
 
124
    AGDBConfig *dbconfig;
 
125
    
 
126
    AGWriteInt16(w, CURRENT_RECORD_VERSION);
 
127
    AGWriteInt32(w, config->uid);
 
128
    AGWriteInt16(w, (uint16)config->status);
 
129
    AGWriteCString(w, config->serverName);
 
130
    AGWriteInt16(w, config->serverPort);
 
131
 
 
132
    AGWriteCString(w, config->userName);
 
133
    AGWriteCString(w, config->cleartextPassword);
 
134
 
 
135
    if (digestIsNull(config->password))
 
136
        AGWriteInt8(w, 0);
 
137
    else {
 
138
        AGWriteInt8(w, 16);
 
139
        AGWriteBytes(w, config->password, 16);
 
140
    }
 
141
 
 
142
    if (digestIsNull(config->nonce))
 
143
        AGWriteInt8(w, 0);
 
144
    else {
 
145
        AGWriteInt8(w, 16);
 
146
        AGWriteBytes(w, config->nonce, 16);
 
147
    }
 
148
 
 
149
    if (config->disabled)
 
150
        AGWriteInt8(w, 1);
 
151
    else
 
152
        AGWriteInt8(w, 0);
 
153
 
 
154
    AGWriteCString(w, config->friendlyName);
 
155
    AGWriteCString(w, config->userUrl);
 
156
    AGWriteCString(w, config->description);
 
157
    AGWriteCString(w, config->serverUri);
 
158
 
 
159
    AGWriteInt32(w, config->sequenceCookieLength);
 
160
    if (config->sequenceCookieLength > 0) {
 
161
        AGWriteBytes(w, config->sequenceCookie, 
 
162
                     config->sequenceCookieLength);
 
163
    }
 
164
 
 
165
    count = AGArrayCount(config->dbconfigs);
 
166
    AGWriteInt32(w, count);
 
167
    for (i = 0; i < count; i++) {
 
168
        dbconfig = (AGDBConfig*)AGArrayElementAt(config->dbconfigs, i);
 
169
        MAL31DBConfigWriteData(dbconfig, w);
 
170
    }
 
171
    if (config->sendDeviceInfo)
 
172
        AGWriteInt8(w, 1);
 
173
    else
 
174
        AGWriteInt8(w, 0);
 
175
 
 
176
    AGWriteBoolean(w, config->hashPassword);
 
177
    AGWriteCompactInt(w, config->connectTimeout);
 
178
    AGWriteCompactInt(w, config->writeTimeout);
 
179
    AGWriteCompactInt(w, config->readTimeout);
 
180
 
 
181
    AGWriteBoolean(w, config->connectSecurely);
 
182
    AGWriteBoolean(w, config->allowSecureConnection);
 
183
 
 
184
}
 
185
 
 
186
 
 
187