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"
31 #include "libnfs-raw.h"
32 #include "libnfs-private.h"
34 struct rpc_context
*rpc_init_context(void)
36 struct rpc_context
*rpc
;
38 rpc
= malloc(sizeof(struct rpc_context
));
42 memset(rpc
, 0, sizeof(struct rpc_context
));
44 rpc
->encodebuflen
= 65536;
45 rpc
->encodebuf
= malloc(rpc
->encodebuflen
);
46 if (rpc
->encodebuf
== NULL
) {
52 rpc
->auth
= authunix_create("LibNFS", 65535, 65535, 0, NULL
);
54 rpc
->auth
= authunix_create_default();
56 if (rpc
->auth
== NULL
) {
68 struct rpc_context
*rpc_init_udp_context(void)
70 struct rpc_context
*rpc
;
72 rpc
= rpc_init_context();
80 void rpc_set_auth(struct rpc_context
*rpc
, struct AUTH
*auth
)
82 if (rpc
->auth
!= NULL
) {
83 auth_destroy(rpc
->auth
);
85 rpc
->auth
= (AUTH
*)auth
;
89 void rpc_set_error(struct rpc_context
*rpc
, char *error_string
, ...)
93 if (rpc
->error_string
!= NULL
) {
94 free(rpc
->error_string
);
96 va_start(ap
, error_string
);
97 rpc
->error_string
= malloc(1024);
98 vsnprintf(rpc
->error_string
, 1024, error_string
, ap
);
102 char *rpc_get_error(struct rpc_context
*rpc
)
104 return rpc
->error_string
;
107 void rpc_error_all_pdus(struct rpc_context
*rpc
, char *error
)
111 while((pdu
= rpc
->outqueue
) != NULL
) {
112 pdu
->cb(rpc
, RPC_STATUS_ERROR
, error
, pdu
->private_data
);
113 SLIST_REMOVE(&rpc
->outqueue
, pdu
);
114 rpc_free_pdu(rpc
, pdu
);
116 while((pdu
= rpc
->waitpdu
) != NULL
) {
117 pdu
->cb(rpc
, RPC_STATUS_ERROR
, error
, pdu
->private_data
);
118 SLIST_REMOVE(&rpc
->waitpdu
, pdu
);
119 rpc_free_pdu(rpc
, pdu
);
124 void rpc_destroy_context(struct rpc_context
*rpc
)
128 while((pdu
= rpc
->outqueue
) != NULL
) {
129 pdu
->cb(rpc
, RPC_STATUS_CANCEL
, NULL
, 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_CANCEL
, NULL
, pdu
->private_data
);
135 SLIST_REMOVE(&rpc
->waitpdu
, pdu
);
136 rpc_free_pdu(rpc
, pdu
);
139 auth_destroy(rpc
->auth
);
144 closesocket(rpc
->fd
);
150 if (rpc
->encodebuf
!= NULL
) {
151 free(rpc
->encodebuf
);
152 rpc
->encodebuf
= NULL
;
155 if (rpc
->error_string
!= NULL
) {
156 free(rpc
->error_string
);
157 rpc
->error_string
= NULL
;
160 if (rpc
->udp_dest
!= NULL
) {
162 rpc
->udp_dest
= NULL
;