ecfdcf58ad9d0c8551ec13eb1c1d8586383f81e0
2 Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
6 This program is distributed in the hope that it will be useful,
7 but WITHOUT ANY WARRANTY; without even the implied warranty of
8 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 GNU Lesser General Public License for more details.
11 You should have received a copy of the GNU Lesser General Public License
12 along with this program; if not, see <http://www.gnu.org/licenses/>.
16 #include "win32_compat.h"
17 #define close closesocket
31 #include "libnfs-zdr.h"
33 #include "libnfs-raw.h"
34 #include "libnfs-private.h"
37 #include "aros_compat.h"
40 struct rpc_context
*rpc_init_context(void)
42 struct rpc_context
*rpc
;
43 static uint32_t salt
= 0;
45 rpc
= malloc(sizeof(struct rpc_context
));
49 memset(rpc
, 0, sizeof(struct rpc_context
));
51 rpc
->magic
= RPC_CONTEXT_MAGIC
;
52 rpc
->encodebuflen
= 65536;
53 rpc
->encodebuf
= malloc(rpc
->encodebuflen
);
54 if (rpc
->encodebuf
== NULL
) {
60 rpc
->auth
= authunix_create("LibNFS", 65535, 65535, 0, NULL
);
62 rpc
->auth
= authunix_create_default();
64 if (rpc
->auth
== NULL
) {
69 rpc
->xid
= salt
+ time(NULL
);
77 struct rpc_context
*rpc_init_udp_context(void)
79 struct rpc_context
*rpc
;
81 rpc
= rpc_init_context();
89 void rpc_set_auth(struct rpc_context
*rpc
, struct AUTH
*auth
)
91 assert(rpc
->magic
== RPC_CONTEXT_MAGIC
);
93 if (rpc
->auth
!= NULL
) {
94 auth_destroy(rpc
->auth
);
100 void rpc_set_error(struct rpc_context
*rpc
, char *error_string
, ...)
104 assert(rpc
->magic
== RPC_CONTEXT_MAGIC
);
106 if (rpc
->error_string
!= NULL
) {
107 free(rpc
->error_string
);
109 va_start(ap
, error_string
);
110 rpc
->error_string
= malloc(1024);
111 vsnprintf(rpc
->error_string
, 1024, error_string
, ap
);
115 char *rpc_get_error(struct rpc_context
*rpc
)
117 assert(rpc
->magic
== RPC_CONTEXT_MAGIC
);
119 return rpc
->error_string
;
122 void rpc_error_all_pdus(struct rpc_context
*rpc
, char *error
)
126 assert(rpc
->magic
== RPC_CONTEXT_MAGIC
);
128 while((pdu
= rpc
->outqueue
) != NULL
) {
129 pdu
->cb(rpc
, RPC_STATUS_ERROR
, error
, pdu
->private_data
);
130 SLIST_REMOVE(&rpc
->outqueue
, pdu
);
131 rpc_free_pdu(rpc
, pdu
);
133 while((pdu
= rpc
->waitpdu
) != NULL
) {
134 pdu
->cb(rpc
, RPC_STATUS_ERROR
, error
, pdu
->private_data
);
135 SLIST_REMOVE(&rpc
->waitpdu
, pdu
);
136 rpc_free_pdu(rpc
, pdu
);
140 static void rpc_free_fragment(struct rpc_fragment
*fragment
)
142 if (fragment
->data
!= NULL
) {
143 free(fragment
->data
);
148 void rpc_free_all_fragments(struct rpc_context
*rpc
)
150 assert(rpc
->magic
== RPC_CONTEXT_MAGIC
);
152 while (rpc
->fragments
!= NULL
) {
153 struct rpc_fragment
*fragment
= rpc
->fragments
;
155 SLIST_REMOVE(&rpc
->fragments
, fragment
);
156 rpc_free_fragment(fragment
);
160 int rpc_add_fragment(struct rpc_context
*rpc
, char *data
, uint64_t size
)
162 struct rpc_fragment
*fragment
;
164 assert(rpc
->magic
== RPC_CONTEXT_MAGIC
);
166 fragment
= malloc(sizeof(struct rpc_fragment
));
167 if (fragment
== NULL
) {
171 fragment
->size
= size
;
172 fragment
->data
= malloc(fragment
->size
);
173 if(fragment
->data
== NULL
) {
178 memcpy(fragment
->data
, data
, fragment
->size
);
179 SLIST_ADD_END(&rpc
->fragments
, fragment
);
183 void rpc_destroy_context(struct rpc_context
*rpc
)
187 assert(rpc
->magic
== RPC_CONTEXT_MAGIC
);
189 while((pdu
= rpc
->outqueue
) != NULL
) {
190 pdu
->cb(rpc
, RPC_STATUS_CANCEL
, NULL
, pdu
->private_data
);
191 SLIST_REMOVE(&rpc
->outqueue
, pdu
);
192 rpc_free_pdu(rpc
, pdu
);
194 while((pdu
= rpc
->waitpdu
) != NULL
) {
195 pdu
->cb(rpc
, RPC_STATUS_CANCEL
, NULL
, pdu
->private_data
);
196 SLIST_REMOVE(&rpc
->waitpdu
, pdu
);
197 rpc_free_pdu(rpc
, pdu
);
200 rpc_free_all_fragments(rpc
);
202 auth_destroy(rpc
->auth
);
209 if (rpc
->encodebuf
!= NULL
) {
210 free(rpc
->encodebuf
);
211 rpc
->encodebuf
= NULL
;
214 if (rpc
->error_string
!= NULL
) {
215 free(rpc
->error_string
);
216 rpc
->error_string
= NULL
;
219 if (rpc
->udp_dest
!= NULL
) {
221 rpc
->udp_dest
= NULL
;