222bee92405009fc3294fb58600ca8627ee82dc3
2 Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>.
35 #include "libnfs-raw.h"
36 #include "libnfs-private.h"
38 struct rpc_context
*rpc_init_context(void)
40 struct rpc_context
*rpc
;
42 rpc
= malloc(sizeof(struct rpc_context
));
46 bzero(rpc
, sizeof(struct rpc_context
));
48 rpc
->encodebuflen
= 65536;
49 rpc
->encodebuf
= malloc(rpc
->encodebuflen
);
50 if (rpc
->encodebuf
== NULL
) {
56 rpc
->auth
= authunix_create("LibNFS", 65535, 65535, 0, NULL
);
58 rpc
->auth
= authunix_create_default();
60 if (rpc
->auth
== NULL
) {
72 struct rpc_context
*rpc_init_udp_context(void)
74 struct rpc_context
*rpc
;
76 rpc
= rpc_init_context();
84 void rpc_set_auth(struct rpc_context
*rpc
, struct AUTH
*auth
)
86 if (rpc
->auth
!= NULL
) {
87 auth_destroy(rpc
->auth
);
93 void rpc_set_error(struct rpc_context
*rpc
, char *error_string
, ...)
98 if (rpc
->error_string
!= NULL
) {
99 free(rpc
->error_string
);
101 va_start(ap
, error_string
);
102 // vasprintf(&str, error_string, ap);
103 // rpc->error_string = str;
107 char *rpc_get_error(struct rpc_context
*rpc
)
109 return rpc
->error_string
;
112 void rpc_error_all_pdus(struct rpc_context
*rpc
, char *error
)
116 while((pdu
= rpc
->outqueue
) != NULL
) {
117 pdu
->cb(rpc
, RPC_STATUS_ERROR
, error
, pdu
->private_data
);
118 SLIST_REMOVE(&rpc
->outqueue
, pdu
);
119 rpc_free_pdu(rpc
, pdu
);
121 while((pdu
= rpc
->waitpdu
) != NULL
) {
122 pdu
->cb(rpc
, RPC_STATUS_ERROR
, error
, pdu
->private_data
);
123 SLIST_REMOVE(&rpc
->waitpdu
, pdu
);
124 rpc_free_pdu(rpc
, pdu
);
129 void rpc_destroy_context(struct rpc_context
*rpc
)
133 while((pdu
= rpc
->outqueue
) != NULL
) {
134 pdu
->cb(rpc
, RPC_STATUS_CANCEL
, NULL
, pdu
->private_data
);
135 SLIST_REMOVE(&rpc
->outqueue
, pdu
);
136 rpc_free_pdu(rpc
, pdu
);
138 while((pdu
= rpc
->waitpdu
) != NULL
) {
139 pdu
->cb(rpc
, RPC_STATUS_CANCEL
, NULL
, pdu
->private_data
);
140 SLIST_REMOVE(&rpc
->waitpdu
, pdu
);
141 rpc_free_pdu(rpc
, pdu
);
144 auth_destroy(rpc
->auth
);
149 closesocket(rpc
->fd
);
155 if (rpc
->encodebuf
!= NULL
) {
156 free(rpc
->encodebuf
);
157 rpc
->encodebuf
= NULL
;
160 if (rpc
->error_string
!= NULL
) {
161 free(rpc
->error_string
);
162 rpc
->error_string
= NULL
;
165 if (rpc
->udp_dest
!= NULL
) {
167 rpc
->udp_dest
= NULL
;