~ubuntu-branches/ubuntu/vivid/samba/vivid

« back to all changes in this revision

Viewing changes to lib/tevent/tevent_req.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include "tevent_internal.h"
28
28
#include "tevent_util.h"
29
29
 
30
 
/**
31
 
 * @brief The default print function for creating debug messages
32
 
 * @param[in] req       The request to be printed
33
 
 * @param[in] mem_ctx   The memory context for the result
34
 
 * @retval              Text representation of req
35
 
 *
36
 
 * The function should not be used by users of the asynx API,
37
 
 * but custom print function can use it and append custom text
38
 
 * to the string.
39
 
 */
40
 
 
41
30
char *tevent_req_default_print(struct tevent_req *req, TALLOC_CTX *mem_ctx)
42
31
{
43
32
        return talloc_asprintf(mem_ctx,
53
42
                               );
54
43
}
55
44
 
56
 
/**
57
 
 * @brief Print an tevent_req structure in debug messages
58
 
 * @param[in] mem_ctx   The memory context for the result
59
 
 * @param[in] req       The request to be printed
60
 
 * @retval              Text representation of req
61
 
 *
62
 
 * This function should be used by callers of the async API
63
 
 */
64
 
 
65
45
char *tevent_req_print(TALLOC_CTX *mem_ctx, struct tevent_req *req)
66
46
{
67
47
        if (!req->private_print) {
71
51
        return req->private_print(req, mem_ctx);
72
52
}
73
53
 
74
 
/**
75
 
 * @brief Create an async request
76
 
 * @param[in] mem_ctx   The memory context for the result
77
 
 * @param[in] ev        The event context this async request will be driven by
78
 
 * @retval              A new async request
79
 
 *
80
 
 * The new async request will be initialized in state ASYNC_REQ_IN_PROGRESS
81
 
 */
82
 
 
83
54
struct tevent_req *_tevent_req_create(TALLOC_CTX *mem_ctx,
84
55
                                    void *pdata,
85
56
                                    size_t data_size,
133
104
        _tevent_req_notify_callback(req, location);
134
105
}
135
106
 
136
 
/**
137
 
 * @brief An async request has successfully finished
138
 
 * @param[in] req       The finished request
139
 
 *
140
 
 * tevent_req_done is to be used by implementors of async requests. When a
141
 
 * request is successfully finished, this function calls the user's completion
142
 
 * function.
143
 
 */
144
 
 
145
107
void _tevent_req_done(struct tevent_req *req,
146
108
                      const char *location)
147
109
{
148
110
        tevent_req_finish(req, TEVENT_REQ_DONE, location);
149
111
}
150
112
 
151
 
/**
152
 
 * @brief An async request has seen an error
153
 
 * @param[in] req       The request with an error
154
 
 * @param[in] error     The error code
155
 
 *
156
 
 * tevent_req_done is to be used by implementors of async requests. When a
157
 
 * request can not successfully completed, the implementation should call this
158
 
 * function with the appropriate status code.
159
 
 *
160
 
 * If error is 0 the function returns false and does nothing more.
161
 
 *
162
 
 * Call pattern would be
163
 
 * \code
164
 
 * int error = first_function();
165
 
 * if (tevent_req_error(req, error)) {
166
 
 *      return;
167
 
 * }
168
 
 *
169
 
 * error = second_function();
170
 
 * if (tevent_req_error(req, error)) {
171
 
 *      return;
172
 
 * }
173
 
 *
174
 
 * tevent_req_done(req);
175
 
 * return;
176
 
 * \endcode
177
 
 */
178
 
 
179
113
bool _tevent_req_error(struct tevent_req *req,
180
114
                       uint64_t error,
181
115
                       const char *location)
189
123
        return true;
190
124
}
191
125
 
192
 
/**
193
 
 * @brief Helper function for nomem check
194
 
 * @param[in] p         The pointer to be checked
195
 
 * @param[in] req       The request being processed
196
 
 *
197
 
 * Convenience helper to easily check alloc failure within a callback
198
 
 * implementing the next step of an async request.
199
 
 *
200
 
 * Call pattern would be
201
 
 * \code
202
 
 * p = talloc(mem_ctx, bla);
203
 
 * if (tevent_req_nomem(p, req)) {
204
 
 *      return;
205
 
 * }
206
 
 * \endcode
207
 
 */
208
 
 
209
126
bool _tevent_req_nomem(const void *p,
210
127
                       struct tevent_req *req,
211
128
                       const char *location)
218
135
}
219
136
 
220
137
/**
221
 
 * @brief Immediate event callback
222
 
 * @param[in] ev        Event context
223
 
 * @param[in] im        The immediate event
224
 
 * @param[in] priv      The async request to be finished
 
138
 * @internal
 
139
 *
 
140
 * @brief Immediate event callback.
 
141
 *
 
142
 * @param[in]  ev       The event context to use.
 
143
 *
 
144
 * @param[in]  im       The immediate event.
 
145
 *
 
146
 * @param[in]  priv     The async request to be finished.
225
147
 */
226
148
static void tevent_req_trigger(struct tevent_context *ev,
227
149
                               struct tevent_immediate *im,
234
156
                          req->internal.finish_location);
