-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparsecmdline.c
More file actions
218 lines (180 loc) · 7.52 KB
/
parsecmdline.c
File metadata and controls
218 lines (180 loc) · 7.52 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifndef TRUE
# define TRUE 1
# define FALSE 0
#endif
int parseCmdLine(int argc, char* argv[], char *primarylogin, char *primarypass, char *primarydblink, char *standbylogin, char *standbypass, char *standbydblink, char *pathparameter)
{
const char *usage = "Usage: osp primary=login/pass@server standby=login/pass@server primarylike|auto|autoforce|gennext|\"/real/path/you need\"\n\"primarylike\" - the path for the datafile will remain the same as on the primary server\n\
\"auto\" - the directory for the datafile will be the same as the last one in this table space\n\"autoforce\" - the directory for the datafile will be the same as the last one in this tablespace. If there is no tablespace yet, the directory for the datafile will be the same as the SYSTEM tablespace\n\
\"gennext\" - the datafile name will be generated based on the previous one without connecting to the primary server\n\
/real/path - directory for the datafile\n\nosp version - 1.1.0\n";
if (!(argc == 4 || argc == 3) )
{
printf("%s\n", usage);
//printf("Arguments count is %d\n", argc);
exit(EXIT_FAILURE);
}
int i;
int gotprimary = FALSE;
int gotstandby = FALSE;
int gotpathparameter = FALSE;
for (i = 1; i < argc; i++)
{
if (strstr(argv[i], "primary=") == argv[i])
{
if (gotprimary == FALSE)
{
char *slashpointer, *atpointer;
int connectlinelen;
char connectline[256];
strncpy(connectline, argv[i] + (int)strlen("primary="), 256);
connectlinelen = strlen(connectline);
//printf("Connect line lengh - %d\n", connectlinelen);
slashpointer = strchr(connectline, '/');
atpointer = strchr(connectline, '@');
if ((slashpointer - connectline) == 0 || *(connectline) == '/')
{
printf("Primary login is not found\n");
printf("%s\n", usage);
exit(EXIT_FAILURE);
}
if (slashpointer == NULL || (atpointer - slashpointer - 1) == 0)
{
printf("Primary pass is not found\n");
printf("%s\n", usage);
exit(EXIT_FAILURE);
}
if (atpointer == NULL || (connectlinelen - (atpointer - connectline) - 1) == 0)
{
printf("Primary dblink is not found\n");
printf("%s\n", usage);
exit(EXIT_FAILURE);
}
if ((slashpointer - connectline) > 30)
{
printf("Primary login is too large\n");
exit(EXIT_FAILURE);
}
if (atpointer - slashpointer - 1 > 30)
{
printf("Primary pass is too large\n");
exit(EXIT_FAILURE);
}
if ((connectlinelen - (atpointer - connectline) - 1) > 127)
{
printf("Primary dblink is too large\n");
exit(EXIT_FAILURE);
}
strncpy(primarylogin, connectline, slashpointer - connectline);
strncpy(primarypass, slashpointer + 1, atpointer - slashpointer - 1);
strncpy(primarydblink, atpointer + 1, connectlinelen - (atpointer - connectline) - 1);
gotprimary = TRUE;
//printf("primarylogin - %s\n", primarylogin);
//printf("primarypass - %s\n", primarypass);
//printf("primarydblink - %s\n", primarydblink);
continue;
}
else
{
printf("Argument \"primary\" is already got\n");
printf("%s\n", usage);
exit(EXIT_FAILURE);
}
}
else if (strstr(argv[i], "standby=") == argv[i])
{
if (gotstandby == FALSE)
{
char *slashpointer, *atpointer;
int connectlinelen;
char connectline[256];
strncpy(connectline, argv[i] + (int) strlen("standby="), 256);
connectlinelen = strlen(connectline);
//printf("Connect line lengh - %d\n", connectlinelen);
slashpointer = strchr(connectline, '/');
atpointer = strchr(connectline, '@');
if ((slashpointer - connectline) == 0 || *(connectline) == '/') {
printf("Standby login is not found\n");
printf("%s\n", usage);
exit(EXIT_FAILURE);
}
if (slashpointer == NULL || (atpointer - slashpointer - 1) == 0) {
printf("Standby pass is not found\n");
printf("%s\n", usage);
exit(EXIT_FAILURE);
}
if (atpointer == NULL || (connectlinelen - (atpointer - connectline) - 1) == 0) {
printf("Standby dblink is not found\n");
printf("%s\n", usage);
exit(EXIT_FAILURE);
}
if ((slashpointer - connectline) > 30) {
printf("Standby login is too large\n");
exit(EXIT_FAILURE);
}
if (atpointer - slashpointer - 1 > 30) {
printf("Standby pass is too large\n");
exit(EXIT_FAILURE);
}
if ((connectlinelen - (atpointer - connectline) - 1) > 127) {
printf("Standby dblink is too large\n");
exit(EXIT_FAILURE);
}
strncpy(standbylogin, connectline, slashpointer - connectline);
strncpy(standbypass, slashpointer + 1, atpointer - slashpointer - 1);
strncpy(standbydblink, atpointer + 1, connectlinelen - (atpointer - connectline) - 1);
gotstandby = TRUE;
//printf("standbylogin - %s\n", standbylogin);
//printf("standbypass - %s\n", standbypass);
//printf("standbydblink - %s\n", standbydblink);
continue;
}
else
{
printf("Argument \"standby\" is already got\n");
printf("%s\n", usage);
exit(EXIT_FAILURE);
}
}
else
{
if (gotpathparameter == FALSE)
{
strncpy(pathparameter, argv[i], 256);
gotpathparameter = TRUE;
//printf("Path parameter - %s\n", pathparameter);
continue;
}
else
{
printf("Argument \"pathparameter\" is alredy got\n");
printf("%s\n", usage);
exit(EXIT_FAILURE);
}
}
}
if (gotprimary == FALSE && strcmp(pathparameter, "gennext") != 0)
{
printf("Argument primary is missed\n");
exit(EXIT_FAILURE);
}
if (gotstandby == FALSE)
{
printf("Argument standby is missed\n");
exit(EXIT_FAILURE);
}
if (gotpathparameter == FALSE)
{
printf("Path parameter is missed\n");
exit(EXIT_FAILURE);
}
return TRUE;
}