BSD 4_3_Net_2 development
[unix-history] / usr / src / contrib / isode / others / rfa / rfa2fi.c
CommitLineData
11492ebf
C
1/*
2 * RFA - Remote File Access
3 *
4 * Access and Management for a partial file system tree that exists
5 * at two sites either as master files or slave files
6 *
7 * rfa2fi.c : convert between RfaInfo and type_RFA_FileInfoList and vice versa
8 *
9 * Contributed by Oliver Wenzel, GMD Berlin, 1990
10 *
11 * $Header: /f/osi/others/rfa/RCS/rfa2fi.c,v 7.3 91/02/22 09:28:20 mrose Interim $
12 *
13 * $Log: rfa2fi.c,v $
14 * Revision 7.3 91/02/22 09:28:20 mrose
15 * Interim 6.8
16 *
17 * Revision 7.2 91/01/14 13:54:56 mrose
18 * update
19 *
20 * Revision 1.1 91/01/04 16:07:24 ow
21 * Initial revision
22 *
23 */
24
25#ifndef lint
26static char *rcsid = "$Header: /f/osi/others/rfa/RCS/rfa2fi.c,v 7.3 91/02/22 09:28:20 mrose Interim $";
27#endif
28
29/*
30 * NOTICE
31 *
32 * Acquisition, use, and distribution of this module and related
33 * materials are subject to the restrictions of a license agreement.
34 * Consult the Preface in the User's Manual for the full terms of
35 * this agreement.
36 *
37 */
38
39
40#include <stdio.h>
41#include "rfa.h"
42#include "RFA-types.h"
43#include "rfainfo.h"
44
45extern char *getRelativeFN();
46extern char *fsBase;
47
48/*--------------------------------------------------------------------
49 * rfa2fi - RfaInfo to type_RFA_FileInfo
50 *--------------------------------------------------------------------*/
51struct type_RFA_FileInfo *rfa2fi(dir, rfa)
52 char *dir;
53 struct RfaInfo *rfa;
54{
55 struct type_RFA_FileInfo *fi;
56 char *l;
57
58 if ((fi = (struct type_RFA_FileInfo *)
59 malloc(sizeof(struct type_RFA_FileInfo))) == NULL)
60 {
61 sprintf(rfaErrStr, "out of memory");
62 return NULL;
63 }
64 fi->name = str2qb(rfa->ri_filename, strlen(rfa->ri_filename), 1);
65 fi->mode = rfa->ri_mode;
66 fi->user = str2qb(rfa->ri_owner, strlen(rfa->ri_owner), 1);
67 fi->group = str2qb(rfa->ri_group, strlen(rfa->ri_group), 1);
68 fi->size = rfa->ri_size;
69 fi->accTime = rfa->ri_accTime;
70 fi->modTime = rfa->ri_modTime;
71 if (l = rfa->ri_lnkName) {
72 if (*l != '/') {
73 if (getRelativeFN(realPath3(fsBase, dir, l)) == NULL)
74 l = "(link outside RFA context)";
75 } else
76 if ((l = getRelativeFN(rfa->ri_lnkName)) == NULL)
77 l = "(link outside RFA context)";
78 fi->lnkName = str2qb(l, strlen(l), 1);
79 } else
80 fi->lnkName = NULL;
81 fi->status = rfa->ri_status;
82 if (IS_LOCKED(rfa->ri_status)) {
83 fi->lockedBy = str2qb(rfa->ri_lckname, strlen(rfa->ri_lckname), 1);
84 fi->lockedSince = rfa->ri_lcksince;
85 } else {
86 fi->lockedBy = NULL;
87 fi->lockedSince = NULL;
88 }
89 return fi;
90}
91
92/*--------------------------------------------------------------------
93 * rfa2fil - RfaInfo to type_RFA_FileInfoList
94 *--------------------------------------------------------------------*/
95struct type_RFA_FileInfoList *rfa2fil(dir, rfa)
96 char *dir;
97 struct RfaInfo *rfa;
98{
99 struct type_RFA_FileInfoList *fil, **filp;
100
101 filp = &fil;
102 for (; rfa; rfa = rfa->ri_next) {
103 if (((*filp) = (struct type_RFA_FileInfoList *)
104 malloc(sizeof(struct type_RFA_FileInfoList))) == NULL)
105 {
106 free_RFA_FileInfoList(fil);
107 sprintf(rfaErrStr, "out of memory");
108 return NULL;
109 }
110 (*filp)->next = NULL;
111 if (((*filp)->FileInfo = rfa2fi(dir, rfa)) == NULL) {
112 free_RFA_FileInfoList(fil);
113 return NULL;
114 }
115 filp = &((*filp)->next);
116 }
117 return fil;
118}
119
120/*--------------------------------------------------------------------
121 * fi2rfa - type_RFA_FileInfoList to RfaInfo
122 *--------------------------------------------------------------------*/
123struct RfaInfo *fi2rfa(fil)
124 struct type_RFA_FileInfoList *fil;
125{
126 struct type_RFA_FileInfo *fi;
127 struct RfaInfo *rfa, *rfaNew;
128 char *l;
129
130 rfa = NULL;
131 for (; fil; fil = fil->next) {
132 fi = fil->FileInfo;
133 if ((rfaNew = mallocRfaInfo(qb2str(fi->name))) == NULL) {
134 freeRfaInfoList(rfa);
135 return NULL;
136 }
137 rfaNew->ri_next = rfa;
138 rfa = rfaNew;
139
140 rfa->ri_mode = fi->mode;
141 rfa->ri_owner = qb2str(fi->user);
142 rfa->ri_group = qb2str(fi->group);
143 rfa->ri_size = fi->size;
144 rfa->ri_accTime = fi->accTime;
145 rfa->ri_modTime = fi->modTime;
146 if (fi->lnkName) {
147 l = qb2str(fi->lnkName);
148 if (*l == '/')
149 l = makeFN(l);
150 rfa->ri_lnkName = strdup(l);
151 } else
152 rfa->ri_lnkName = NULL;
153 rfa->ri_status = fi->status;
154 if (IS_LOCKED(rfa->ri_status)) {
155 rfa->ri_lckname = qb2str(fi->lockedBy);
156 rfa->ri_lcksince = fi->lockedSince;
157 } else {
158 rfa->ri_lckname = NULL;
159 rfa->ri_lcksince = NULL;
160 }
161 }
162 return rfa;
163}
164
165