r14541: separate smbsrv_request and ntvfs_request,
[amitay/samba.git] / source4 / ntvfs / ntvfs_util.c
1 /* 
2    Unix SMB/CIFS implementation.
3    NTVFS utility code
4    Copyright (C) Stefan Metzmacher 2004
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20 /*
21   this implements common utility functions that many NTVFS backends may wish to use
22 */
23
24 #include "includes.h"
25 #include "dlinklist.h"
26 #include "smb_server/smb_server.h"
27 #include "ntvfs/ntvfs.h"
28
29
30 _PUBLIC_ struct ntvfs_request *ntvfs_request_create(struct ntvfs_context *ctx, TALLOC_CTX *mem_ctx,
31                                                     struct auth_session_info *session_info,
32                                                     uint16_t smbpid, uint16_t smbmid,
33                                                     struct timeval request_time,
34                                                     void *private_data,
35                                                     void (*send_fn)(struct ntvfs_request *),
36                                                     uint32_t state)
37 {
38         struct ntvfs_request *req;
39         struct ntvfs_async_state *async;
40
41         req = talloc(mem_ctx, struct ntvfs_request);
42         if (!req) return NULL;
43         req->ctx                        = ctx;
44         req->async_states               = NULL;
45         req->session_info               = session_info;
46         req->smbpid                     = smbpid;
47         req->smbmid                     = smbmid;
48         req->statistics.request_time    = request_time;
49
50         async = talloc(req, struct ntvfs_async_state);
51         if (!async) goto failed;
52
53         async->state            = state;
54         async->private_data     = private_data;
55         async->send_fn          = send_fn;
56         async->status           = NT_STATUS_INTERNAL_ERROR;
57         async->ntvfs            = NULL;
58
59         DLIST_ADD(req->async_states, async);
60
61         return req;
62
63 failed:
64         return NULL;
65 }
66
67 _PUBLIC_ NTSTATUS ntvfs_async_state_push(struct ntvfs_module_context *ntvfs,
68                                          struct ntvfs_request *req,
69                                          void *private_data,
70                                          void (*send_fn)(struct ntvfs_request *))
71 {
72         struct ntvfs_async_state *async;
73
74         async = talloc(req, struct ntvfs_async_state);
75         NT_STATUS_HAVE_NO_MEMORY(async);
76
77         async->state            = req->async_states->state;
78         async->private_data     = private_data;
79         async->send_fn          = send_fn;
80         async->status           = NT_STATUS_INTERNAL_ERROR;
81
82         async->ntvfs            = ntvfs;
83
84         DLIST_ADD(req->async_states, async);
85
86         return NT_STATUS_OK;
87 }
88
89 _PUBLIC_ void ntvfs_async_state_pop(struct ntvfs_request *req)
90 {
91         struct ntvfs_async_state *async;
92
93         async = req->async_states;
94
95         DLIST_REMOVE(req->async_states, async);
96
97         req->async_states->state        = async->state;
98         req->async_states->status       = async->status;
99
100         talloc_free(async);
101 }