r14736: - the ntvfs subsystem should not know about smb_server.h
[jra/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 "ntvfs/ntvfs.h"
27
28
29 _PUBLIC_ struct ntvfs_request *ntvfs_request_create(struct ntvfs_context *ctx, TALLOC_CTX *mem_ctx,
30                                                     struct auth_session_info *session_info,
31                                                     uint16_t smbpid, uint16_t smbmid,
32                                                     struct timeval request_time,
33                                                     void *private_data,
34                                                     void (*send_fn)(struct ntvfs_request *),
35                                                     uint32_t state)
36 {
37         struct ntvfs_request *req;
38         struct ntvfs_async_state *async;
39
40         req = talloc(mem_ctx, struct ntvfs_request);
41         if (!req) return NULL;
42         req->ctx                        = ctx;
43         req->async_states               = NULL;
44         req->session_info               = session_info;
45         req->smbpid                     = smbpid;
46         req->smbmid                     = smbmid;
47         req->statistics.request_time    = request_time;
48
49         async = talloc(req, struct ntvfs_async_state);
50         if (!async) goto failed;
51
52         async->state            = state;
53         async->private_data     = private_data;
54         async->send_fn          = send_fn;
55         async->status           = NT_STATUS_INTERNAL_ERROR;
56         async->ntvfs            = NULL;
57
58         DLIST_ADD(req->async_states, async);
59
60         return req;
61
62 failed:
63         return NULL;
64 }
65
66 _PUBLIC_ NTSTATUS ntvfs_async_state_push(struct ntvfs_module_context *ntvfs,
67                                          struct ntvfs_request *req,
68                                          void *private_data,
69                                          void (*send_fn)(struct ntvfs_request *))
70 {
71         struct ntvfs_async_state *async;
72
73         async = talloc(req, struct ntvfs_async_state);
74         NT_STATUS_HAVE_NO_MEMORY(async);
75
76         async->state            = req->async_states->state;
77         async->private_data     = private_data;
78         async->send_fn          = send_fn;
79         async->status           = NT_STATUS_INTERNAL_ERROR;
80
81         async->ntvfs            = ntvfs;
82
83         DLIST_ADD(req->async_states, async);
84
85         return NT_STATUS_OK;
86 }
87
88 _PUBLIC_ void ntvfs_async_state_pop(struct ntvfs_request *req)
89 {
90         struct ntvfs_async_state *async;
91
92         async = req->async_states;
93
94         DLIST_REMOVE(req->async_states, async);
95
96         req->async_states->state        = async->state;
97         req->async_states->status       = async->status;
98
99         talloc_free(async);
100 }