235
157
}
236
158
 
237
 
/**
238
 
 * @brief Finish a request before the caller had the change to set the callback
239
 
 * @param[in] req       The finished request
240
 
 * @param[in] ev        The tevent_context for the timed event
241
 
 * @retval              req will be returned
242
 
 *
243
 
 * An implementation of an async request might find that it can either finish
244
 
 * the request without waiting for an external event, or it can't even start
245
 
 * the engine. To present the illusion of a callback to the user of the API,
246
 
 * the implementation can call this helper function which triggers an
247
 
 * immediate timed event. This way the caller can use the same calling
248
 
 * conventions, independent of whether the request was actually deferred.
249
 
 */
250
 
 
251
159
struct tevent_req *tevent_req_post(struct tevent_req *req,
252
160
                                   struct tevent_context *ev)
253
161
{
256
164
        return req;
257
165
}
258
166
 
259
 
/**
260
 
 * @brief This function destroys the attached private data
261
 
 * @param[in] req       The request to poll
262
 
 * @retval              The boolean form of "is in progress".
263
 
 *
264
 
 * This function can be used to ask if the given request
265
 
 * is still in progress.
266
 
 *
267
 
 * This function is typically used by sync wrapper functions.
268
 
 */
269
167
bool tevent_req_is_in_progress(struct tevent_req *req)
270
168
{
271
169
        if (req->internal.state == TEVENT_REQ_IN_PROGRESS) {
275
173
        return false;
276
174
}
277
175
 
278
 
/**
279
 
 * @brief This function destroys the attached private data
280
 
 * @param[in] req       The finished request
281
 
 *
282
 
 * This function can be called as last action of a _recv()
283
 
 * function, it destroys the data attached to the tevent_req.
284
 
 */
285
176
void tevent_req_received(struct tevent_req *req)
286
177
{
287
178
        TALLOC_FREE(req->data);
293
184
        req->internal.state = TEVENT_REQ_RECEIVED;
294
185
}
295
186
 
296
 
/**
297
 
 * @brief This function destroys the attached private data
298
 
 * @param[in] req       The request to poll
299
 
 * @param[in] ev        The tevent_context to be used
300
 
 * @retval              If a critical error has happened in the
301
 
 *                      tevent loop layer false is returned.
302
 
 *                      Otherwise true is returned.
303
 
 *                      This is not the return value of the given request!
304
 
 *
305
 
 * This function can be used to actively poll for the
306
 
 * given request to finish.
307
 
 *
308
 
 * Note: this should only be used if the given tevent context
309
 
 *       was created by the caller, to avoid event loop nesting.
310
 
 *
311
 
 * This function is typically used by sync wrapper functions.
312
 
 */
313
187
bool tevent_req_poll(struct tevent_req *req,
314
188
                     struct tevent_context *ev)
315
189
{
383
257
        return req->data;
384
258
}
385
259
 
386
 
/**
387
 
 * @brief This function sets a print function for the given request
388
 
 * @param[in] req       The given request
389
 
 * @param[in] fn        A pointer to the print function
390
 
 *
391
 
 * This function can be used to setup a print function for the given request.
392
 
 * This will be triggered if the tevent_req_print() function was
393
 
 * called on the given request.
394
 
 *
395
 
 * Note: this function should only be used for debugging.
396
 
 */
397
260
void tevent_req_set_print_fn(struct tevent_req *req, tevent_req_print_fn fn)
398
261
{
399
262
        req->private_print = fn;
400
263
}
401
264
 
402
 
/**
403
 
 * @brief This function sets a cancel function for the given request
404
 
 * @param[in] req       The given request
405
 
 * @param[in] fn        A pointer to the cancel function
406
 
 *
407
 
 * This function can be used to setup a cancel function for the given request.
408
 
 * This will be triggered if the tevent_req_cancel() function was
409
 
 * called on the given request.
410
 
 *
411
 
 */
412
265
void tevent_req_set_cancel_fn(struct tevent_req *req, tevent_req_cancel_fn fn)
413
266
{
414
267
        req->private_cancel = fn;
415
268
}
416
269
 
417
 
/**
418
 
 * @brief This function tries to cancel the given request
419
 
 * @param[in] req       The given request
420
 
 * @param[in] location  Automaticly filled with the __location__ macro
421
 
 *                      via the tevent_req_cancel() macro. This is for debugging
422
 
 *                      only!
423
 
 * @retval              This function returns true is the request is cancelable.
424
 
 *                      Otherwise false is returned.
425
 
 *
426
 
 * This function can be used to cancel the given request.
427
 
 *
428
 
 * It is only possible to cancel a request when the implementation
429
 
 * has registered a cancel function via the tevent_req_set_cancel_fn().
430
 
 *
431
 
 * Note: Even if the function returns true, the caller need to wait
432
 
 *       for the function to complete normally.
433
 
 *       Only the _recv() function of the given request indicates
434
 
 *       if the request was really canceled.
435
 
 */
436
270
bool _tevent_req_cancel(struct tevent_req *req, const char *location)
437
271
{
438
272
        if (req->private_cancel == NULL) {