-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGS_NETW.CPP
More file actions
2136 lines (1783 loc) · 73.7 KB
/
Copy pathGS_NETW.CPP
File metadata and controls
2136 lines (1783 loc) · 73.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**********************************************************
Name: GS_NETW.CPP
Module description: File funzioni di base per la gestione
dei nodi di rete e conversione tra path logico
e path reale.
Author: Roberto Poltini & Paolo De Sole
(c) Copyright 2003-2015 by IREN ACQUA GAS S.p.a.
**********************************************************/
/**************************************************************************/
/* INCLUDE */
/**************************************************************************/
#include "stdafx.h" // MFC core and standard components
#define INITGUID
#import "msado15.dll" no_namespace rename ("EOF", "EndOfFile") rename ("EOS", "ADOEOS")
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "rxdefs.h"
#include "adslib.h"
#include <adeads.h>
#include "gs_opcod.h" // codici delle operazioni
#include "..\gs_def.h" // definizioni globali
#include "gs_error.h"
#include "gs_list.h"
#include "gs_utily.h"
#include "gs_init.h"
#include "gs_user.h" // check_op
#include "gs_sql.h"
#include "gs_netw.h"
#include "gs_resbf.h"
#include "gs_class.h"
#include "gs_sec.h"
#include "gs_prjct.h" // gestione progetti
#include "gs_graph.h"
#include "gs_cmd.h"
/**********************************************************************/
/* PRIVATE VARIABLES */
/**********************************************************************/
/**********************************************************************/
/* GLOBAL VARIABLES */
/**********************************************************************/
/**********************************************************************/
/* PRIVATE FUNCTIONS */
/**********************************************************************/
int gsc_ConvAlias(const TCHAR *NewAlias, const TCHAR *OldAlias, int prj = -1,
int cls = -1, int sub = -1, int sec = -1, const TCHAR *AttribName = NULL);
int gsc_ConvUDLProperties(C_STRING &FullUDLFile, C_STRING &UDLProperties,
C_STRING &CpyOldAlias, C_STRING &CpyNewAlias);
/*************************************************************************/
/*.doc gsc_OSCode2OSName */
/*+
Funzione che restituisce il nome del sistema operativo
prendendo in input il codice che lo rappresenta.
Parametri:
enum OperatingSystemsEnum OSCode; Codice del sistema operativo
Restituisce il nome del sistema operativo in caso di successo altrimenti NULL.
-*/
/*************************************************************************/
const TCHAR* gsc_OSCode2OSName(enum OperatingSystemsEnum OSCode)
{
switch (OSCode)
{
case GS_OS_DOS:
return gsc_msg(167); // "DOS"
case GS_OS_WINDOWS:
return gsc_msg(168); // "WINDOWS"
case GS_OS_WINDOWS_NT_2000:
return gsc_msg(169); // "WINDOWS NT/2000"
case GS_OS_UNIX:
return gsc_msg(170); // "UNIX"
case GS_OS_WINDOWS_95_98:
return gsc_msg(599); // "WINDOWS 95/98"
case GS_OS_WINDOWS_XP:
return gsc_msg(469); // "WINDOWS XP"
case GS_OS_WINDOWS_VISTA:
return gsc_msg(470); // "WINDOWS VISTA"
default:
GS_ERR_COD = eGSInvOpSys;
return NULL;
}
}
/*************************************************************************/
/*.doc gsc_OSName2OSCode */
/*+
Funzione che restituisce il codice del sistema operativo
prendendo in inpout il nome che lo rappresenta.
Parametri
const TCHAR *OSName;
Ritorna il codice del sistema operativo
-*/
/*************************************************************************/
enum OperatingSystemsEnum gsc_OSName2OSCode(const TCHAR *OSName)
{
if (_wcsicmp(OSName, gsc_msg(167)) == 0) // "DOS"
return GS_OS_DOS;
else if (_wcsicmp(OSName, gsc_msg(168)) == 0) // "WINDOWS"
return GS_OS_WINDOWS;
else if (_wcsicmp(OSName, gsc_msg(169)) == 0) // "WINDOWS NT/2000"
return GS_OS_WINDOWS_NT_2000;
else if (_wcsicmp(OSName, gsc_msg(170)) == 0) // "UNIX"
return GS_OS_UNIX;
else if (_wcsicmp(OSName, gsc_msg(599)) == 0) // "WINDOWS 95/98"
return GS_OS_WINDOWS_95_98;
else if (_wcsicmp(OSName, gsc_msg(469)) == 0) // "WINDOWS XP"
return GS_OS_WINDOWS_XP;
else if (_wcsicmp(OSName, gsc_msg(470)) == 0) // "WINDOWS VISTA"
return GS_OS_WINDOWS_VISTA;
GS_ERR_COD = eGSInvOpSys;
return GS_OS_UNKNOWN;
}
/**********************************************************************/
/* C_ALIAS INIZIO */
/**********************************************************************/
//-----------------------------------------------------------------------//
int C_ALIAS::set_host(const TCHAR *in)
{
size_t len, lenhost;
if ((in == NULL) || (wcslen(in) == 0))
{
if (host != NULL) { free(host); host = NULL; }
return GS_GOOD;
}
len = wcslen(in);
if (len == 0) { GS_ERR_COD = eGSStringNull; return GS_BAD; }
lenhost = (host == NULL) ? 0 : wcslen(host);
if (len > lenhost)
if ((host = (TCHAR *) realloc(host, (len + 1) * sizeof(TCHAR))) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return GS_BAD; }
wcscpy(host, in);
return GS_GOOD;
}
//-----------------------------------------------------------------------//
int C_ALIAS::set_path(const TCHAR *in)
{
size_t len, lenpath;
if ((in == NULL) || (wcslen(in) == 0))
{
if (path != NULL) { free(path); path = NULL; }
return GS_GOOD;
}
len = wcslen(in);
if (len == 0) { GS_ERR_COD = eGSStringNull; return GS_BAD; }
lenpath = (path == NULL) ? 0 : wcslen(path);
if (len > lenpath)
if ((path = (TCHAR *) realloc(path, (len + 1) * sizeof(TCHAR))) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return GS_BAD; }
wcscpy(path, in);
return GS_GOOD;
}
/*************************************************************************/
/*.doc (new 2) C_ALIAS::is_valid_path() */
/*+
Funzione che controlla la correttezza della path in base al sistema operativo
ritorna:
GS_BAD errore
GS_GOOD Ok, path corretta
-*/
/*************************************************************************/
int C_ALIAS::is_valid_path()
{
int Result = GS_GOOD;
switch (op_sys)
{
case GS_OS_UNIX:
if (!path || wcslen(path) == 0) Result = GS_BAD;
break;
default:
if (!path || wcslen(path) > 2) Result = GS_BAD;
else
if (!iswalpha(path[0]) || path[1] != _T(':')) Result = GS_BAD;
gsc_toupper(path);
}
if (Result == GS_BAD)
{
if (host) acutPrintf(gsc_msg(618), host); // \nLa path dell'alias <%s> non è valida (deve essere 2 caratteri, es. 'C:', 'D:'...).
GS_ERR_COD = eGSInvalidPath;
}
return Result;
}
/*************************************************************************/
/*.doc (new 2) C_ALIAS::is_valid_host() */
/*+
Funzione che controlla la correttezza dell'host
ritorna:
GS_GOOD errore
GS_BAD Ok, host corretto
-*/
/*************************************************************************/
int C_ALIAS::is_valid_host()
{
TCHAR insieme_valido[] = _T("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz");
size_t i, len;
int Result = GS_GOOD;
do
{
if (!host) { Result = GS_BAD; break; }
gsc_toupper(host);
len = wcslen(host);
if (len >= MAX_LEN_HOSTNAME || wcslen(host) == 0) { Result = GS_BAD; break; }
for (i = 0; i < len; i++)
if (wcschr(insieme_valido, host[i]) == NULL)
{ GS_ERR_COD = eGSInvalidHost; Result = GS_BAD; break; }
if (Result == GS_BAD) break;
Result = GS_GOOD;
}
while (0);
if (Result == GS_BAD)
{
acutPrintf(gsc_msg(619), host); // "\nL'alias <%s> non è valida (ammessi solo caratteri alfanumerici + '_')."
GS_ERR_COD = eGSInvalidHost;
}
return Result;
}
/*************************************************************************/
/*.doc (new 2) C_ALIAS::is_valid() */
/*+
Funzione che controlla la correttezza dei valori di
Path, Host, System
ritorna:
GS_BAD errore
GS_GOOD Ok, dati giusti
-*/
/*************************************************************************/
int C_ALIAS::is_valid()
{
if (is_valid_path()==GS_GOOD)
if (is_valid_host()==GS_GOOD)
return GS_GOOD;
return GS_BAD;
}
/*************************************************************************/
/*.doc (new 2) C_ALIAS::save() */
/*+
Funzione che salva un elemento della classe C_ALIAS
parametri:
FILE *file; puntatore al file di inizializzazione di GEOsim
bool Unicode; Flag che determina se il contenuto del file è in
formato UNICODE o ANSI (default = false)
Ritorna GS_BAD in caso di errore altrimenti GS_GOOD.
-*/
/*************************************************************************/
int C_ALIAS::save(FILE *file, bool Unicode)
{
C_ALIAS *pogg;
if ((pogg = GEOsimAppl::GS_NET_LIST.search_host(get_host()))==NULL)
{
// inserimento nuovo alias (scrivo su file) con funzioni di ADE
if (ade_aliasadd(get_host(), get_path()) == RTERROR)
{ GS_ERR_COD = eGSInvalidAdeIni; return GS_BAD; }
// inserimento nuovo alias (scrivo su file) sezione di GEOsim
if (gsc_set_profile(file, GS_NET_LABEL, get_host(),
gsc_OSCode2OSName(get_op_sys()), 0 , Unicode) == GS_BAD)
return GS_BAD;
if ((pogg = new C_ALIAS)==NULL)
{ GS_ERR_COD = eGSOutOfMem; return GS_BAD; }
pogg->set_path(get_path());
pogg->set_host(get_host());
pogg->set_op_sys(get_op_sys());
GEOsimAppl::GS_NET_LIST.add_tail(pogg);
}
else
{
// modifica di un alias (scrivo su file) con funzioni di ADE
if (ade_aliasupdate(get_host(), get_path()) == RTERROR)
{ GS_ERR_COD = eGSInvalidAdeIni; return GS_BAD; }
// modifica di un alias (scrivo su file) sezione di GEOsim
if (gsc_set_profile(file, GS_NET_LABEL, get_host(),
gsc_OSCode2OSName(get_op_sys()), 0, Unicode) == GS_BAD)
return GS_BAD;
pogg->set_path(get_path());
pogg->set_host(get_host());
pogg->set_op_sys(get_op_sys());
}
return GS_GOOD;
}
/*************************************************************************/
/*.doc (new 2) C_ALIAS::del() */
/*+
Funzione che cancella un elemento della classe C_ALIAS
parametri:
FILE *file; puntatore al file di inizializzazione di GEOsim
bool Unicode; Flag che determina se il contenuto del file è in
formato UNICODE o ANSI (default = false)
Ritorna GS_BAD in caso di errore altrimenti GS_GOOD.
-*/
/*************************************************************************/
int C_ALIAS::del(FILE *file, bool Unicode)
{
C_ALIAS *pogg;
C_STRING Buffer;
// cancellazione alias con funzioni di ADE
// non funziona se ci sono DWG attaccati che utilizzano l'alias
if (ade_aliasdelete(get_host()) == RTERROR)
{ GS_ERR_COD = eGSInvalidAdeIni; return GS_BAD; }
// se esiste nella sezione
if (gsc_get_profile(file, GS_NET_LABEL, get_host(), Buffer, Unicode) == GS_GOOD &&
Buffer.len() > 0)
// cancellazione alias dalla sezione di GEOsim
if (gsc_delete_entry(file, GS_NET_LABEL, get_host(), Unicode) == GS_BAD)
return GS_BAD;
if ((pogg = (C_ALIAS *) GEOsimAppl::GS_NET_LIST.search_host(get_host())) == NULL) return GS_BAD;
GEOsimAppl::GS_NET_LIST.remove(pogg);
return GS_GOOD;
}
/**********************************************************************/
/* C_ALIAS FINE */
/* C_ALIAS_LIST INIZIO */
/**********************************************************************/
/*************************************************************************/
/*.doc (new 2) C_ALIAS_LIST::save() */
/*+
Funzione che la lista degli Alias
parametri:
<char *path> .. file Ade.ini(.. per ora)
ritorna:
GS_BAD errore
GS_GOOD Ok il salvataggio è andato bene
-*/
/*************************************************************************/
int C_ALIAS_LIST::save()
{
C_ALIAS *punt;
C_STRING pathfile;
FILE *file;
bool Unicode = false;
// Questa funzione è utilizzabile solo se non esiste una sessione di lavoro attiva
// e quindi non ci sono DWG attaccati perchè vengono richiamate alcune funzioni ADE
// (es. "ade_aliasdelete") che non vanno e non restituiscono messaggio di errore
// se ci sono dei DWG attaccati che utilizzano l'alias.
if (GS_CURRENT_WRK_SESSION) { GS_ERR_COD = eGSSessionsFound; return GS_BAD; }
if (get_count() <= 0) { GS_ERR_COD = eGSInvalidArg; return GS_BAD; }
// Apro il file di inizializzazione GEOSIM.INI
pathfile = GEOsimAppl::CURRUSRDIR; // Directory locale dell'utente corrente;
pathfile += _T('\\');
pathfile += GS_INI_FILE;
if ((file = gsc_open_profile(pathfile, UPDATEABLE, MORETESTS, &Unicode)) == NULL)
return GS_BAD;
// ciclo di aggiornamento e inserimento nuovi nodi
punt = (C_ALIAS *) get_head();
while (punt)
{
if (punt->save(file, Unicode) == GS_BAD)
{ gsc_close_profile(file); return GS_BAD; }
punt =(C_ALIAS *) punt->get_next();
}
// ciclo di cancellazione nodi
punt = (C_ALIAS *) GEOsimAppl::GS_NET_LIST.get_head();
while (punt)
{
if (search_host(punt->get_host()) == NULL)
{
if (punt->del(file, Unicode) == GS_BAD)
{ gsc_close_profile(file); return GS_BAD; }
punt = (C_ALIAS *) GEOsimAppl::GS_NET_LIST.get_cursor();
}
else punt =(C_ALIAS *) punt->get_next();
}
// Chiudo il file di inizializzazione GEOSIM.INI
if (gsc_close_profile(file) == GS_BAD) return GS_BAD;
// Salvo la lista degli host sul server
saveHostsToSrv();
return GS_GOOD;
}
//-----------------------------------------------------------------------//
C_ALIAS *C_ALIAS_LIST::search_host(const TCHAR *in, int CaseSensitive)
{
C_ALIAS *p;
p = (C_ALIAS *) get_head();
while (p != NULL)
{
if (gsc_strcmp(p->get_host(), in, CaseSensitive) == 0) break;
p = (C_ALIAS *) get_next();
}
return p;
}
//-----------------------------------------------------------------------//
C_ALIAS *C_ALIAS_LIST::search_host_xptr(const TCHAR *in, C_ALIAS *pAlias,
int CaseSensitive)
{
C_ALIAS *p;
if (CaseSensitive==GS_GOOD)
{
p = (C_ALIAS *) get_head();
while (p != NULL)
{
if (pAlias!=p && gsc_strcmp(p->get_host(), in) == 0) break;
p = (C_ALIAS *) get_next();
}
}
else
{
TCHAR dummy1[MAX_LEN_HOSTNAME], dummy2[MAX_LEN_HOSTNAME];
wcscpy(dummy1, in);
gsc_toupper(dummy1);
p = (C_ALIAS *) get_head();
while (p != NULL)
{
wcscpy(dummy2, p->get_host());
gsc_toupper(dummy2);
if (pAlias!=p && gsc_strcmp(dummy2, dummy1) == 0) break;
p = (C_ALIAS *) get_next();
}
}
if (p==NULL) GS_ERR_COD=eGSInvalidHost;
return p;
}
//-----------------------------------------------------------------------//
C_ALIAS *C_ALIAS_LIST::search_path(const TCHAR *in, int CaseSensitive)
{
C_ALIAS *p;
if (CaseSensitive==GS_GOOD)
{
p = (C_ALIAS *) get_head();
while (p != NULL)
{
if (gsc_strcmp(p->get_path(), in) == 0) break;
p = (C_ALIAS *) get_next();
}
}
else
{
TCHAR dummy1[MAX_LEN_HOSTNAME], dummy2[MAX_LEN_HOSTNAME];
wcscpy(dummy1, in);
gsc_toupper(dummy1);
p = (C_ALIAS *) get_head();
while (p != NULL)
{
wcscpy(dummy2, p->get_path());
gsc_toupper(dummy2);
if (gsc_strcmp(dummy2, dummy1) == 0) break;
p = (C_ALIAS *) get_next();
}
}
return p;
}
//-----------------------------------------------------------------------//
C_ALIAS *C_ALIAS_LIST::search_path_xptr(const TCHAR *in, C_ALIAS *pAlias,
int CaseSensitive)
{
C_ALIAS *p;
if (CaseSensitive==GS_GOOD)
{
p = (C_ALIAS *) get_head();
while (p != NULL)
{
if (pAlias!=p && gsc_strcmp(p->get_path(), in) == 0) break;
p = (C_ALIAS *) get_next();
}
}
else
{
TCHAR dummy1[MAX_LEN_HOSTNAME], dummy2[MAX_LEN_HOSTNAME];
wcscpy(dummy1, in);
gsc_toupper(dummy1);
p = (C_ALIAS *) get_head();
while (p != NULL)
{
wcscpy(dummy2, p->get_path());
gsc_toupper(dummy2);
if (pAlias!=p && gsc_strcmp(dummy2, dummy1) == 0) break;
p = (C_ALIAS *) get_next();
}
}
return p;
}
//-----------------------------------------------------------------------//
int C_ALIAS_LIST::copy(C_ALIAS_LIST *out)
{
C_ALIAS *new_node, *punt;
if (out==NULL) { GS_ERR_COD = eGSNotAllocVar; return GS_BAD; }
punt=(C_ALIAS*)get_head();
out->remove_all();
while(punt!=NULL)
{
if ((new_node= new C_ALIAS)==NULL)
{ remove_all(); GS_ERR_COD=eGSOutOfMem; return GS_BAD; }
new_node->set_path(punt->get_path());
new_node->set_host(punt->get_host());
new_node->set_op_sys(punt->get_op_sys());
out->add_tail(new_node);
punt=(C_ALIAS*)get_next();
}
return GS_GOOD;
}
//-----------------------------------------------------------------------//
int C_ALIAS_LIST::add_to_mem(C_ALIAS *pAlias)
{
if (!pAlias) { GS_ERR_COD = eGSInvalidArg; return GS_BAD; }
if (pAlias->is_valid() == GS_BAD) return GS_BAD;
// verifico eventuale esistenza di un path uguale (se UNIX case sensitive)
if (search_path(pAlias->get_path(),
(pAlias->get_op_sys() != GS_OS_UNIX) ? GS_BAD : GS_GOOD) != NULL)
{ // "\nLa path <%s> avente alias <%s>, è stata scartata perchè già presente in lista."
acutPrintf(gsc_msg(635), pAlias->get_host(), pAlias->get_path());
GS_ERR_COD = eGSPathAlreadyExisting;
return GS_BAD;
}
// verifico eventuale esistenza di un host uguale
if (search_host(pAlias->get_host()) != NULL)
{ // "\nL'alias <%s> avente path <%s>, è stato scartato perchè già presente in lista."
acutPrintf(gsc_msg(288), pAlias->get_host(), pAlias->get_path());
GS_ERR_COD = eGSAliasAlreadyExisting;
return GS_BAD;
}
if (pAlias->get_op_sys() == GS_OS_UNIX)
{
C_STRING upperstr;
C_ALIAS *punt;
// cerco il path maiuscolo e, se esiste, verifico che sia UNIX altrimenti errore
upperstr = pAlias->get_path();
upperstr.toupper();
if ((punt = search_path(upperstr.get_name())) != NULL &&
punt->get_op_sys() != GS_OS_UNIX)
{ GS_ERR_COD = eGSPathAlreadyExisting; return GS_BAD; }
}
add_tail(pAlias);
return GS_GOOD;
}
//-----------------------------------------------------------------------//
int C_ALIAS_LIST::upd_to_mem(C_ALIAS *pOrig, C_ALIAS *pAlias)
{
C_ALIAS *p;
int unix_sys;
if (!pOrig || !pAlias) { GS_ERR_COD = eGSInvalidArg; return GS_BAD; }
if (pAlias->is_valid() == GS_BAD) return GS_BAD;
unix_sys = (pAlias->get_op_sys() != GS_OS_UNIX) ? GS_BAD : GS_GOOD;
// verifico eventuale esistenza di un path uguale (se UNIX case sensitive)
if ((p = search_path_xptr(pAlias->get_path(), pOrig, unix_sys)) != NULL)
{ GS_ERR_COD = eGSAliasAlreadyExisting; return GS_BAD; }
// verifico eventuale esistenza di un host uguale (se UNIX case sensitive)
if ((p = search_host_xptr(pAlias->get_host(), pOrig, unix_sys)) != NULL)
{ GS_ERR_COD = eGSAliasAlreadyExisting; return GS_BAD; }
if (unix_sys == GS_GOOD)
{
C_STRING upperstr;
C_ALIAS *punt;
// cerco il path maiuscolo e, se esiste, verifico che sia UNIX altrimenti errore
upperstr = pAlias->get_path();
upperstr.toupper();
if ((punt = search_path_xptr(upperstr.get_name(), pOrig))!=NULL &&
punt->get_op_sys() != GS_OS_UNIX)
{ GS_ERR_COD = eGSAliasAlreadyExisting; return GS_BAD; }
// cerco l'host maiuscolo e, se esiste, verifico che sia UNIX altrimenti errore
upperstr = pAlias->get_host();
upperstr.toupper();
if ((punt = search_host_xptr(upperstr.get_name(), pOrig))!=NULL &&
punt->get_op_sys() != GS_OS_UNIX)
{ GS_ERR_COD = eGSAliasAlreadyExisting; return GS_BAD; }
}
pOrig->set_path(pAlias->get_path());
pOrig->set_host(pAlias->get_host());
pOrig->set_op_sys(pAlias->get_op_sys());
return GS_GOOD;
}
//-----------------------------------------------------------------------//
int C_ALIAS_LIST::del_to_mem(C_ALIAS *pAlias)
{
C_ALIAS *p;
if (!pAlias) { GS_ERR_COD = eGSInvalidArg; return GS_BAD; }
if (pAlias->is_valid() == GS_BAD) return GS_BAD;
if ((p = search_path(pAlias->get_path())) == NULL)
{ GS_ERR_COD = eGSInvalidPath; return GS_BAD; }
remove((C_NODE*) p);
return GS_GOOD;
}
//-----------------------------------------------------------------------//
int C_ALIAS_LIST::load()
{
C_STRING desc_host;
int count=0, parola=0, indprinc=0, indtemp=0, cont=0;
enum OperatingSystemsEnum OSCode = GS_OS_UNKNOWN;
C_ALIAS *punt;
presbuf p, prb;
remove_all();
// Chiamata funzione Ade che restituisce lista Alias
if ((prb = p = ade_aliasgetlist()) == NULL) return GS_GOOD;
while (p)
{
switch (p->restype)
{
case RTLB: // parentesi aperta
case RTLE: // parentesi chiusa
p = p->rbnext;
break;
case RTSTR: // Alias
if ((cont%2)!=0)
{
if ((punt = new C_ALIAS) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
punt->set_path(p->resval.rstring);
punt->set_host(desc_host.get_name());
if (add_to_mem(punt) == GS_BAD)
delete punt;
}
else desc_host = p->resval.rstring;
p = p->rbnext;
cont++;
break;
default:
GS_ERR_COD = eGSInvRBType;
return GS_BAD;
}
}
if (prb) acutRelRb(prb);
// Lettura sezione GS_NET_LABEL = "GEOsim Net Nodes" nel file di
// inizializzazione GEOSIM.INI
FILE *file;
C_STRING pathfile, Buffer;
bool Unicode;
pathfile = GEOsimAppl::CURRUSRDIR; // Directory locale dell'utente corrente;
pathfile += _T('\\');
pathfile += GS_INI_FILE;
if ((file = gsc_open_profile(pathfile, READONLY, MORETESTS, &Unicode)) == NULL)
{
punt = (C_ALIAS *) get_head();
while (punt)
{ //"\nL'alias <%s> avente path <%s>, pur non avendo riferimento in GEOsim, è stato considerato per WINDOWS."
acutPrintf(gsc_msg(439), punt->get_host(), punt->get_path());
punt->set_op_sys(GS_OS_WINDOWS);
punt = (C_ALIAS *) get_next();
}
return GS_GOOD;
}
punt = (C_ALIAS *) get_head();
while (punt)
{
// se esiste nella sezione
if (gsc_get_profile(file, GS_NET_LABEL, punt->get_host(), Buffer, Unicode) == GS_GOOD &&
Buffer.len() > 0)
{
// Setto il sistema operativo
if ((OSCode = gsc_OSName2OSCode(Buffer.get_name())) == GS_OS_UNKNOWN)
{ //"\nL'alias <%s> avente path <%s>, pur non avendo riferimento in GEOsim, è stato considerato per WINDOWS."
acutPrintf(gsc_msg(439), punt->get_host(), punt->get_path());
punt->set_op_sys(GS_OS_WINDOWS);
}
else
punt->set_op_sys(OSCode);
}
else // c'è un disallineamento
{ //"\nL'alias <%s> avente path <%s>, pur non avendo riferimento in GEOsim, è stato considerato per WINDOWS."
acutPrintf(gsc_msg(439), punt->get_host(), punt->get_path());
punt->set_op_sys(GS_OS_WINDOWS);
}
punt = (C_ALIAS *) get_next();
}
// Chiudo il file di inizializzazione GEOSIM.INI
return gsc_close_profile(file);
}
/*****************************************************************************/
/*.doc int C_ALIAS_LIST::loadHostsFromSrv() <internal> */
/*+
Questa funzione carica la lista degli host registrati sul server
di GEOsim dal file GEOSIM.INI nella cartella SUPPORT.
La lista avrà solo gli host e i sistemi operativi settati
opportunamente, le path saranno nulle.
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*****************************************************************************/
int C_ALIAS_LIST::loadHostsFromSrv()
{
// Lettura sezione GS_NET_LABEL = "GEOsim Net Nodes" nel file di
// inizializzazione GEOSIM.INI sul server
C_STRING PathFile;
FILE *file;
C_2STR_LIST EntryList;
bool Unicode;
remove_all(); // svuoto la lista
PathFile = GEOsimAppl::GEODIR; // Directory server di GEOsim
PathFile += _T('\\');
PathFile += GEOSUPPORTDIR;
PathFile += _T('\\');
PathFile += GS_INI_FILE;
if ((file = gsc_open_profile(PathFile, READONLY, MORETESTS, &Unicode)) == NULL)
return GS_GOOD;
if (gsc_get_profile(file, GS_NET_LABEL, EntryList, Unicode) == GS_GOOD)
{
C_2STR *pEntry = (C_2STR *) EntryList.get_head();
C_ALIAS *pAlias;
enum OperatingSystemsEnum OSCode;
while (pEntry)
{
if ((pAlias = new C_ALIAS()) == NULL)
{ gsc_close_profile(file); GS_ERR_COD = eGSOutOfMem; return GS_BAD; }
pAlias->set_host(pEntry->get_name());
// Setto il sistema operativo
if ((OSCode = gsc_OSName2OSCode(pEntry->get_name2())) == GS_BAD)
pAlias->set_op_sys(GS_OS_WINDOWS);
else
pAlias->set_op_sys(OSCode);
add_tail(pAlias);
pEntry = (C_2STR *) pEntry->get_next();
}
}
// Chiudo il file di inizializzazione GEOSIM.INI
return gsc_close_profile(file);
}
/*****************************************************************************/
/*.doc int C_ALIAS_LIST::saveHostsToSrv() <internal> */
/*+
Questa funzione salva la lista degli host locali facendo una unione con quella
degli host già registrati sul server di GEOsim.
Il salvataggio viene effettuato nel file GEOSIM.INI nella cartella SUPPORT.
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*****************************************************************************/
int C_ALIAS_LIST::saveHostsToSrv()
{
// Lettura sezione GS_NET_LABEL = "GEOsim Net Nodes" nel file di
// inizializzazione GEOSIM.INI sul server
C_STRING PathFile;
FILE *file;
C_ALIAS_LIST ResultList;
C_ALIAS *pAlias, *p;
bool Unicode = false;
ResultList.loadHostsFromSrv(); // carico la lista dal server
// Unisco le due liste
pAlias = (C_ALIAS *) get_head();
while (pAlias)
{
if (!(p = ResultList.search_host(pAlias->get_host())))
{
if ((p = new C_ALIAS()) == NULL) // se non esiste lo aggiungo
{ GS_ERR_COD = eGSOutOfMem; return GS_BAD; }
ResultList.add_tail(p);
}
p->set_host(pAlias->get_host()); // Setto il nome dell'host
p->set_op_sys(pAlias->get_op_sys()); // Setto il sistema operativo
pAlias = (C_ALIAS *) get_next();
}
C_2STR_LIST EntryList;
C_2STR *pEntry;
// Creo una lista C_2STR_LIST
pAlias = (C_ALIAS *) ResultList.get_head();
while (pAlias)
{
if (!(pEntry = new C_2STR(pAlias->get_host(), gsc_OSCode2OSName(pAlias->get_op_sys()))))
{ GS_ERR_COD = eGSOutOfMem; return GS_BAD; }
EntryList.add_tail(pEntry);
pAlias = (C_ALIAS *) pAlias->get_next();
}
PathFile = GEOsimAppl::GEODIR; // Directory server di GEOsim
PathFile += _T('\\');
PathFile += GEOSUPPORTDIR;
PathFile += _T('\\');
PathFile += GS_INI_FILE;
if ((file = gsc_open_profile(PathFile, UPDATEABLE, MORETESTS, &Unicode)) == NULL)
return GS_GOOD;
if (gsc_set_profile(file, GS_NET_LABEL, EntryList, Unicode) == GS_BAD)
{ gsc_close_profile(file); return GS_BAD; }
// Chiudo il file di inizializzazione GEOSIM.INI
return gsc_close_profile(file);
}
/**********************************************************************/
/* C_ALIAS_LIST FINE */
/**********************************************************************/
/*************************************************************************/
/*.doc int gsc_nethost2drive(char *path) */
/*+
Traduce un path sostituendo il nome della connessione in rete
(<nome macchina+directory condivise>) all'inizio del path con il drive
corrispondente (es. <MACCHINA1>\DIR -> C:\DIR oppure $GEOWORK$\DIR e
$GEOSIM$\DIR che si riferiscono rispettivamente al direttorio di lavoro
locale e al direttorio di installazione della parte "server" di GEOsim).
Paramertri:
C_STRING &path; Path da tradurre
int PrintError; Se il flag = GS_GOOD in caso di errore viene
stampato il messaggio relativo altrimenti non
viene stampato alcun messaggio (default = GS_GOOD)
oppure:
char *path; Path da tradurre
int maxlen; Lunghezza max. stringa
int PrintError; Se il flag = GS_GOOD in caso di errore viene
stampato il messaggio relativo altrimenti non
viene stampato alcun messaggio (default = GS_GOOD)
Ritorna GS_BAD in caso di errore GS_GOOD altrimenti.
-*/
/*************************************************************************/
int gsc_nethost2drive(C_STRING &path, int PrintError)
{
C_STRING Prefix;
C_ALIAS *punt = NULL;
int i;
if (path.len() == 0) return GS_GOOD;
path.alltrim();
if (path.get_chr(0) == _T('<'))
{
i = 0;
while (path.get_chr(++i) != _T('>'))
{
if (path.get_chr(i) == _T('\0'))
{ GS_ERR_COD = eGSInvalidPath; return GS_BAD; }
Prefix += path.get_chr(i);
}
if ((punt = GEOsimAppl::GS_NET_LIST.search_host(Prefix.get_name())) == NULL)
{
if (PrintError == GS_GOOD)
acutPrintf(gsc_msg(524), Prefix.get_name(), path.get_name()); // Trovato Host sconosciuto: <%s> nel riferimento: <%s>
GS_ERR_COD = eGSInvHostName;
return GS_BAD;
}
}
else
if (path.get_chr(0) == _T('$')) // macro di $GEOWORK$ o $GEOSIM$
{
i = 0;
while (path.get_chr(++i) != _T('$'))
{
if (path.get_chr(i) == _T('\0'))
{ GS_ERR_COD = eGSInvalidPath; return GS_BAD; }
Prefix += path.get_chr(i);
}
if (Prefix.comp(ENV_WORK_DIR, FALSE) == 0) // no case sensitive ("GEOWORK")
Prefix = GEOsimAppl::WORKDIR;
else
if (Prefix.comp(ENV_GEO_DIR, FALSE) == 0) // no case sensitive ("GEOSIM")
Prefix = GEOsimAppl::GEODIR;
else
{ GS_ERR_COD = eGSInvHostName; return GS_BAD; }
}
else // o si tratta di un alias stile ADE (es. "COMPUTER1:\DIR\A.DWG")
{ // oppure di un direttorio senza alias (es. "C:\DIR\A.DWG")
// oppure di un direttorio senza drive (es. "\DIR\A.DWG")
C_STRING TempPath;
i = 0;
while (path.get_chr(i) != _T('\0') && path.get_chr(i) != _T(':'))
{
Prefix += path.get_chr(i);
i++;