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/>.
29 #include "libnfs-raw.h"
30 #include "libnfs-private.h"
32 struct rpc_context
*rpc_init_context(void)
34 struct rpc_context
*rpc
;
36 rpc
= malloc(sizeof(struct rpc_context
));
40 bzero(rpc
, sizeof(struct rpc_context
));
42 rpc
->encodebuflen
= 65536;
43 rpc
->encodebuf
= malloc(rpc
->encodebuflen
);
44 if (rpc
->encodebuf
== NULL
) {
49 rpc
->auth
= authunix_create_default();
50 if (rpc
->auth
== NULL
) {
62 void rpc_set_auth(struct rpc_context
*rpc
, struct AUTH
*auth
)
64 if (rpc
->auth
!= NULL
) {
65 auth_destroy(rpc
->auth
);
71 void rpc_set_error(struct rpc_context
*rpc
, char *error_string
, ...)
76 if (rpc
->error_string
!= NULL
) {
77 free(rpc
->error_string
);
79 va_start(ap
, error_string
);
80 vasprintf(&str
, error_string
, ap
);
81 rpc
->error_string
= str
;
85 char *rpc_get_error(struct rpc_context
*rpc
)
87 return rpc
->error_string
;
90 void rpc_error_all_pdus(struct rpc_context
*rpc
, char *error
)
94 while((pdu
= rpc
->outqueue
) != NULL
) {
95 pdu
->cb(rpc
, RPC_STATUS_ERROR
, error
, pdu
->private_data
);
96 SLIST_REMOVE(&rpc
->outqueue
, pdu
);
97 rpc_free_pdu(rpc
, pdu
);
99 while((pdu
= rpc
->waitpdu
) != NULL
) {
100 pdu
->cb(rpc
, RPC_STATUS_ERROR
, error
, pdu
->private_data
);
101 SLIST_REMOVE(&rpc
->waitpdu
, pdu
);
102 rpc_free_pdu(rpc
, pdu
);
107 void rpc_destroy_context(struct rpc_context
*rpc
)
111 while((pdu
= rpc
->outqueue
) != NULL
) {
112 pdu
->cb(rpc
, RPC_STATUS_CANCEL
, NULL
, 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_CANCEL
, NULL
, pdu
->private_data
);
118 SLIST_REMOVE(&rpc
->waitpdu
, pdu
);
119 rpc_free_pdu(rpc
, pdu
);
122 auth_destroy(rpc
->auth
);
129 if (rpc
->encodebuf
!= NULL
) {
130 free(rpc
->encodebuf
);
131 rpc
->encodebuf
= NULL
;
134 if (rpc
->error_string
!= NULL
) {
135 free(rpc
->error_string
);
136 rpc
->error_string
= NULL
;