/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following functions.
- stringPack
- ca_populateDictionary
- opSplitsen
- ca_readConfig
- ca_getDictionary
- ca_get_int
- ca_get_dirlist
- ca_get_string
- ca_get_boolean
- ca_set_int
- ca_change_int_value
- testFunction
- ca_getDatabase
- ca_getSource
- ca_getAllSources
- ca_getAsource
- ca_getSourceDetails
- ca_get_SourceHandleByPosition
- ca_get_SourceHandleByName
- ca_srchandle2Strelement
- ca_srchandle2Intelement
- ca_get_adminStrElement
- ca_get_adminIntElement
- ca_set_boolean
- ca_set_dirlist
- gets
- ca_writeNewValue
- ca_getStorageLocation
- ca_getConfig
- ca_getType
- ca_get_UpdSourceHandle
- ca_UpdSrcHandle2StrElement
- ca_UpdSrcHandle2IntElement
- ca_sanityChk
- ca_mandVarChk
1 /***************************************
2 $Revision:
3
4 CA module: definitions of most functions.
5
6 Status: NOT REVIEWED, NOT TESTED
7
8 Author(s): Ambrose Magee
9
10 ******************//******************
11 Modification History:
12
13 ******************/
14
15 /************************************
16 Copyright (c) 2000,2001,2002 RIPE NCC
17
18 All Rights Reserved
19
20 Permission to use, copy, modify, and distribute this software and its
21 documentation for any purpose and without fee is hereby granted,
22 provided that the above copyright notice appear in all copies and that
23 both that copyright notice and this permission notice appear in
24 supporting documentation, and that the name of the author not be
25 used in advertising or publicity pertaining to distribution of the
26 software without specific, written prior permission.
27
28 THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
29 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
30 AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
31 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
32 AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
33 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
34 ***************************************/
35
36 #define DICT_INIT
37 #include "rip.h"
38
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <glib.h>
42 #include <string.h>
43 #include <unistd.h>
44
45 int num_sources=0;
46
47 /* #define DEBUG */
48
49 /**********************************************
50 * This file contains the definitions of all *
51 * the functions. *
52 **********************************************/
53
54 void
55 stringPack(char *dest, const char *source)
/* [<][>][^][v][top][bottom][index][help] */
56 /****************************************************************
57 * stringPack -- function to rewrite a line of text with only *
58 * one blankspace between each word. *
59 * *
60 * Parameters *
61 * dest -- destination character, the character to be *
62 * outputted *
63 * source -- the 'source' character, the original character. *
64 * *
65 * Returns *
66 * Nothing (may change this to the number of characters *
67 * read or copied). *
68 * *
69 ****************************************************************/
70 {
71 #ifdef DEBUG
72 printf("\nInside stringPack function\n");
73 #endif /* DEBUG */
74
75 /*
76 * This while loop continues until the NULL character is copied into
77 * the destination string. If a tab character is copied into the
78 * destination string, it is replaced with a blank-space character.
79 *
80 * Multiple blank-space and/or tab characters are skipped in the source
81 * string until any other character is found.
82 */
83
84 while (1) {
85 *dest = *source;
86
87 if (*dest == '\t')
88 (*dest = ' ');
89
90 /* Exit if have copied the end of the string. */
91 if (*dest == '\0')
92 return;
93
94 /*
95 * If the source character was a blank-space or a tab, move
96 * to the next source character. While the source character
97 * is a blank-space or a tab, move to the next character
98 * (i.e. ignore these characters). When any other character
99 * is found in the source string, move to the next element of
100 * the destination string.
101 *
102 * Otherwise, simultaneously, move to the next elements of the
103 * destination and the source strings.
104 */
105
106
107
108 if ((*source == ' ') || (*source == '\t')) {
109 ++source;
110 while ((*source == ' ') || (*source == '\t')) {
111 ++source;
112 }
113
114 ++dest;
115 }
116 else {
117 ++dest;
118 ++source;
119 }
120 }
121 }
122
123
124 void
125 ca_populateDictionary(dict_t woordenboek[], int size)
/* [<][>][^][v][top][bottom][index][help] */
126 /*******************************************************************
127 * ca_populateDictionary -- Parses dictionary file, initializes *
128 * the dictionary structure and writes *
129 * the file of dictionary symbols, *
130 * ca_dictSyms.h *
131 * *
132 * Parameters *
133 * woordenboek -- the dictionary to be populated *
134 * size -- the total number of variables i.e. the size of the *
135 * array of dict_t structures. See D. & D., p.276 *
136 * *
137 * Returns *
138 * Nothing ? (may change this later) *
139 * *
140 *******************************************************************/
141
142 {
143 const char *blankLine = "\n";
144 const char *comment = "#";
145 char line[120];
146 char input[120];
147 int entry = 0;
148 FILE *dictPtr;
149 #ifdef DEBUG
150 int i;
151 FILE *defnPtr;
152 #endif /* DEBUG */
153
154 gchar **tokens; /* Pointer to an array of strings. */
155
156 /*
157 * Try to open the dictionary file for reading. If it cannot be
158 * opened, exit with an error.
159 */
160 if ((dictPtr = fopen("dictionary.txt", "r")) == NULL) {
161 fprintf(stderr, "Error: Unable to open 'dictionary.txt'\n");
162 die;
163 }
164
165
166 /*
167 * DEBUG mode only. Try to open the definitions file for writing. If
168 * it cannot be opened,exit with an error
169 */
170 #ifdef DEBUG
171 if ((defnPtr = fopen("defs.txt", "w")) == NULL) {
172 fprintf(stderr, "Error: Unable to open 'defs.txt'\n");
173 die;
174 }
175 #endif /* DEBUG */
176
177 /*
178 * Read the file one line at a time; if the line begins with a
179 * comment, ignore it; otherwise, split each line into tokens; print
180 * each token. Assign each token to the appropriate member of the
181 * appropriate element of the dictionary array.
182 */
183
184 fgets(input, sizeof(input), dictPtr);
185
186 if ((strncmp(input, comment, 1) != 0) && (strncmp(input, blankLine, 1) != 0)) {
187 /*
188 * First remove the newline character. Then replace multiple
189 * tab and space characters with single space characters.
190 */
191
192 /*
193 * Remove the newline character, if present. Replace the last
194 * character of the string array with with '\0'.
195 */
196
197 input[strlen(input) - 1] = '\0';
198
199 /*
200 * Now, remove the multiple space and tab characters.
201 */
202
203 stringPack(line, input);
204
205 g_strchomp(line); /* Remove trailing w-space. */
206 #ifdef DEBUG
207 puts(line);
208 #endif /* DEBUG */
209
210 tokens = g_strsplit(line, " ", 0);
211
212 #ifdef DEBUG
213 for (i = 0; tokens[i] != NULL; i++)
214 printf("tokens[%d] = %s\n", i, tokens[i]);
215 #endif /* DEBUG */
216
217 /*
218 * We no longer need a variable for scope
219 * woordenboek[entry].varScope = atoi(tokens[1]);
220 */
221
222 strcpy(woordenboek[entry].varName, tokens[0]);
223 strcpy(woordenboek[entry].varSym, tokens[1]);
224 strcpy(woordenboek[entry].varType, tokens[2]);
225 woordenboek[entry].varNum = entry;
226
227 /*
228 * DEBUG mode only. Write the dictionary symbol and the entry
229 * number to the definitions file.
230 */
231 #ifdef DEBUG
232 fprintf(defnPtr, "%s\t%d\n", tokens[1], entry);
233 #endif /* DEBUG */
234
235 ++entry;
236 g_strfreev(tokens);
237 }
238 /*
239 * Get the 2nd and subsequent line of the file.
240 */
241
242 fgets(input, sizeof(input), dictPtr);
243
244 while (!feof(dictPtr)) {
245 /*
246 * Process the line if it is not a comment.
247 */
248
249 if ((strncmp(input, comment, 1) != 0) && (strncmp(input, blankLine, 1) != 0)) {
250 /*
251 * First remove the newline character. Then replace
252 * multiple tab and space characters with single
253 * space characters.
254 */
255
256 /*
257 * Remove the newline character, if present. Replace
258 * the last character of the string array with with
259 * '\0'.
260 */
261
262 input[strlen(input) - 1] = '\0';
263
264 /*
265 * Now, remove the multiple space and tab characters.
266 */
267
268 stringPack(line, input);
269
270 g_strchomp(line); /* Remove trailing w/space. */
271
272 #ifdef DEBUG
273 puts(line);
274 #endif /* DEBUG */
275 tokens = g_strsplit(line, " ", 0);
276
277 #ifdef DEBUG
278 for (i = 0; tokens[i] != NULL; i++)
279 printf("tokens[%d] = %s\n", i, tokens[i]);
280 #endif /* DEBUG */
281
282 /*
283 * We no longer need to know the scope of a variable
284 * woordenboek[entry].varScope = atoi(tokens[1]);
285 */
286
287 strcpy(woordenboek[entry].varName, tokens[0]);
288 strcpy(woordenboek[entry].varSym, tokens[1]);
289 strcpy(woordenboek[entry].varType, tokens[2]);
290 woordenboek[entry].varNum = entry;
291
292 #ifdef DEBUG
293 fprintf(defnPtr, "%s\t%d\n", tokens[1], entry);
294 #endif /* DEBUG */
295
296 ++entry;
297
298 g_strfreev(tokens);
299 }
300 fgets(input, sizeof(input), dictPtr);
301 }
302
303 fclose(dictPtr);
304
305 #ifdef DEBUG
306 fclose(defnPtr);
307 #endif /* DEBUG */
308
309 } /* End of ca_populateDictionary() function. */
310
311
312 void
313 opSplitsen(FILE * filePtr, gchar ** tokenArray)
/* [<][>][^][v][top][bottom][index][help] */
314 /*******************************************************************
315 * opSplitsen -- reads a file and splits it into tokens. *
316 * *
317 * Parameters *
318 * filePtr -- a text file *
319 * tokenArray -- pointer to an array of strings *
320 * *
321 * Returns *
322 * Nothing *
323 * *
324 *******************************************************************/
325 {
326 /*
327 * Declaring character constants is safer than using #define.
328 */
329
330 const char *blankLine = "\n"; /* Declared as a string, not a
331 * character. */
332 const char *comment = "#"; /* Declared as a string. */
333 char line[99];
334 char input[99];
335 #ifdef DEBUG
336 int lineNo = 0;
337 int j;
338 #endif /* DEBUG */
339
340
341 fgets(input, sizeof(input), filePtr); /* Get the (first) line from
342 * the */
343 /* file to which filePtr points. */
344
345 #ifdef DEBUG
346 printf("\nFIRST INPUT >>> %s\n", input);
347 #endif /* DEBUG */
348
349 /* Compare the first character of the input */
350 /* to the comment and the newline strings. */
351
352 if ((strncmp(input, comment, 1) != 0) && (strncmp(input, blankLine, 1) != 0)) {
353 /* Remove the newline character, if present. */
354 /* Replace the last character */
355 /* of the string array with '\0'. */
356
357 input[strlen(input) - 1] = '\0';
358 #ifdef DEBUG
359 printf("First Input >>> %s\n", input);
360 #endif /* DEBUG */
361
362 strcpy(line, input);
363 #ifdef DEBUG
364 printf("First Line after copy >>> %s\n", line);
365 #endif /* DEBUG */
366
367 stringPack(line, input);
368 #ifdef DEBUG
369 printf("Line: %s\n", line);
370 #endif /* DEBUG */
371
372 g_strchomp(line);
373 /*
374 * g_strdelimit(line, " ", ':'); g_strdelimit(line, "\t",
375 * '*');
376 */
377
378 #ifdef DEBUG
379 printf("%3d> %s\n", ++lineNo, line);
380 #endif /* DEBUG */
381
382 /*
383 * g_strsplit() is a GLib function; it returns an array of
384 * strings.
385 *
386 * Here, we split on two spaces, " ". We set max_tokenArray to
387 * be 0. We want the first token to be the name of the
388 * variable and the other tokens to be the value of the
389 * variable, qualifiers, etc.
390 */
391
392 tokenArray = g_strsplit(line, " ", 0);
393
394 #ifdef DEBUG
395 for (j = 0; tokenArray[j] != NULL; j++)
396 printf("token[%d] = %s\n", j, tokenArray[j]);
397 #endif /* DEBUG */
398
399 } /* End of processing the first line, if not commented. */
400
401 /* End of getting the first line. */
402
403
404 /* Get the 2nd line of the file. */
405 fgets(input, sizeof(input), filePtr);
406
407 while (!feof(filePtr)) {
408
409 /* Process the line if it is not commented. */
410 if ((strncmp(input, comment, 1) != 0) && (strncmp(input, blankLine, 1) != 0)) {
411 /* Remove the newline character, if present. */
412 input[strlen(input) - 1] = '\0';
413 #ifdef DEBUG
414 printf("Subsequent Input >>> %s\n", input);
415 #endif /* DEBUG */
416
417 strcpy(line, input);
418 #ifdef DEBUG
419 printf("Subsequent Line after copy >>> %s\n", line);
420 #endif /* DEBUG */
421
422 stringPack(line, input);
423 #ifdef DEBUG
424 printf("Line: %s\n", line);
425 #endif /* DEBUG */
426
427 g_strchomp(line);
428
429 #ifdef DEBUG
430 printf("%3d> %s\n", ++lineNo, line);
431 #endif /* DEBUG */
432
433 /*
434 * See the comment above about the maximum number of
435 * tokens being set to 0.
436 */
437
438 tokenArray = g_strsplit(line, " ", 0);
439
440 #ifdef DEBUG
441 for (j = 0; tokenArray[j] != NULL; j++) {
442 printf("token[%d] = %s\n", j, tokenArray[j]);
443 /* Can also use puts(tokenArray[j]) here. */
444 }
445 #endif /* DEBUG */
446 } /* Processed uncommented lines. */
447
448 fgets(input, sizeof(input), filePtr);
449 } /* Processed the 2nd & subsequent lines of the file. */
450
451 } /* End of processing the opened file. */
452
453
454 void
455 ca_readConfig(const char *configFile, values_t confVars[], int size)
/* [<][>][^][v][top][bottom][index][help] */
456 /*******************************************************************
457 * *
458 * ca_readConfig -- parses the config file and writes the values *
459 * into memory. *
460 * *
461 * Parameters *
462 * configFile -- the configuration file
463 * confVars[] -- the array of values structures *
464 * size -- the number of configuration variables *
465 * *
466 * Returns *
467 * Nothing -- perhaps make this return 0 on successful exit ? *
468 * *
469 * Note: Should we make the name of the config file a global *
470 * variable ? *
471
472 *
473 * Using UT_calloc; no need to check that a NULL pointer is
474 * returned.
475 *
476 *
477 *******************************************************************/
478 {
479 FILE *confPtr; /* Pointer to config file. */
480 char name[STRLENGTH_M]; /* The name of the config variable */
481 /* 80 characters */
482 char value[STRLENGTH_XXL]; /* The value of the variable */
483 /* 640 characters */
484 int location; /* Storage Location of the variable's value. */
485 int type; /* Data type of the variable, represented by an
486 * integer. */
487
488
489 const char *blankLine = "\n"; /* Declared as a string, not a
490 * character. */
491 const char *comment = "#"; /* Declared as a string. */
492
493 char source[16]; /* The name of a source. */
494 char database[STRLENGTH_M]; /* The elements of a database. */
495 /* 80 characters */
496
497 /*
498 * UPDSOURCE variables: whoisd host, query-port, update-port.
499 */
500 char updDetails[STRLENGTH_M]; /* The details of the update host: */
501 /* the name of the qry & upd machine; */
502 /* the query port; */
503 /* the update port. */
504
505
506 gchar **dbcomps; /* Pointer to an array of strings that
507 * represents */
508 /* the components of a db. */
509
510
511 gchar **updDbcomps; /* Pointer to an array of strings that */
512 /* represents the components of an UPD Source. */
513
514 ca_ripadmin_t *newAdminPtr; /* A pointer to a new instance of */
515 /* a ca_ripadmin_t variable. */
516
517 ca_database_t *newUpdDbPtr; /* A pointer to a new instance of */
518 /* ca_database_t, for UPDSOURCE. */
519
520 ca_updDbSource_t *newUpdSrc; /* A pointer to a new instance of */
521 /* ca_updDbSource_t structure. */
522
523 #ifdef DEBUG
524 int i; /* A counting variable used for debugging. */
525 #endif /* DEBUG */
526
527 /*
528 * Function Prototype for ca_getStorageLocation() We put it here;
529 * thus it can only be called from within ca_readConfig()
530 *
531 * This function finds the location in the values_t array where we store
532 * pointers to the string value and the actual value of the variable.
533 * It returns this location as an integer.
534 *
535 */
536 int ca_getStorageLocation(char[], dict_t[], int);
537
538 /*
539 * Function Prototype for ca_getType() We put it here so that it can
540 * only be called from within ca_readConfig()
541 *
542 * This function returns the type of the configuration variable. It
543 * returns it as a string.
544 *
545 */
546 int ca_getType(char[], dict_t[], int);
547
548
549 #ifdef DEBUG
550 printf("\nInside readConfig() function.\n");
551 printf("Configuration file is: %s\n", configFile);
552 #endif /* DEBUG */
553
554 /* create an aray for the multiple source data pointers */
555 confVars[CA_UPDSOURCE].valPtr = (ca_updDbSource_t **) UT_malloc(CA_MAXSOURCES);
556 /* first entry used to check for at least one valid source found */
557 ((ca_updDbSource_t **)confVars[CA_UPDSOURCE].valPtr)[0] = NULL;
558
559 /*
560 * Open the configuration file for reading .....
561 */
562 if ((confPtr = fopen(configFile, "r")) == NULL) {
563 printf("Error: file %s could not be opened.\n", configFile);
564 die;
565 }
566
567 /*
568 * Read the first record in the configuration file ..... We read the
569 * _name_ of the variable using fscanf into a string array. We read
570 * the _value_ of the variable using fgets into an array; thus, we
571 * can handle values of variables with qualifiers (e.g. SPLIT after
572 * DBLIST) and values with blank characters (e.g. REPLYBANNER).
573 */
574 fscanf(confPtr, "%s", name);
575 fgets(value, sizeof(value), confPtr);
576 g_strstrip(value);
577
578
579 /*
580 * While there are records to be read in the config file. write the
581 * current record into memory, read the next record in the config
582 * file
583 */
584
585 while (!feof(confPtr)) {
586
587 /*
588 * From the variable name, find the dictionary number. The
589 * dictionary number is defined as the place in the values
590 * array in which to store the value of the variable.
591 *
592 */
593
594 /*
595 * Process the line only when/if it is not a comment or a
596 * blankline.
597 */
598 if ((strncmp(name, comment, 1) != 0) && (strncmp(name, blankLine, 1) != 0)) {
599 /*
600 * If the last character of "value" is '\n', replace
601 * it with '\0'.
602 */
603 if (value[strlen(value) - 1] == '\n') {
604 value[strlen(value) - 1] = '\0';
605 }
606
607 /*
608 * From the variable name, find the element of the
609 * values array in which to store the value of the
610 * variable.
611 *
612 */
613 location = ca_getStorageLocation(name, dictionary, VARS);
614
615 #ifdef DEBUG
616 printf("The location is: %d\n", location);
617 #endif /* DEBUG */
618
619 /*
620 * See if the string value has already been stored;
621 * if it has, then concatenate the new value to it;
622 * if not, then allocate some memory and copy the
623 * string into it.
624 */
625
626 /*
627 * If this variable already exists, it has a non-zero
628 * value and this 'if' statement returns a "true"
629 * value. Otherwise, it returns a "zero" or "false"
630 * value.
631 */
632 if (confVars[location].strPtr) {
633 /*
634 * strcat(confVars[location].strPtr, "\n");
635 * strcat(confVars[location].strPtr, value);
636 */
637 g_string_append(confVars[location].strPtr, "\n");
638 g_string_append(confVars[location].strPtr, value);
639 }
640 else {
641 /*
642 * Store a pointer to the string that
643 * contains the value This is not necessarily
644 * the actual value itself.
645 */
646
647 confVars[location].strPtr = g_string_new(value);
648 }
649
650 /*
651 * Now, store a pointer to the _value_ of the
652 * variable. Do this as follows: (a) get the _type_
653 * of the variable (b) store a pointer to the value
654 * of the variable in a way that depends on the
655 * _type_ of the variable.
656 */
657 #ifdef DEBUG
658 printf("Variable \"%s\" is data-type \"%d\"\n", name, ca_getType(name, dictionary, VARS));
659 #endif /* DEBUG */
660
661
662 type = ca_getType(name, dictionary, VARS);
663
664 /*
665 * Given the _type_ of the variable, store the value
666 * of the variable in the appropriate way.
667 */
668 switch (type) {
669 case 11:
670
671 #ifdef DEBUG
672 puts("Data type is Integer");
673 #endif /* DEBUG */
674
675 confVars[location].valPtr = UT_malloc(sizeof(int));
676
677 sscanf(value, "%d", (int *) confVars[location].valPtr);
678 break;
679
680 case 12:
681
682 #ifdef DEBUG
683 puts("Data type is String !!! *** !!!");
684 #endif /* DEBUG */
685
686
687 /*
688 * Test if this variable has already been
689 * created. Look for a non-zero i.e. true
690 * value.
691 *
692 * First put a '\n' character at the end of the
693 * existing string. Then, concatenate the
694 * additional string.
695 */
696 if (confVars[location].valPtr) {
697 #ifdef DEBUG
698 printf("\n%s variable already exists\n", name);
699 #endif /* DEBUG */
700 g_string_append(confVars[location].valPtr, value);
701 g_string_append(confVars[location].valPtr, "\n");
702 }
703 else {
704 /*
705 * If the variable has not already
706 * been created, then create it.
707 */
708 #ifdef DEBUG
709 printf("\n%s variable does not exist\n", name);
710 #endif /* DEBUG */
711
712 /*
713 * We use g_string_new() to create a
714 * new GString. This is a _structure_
715 * of str and len. The actual string
716 * is stored in the str component.
717 * Thus, when we want to access the
718 * string, we must look into
719 * structure.
720 */
721 confVars[location].valPtr = g_string_new(value);
722 g_string_append(confVars[location].valPtr, "\n");
723 }
724
725 break;
726
727 case 13:
728 #ifdef DEBUG
729 puts("Data type is Dirlist");
730 #endif /* DEBUG */
731 confVars[location].valPtr = (char *) UT_malloc(STRLENGTH);
732
733 strcpy(confVars[location].valPtr, value);
734 break;
735
736 case 14:
737 #ifdef DEBUG
738 puts("Data type is Boolean");
739 #endif /* DEBUG */
740
741 confVars[location].valPtr = UT_malloc(sizeof(int));
742
743 sscanf(value, "%d", (int *) confVars[location].valPtr);
744 break;
745
746
747 case 16:
748 #ifdef DEBUG
749 puts("Found the CA_ADMIN stuff !!!");
750 #endif /* DEBUG */
751 /*
752 * The elements of the Admin-DB have already
753 * been read in.
754 * Now, split up the elements and assign them
755 * to the
756 * components of the Admin-DB structure.
757 *
758 * First, separate the values in "value",
759 * using ',' as a
760 * delimiting character.
761 */
762 dbcomps = g_strsplit(value, ",", 0);
763
764 #ifdef DEBUG
765 for (i = 0; dbcomps[i] != NULL; i++)
766 printf("dbcomps[%d] = %s\n", i, dbcomps[i]);
767 #endif /* DEBUG */
768
769 /*
770 * Now, allocate some memory to the
771 * newAdminPtr.
772 */
773 newAdminPtr = UT_calloc(1, sizeof(ca_ripadmin_t));
774
775 /*
776 * Now, assign the elements of the dbcomps
777 * array to the appropriate components of the
778 * structure to which newAdminPtr points.
779 */
780
781 /*
782 * Strip leading and trailing whitespace from
783 * dbcomps[0]
784 */
785 /*
786 * g_strstrip( dbcomps[0] );
787 */
788
789 strcpy(newAdminPtr->host, dbcomps[0]);
790 newAdminPtr->port = atoi(dbcomps[1]);
791 strcpy(newAdminPtr->user, dbcomps[2]);
792 strcpy(newAdminPtr->password, dbcomps[3]);
793 strcpy(newAdminPtr->tableName, dbcomps[4]);
794
795 g_strfreev(dbcomps);
796
797 #ifdef DEBUG
798 puts("Testing the population of the rip-admin db structure:");
799 printf("\n%s::%d::%s::%s::%s\n", newAdminPtr->host, newAdminPtr->port, newAdminPtr->user, newAdminPtr->password, newAdminPtr->tableName);
800 #endif /* DEBUG */
801
802 /*
803 * Now, assign these values into the correct
804 * long-term storage.
805 */
806
807 confVars[location].valPtr = (ca_ripadmin_t *) UT_calloc(1, sizeof(ca_ripadmin_t));
808
809 memcpy(confVars[location].valPtr, newAdminPtr, sizeof(ca_ripadmin_t));
810
811 UT_free(newAdminPtr);
812
813 #ifdef DEBUG
814 printf("The ripadmin machine is: %s\n", ((ca_ripadmin_t *) confVars[location].valPtr)->host);
815 #endif /* DEBUG */
816
817 break;
818
819 case 17:
820 /*
821 * Found Update_Source variable.
822 There may be multiple instances of this
823 */
824 #ifdef DEBUG
825 printf("Found Update_Source variable !!!\n");
826 #endif /* DEBUG */
827
828 #ifdef DEBUG
829 puts(name);
830 puts(value);
831 #endif /* DEBUG */
832
833 /*
834 * Split the value into DB-name, DB-details,
835 * updDetails. Use blankspace as the
836 * delimiter between each of these variables.
837 */
838 sscanf(value, "%s %s %s", source, database, updDetails);
839 #ifdef DEBUG
840 puts(source);
841 puts(database);
842 puts(updDetails);
843 #endif /* DEBUG */
844
845 /*
846 * Using the values in "database", populate a
847 * ca_database_t structure. Give this
848 * variable a name.
849 */
850
851 /*
852 * First, separate the values in "database",
853 * using "," as as a delimiting character.
854 */
855 dbcomps = g_strsplit(database, ",", 0);
856
857 #ifdef DEBUG
858 for (i = 0; dbcomps[i] != NULL; i++)
859 printf("dbcomps[%d] = %s\n", i, dbcomps[i]);
860 #endif /* DEBUG */
861
862 /*
863 * Create a structure for this database.
864 */
865 newUpdDbPtr = UT_calloc(1, sizeof(ca_database_t));
866
867 strcpy(newUpdDbPtr->host, dbcomps[0]);
868 newUpdDbPtr->port = atoi(dbcomps[1]);
869 strcpy(newUpdDbPtr->user, dbcomps[2]);
870 strcpy(newUpdDbPtr->password, dbcomps[3]);
871 strcpy(newUpdDbPtr->dbName, dbcomps[4]);
872
873 g_strfreev(dbcomps);
874
875 #ifdef DEBUG
876 puts("Testing the population of the UPD db structure:");
877 printf("\n%s::%d::%s::%s::%s\n", newUpdDbPtr->host, newUpdDbPtr->port, newUpdDbPtr->user, newUpdDbPtr->password, newUpdDbPtr->dbName);
878 #endif /* DEBUG */
879
880 /*
881 * Now, store the values contained in the
882 * updDetails string.
883 */
884
885 /*
886 * First, separate the values in the
887 * 'updDetails' string, using "," as a
888 * delimiting character.
889 */
890 updDbcomps = g_strsplit(updDetails, ",", 0);
891
892 #ifdef DEBUG
893 for (i = 0; updDbcomps[i] != NULL; i++)
894 printf("updDbcomps[%d] = %s\n", i, updDbcomps[i]);
895 #endif /* DEBUG */
896
897 /*
898 * Using the above ca_database_t structure,
899 * the "source" value and the values of
900 * updDbcomps, populate the ca_updDbSource_t
901 * structure.
902 *
903 */
904
905 /*
906 * Create a new structure for this UPD
907 * Source.
908 */
909 newUpdSrc = UT_calloc(1, sizeof(ca_updDbSource_t));
910
911 #ifdef DEBUG
912 puts("Created a structure for the UPD Source variable");
913 #endif /* DEBUG */
914
915 /*
916 * Now, populate this structure.
917 */
918
919 strcpy(newUpdSrc->name, source);
920 newUpdSrc->updDb = *newUpdDbPtr;
921 strcpy(newUpdSrc->whoisd_host, updDbcomps[0]);
922 newUpdSrc->qryPort = atoi(updDbcomps[1]);
923 newUpdSrc->updPort = atoi(updDbcomps[2]);
924
925 UT_free(newUpdDbPtr); /* Was copied */
926 g_strfreev(updDbcomps);
927
928 #ifdef DEBUG
929 puts("Testing the population of the ca_updDbSource_t structure:");
930 printf("Update Source name: %s\n", newUpdSrc->name);
931 printf("\nUPD-DB == %s::%d::%s::%s::%s\n", (newUpdSrc->updDb).host, (newUpdSrc->updDb).port, (newUpdSrc->updDb).user, (newUpdSrc->updDb).password, (newUpdSrc->updDb).dbName);
932 printf("\nUpdate Source Machine Details: %s::%d::%d\n", newUpdSrc->whoisd_host, newUpdSrc->qryPort, newUpdSrc->updPort);
933 #endif /* DEBUG */
934
935 /*
936 * Now, assign these values into the correct
937 * long-term storage.
938 */
939
940 if ( num_sources < CA_MAXSOURCES )
941 {
942 ((ca_updDbSource_t **)confVars[location].valPtr)[num_sources] = (ca_updDbSource_t *) UT_calloc(1, sizeof(ca_updDbSource_t));
943
944 memcpy( ((ca_updDbSource_t **)confVars[location].valPtr)[num_sources++], newUpdSrc, sizeof(ca_updDbSource_t));
945 }
946 else
947 {
948 fprintf(stderr, "Max number of Update Sources exceeded\n");
949 die;
950 }
951
952 /* No longer needed. */
953 UT_free(newUpdSrc);
954
955 #ifdef DEBUG
956 printf("UPD-Source/DB-details/user: %s\n", (((ca_updDbSource_t *) (confVars[location].valPtr)[num_sources-1])->updDb).user);
957 #endif /* DEBUG */
958
959 break;
960
961 default:
962 fprintf(stderr, "Data type not found for variable \"%s\".\n", name);
963 die;
964 break;
965 }
966 }
967
968 fscanf(confPtr, "%s", name);
969 fgets(value, sizeof(value), confPtr);
970 g_strstrip(value);
971
972 } /* End of processing the config file. */
973
974 } /* End of readConfig() function */
975
976
977
978
979 void
980 ca_getDictionary(dict_t woordenboek[], int size)
/* [<][>][^][v][top][bottom][index][help] */
981 {
982 int k;
983
984 for (k = 0; k < size; k++) {
985 printf("\nj = %d\n", k);
986 /*
987 * printf("%s\t%d\t%s\n", woordenboek[k].varName,
988 * woordenboek[k].varScope, woordenboek[k].varType);
989 */
990 printf("%s\t%s\t%s\t%d\n", woordenboek[k].varName, woordenboek[k].varSym, woordenboek[k].varType, woordenboek[k].varNum);
991
992 }
993 }
994
995
996 int
997 ca_get_int(int symbol)
/* [<][>][^][v][top][bottom][index][help] */
998 {
999 int *xPtr;
1000
1001 /*
1002 * First print a message saying that the ca_get_int() function is
1003 * being called.
1004 */
1005 #ifdef DEBUG
1006 printf("\nDEBUG: ca_get_int() function is called .....\n");
1007 printf("DEBUG: New value of StringPtr: %s\n", confVars[symbol].strPtr);
1008 #endif /* DEBUG */
1009
1010 /*
1011 * Look at the appropriate place in the dictionary; e.g. C_BINDPORT
1012 * => the first element, index = 0.
1013 *
1014 * if the varType is not an integer, exit with an error;
1015 *
1016 * otherwise, return an integer.
1017 *
1018 */
1019
1020 /* Look at the appropriate place in the dictionary. */
1021
1022 #ifdef DEBUG
1023 printf("\nDEBUG: Variable type: %s\n", dictionary[symbol].varType);
1024 #endif /* DEBUG */
1025
1026 /* If the variable type is not an integer, exit with an error. */
1027 if (strcmp(dictionary[symbol].varType, "CA_INT") != 0) {
1028 fprintf(stderr, "Error: unexpected variable type.\n");
1029 die;
1030 }
1031 else {
1032 /*
1033 * Lock the value of the variable before reading it.
1034 */
1035
1036 pthread_mutex_lock(&Lock);
1037
1038 xPtr = confVars[symbol].valPtr;
1039 /*
1040 * Unlock the value of the variable after reading it.
1041 */
1042 pthread_mutex_unlock(&Lock);
1043 }
1044
1045 if (xPtr == NULL) {
1046 printf("Error: undefined integer variable: %s\n ", dictionary[symbol].varName);
1047
1048 die;
1049 }
1050 return (*xPtr);
1051 }
1052
1053 char *
1054 ca_get_dirlist(int symbol)
/* [<][>][^][v][top][bottom][index][help] */
1055 {
1056 /*
1057 * This function returns a pointer to a character array. Thus, we
1058 * need to declare such a pointer.
1059 *
1060 */
1061
1062 char *xPtr;
1063 #ifdef DEBUG
1064 printf("\nca_get_dirlist() function is called .....\n");
1065 #endif /* DEBUG */
1066
1067
1068 /*
1069 * Look at the appropriate place in the dictionary; e.g. CA_HELP =>
1070 * the second element, index = 1.
1071 *
1072 * if the varType is not CA_DIRLIST, exit with an error;
1073 *
1074 * otherwise, return a pointer to the value.
1075 *
1076 */
1077
1078 /* Look at the appropriate place in the dictionary. */
1079 #ifdef DEBUG
1080 printf("\nVariable type: %s\n", dictionary[symbol].varType);
1081 #endif /* DEBUG */
1082
1083 /* If the variable type is not CA_DIRLIST, exit with an error. */
1084 if (strcmp(dictionary[symbol].varType, "CA_DIRLIST") != 0) {
1085 fprintf(stderr, "Error: unexpected variable type.\n");
1086 die;
1087 }
1088 else {
1089 pthread_mutex_lock(&Lock);
1090 /*
1091 * Test if a value for this variable has been defined. If
1092 * yes, return a copy of it. If not, print an error message
1093 * and die.
1094 */
1095 if (confVars[symbol].valPtr) {
1096 xPtr = (UT_strdup(confVars[symbol].valPtr));
1097 #ifdef DEBUG
1098 printf("Value: %s\n", xPtr);
1099 #endif /* DEBUG */
1100 }
1101 else {
1102 printf("Error: undefined DIRLIST variable: %s\n", dictionary[symbol].varName);
1103 die;
1104 }
1105 pthread_mutex_unlock(&Lock);
1106 }
1107 return (xPtr);
1108 }
1109
1110
1111 char *
1112 ca_get_string(int symbol)
/* [<][>][^][v][top][bottom][index][help] */
1113 {
1114 /*
1115 * This function returns a pointer to a character array. Thus, we
1116 * need to declare such a pointer.
1117 *
1118 */
1119
1120 char *xPtr;
1121 #ifdef DEBUG
1122 printf("\nca_get_text() function is called .....\n");
1123 #endif /* DEBUG */
1124
1125
1126 /*
1127 * Look at the appropriate place in the dictionary; e.g.
1128 * CA_REPLYBANNER => the third element, index = 2.
1129 *
1130 * if the varType is not CA_STRING, exit with an error;
1131 *
1132 * otherwise, return the value.
1133 *
1134 */
1135
1136 /* Look at the appropriate place in the dictionary. */
1137
1138 #ifdef DEBUG
1139 printf("\nVariable type: %s\n", dictionary[symbol].varType);
1140 #endif /* DEBUG */
1141
1142 /* If the variable type is not CA_STRING, exit with an error. */
1143 if (strcmp(dictionary[symbol].varType, "CA_STRING") != 0) {
1144 fprintf(stderr, "Error: unexpected variable type.\n");
1145 die;
1146 }
1147 else {
1148 pthread_mutex_lock(&Lock);
1149
1150 /*
1151 * Test if a value for this variable has been defined. If
1152 * yes, return a copy of it. If not, return a NULL pointer.
1153 */
1154 if (((GString *) confVars[symbol].valPtr)) {
1155 xPtr = (UT_strdup(((GString *) confVars[symbol].valPtr)->str));
1156 #ifdef DEBUG
1157 printf("Value: %s\n", xPtr);
1158 #endif /* DEBUG */
1159 }
1160 else {
1161 #ifdef DEBUG
1162 printf("STRING value is undefined !!!\n");
1163 #endif /* DEBUG */
1164 xPtr = NULL;
1165 }
1166 pthread_mutex_unlock(&Lock);
1167 }
1168 return (xPtr);
1169 }
1170
1171
1172 int
1173 ca_get_boolean(int symbol)
/* [<][>][^][v][top][bottom][index][help] */
1174 {
1175 /**********************************************
1176 * ca_get_boolean() *
1177 * *
1178 * *
1179 * Parameters *
1180 * *
1181 * symbol -- the symbol for the variable *
1182 * *
1183 * *
1184 * Returns *
1185 * *
1186 * 1 if true, 0 if false. *
1187 * *
1188 * Remarks *
1189 * *
1190 * Is there a better way to implement *
1191 * Boolean values in C ? *
1192 * *
1193 *********************************************/
1194
1195 int *xPtr;
1196
1197 /*
1198 * Print this message if in debug mode.
1199 *
1200 */
1201 #ifdef DEBUG
1202 printf("\nca_get_boolean() function is called .....\n");
1203 printf("DEBUG 5: New value of StringPtr: %s\n", globals[symbol].strPtr);
1204 #endif /* DEBUG */
1205
1206 /**********************************************\
1207 * *
1208 * Here is how this works: *
1209 * *
1210 * (a) Check that the type of variable whose *
1211 * value is being read is CA_BOOLEAN. *
1212 * *
1213 * (b) Lock the value of the variable before *
1214 * reading it. *
1215 * *
1216 * (c) Depending on the scope of the variable *
1217 * look for it in the appropriate array. *
1218 * *
1219 * (d) Read the value of the variable. *
1220 * *
1221 * (e) Unlock the value of the variable after *
1222 * reading it. *
1223 * *
1224 * *
1225 * Returns *
1226 *
1227 * an integer value as follows: *
1228 * 1 if the db is in testmode (true), *
1229 * 0 if the db is not in testmode (false). *
1230 \*********************************************/
1231
1232
1233 /*
1234 * Look at the appropriate place in the dictionary; e.g. CA_BOOLEAN =
1235 * the fifth element of the dict_t array, => index = 4.
1236 *
1237 * If the varType is not Boolean, exit with an error
1238 *
1239 * Otherwise,
1240 *
1241 */
1242
1243 #ifdef DEBUG
1244 /* Look in the appropriate place in the dictionary. */
1245 printf("\nVariable type: %s\n", dictionary[symbol].varType);
1246 #endif /* DEBUG */
1247
1248 /* If the variable type is not Boolean, exit with an error. */
1249
1250 if (strcmp(dictionary[symbol].varType, "CA_BOOLEAN") != 0) {
1251 fprintf(stderr, "Error: Boolean type expected.\n");
1252 die;
1253 }
1254
1255 else {
1256
1257 /*
1258 * Otherwise, return an integer value.
1259 *
1260 */
1261
1262 /*
1263 * Lock the value of the variable before reading it.
1264 *
1265 */
1266
1267 pthread_mutex_lock(&Lock);
1268 xPtr = confVars[symbol].valPtr;
1269 /*
1270 * Unlock the value of the variable after reading it.
1271 */
1272 pthread_mutex_unlock(&Lock);
1273
1274 }
1275 if (xPtr == NULL) {
1276 printf("Undefined Boolean variable: %s\n", dictionary[symbol].varName);
1277 die;
1278 }
1279 return (*xPtr);
1280 }
1281
1282
1283
1284 void
1285 ca_set_int(int symbol)
/* [<][>][^][v][top][bottom][index][help] */
1286 {
1287 /*********************************************
1288 * ca_set_int() *
1289 * *
1290 * Parameters *
1291 * symbol -- the symbol for the variable. *
1292 * *
1293 * Returns *
1294 * 1 if successful 0 if not ? *
1295 * *
1296 * Remarks *
1297 * Needs a better way to check for valid *
1298 * values from the keyboard. *
1299 * *
1300 *********************************************/
1301
1302 /*
1303 * void *tempPtr;
1304 *//* Temp pointer to point to the value pointer in the appropriate
1305 * values array. */
1306 char newPort[16];
1307 int invalid;
1308 int portNr;
1309
1310 /*
1311 * Function to change the value in a given values array. This
1312 * function can only be called from within ca_set_int().
1313 */
1314 int *ca_change_int_value(char[]);
1315 void testFunction(values_t values[]);
1316
1317 /*
1318 * Using the symbol, look at the appropriate place in the dictionary.
1319 */
1320 #ifdef DEBUG
1321 printf("\nca_set_int() function called .....\n");
1322 printf("Variable type: %s\n", dictionary[symbol].varType);
1323 #endif /* DEBUG */
1324
1325
1326 /*
1327 * Make sure that a reasonable, sensible value of bind-port has been
1328 * read from the keyboard.
1329 */
1330
1331 do {
1332
1333 /*
1334 * First, flush input stream.
1335 */
1336 fflush(stdin);
1337
1338 /*
1339 * Prompt for the new value of the bind-port.
1340 */
1341
1342 printf("\nNew value of bind-port (non-zero positive integer) >>> ");
1343 scanf("%s", newPort);
1344 /*
1345 * gets(newPort);
1346 */
1347 #ifdef DEBUG
1348 printf("\nDEBUG: Value of newPort variable: %s\n", newPort);
1349 #endif /* DEBUG */
1350
1351 sscanf(newPort, "%d", &portNr);
1352
1353 #ifdef DEBUG
1354 printf("\nDEBUG: Value of integer variable, portNr: %d\n", portNr);
1355 #endif /* DEBUG */
1356
1357 if (portNr < 0) {
1358 invalid = 1;
1359 puts("Only non-zero positive integer values accepted for bind-port");
1360 }
1361 else {
1362 invalid = 0;
1363 }
1364
1365 } while (invalid);
1366
1367 /*
1368 * Check that the function is attempting to set the correct type of
1369 * value. If not, do not set the value and exit.
1370 */
1371
1372 if (strcmp(dictionary[symbol].varType, "CA_INT") != 0) {
1373 fprintf(stderr, "Error: unexpected variable type.\n");
1374 die;
1375 }
1376
1377 /*
1378 * Choose the appropriate values array.
1379 */
1380 switch (dictionary[symbol].varScope) {
1381 /*
1382 * If the variable has global scope, write it into the
1383 * globals array. If it has local scope, write it into the
1384 * local array. If the scope cannot be found, then report an
1385 * error.
1386 */
1387 case 1:
1388 globals[symbol].valPtr = ca_change_int_value(newPort);
1389
1390 /************************************************************
1391 * *
1392 * We comment out this code. We use the GLib string *
1393 * now. It also checks if we got the memory :-) *
1394 * *
1395 ************************************************************/
1396
1397 /*
1398 * globals[symbol].strPtr = newPort;
1399 *
1400 * globals[symbol].strPtr = (char *) calloc(1, sizeof(newPort));
1401 */
1402
1403 /*
1404 * Check the return value of calloc() to make sure that we
1405 * actually got the memory.
1406 */
1407
1408 /*
1409 * if (globals[symbol].strPtr == NULL) {
1410 * fprintf(stderr, "Cannot allocate memory for globals[symbol].strPtr.\n");
1411 * die;
1412 * }
1413 */
1414
1415 #ifdef DEBUG
1416 printf("DEBUG: New value of StringPtr: %s\n", globals[symbol].strPtr);
1417 #endif /* DEBUG */
1418
1419 /*
1420 * strcpy(globals[symbol].strPtr, newPort);
1421 */
1422
1423 g_string_assign (globals[symbol].strPtr, newPort);
1424
1425
1426 #ifdef DEBUG
1427 printf("DEBUG 2: New value of StringPtr: %s\n", globals[symbol].strPtr);
1428 #endif /* DEBUG */
1429 break;
1430
1431 case 99:
1432 locals[symbol].valPtr = ca_change_int_value(newPort);
1433 /*
1434 * First allocate some memory and then copy the value of the
1435 * new Port into it.
1436 */
1437
1438 /************************************************************
1439 * *
1440 * We comment out this code. We use the GLib string *
1441 * now. It also checks if we got the memory :-) *
1442 * *
1443 ************************************************************/
1444
1445 /*
1446 * locals[symbol].strPtr = (char *) calloc(1, sizeof(newPort));
1447 */
1448
1449 /*
1450 * Now, check that the memory was actually allocated.
1451 */
1452
1453 /*
1454 * if (locals[symbol].strPtr == NULL) {
1455 * fprintf(stderr, "Cannot allocate memory for locals[symbol].strPtr\n");
1456 * exit(8);
1457 * }
1458 *
1459 * strcpy(locals[symbol].strPtr, newPort);
1460 */
1461
1462 g_string_assign (locals[symbol].strPtr, newPort);
1463
1464 /*
1465 * locals[symbol].strPtr = newPort;
1466 */
1467 break;
1468
1469 default:
1470 fprintf(stderr, "Error; unknown scope: %d\n", dictionary[symbol].varScope);
1471 break;
1472 }
1473
1474 /*
1475 * Write the new value of the variable to the correct place in this
1476 * array. (First, set a mutex lock ???).
1477 */
1478
1479 /*
1480 * Write the new value of this variable back to the config. file
1481 */
1482
1483 ca_writeNewValue(symbol, newPort);
1484
1485 printf("DEBUG 3: New value of StringPtr: %s\n", (globals[symbol].strPtr)->str);
1486
1487 }
1488
1489 int *
1490 ca_change_int_value(char value[])
/* [<][>][^][v][top][bottom][index][help] */
1491 {
1492 void *tempPtr;
1493
1494 tempPtr = UT_malloc(sizeof(int));
1495
1496 /*
1497 * No need to check the return value of UT_malloc() in case we did not
1498 * actually get the memory.
1499 *
1500 *if (tempPtr == NULL) {
1501 * fprintf(stderr, "Cannot allocate memory for tempPtr\n");
1502 * die;
1503 * }
1504 */
1505
1506 sscanf(value, "%d", (int *) tempPtr);
1507 return (tempPtr);
1508 }
1509
1510
1511
1512 void
1513 testFunction(values_t array[])
/* [<][>][^][v][top][bottom][index][help] */
1514 {
1515 printf("\nInside the Test function.\n");
1516 }
1517
1518
1519 void
1520 ca_getDatabase(ca_database_t db)
/* [<][>][^][v][top][bottom][index][help] */
1521 {
1522 printf("\n%s\t%d\t%s\t%s\t%s\n", db.host, db.port, db.user, db.password, db.dbName);
1523 }
1524
1525 void
1526 ca_getSource(ca_database_list_t src)
/* [<][>][^][v][top][bottom][index][help] */
1527 {
1528 printf("\n%s\t%s\t%d\t%s\t%s\t%s\n", src.name, (src.db).host, (src.db).port, (src.db).user, (src.db).password, (src.db).dbName);
1529 }
1530
1531
1532 void
1533 ca_getAllSources(GSList * sources)
/* [<][>][^][v][top][bottom][index][help] */
1534 {
1535
1536 GSList *currentPtr; /* Pointer to the structure at which we look. */
1537
1538 /*
1539 * Look at the first member of the linked-list of sources.
1540 */
1541 currentPtr = sources;
1542
1543 /*
1544 * Look at each data component of the source list, untill we reach
1545 * the end of the list.
1546 */
1547 while (currentPtr != NULL) {
1548 ca_database_list_t *srcPtr = currentPtr->data;
1549 printf("\n%s\t%s\t%d\t%s\t%s\t%s\n", srcPtr->name, (srcPtr->db).host, (srcPtr->db).port, (srcPtr->db).user, (srcPtr->db).password, (srcPtr->db).dbName);
1550 currentPtr = currentPtr->next;
1551 }
1552 }
1553
1554 void
1555 ca_getAsource(char *sourceName, GSList * sources)
/* [<][>][^][v][top][bottom][index][help] */
1556 /*******************************************************************
1557 * ca_getAsource -- looks for a source in the linked list *
1558 * *
1559 * Parameters *
1560 * sourceName -- the name of a source for which to look *
1561 * sources -- the list of sources in which to look *
1562 * *
1563 * Returns *
1564 * nothing, so far. *
1565 * *
1566 *******************************************************************/
1567 {
1568
1569 GSList *currentPtr = sources;
1570
1571 #ifdef DEBUG
1572 printf("\nLooking for source: %s\n", sourceName);
1573 #endif /* DEBUG */
1574
1575 /*
1576 * Look at each data component of the source list, compare the name
1577 * of the source with the sourceName untill we find the source o we
1578 * reach the end of the list
1579 */
1580 { /* Begin special block I got a syntax error when I defined
1581 * "ca_database_list_t *srcPtr = currentPtr->data;" in the
1582 * usual way, with all the other local variables.
1583 *
1584 * However, if I define it inside this block, I do not get any
1585 * syntax errors.
1586 *
1587 */
1588
1589
1590 ca_database_list_t *srcPtr = currentPtr->data;
1591 #ifdef DEBUG
1592 printf("FirstSource is: %s\n", srcPtr->name);
1593 #endif /* DEBUG */
1594 while ((currentPtr != NULL) && (strcmp(srcPtr->name, sourceName) != 0)) {
1595 #ifdef DEBUG
1596 puts("Now printing the current source .....");
1597 printf("CurrentSource is: %s\n", srcPtr->name);
1598 printf("%d\n", strcmp(srcPtr->name, sourceName));
1599 if (strcmp(srcPtr->name, sourceName) == 0) {
1600 printf("Found it !!! Source: %s\n", srcPtr->name);
1601 }
1602 #endif /* DEBUG */
1603 currentPtr = currentPtr->next;
1604 puts("currentPtr = currentPtr->next");
1605 if (currentPtr != NULL) {
1606 srcPtr = currentPtr->data;
1607 puts("srcPtr = currentPtr->data");
1608 }
1609 #ifdef DEBUG
1610 puts("At the end of the while loop inside ca_getAsource function .....");
1611 printf("The NewSource is: %s\n", srcPtr->name);
1612 #endif /* DEBUG */
1613 }
1614 #ifdef DEBUG
1615 puts("Exited from while loop in ca_getAsource function .....");
1616 #endif /* DEBUG */
1617
1618 if (currentPtr != NULL) {
1619 printf("\nFound the source: %s\n", srcPtr->name);
1620 /*
1621 * printf("\n%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
1622 * srcPtr->name, (srcPtr->db).host,
1623 * (srcPtr->db).port, (srcPtr->db).user,
1624 * (srcPtr->db).password, (srcPtr->db).canupd,
1625 * (srcPtr->db).deflook, (srcPtr->db).dbName);
1626 */
1627 }
1628 else {
1629 printf("\nCould not find source: %s\n", sourceName);
1630 }
1631 } /* End special block */
1632
1633 }
1634
1635
1636 ca_dbSource_t *
1637 ca_getSourceDetails(char *sourceName, GSList * sources)
/* [<][>][^][v][top][bottom][index][help] */
1638 /*******************************************************************
1639 * ca_getSourceDetails *
1640 * -- A function that compares each 'name' component of every *
1641 * ca_database_list_t element in the linked-list of sources *
1642 * (the first element of which is a parameter of this function)*
1643 * with the name of the source to be found. If the required *
1644 * source is found, a pointer to the structure representing *
1645 * this source is returned. *
1646 * *
1647 * Parameters *
1648 * -- sourceName - the name of the required source *
1649 * -- sources - the list of sources in which to look *
1650 * *
1651 * Returns *
1652 * -- srcPtr - a pointer to the structure representing the source *
1653 * - or a pointer to NULL, if we cannot find the source *
1654 * *
1655 *******************************************************************/
1656 {
1657 /*
1658 * Define a pointer to the current element in the linked list.
1659 * Initialise it to the start of the list;
1660 */
1661 GSList *currentPtr = sources;
1662
1663 /*
1664 * Define and initialise a pointer that points to the 'data'
1665 * component of the GSList struct; i.e. a pointer to a variable of
1666 * type ca_dbSource_t.
1667 */
1668 ca_dbSource_t *srcPtr = currentPtr->data;
1669
1670
1671 /*
1672 * Look at each data component of list of sources; (each data
1673 * component is a structure of type ca_dbSource_t i.e.
1674 * ca_database_list_t). Compare the 'name' component of of each
1675 * ca_dbSource_t structure with the value of sourceName untill we get
1676 * a match or we reach the end of the list.
1677 */
1678 /*
1679 * We first check if currentPtr is pointing to NULL; if yes, we exit
1680 * the while loop; if no, we make srcPtr point to the data component
1681 * of the current dbSource structure; then, we check if this is the
1682 * source name that we want; if yes, we _break_ from the while loop.
1683 */
1684 while (currentPtr != NULL) {
1685 srcPtr = currentPtr->data;
1686 if (strcasecmp(srcPtr->name, sourceName) == 0)
1687 break;
1688 currentPtr = currentPtr->next;
1689 }
1690
1691 /*
1692 * We return a pointer. If we found the source, this pointer points
1693 * to the ca_dbSource_t structure which represents the source. If we
1694 * did not find the source, we return a pointer to NULL.
1695 */
1696 if (currentPtr == NULL) {
1697 srcPtr = NULL;
1698 return (srcPtr);
1699 }
1700 else {
1701 return (srcPtr);
1702 }
1703
1704 } /* End of ca_getSourceDetails function */
1705
1706
1707 ca_SrcHdl_t *
1708 ca_get_SourceHandleByPosition(int position)
/* [<][>][^][v][top][bottom][index][help] */
1709 /*******************************************************************
1710 * ca_get_SourceHandleByPosition *
1711 * -- retrieves the a handle to a Source *
1712 * *
1713 * Parameters *
1714 * -- the position in the linked list of sources *
1715 * *
1716 * *
1717 * Returns *
1718 * -- a pointer to the source or NULL *
1719 * i.e. a pointer to the data component of the appropriate *
1720 * element in the linked list of sources. *
1721 *******************************************************************/
1722 {
1723 ca_dbSource_t *mySource;
1724
1725 mySource = g_slist_nth_data(sourceList, position);
1726 return (mySource);
1727 }
1728
1729 ca_SrcHdl_t *
1730 ca_get_SourceHandleByName(char *srcName)
/* [<][>][^][v][top][bottom][index][help] */
1731 /*******************************************************************
1732 * ca_get_SourceHandleByName *
1733 * -- retrieves the a handle to a source *
1734 * *
1735 * Parameters *
1736 * -- the name of the required source
1737 * *
1738 * *
1739 * Returns *
1740 * -- a pointer to the source or NULL *
1741 * i.e. a pointer to the data component of the appropriate *
1742 * element in the linked list of sources. *
1743 *******************************************************************/
1744
1745 {
1746 ca_dbSource_t *mySource;
1747
1748 mySource = ca_getSourceDetails(srcName, sourceList);
1749 return (mySource);
1750 }
1751
1752 char *
1753 ca_srchandle2Strelement(ca_SrcHdl_t * ah, int srcAttrib)
/* [<][>][^][v][top][bottom][index][help] */
1754 /*******************************************************************
1755 * ca_srchandle2Strelement *
1756 * -- returns a string which represents the attribute of a source *
1757 * e.g. returns the name of a source *
1758 * It allocates the required memory; *
1759 * but it returns NULL if the required memory cannot be *
1760 * allocated.
1761 * *
1762 * Parameters *
1763 * -- source name - the name of the source
1764 * ca_get_SourceHandleByName or ca_get_SourceHandleByPosition *
1765 * *
1766 * -- srcAttrib - an integer which represents the required *
1767 * attribute of the source. We use #define statments to make *
1768 * a mapping between the attributes and the integers. *
1769 * *
1770 * Returns *
1771 * -- a string or NULL *
1772 *******************************************************************/
1773 {
1774 char *myStr;
1775
1776 if (ah == NULL) {
1777 fprintf(stderr, "ca_srchandle2Strelement(): Cannot dereference NULL pointer\n");
1778 die;
1779 }
1780
1781 pthread_mutex_lock(&Lock);
1782 switch (srcAttrib) {
1783 case 0:
1784 /* source name */
1785 myStr = UT_strdup(ah->name);
1786 break;
1787
1788 case 1:
1789 /* canupd */
1790 myStr = UT_strdup(ah->canupd);
1791 break;
1792
1793 case 2:
1794 /* deflook */
1795 /*
1796 * ca_malloc(myStr, 2); strcpy(myStr, (ah->db).deflook);
1797 */
1798 myStr = UT_strdup(ah->deflook);
1799 break;
1800
1801 case 3:
1802 /* machine */
1803 myStr = UT_strdup((ah->db).host);
1804 break;
1805
1806 case 5:
1807 /* user */
1808 myStr = UT_strdup((ah->db).user);
1809 break;
1810
1811 case 6:
1812 /* password */
1813 myStr = UT_strdup((ah->db).password);
1814 break;
1815
1816 case 7:
1817 /* dbName */
1818 myStr = UT_strdup((ah->db).dbName);
1819 break;
1820
1821 case 9:
1822 /* Near-Real-Time Mirror host */
1823 myStr = UT_strdup((ah->nrtm).host);
1824 break;
1825
1826 case 11:
1827 /* NRTM Log */
1828 myStr = UT_strdup((ah->nrtm).log);
1829 break;
1830
1831 default:
1832 puts("Cannot find this source attribute");
1833 myStr = NULL;
1834 }
1835 pthread_mutex_unlock(&Lock);
1836
1837 return (myStr);
1838 }
1839
1840 int
1841 ca_srchandle2Intelement(ca_SrcHdl_t * ah, int srcAttrib)
/* [<][>][^][v][top][bottom][index][help] */
1842 /*******************************************************************
1843 * ca_srchandle2Intelement *
1844 * -- a function that returns the integer value of the requested *
1845 * attribute of the given source. *
1846 * *
1847 * Parameters *
1848 * -- source name - the name of the source
1849 * ca_get_SourceHandleByName or ca_get_SourceHandleByPosition *
1850 * *
1851 * -- srcAttrib - an integer which represents the required *
1852 * attribute of the source. We use #define statments to make *
1853 * a mapping between the attributes and the integers. *
1854 * *
1855 * Returns *
1856 * -- an integer.
1857 *******************************************************************/
1858 {
1859 int myInt; /* The value of this integer is returned. */
1860
1861 if (ah == NULL) {
1862 fprintf(stderr, "ca_srchandle2Intelement(): Cannot dereference NULL pointer\n");
1863 die;
1864 }
1865
1866 pthread_mutex_lock(&Lock);
1867 switch (srcAttrib) {
1868
1869 case 4:
1870 /* DB Port */
1871 myInt = (ah->db).port;
1872 break;
1873
1874 case 8:
1875 /* Mode of Operation of the Source. */
1876 myInt = ah->opMode;
1877 break;
1878
1879 case 10:
1880 /* Near-Real-Time Mirror port */
1881 myInt = (ah->nrtm).port;
1882 break;
1883
1884 case 12:
1885 /* NRTM Delay */
1886 myInt = (ah->nrtm).delay;
1887 break;
1888
1889 case 13:
1890 /* NRTM Protocol Version. */
1891 myInt = (ah->nrtm).protocolVer;
1892 break;
1893
1894 case 14:
1895 /* Source Update Port */
1896 myInt = ah->updPort;
1897 break;
1898
1899 default:
1900 fprintf(stderr, "Could not find source-attribute %d\n", srcAttrib);
1901 die;
1902 }
1903
1904 pthread_mutex_unlock(&Lock);
1905 return (myInt);
1906 }
1907
1908
1909 char *
1910 ca_get_adminStrElement(int symbol, int adminAttrib)
/* [<][>][^][v][top][bottom][index][help] */
1911 /*******************************************************************
1912 * ca_adminStrElement
1913 * -- returns a string which represents the attribute of a admin *
1914 * db
1915 * e.g. returns the name of a host machine. *
1916 * It allocates the required memory; *
1917 * but it returns NULL if the required memory cannot be *
1918 * allocated.
1919 * *
1920 * Parameters *
1921 * -- symbol - the symbol of the variable
1922 * *
1923 * -- adminAttrib - an integer which represents the required *
1924 * attribute of the Admin db. We use #define statements to *
1925 * make a mapping between the attributes and the integers. *
1926 * *
1927 * Returns *
1928 * -- a string or NULL *
1929 *******************************************************************/
1930 {
1931 char *myStr;
1932
1933 /*
1934 * Make sure that we are calling the correct function.
1935 */
1936 if (strcmp(dictionary[symbol].varType, "CA_ADMIN") != 0) {
1937 fprintf(stderr, "Error: unexpected variable type.\n");
1938 die;
1939 }
1940 else {
1941 pthread_mutex_lock(&Lock);
1942 switch (adminAttrib) {
1943 case 0:
1944 /* admin host */
1945 myStr = UT_strdup(((ca_ripadmin_t *) confVars[symbol].valPtr)->host);
1946 break;
1947
1948 case 2:
1949 /* User */
1950 myStr = UT_strdup(((ca_ripadmin_t *) confVars[symbol].valPtr)->user);
1951 break;
1952
1953 case 3:
1954 /* password */
1955 myStr = UT_strdup(((ca_ripadmin_t *) confVars[symbol].valPtr)->password);
1956 break;
1957
1958 case 4:
1959 /* tableName */
1960 myStr = UT_strdup(((ca_ripadmin_t *) confVars[symbol].valPtr)->tableName);
1961 break;
1962
1963 default:
1964 puts("Cannot find this admin attribute");
1965 die;
1966 }
1967 pthread_mutex_unlock(&Lock);
1968
1969 }
1970 return (myStr);
1971 }
1972
1973 int
1974 ca_get_adminIntElement(int symbol, int adminAttrib)
/* [<][>][^][v][top][bottom][index][help] */
1975 /*
1976 * Returns an int element of the admin db structure.
1977 */
1978 {
1979 int myInt; /* The value of this integer is returned. */
1980
1981 pthread_mutex_lock(&Lock);
1982 switch (adminAttrib) {
1983 case 1:
1984 /* Port number */
1985 myInt = ((ca_ripadmin_t *) confVars[symbol].valPtr)->port;
1986 break;
1987
1988 default:
1989 puts("Cannot find this admin attribute");
1990 die;
1991 }
1992 pthread_mutex_unlock(&Lock);
1993
1994 return (myInt);
1995 }
1996
1997 void
1998 ca_set_boolean(int symbol)
/* [<][>][^][v][top][bottom][index][help] */
1999 {
2000 /*************************************************************
2001 * *
2002 * ca_set_boolean() *
2003 * *
2004 * *
2005 * Parameters *
2006 * *
2007 * symbol -- the symbol for the variable. *
2008 * *
2009 * *
2010 * Returns *
2011 * *
2012 * nothing *
2013 * *
2014 * *
2015 * Remarks *
2016 * *
2017 * Must check that a sensible value is given as input. *
2018 * *
2019 * *
2020 *************************************************************/
2021
2022
2023 char newTestmodeStr[2];
2024 int newTestmodeVal; /* The new value of the testmode variable. */
2025 int invalid; /* Flag to indicate an invalid new value. */
2026
2027 FILE *testPtr, *tempPtr; /* The pointer to the files. */
2028 char name[STRLENGTH]; /* The name of the variable. */
2029 char value[STRLENGTH]; /* The value of the variable. */
2030
2031 /*
2032 * Function to change the value in a given values array. This
2033 * function can only be called from within ca_set_boolean().
2034 */
2035 int *ca_change_int_value(char[]);
2036
2037
2038 /*
2039 * Using the symbol, look at the appropriate place in the dictionary.
2040 */
2041 #ifdef DEBUG
2042 printf("\nca_set_int() function called .....\n");
2043 printf("Variable type: %s\n", dictionary[symbol].varType);
2044 #endif /* DEBUG */
2045
2046 /*
2047 * Check that the function is attempting to set the correct type of
2048 * value. If not, do not set the value, but exit instead.
2049 */
2050
2051 if (strcmp(dictionary[symbol].varType, "CA_BOOLEAN") != 0) {
2052 fprintf(stderr, "Error: CA_BOOLEAN data type expected.\n");
2053 die;
2054 }
2055
2056 /*
2057 * First, flush the input stream.
2058 */
2059 fflush(stdin);
2060
2061
2062 /*
2063 * Make sure that a reasonable, sensible value of bind-port has been
2064 * read from the keyboard.
2065 */
2066
2067 do {
2068 /*
2069 * Prompt for the new value of the testmode.
2070 */
2071
2072 printf("\nNew value of testmode (0 or 1) >>> ");
2073 scanf("%s", newTestmodeStr);
2074
2075 /*
2076 * We scanf() the value as a string, but we want it to be an
2077 * integer. Thus, we use sscanf() to scanf the value from
2078 * the string-variable and store it as an integer in an
2079 * integer variable.
2080 */
2081 sscanf(newTestmodeStr, "%d", &newTestmodeVal);
2082
2083 /*
2084 * We only change the testmode when the user is absolutely
2085 * sure that they want to change. Thus, we only accept two
2086 * possible values for testmode.
2087 */
2088
2089 if ((newTestmodeVal < 0) || (newTestmodeVal > 1)) {
2090 invalid = 1;
2091 puts("Only '0' or '1' accepted as value for testmode.");
2092 }
2093 else {
2094 invalid = 0;
2095 }
2096 } while (invalid);
2097
2098
2099 /*
2100 * Lock the value of the variable before changing it.
2101 */
2102
2103 pthread_mutex_lock(&Lock);
2104
2105
2106 /*
2107 * Choose the appropriate values array.
2108 */
2109
2110 switch (dictionary[symbol].varScope) {
2111 /*
2112 * If the variable has global scope, write it into the
2113 * globals array. If it has local scope, write it into the
2114 * local array. If the scope cannot be found, then report an
2115 * error.
2116 */
2117
2118 /************************************************************
2119 * *
2120 * We comment out this code. We use the GLib string *
2121 * now. It also checks if we got the memory :-) *
2122 * *
2123 ************************************************************/
2124
2125 case 1:
2126 globals[symbol].valPtr = ca_change_int_value(newTestmodeStr);
2127 /*
2128 * globals[symbol].strPtr = newTestmodeStr;
2129 */
2130 g_string_assign(globals[symbol].strPtr, newTestmodeStr);
2131 break;
2132
2133 case 99:
2134 locals[symbol].valPtr = ca_change_int_value(newTestmodeStr);
2135 /*
2136 * locals[symbol].strPtr = newTestmodeStr;
2137 */
2138 g_string_assign(locals[symbol].strPtr, newTestmodeStr);
2139 break;
2140
2141 default:
2142 fprintf(stderr, "Error: unknown scope: %d\n", dictionary[symbol].varScope);
2143 break;
2144 }
2145
2146 /*
2147 * Write the new value of this variable back to the config file.
2148 *
2149 * To be implemented.
2150 */
2151
2152 /*
2153 * Find the actual name of the variable from the dictionary structure
2154 * (use the variable symbol as an index into the array of dictionary
2155 * structures.
2156 */
2157
2158 printf("Name of variable to be changed: %s\n", dictionary[symbol].varName);
2159 printf("Type of variable to be changed: %s\n", dictionary[symbol].varType);
2160
2161 /*
2162 * Open the test config file for reading .....
2163 */
2164 if ((testPtr = fopen(testFile, "r")) == NULL) {
2165 printf("File \"%s\" could not be opened.\n", testFile);
2166 die;
2167 }
2168
2169 /*
2170 * Open the temporary file for writing .....
2171 */
2172 if ((tempPtr = fopen(tempFile, "w")) == NULL) {
2173 printf("File \"%s\" could not be opened.\n", tempFile);
2174 die;
2175 }
2176
2177 /*
2178 * Read the first record in the test config file.
2179 */
2180
2181 fscanf(testPtr, "%s", name);
2182 fgets(value, sizeof(value), testPtr);
2183
2184 /*
2185 * If the last character of "value" is '\n', replace it with '\0'.
2186 */
2187 if (value[strlen(value) - 1] == '\n') {
2188 printf("The value string is %s", value);
2189 printf("Replacing last character of \"%s\" with the NULL character\n", name);
2190 value[strlen(value) - 1] = '\0';
2191 printf("The new value string is %s", value);
2192 }
2193
2194
2195 /*
2196 * While there are records to be read in the test config file: Write
2197 * the current record into the temporary file. Read the next record
2198 * in the config file. Repeat untill the EOF has been reached.
2199 */
2200
2201 while (!feof(testPtr)) {
2202 fprintf(tempPtr, "%s %s\n", name, value);
2203 fscanf(testPtr, "%s", name);
2204 fgets(value, sizeof(value), testPtr);
2205
2206 /*
2207 * If the last character of "value" is '\n', replace it with
2208 * '\0'.
2209 */
2210 if (value[strlen(value) - 1] == '\n') {
2211 printf("The last character of the value string is %c", value[strlen(value) - 1]);
2212 printf("The value string is %s", value);
2213 printf("Replacing last character of \"%s\" with the NULL character\n", name);
2214 value[strlen(value) - 1] = '\0';
2215 printf("The new value string is %s", value);
2216 }
2217
2218
2219 /*
2220 * if we read the variable that we want to change, stop
2221 * reading this file and print only the name of this variable
2222 * to the temporary file.
2223 */
2224
2225 /*
2226 * If we read the variable that we want to change, replace
2227 * the value of this variable in the config file with the
2228 * value supplied from the keyboard.
2229 *
2230 */
2231 if (strcmp(name, dictionary[symbol].varName) == 0) {
2232 strcpy(value, newTestmodeStr);
2233 printf("The replacement string is %s", value);
2234 }
2235 /*
2236 * Flush the pointer to the test config file.
2237 */
2238 fflush(testPtr);
2239
2240 }
2241 /*
2242 * Here ends the loop that writes the config file, with the new
2243 * variable, to the temporary file.
2244 */
2245
2246 /*
2247 * While !(the record to be updated) BEGIN Write the record to the
2248 * temporary file Read the next record in the config file END
2249 *
2250 * Write the new value to the temporary file Read the next record in the
2251 * config file COMMENT: this is the record to be updated. COMMENT:
2252 * discard this record.
2253 *
2254 * Read the next record in the config file
2255 *
2256 * While !(EOF) BEGIN write the record to the temporary file read the
2257 * next record in the config file END
2258 *
2259 * Close Config file Close Temporary file
2260 *
2261 * Open Temporary file for reading Open Config file for writing
2262 *
2263 * Read the next record of the Temporary file
2264 *
2265 * While (!EOF of Temporary file) BEGIN write the record into the Config
2266 * file read the next record of the Temporary file END
2267 *
2268 * Close Temporary file Close Config file
2269 *
2270 */
2271
2272 fclose(testPtr);
2273 fclose(tempPtr);
2274
2275 /*
2276 * Now, flush the file pointers
2277 */
2278 fflush(testPtr);
2279 fflush(tempPtr);
2280
2281 /*
2282 * Open the temporary file for reading. Open the config file for
2283 * writing. Write the contents of the temporary file into the config
2284 * file.
2285 */
2286
2287 /*
2288 * Open the temporary file for reading .....
2289 */
2290 if ((tempPtr = fopen(tempFile, "r")) == NULL) {
2291 printf("File \"%s\" could not be opened for reading.\n", tempFile);
2292 die;
2293 }
2294
2295 /*
2296 * Open the config file for writing .....
2297 */
2298 if ((testPtr = fopen(testFile, "w")) == NULL) {
2299 printf("File \"%s\" could not be opened for writing.\n", testFile);
2300 die;
2301 }
2302
2303 /*
2304 * Read the first record in the temporary file.
2305 */
2306
2307 fscanf(tempPtr, "%s", name);
2308 fgets(value, sizeof(value), tempPtr);
2309 printf("\nFIRST LINE: %s %s", name, value);
2310
2311
2312 /*
2313 * While there are records to be read in the temporary file: Write
2314 * the current record into the test config file. Read the next record
2315 * in the temporary file. Repeat untill the EOF has been reached.
2316 */
2317
2318 while (!feof(tempPtr)) {
2319 fprintf(testPtr, "%s %s", name, value);
2320 fscanf(tempPtr, "%s", name);
2321 fgets(value, sizeof(value), tempPtr);
2322 }
2323
2324 fclose(testPtr);
2325 fclose(tempPtr);
2326
2327 /*
2328 * Unlock the value of the variable after setting it and writing the
2329 * new value back to the configuration (and the dictionary) file.
2330 *
2331 */
2332 pthread_mutex_unlock(&Lock);
2333
2334 }
2335
2336
2337 void
2338 ca_set_dirlist(int symbol)
/* [<][>][^][v][top][bottom][index][help] */
2339 {
2340 /****************************************************************
2341 * ca_set_dirlist() *
2342 * *
2343 * Parameters *
2344 * symbol -- the symbol of the variable. *
2345 * *
2346 * Returns *
2347 * 1 if successful, 0 if not successful. *
2348 * *
2349 * Remarks *
2350 * Writing the new value back to the config file has yet to *
2351 * be implemented. *
2352 * *
2353 ****************************************************************/
2354
2355 char newDir[80];
2356 /*
2357 * Declare a pointer to a values_t variable. Later, we shall assign
2358 * this pointer to the first element of either the globals or the
2359 * locals array, as appropriate.
2360 */
2361 values_t *hereValues;
2362
2363 /*
2364 * Using the symbol, look in the appropriate place in the dictionary.
2365 */
2366 #ifdef DEBUG
2367 printf("\nca_set_dirlist() function called ..... \n");
2368 printf("Variable type: %s\n", dictionary[symbol].varType);
2369 #endif
2370
2371 /*
2372 * First, flush the input stream.
2373 */
2374 fflush(stdin);
2375
2376 /*
2377 * Prompt for the new value of the directory.
2378 */
2379 printf("\nNew value of %s [80 characters, maximum] >>> ", dictionary[symbol].varName);
2380 scanf("%s", newDir);
2381
2382 /*
2383 * Make sure that a reasonable, sensible value of the directory value
2384 * has been read from the keyboard.
2385 *
2386 * How do we implement this ???
2387 *
2388 */
2389
2390
2391 /*
2392 * Make sure that the function is attempting to set the correct type
2393 * of value. If not, do not set the value - and exit.
2394 */
2395
2396 if (strcmp(dictionary[symbol].varType, "CA_DIRLIST") != 0) {
2397 fprintf(stderr, "Error: unexpected variable type.\n");
2398 exit(51);
2399 }
2400
2401 /*
2402 * Choose the appropriate values array. Assign a temporary pointer to
2403 * this array.
2404 */
2405
2406 switch (dictionary[symbol].varScope) {
2407 /*
2408 * If the variable has global scope, write it into the
2409 * globals array. If it has local scope, write it into the
2410 * locals array. If the scope cannot be found, report an
2411 * error.
2412 */
2413 case 1:
2414 hereValues = globals;
2415 break;
2416
2417 case 99:
2418 hereValues = locals;
2419 break;
2420
2421 default:
2422 fprintf(stderr, "Error: Unknown scope: %d\n", dictionary[symbol].varScope);
2423 die;
2424 }
2425
2426
2427 /*
2428 * Check for the presence of the mutex lock: if present, wait until
2429 * it is available; else get the lock and proceed with the change of
2430 * value.
2431 */
2432
2433 /*
2434 * Write the new value of the variable to the correct place in the
2435 * [appropriate] values array.
2436 *
2437 * Note that there is no need to check if UT_malloc() actually worked.
2438 *
2439 */
2440
2441 hereValues[symbol].valPtr = (char *) UT_malloc(80);
2442
2443 /*
2444 *if (hereValues[symbol].valPtr == NULL) {
2445 * fprintf(stderr, "Cannot alllocate memory for hereValuesvlPtr\n");
2446 * die;
2447 * }
2448 */
2449
2450 strcpy(hereValues[symbol].valPtr, newDir);
2451
2452
2453 /************************************************************
2454 * *
2455 * We comment out this code. We use the GLib string *
2456 * now. It also checks if we got the memory :-) *
2457 * *
2458 ************************************************************/
2459 /*
2460 * hereValues[symbol].strPtr = (char *) malloc(sizeof(newDir));
2461 * if (hereValues[symbol].strPtr == NULL) {
2462 * fprintf(stderr, "Cannot alllocate memory for hereValuestPtr\n");
2463 * die;
2464 * }
2465 * strcpy(hereValues[symbol].strPtr, newDir);
2466 */
2467 g_string_assign(hereValues[symbol].strPtr, newDir);
2468
2469 /*
2470 * Free the temporary pointer, hereValues.
2471 *
2472 */
2473 UT_free(hereValues);
2474 hereValues = NULL;
2475
2476 /*
2477 * Release the mutex lock.
2478 */
2479
2480 /*
2481 * Write the new value of this variable back to the config file.
2482 */
2483
2484 }
2485
2486
2487 #if 0
2488
2489 XXX: Unused function? Removed because it causes warnings due to gets()
/* [<][>][^][v][top][bottom][index][help] */
2490 invokation. - Shane
2491
2492 void
2493 ca_set_string(int symbol)
2494 {
2495
2496 /****************************************************************
2497 * ca_set_string() *
2498 * *
2499 * Parameters *
2500 * symbol -- the symbol of the variable. *
2501 * *
2502 * Returns *
2503 * 1 if successful, 0 if not successful ? *
2504 * *
2505 * Remarks *
2506 * Writing the new value back to the config file has yet to *
2507 * be implemented. *
2508 * *
2509 ****************************************************************/
2510
2511 char newString[80]; /* May need to make this bigger. */
2512
2513 /*
2514 * Declare a pointer to a values_t variable. Later, we shall assign
2515 * this pointer to the first element of either the globals or the
2516 * locals array, as appropriate.
2517 */
2518 values_t *hereValues;
2519
2520 /*
2521 * Using the symbol, look in the appropriate place in the dictionary.
2522 */
2523 #ifdef DEBUG
2524 printf("\nca_set_string() function called ..... \n");
2525 printf("Variable type: %s\n", dictionary[symbol].varType);
2526 #endif
2527
2528 /*
2529 * First, flush the input stream.
2530 */
2531 fflush(stdin);
2532
2533 /*
2534 * Prompt for the new value of the string.
2535 */
2536 printf("\nNew value of %s [80 characters, maximum] >>> ", dictionary[symbol].varName);
2537 gets(newString);
2538
2539 /*
2540 * Make sure that a reasonable, sensible value of the string value
2541 * has been read from the keyboard.
2542 *
2543 * How do we implement this ???
2544 *
2545 */
2546
2547
2548 /*
2549 * Make sure that the function is attempting to set the correct type
2550 * of value. If not, do not set the value - and exit.
2551 */
2552
2553 if (strcmp(dictionary[symbol].varType, "CA_STRING") != 0) {
2554 fprintf(stderr, "Error: unexpected variable type.\n");
2555 exit(51);
2556 }
2557
2558 /*
2559 * Choose the appropriate values array. Assign a temporary pointer to
2560 * this array.
2561 */
2562
2563 switch (dictionary[symbol].varScope) {
2564 /*
2565 * If the variable has global scope, write it into the
2566 * globals array. If it has local scope, write it into the
2567 * locals array. If the scope cannot be found, report an
2568 * error.
2569 */
2570 case 1:
2571 hereValues = globals;
2572 break;
2573
2574 case 99:
2575 hereValues = locals;
2576 break;
2577
2578 default:
2579 fprintf(stderr, "Error: Unknown scope: %d\n", dictionary[symbol].varScope);
2580 die;
2581 }
2582
2583
2584 /*
2585 * Check for the presence of the mutex lock: if present, wait until
2586 * it is available; else get the lock and proceed with the change of
2587 * value.
2588 */
2589 pthread_mutex_lock(&Lock);
2590
2591 /*
2592 * Write the new value of the variable to the correct place in the
2593 * [appropriate] values array. Note the check to the return value of
2594 * malloc() to see if the memory was actually obtained.
2595 */
2596
2597 hereValues[symbol].valPtr = (char *) UT_malloc(80);
2598
2599 /*
2600 * No need to check that NULL is not returned.
2601 *
2602 *if (hereValues[symbol].valPtr == NULL) {
2603 * fprintf(stderr, "Cannot allocate memory for hereValues[symbol].valPtr\n");
2604 * die;
2605 * }
2606 *
2607 */
2608
2609 strcpy(hereValues[symbol].valPtr, newString);
2610
2611
2612 /************************************************************
2613 * *
2614 * We comment out this code. We use the GLib string *
2615 * now. It also checks if we got the memory :-) *
2616 * *
2617 ************************************************************/
2618 /*
2619 * hereValues[symbol].strPtr = (char *) malloc(sizeof(newString));
2620 * if (hereValues[symbol].strPtr == NULL) {
2621 * fprintf(stderr, "Cannot allocate memory for hereValues[symbol].strPtr\n");
2622 * die;
2623 * }
2624 * strcpy(hereValues[symbol].strPtr, newString);
2625 */
2626
2627 g_string_assign(hereValues[symbol].strPtr, newString);
2628
2629 /*
2630 * Free the temporary pointer, hereValues.
2631 *
2632 */
2633 UT_free(hereValues);
2634 hereValues = NULL;
2635
2636 /*
2637 * Release the mutex lock.
2638 */
2639 pthread_mutex_unlock(&Lock);
2640
2641 /*
2642 * Write the new value of this variable back to the config file.
2643 * Implement this later ?
2644 */
2645
2646 }
2647 #endif /* 0 */
2648
2649
2650 int
2651 ca_writeNewValue(int dictSymbol, char *newValue)
/* [<][>][^][v][top][bottom][index][help] */
2652 {
2653
2654 FILE *confPtr; /* Pointer to config file */
2655 FILE *tempPtr; /* The pointer to temp file. */
2656 char name[STRLENGTH]; /* The name of the variable. */
2657 char value[STRLENGTH]; /* The value of the variable. */
2658
2659
2660 /*
2661 * Find the actual name of the variable from the dictionary structure
2662 * (use the variable symbol as an index into the array of dictionary
2663 * structures.
2664 */
2665 #ifdef DEBUG
2666 printf("Name of variable to be changed: %s\n", dictionary[dictSymbol].varName);
2667 printf("Type of variable to be changed: %s\n", dictionary[dictSymbol].varType);
2668 #endif /* DEBUG */
2669
2670 /*
2671 * Open the test config file for reading .....
2672 */
2673 if ((confPtr = fopen(testFile, "r")) == NULL) {
2674 printf("File \"%s\" could not be opened.\n", testFile);
2675 die;
2676 }
2677
2678 /*
2679 * Open the temporary file for writing .....
2680 */
2681 if ((tempPtr = fopen(tempFile, "w")) == NULL) {
2682 printf("File \"%s\" could not be opened.\n", tempFile);
2683 die;
2684 }
2685
2686 /*
2687 * Read the first record in the test config file.
2688 */
2689
2690 fscanf(confPtr, "%s", name);
2691 fgets(value, sizeof(value), confPtr);
2692
2693 /*
2694 * If the last character of "value" is '\n', replace it with '\0'.
2695 */
2696 if (value[strlen(value) - 1] == '\n') {
2697 #ifdef DEBUG
2698 printf("The value string is %s", value);
2699 printf("Replacing last character of \"%s\" with the NULL character\n", name);
2700 #endif /* DEBUG */
2701
2702 value[strlen(value) - 1] = '\0';
2703
2704 #ifdef DEBUG
2705 printf("The new value string is %s", value);
2706 #endif /* DEBUG */
2707 }
2708
2709 /*
2710 * If we read the variable that we want to change, replace the value
2711 * of this variable in the config file with the value supplied from
2712 * the keyboard.
2713 *
2714 */
2715 if (strcmp(name, dictionary[dictSymbol].varName) == 0) {
2716 strcpy(value, newValue);
2717
2718 #ifdef DEBUG
2719 printf("The replacement string is %s", value);
2720 #endif /* DEBUG */
2721 }
2722
2723 /*
2724 * While there are records to be read in the test config file: Write
2725 * the current record into the temporary file. Read the next record
2726 * in the config file. Repeat untill the EOF has been reached.
2727 */
2728
2729 while (!feof(confPtr)) {
2730 fprintf(tempPtr, "%s %s\n", name, value);
2731 fscanf(confPtr, "%s", name);
2732 fgets(value, sizeof(value), confPtr);
2733
2734 /*
2735 * If the last character of "value" is '\n', replace it with
2736 * '\0'.
2737 */
2738 if (value[strlen(value) - 1] == '\n') {
2739 #ifdef DEBUG
2740 printf("The last character of the value string is %c", value[strlen(value) - 1]);
2741 printf("The value string is %s", value);
2742 printf("Replacing last character of \"%s\" with the NULL character\n", name);
2743 #endif /* DEBUG */
2744
2745 value[strlen(value) - 1] = '\0';
2746 #ifdef DEBUG
2747 printf("The new value string is %s", value);
2748 #endif /* DEBUG */
2749 }
2750
2751
2752 /*
2753 * If we read the variable that we want to change, replace
2754 * the value of this variable in the config file with the
2755 * value supplied from the keyboard.
2756 *
2757 */
2758 if (strcmp(name, dictionary[dictSymbol].varName) == 0) {
2759 strcpy(value, newValue);
2760
2761 #ifdef DEBUG
2762 printf("The replacement string is %s", value);
2763 #endif /* DEBUG */
2764 }
2765
2766 /*
2767 * Flush the pointer to the test config file.
2768 */
2769 fflush(confPtr);
2770
2771 }
2772 /*
2773 * Here ends the loop that writes the config file, with the new
2774 * variable, to the temporary file.
2775 */
2776
2777 /*
2778 * While !(the record to be updated) BEGIN Write the record to the
2779 * temporary file Read the next record in the config file END
2780 *
2781 * Write the new value to the temporary file Read the next record in the
2782 * config file COMMENT: this is the record to be updated. COMMENT:
2783 * discard this record.
2784 *
2785 * Read the next record in the config file
2786 *
2787 * While !(EOF) BEGIN write the record to the temporary file read the
2788 * next record in the config file END
2789 *
2790 * Close Config file Close Temporary file
2791 *
2792 * Open Temporary file for reading Open Config file for writing
2793 *
2794 * Read the next record of the Temporary file
2795 *
2796 * While (!EOF of Temporary file) BEGIN write the record into the Config
2797 * file read the next record of the Temporary file END
2798 *
2799 * Close Temporary file Close Config file
2800 *
2801 */
2802
2803 fclose(confPtr);
2804 fclose(tempPtr);
2805
2806 /*
2807 * Now, flush the file pointers
2808 */
2809 fflush(confPtr);
2810 fflush(tempPtr);
2811
2812 /*
2813 * Open the temporary file for reading. Open the config file for
2814 * writing. Write the contents of the temporary file into the config
2815 * file.
2816 */
2817
2818 /*
2819 * Open the temporary file for reading .....
2820 */
2821 if ((tempPtr = fopen(tempFile, "r")) == NULL) {
2822 printf("File \"%s\" could not be opened for reading.\n", tempFile);
2823 die;
2824 }
2825
2826 /*
2827 * Open the config file for writing .....
2828 */
2829 if ((confPtr = fopen(testFile, "w")) == NULL) {
2830 printf("File \"%s\" could not be opened for writing.\n", testFile);
2831 die;
2832 }
2833
2834 /*
2835 * Read the first record in the temporary file.
2836 */
2837
2838 fscanf(tempPtr, "%s", name);
2839 fgets(value, sizeof(value), tempPtr);
2840 #ifdef DEBUG
2841 printf("\nFIRST LINE: %s %s", name, value);
2842 #endif /* DEBUG */
2843
2844 /*
2845 * While there are records to be read in the temporary file: Write
2846 * the current record into the test config file. Read the next record
2847 * in the temporary file. Repeat untill the EOF has been reached.
2848 */
2849
2850 while (!feof(tempPtr)) {
2851 fprintf(confPtr, "%s %s", name, value);
2852 fscanf(tempPtr, "%s", name);
2853 fgets(value, sizeof(value), tempPtr);
2854 }
2855
2856 fclose(confPtr);
2857 fclose(tempPtr);
2858 unlink(tempFile);
2859
2860 return (0);
2861 }
2862
2863
2864 int
2865 ca_getStorageLocation(char *confVar, dict_t woordenboek[], int size)
/* [<][>][^][v][top][bottom][index][help] */
2866 /*************************************************************
2867 * ca_getStorageLocation() *
2868 * - takes the name of a config variable and searches the *
2869 * dictionary structure for the storage location for this *
2870 * variable. *
2871 * *
2872 * Parameters *
2873 * confVar -- the string variable that contains the name *
2874 * of the variable. *
2875 * woordenboek -- the dictionary structure to be searched *
2876 * size -- the size of the dictionary structure to *
2877 * searched. *
2878 * *
2879 * Returns *
2880 * the location (integer) in the values array. *
2881 * *
2882 *************************************************************/
2883 {
2884 int i, where, found = 0; /* Whether or not the symbol has been
2885 * found. */
2886
2887
2888 #ifdef DEBUG
2889 printf("The variable name in ca_getStorageLocation is: %s\n", confVar);
2890 #endif /* DEBUG */
2891
2892 /*
2893 * Compares each name in the dictionary with the one for which we are
2894 * looking.
2895 */
2896 i = 0;
2897 while (!found && i < size) {
2898 if (strcmp(woordenboek[i].varName, confVar) == 0) {
2899 found = 1;
2900 }
2901 else {
2902 ++i;
2903 }
2904 }
2905
2906 /*
2907 * Returns the storage location for the given variable name or else
2908 * returns NOT_FOUND
2909 */
2910 if (found) {
2911 /* mySymbol = atoi(woordenboek[i].varSym); */
2912 #ifdef DEBUG
2913 printf("Symbol is %s\n", woordenboek[i].varSym);
2914 printf("Storage Location is: %d\n", woordenboek[i].varNum);
2915 #endif /* DEBUG */
2916 where = woordenboek[i].varNum;
2917 }
2918 else {
2919 fprintf(stderr, "Error: cannot find storage location for variable %s\n", confVar);
2920 where = NOT_FOUND;
2921 }
2922 return (where);
2923
2924 }
2925
2926
2927 void
2928 ca_getConfig(values_t confVars[], int size)
/* [<][>][^][v][top][bottom][index][help] */
2929 /*************************************************************
2930 * ca_getConfig -- prints the strings representing the *
2931 * values of the configuration variables *
2932 * *
2933 * Parameters *
2934 * confVars -- the values_t array which stores the *
2935 * values of the configuration variables. *
2936 * size -- the number of configuration variables, *
2937 * the number of elements in the confVars array *
2938 * *
2939 * *
2940 *************************************************************/
2941 {
2942 int i = 0; /* A counting variable. */
2943
2944 puts("A dump of the strings of the values of the Config Vars:");
2945 puts("Number\t\tString");
2946 puts("----------");
2947
2948 while (i < size) {
2949 printf("%d\t\t%s\n", i, (confVars[i].strPtr)->str);
2950 ++i;
2951 }
2952
2953 }
2954
2955
2956 int
2957 ca_getType(char *confVar, dict_t woordenboek[], int size)
/* [<][>][^][v][top][bottom][index][help] */
2958 /****************************************************************
2959 * ca_getType -- returns the data type of the variable. *
2960 * *
2961 * Parameters *
2962 * confVar -- the name of the configuration variable. *
2963 * woordenboek -- the array of dict_t structures. *
2964 * size -- the number of configuration variables. *
2965 * *
2966 * Returns *
2967 * an integer representing the data type of the variable *
2968 * *
2969 ****************************************************************/
2970 {
2971 int i = 0, /* Counter variable. */
2972 found = 0; /* Set this == 1 when we find the variable. */
2973 int myType; /* Integer representing the type of the config
2974 * variable. */
2975
2976 /*
2977 * Compare each name in the dictionary with the one for which we are
2978 * looking.
2979 */
2980
2981 myType = 0;
2982
2983 #ifdef DEBUG
2984 printf("ca_getType function called for variable: %s\n", confVar);
2985 #endif /* DEBUG */
2986
2987 while (!found && i <= size) {
2988 if (strcmp(woordenboek[i].varName, confVar) == 0) {
2989 found = 1;
2990 #ifdef DEBUG
2991 printf("ca_getType function: %s, %s matched.\n", woordenboek[i].varName, confVar);
2992 #endif /* DEBUG */
2993 }
2994 else {
2995 ++i;
2996 }
2997 }
2998
2999 /*
3000 * Return the type of the config variable or else return "NOT FOUND".
3001 */
3002 if (found) {
3003 if (strcmp(woordenboek[i].varType, "CA_INT") == 0) {
3004 #ifdef DEBUG
3005 printf("ca_getType function: %s variable of type %s is Integer type\n", woordenboek[i].varName, woordenboek[i].varType);
3006
3007 printf("ca_getType function: %s, %s\n", woordenboek[i].varName, woordenboek[i].varType);
3008 #endif /* DEBUG */
3009 myType = 11;
3010 #ifdef DEBUG
3011 printf("For type CA_INT, myType is %d\n", myType);
3012 printf("ca_getType function: %s, %s, %d\n", woordenboek[i].varName, woordenboek[i].varType, myType);
3013 #endif /* DEBUG */
3014 }
3015 else {
3016 if (strcmp(woordenboek[i].varType, "CA_STRING") == 0) {
3017 #ifdef DEBUG
3018 printf("ca_getType function: %s variable of type %s is String type\n", woordenboek[i].varName, woordenboek[i].varType);
3019 printf("ca_getType function: %s, %s\n", woordenboek[i].varName, woordenboek[i].varType);
3020 #endif /* DEBUG */
3021 myType = 12;
3022 #ifdef DEBUG
3023 printf("ca_getType function: %s, %s, %d\n", woordenboek[i].varName, woordenboek[i].varType, myType);
3024 #endif /* DEBUG */
3025 }
3026 else {
3027 if (strcmp(woordenboek[i].varType, "CA_DIRLIST") == 0) {
3028 #ifdef DEBUG
3029 printf("ca_getType function: %s, %s\n", woordenboek[i].varName, woordenboek[i].varType);
3030 #endif /* DEBUG */
3031 myType = 13;
3032 #ifdef DEBUG
3033 printf("ca_getType function: %s, %s, %d\n", woordenboek[i].varName, woordenboek[i].varType, myType);
3034 #endif /* DEBUG */
3035 }
3036 else {
3037 if (strcmp(woordenboek[i].varType, "CA_BOOLEAN") == 0) {
3038 #ifdef DEBUG
3039 printf("ca_getType function: %s, %s\n", woordenboek[i].varName, woordenboek[i].varType);
3040 #endif /* DEBUG */
3041 myType = 14;
3042 #ifdef DEBUG
3043 printf("ca_getType function: %s, %s, %d\n", woordenboek[i].varName, woordenboek[i].varType, myType);
3044 #endif /* DEBUG */
3045 }
3046 else {
3047 if (strcmp(woordenboek[i].varType, "CA_SOURCETYPE") == 0) {
3048 #ifdef DEBUG
3049 printf("ca_getType function: %s, %s\n", woordenboek[i].varName, woordenboek[i].varType);
3050 #endif /* DEBUG */
3051 myType = 15;
3052 #ifdef DEBUG
3053 printf("ca_getType function: %s, %s, %d\n", woordenboek[i].varName, woordenboek[i].varType, myType);
3054 #endif /* DEBUG */
3055 }
3056 else {
3057 if (strcmp(woordenboek[i].varType, "CA_ADMIN") == 0) {
3058 #ifdef DEBUG
3059 printf("ca_getType function: %s, %s\n", woordenboek[i].varName, woordenboek[i].varType);
3060 #endif /* DEBUG */
3061 myType = 16;
3062 #ifdef DEBUG
3063 printf("ca_getType function: %s, %s, %d\n", woordenboek[i].varName, woordenboek[i].varType, myType);
3064 #endif /* DEBUG */
3065
3066 }
3067 else {
3068 if (strcmp(woordenboek[i].varType, "CA_UPDSOURCE") == 0) {
3069 #ifdef DEBUG
3070 printf("ca_getType function: %s, %s\n", woordenboek[i].varName, woordenboek[i].varType);
3071 #endif /* DEBUG */
3072 myType = 17;
3073 #ifdef DEBUG
3074 printf("ca_getType function: %s, %s, %d\n", woordenboek[i].varName, woordenboek[i].varType, myType);
3075 #endif /* DEBUG */
3076 }
3077 }
3078 }
3079 }
3080 }
3081 }
3082 }
3083 }
3084 else {
3085 myType = NOT_FOUND;
3086 }
3087 return (myType);
3088 }
3089
3090
3091 ca_updDbSource_t **
3092 ca_get_UpdSourceHandle(int symbol)
/* [<][>][^][v][top][bottom][index][help] */
3093 /*******************************************************************
3094 * ca_get_UpdSourceHandle *
3095 * -- returns the handle to the Update source *
3096 * *
3097 * Parameters *
3098 * -- none; there is only one Update Source in the Configuration *
3099 * file because a single DBupdate process cannot update more *
3100 * than one source. *
3101 * There are now multiple Update Sources in the Configuration *
3102 * file. This was a self imposed limit that is no longer!! *
3103 * *
3104 * Returns *
3105 * -- a pointer to an array of the Update Source structure (type *
3106 * ca_updDbSource_t) or NULL. *
3107 * *
3108 *******************************************************************/
3109 {
3110 ca_updDbSource_t **myUpdSourcePtr;
3111
3112 /*
3113 * Make sure that we are calling the correct function.
3114 */
3115 if (strcmp(dictionary[symbol].varType, "CA_UPDSOURCE") != 0)
3116 {
3117 fprintf(stderr, "Error: unexpected variable type.\n");
3118 die;
3119 }
3120 else
3121 {
3122 /* get a pointer to the array of source data pointers */
3123 myUpdSourcePtr = (ca_updDbSource_t **) confVars[symbol].valPtr;
3124 }
3125 return (myUpdSourcePtr);
3126 }
3127
3128
3129 char *
3130 ca_UpdSrcHandle2StrElement(ca_updDbSource_t * uh, int srcAttrib)
/* [<][>][^][v][top][bottom][index][help] */
3131 /*******************************************************************
3132 * ca_UpdSrcHandle2StrElement *
3133 * -- returns a string which represents the attribute of an *
3134 * update source e.g. the name, the user, etc. *
3135 * It allocates the required memory, but it returns NULL if *
3136 * the required memory cannot be allocated. *
3137 * *
3138 * *
3139 * Parameters *
3140 * -- the Update Source Handle, i.e. a pointer to the structure *
3141 * which contains the data about the Update Source. *
3142 * *
3143 * -- srcAttrib - an integer which represents the required *
3144 * attribute of the source. This is also used in the *
3145 * ca_srchandle2Strelement() function. *
3146 * *
3147 * Returns *
3148 * -- a string or NULL *
3149 * *
3150 *******************************************************************/
3151 {
3152 char *myStr;
3153
3154 if (uh == NULL) {
3155 fprintf(stderr, "ca_UpdSrcHandle2StrElement(): Cannot dereference NULL pointer.\n");
3156 die;
3157 }
3158
3159 switch (srcAttrib) {
3160 case 0:
3161 /* Update Source Name */
3162 myStr = UT_strdup(uh->name);
3163 break;
3164
3165 case 3:
3166 /* Machine */
3167 myStr = UT_strdup((uh->updDb).host);
3168 break;
3169
3170 case 5:
3171 /* User */
3172 myStr = UT_strdup((uh->updDb).user);
3173 break;
3174
3175 case 6:
3176 /* Password */
3177 myStr = UT_strdup((uh->updDb).password);
3178 break;
3179
3180 case 7:
3181 /* Update DB Name */
3182 myStr = UT_strdup((uh->updDb).dbName);
3183 break;
3184
3185 case 15:
3186 /* Update Source Whois Machine */
3187 myStr = UT_strdup((uh->whoisd_host));
3188 break;
3189
3190 default:
3191 puts("Cannot find this Update source attribute");
3192 myStr = NULL;
3193 }
3194
3195 return (myStr);
3196 }
3197
3198
3199 int
3200 ca_UpdSrcHandle2IntElement(ca_updDbSource_t * uh, int srcAttrib)
/* [<][>][^][v][top][bottom][index][help] */
3201 /*******************************************************************
3202 * ca_UpdSrcHandle2IntElement *
3203 * -- a function that returns the integer value of the requested *
3204 * attribute of the given source. *
3205 * *
3206 * Parameters *
3207 * -- the Update Source Handle, i.e. a pointer to the structure *
3208 * which contains the data about the Update Source. *
3209 *
3210 * -- srcAttrib - an integer which represents the required *
3211 * attribute of the source. This is also used in the *
3212 * ca_srchandle2Strelement() function. *
3213 * *
3214 * Returns *
3215 * -- an integer.
3216 *******************************************************************/
3217 {
3218
3219 int myInt; /* The value of this integer is returned. */
3220
3221 if (uh == NULL) {
3222 fprintf(stderr, "ca_srchandle2Intelement(): Cannot dereference NULL pointer\n");
3223 die;
3224 }
3225
3226 switch (srcAttrib) {
3227
3228 case 4:
3229 /* Update Source DB Port */
3230 myInt = (uh->updDb).port;
3231 break;
3232
3233 case 16:
3234 /* Update Source QRY Port */
3235 myInt = (uh->qryPort);
3236 break;
3237
3238 case 17:
3239 /* Update Source UPD Port */
3240 myInt = (uh->updPort);
3241 break;
3242
3243 default:
3244 fprintf(stderr, "Could not find source-attribute %d\n", srcAttrib);
3245 die;
3246 }
3247
3248 return (myInt);
3249
3250 }
3251
3252 /*
3253 * void ca_init(dict_t theDict[], const char *configFile, values_t
3254 * configVars[], int varNo)
3255 */
3256 /*
3257 * ca_init() -- Initialisation function.
3258 */
3259 /*
3260 * { char sourcesFile[80];
3261 *
3262 * ca_populateDictionary(theDict, varNo); ca_readConfig(configFile, configVars,
3263 * varNo);
3264 *
3265 * sourcesFile = ca_get_dirlist(CA_SOURCEFILE); ca_readSources(sourcesFile,
3266 * confVars); }
3267 */
3268
3269 int ca_sanityChk(values_t confVars[])
/* [<][>][^][v][top][bottom][index][help] */
3270 /*
3271 - does a simple sanity check
3272 - Parameters
3273 - confVars - the array of configuration variables
3274 - Returns
3275 - an integer: -1 or 0
3276 */
3277 {
3278 int symbol; /* A counting variable */
3279 int status = 0; /* Assume that the Configuration File is complete. */
3280 int undefVars = 0; /* Number of undefined variables. */
3281
3282 /*
3283 * Instead of using VARS here, we use CA_NUMBEROFSYMBOLS.
3284 *
3285 */
3286 for(symbol = 0; symbol < CA_NUMBEROFSYMBOLS; symbol++)
3287 {
3288 if (!confVars[symbol].strPtr)
3289 {
3290 ++undefVars;
3291 fprintf(stderr, "%s %s\n", configWarningStr, dictionary[symbol].varName);
3292 }
3293 }
3294
3295 if (undefVars)
3296 {
3297 status = INCOMPLETE;
3298 }
3299
3300 fprintf(stderr, "%s\n", configError_1Str);
3301 fprintf(stderr, "%d%s\n", undefVars, configError_2Str);
3302 return(status);
3303 }
3304
3305 int ca_mandVarChk(void)
/* [<][>][^][v][top][bottom][index][help] */
3306 /****************************************************************
3307 * ca_mandVarChk *
3308 * - Looks for undefined mandatory variables *
3309 * Parameters *
3310 * - confVars, the array of Configuration Variables *
3311 * - dictionary, the dictionary of Configuration Variables *
3312 * *
3313 * Returns *
3314 * an integer, -1 or 0. *
3315 * *
3316 ****************************************************************/
3317 {
3318 int symbol; /* A counting variable */
3319 int status = 0; /* Assume that the Configuration File is complete. */
3320 int undefVars = 0; /* Number of undefined variables. */
3321
3322 /*
3323 * This output does not tell us anything useful.
3324 * Thus, we comment it out.
3325 *
3326 * puts("Running mandatory variables check .....");
3327 */
3328
3329 for(symbol = 0; symbol < CA_NUMBEROFSYMBOLS; symbol++)
3330 {
3331 if ( dictionary[symbol].varMandatory && (!confVars[symbol].strPtr) )
3332 {
3333 ++undefVars;
3334 fprintf(stderr, "%s %s\n", configWarningStr, dictionary[symbol].varName);
3335 }
3336 }
3337
3338
3339 if (undefVars)
3340 {
3341 status = INCOMPLETE;
3342
3343 fprintf(stderr, "%s\n", configError_1Str);
3344 fprintf(stderr, "%d%s\n", undefVars, configError_2Str);
3345 }
3346 else
3347 {
3348 /*
3349 * This output does not give us new information.
3350 * Thus, we comment it out.
3351 *
3352 * fprintf(stderr, "%s\n", configVarChk_OK_Str);
3353 */
3354 }
3355
3356 return(status);
3357
3358 }