| 1 | /* |
| 2 | * This file is part of DisOrder. |
| 3 | * Copyright (C) 2007 Richard Kettlewell |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 18 | * USA |
| 19 | */ |
| 20 | /** @file lib/queue-rights.c |
| 21 | * @brief Various rights-checking operations |
| 22 | */ |
| 23 | |
| 24 | #include <config.h> |
| 25 | #include "types.h" |
| 26 | |
| 27 | #include <string.h> |
| 28 | |
| 29 | #include "queue.h" |
| 30 | #include "rights.h" |
| 31 | |
| 32 | /** @brief Test for scratchability |
| 33 | * @param rights User rights |
| 34 | * @param who Username |
| 35 | * @param q Queue entry or NULL |
| 36 | * @return non-0 if scratchable, else 0 |
| 37 | */ |
| 38 | int right_scratchable(rights_type rights, const char *who, |
| 39 | const struct queue_entry *q) { |
| 40 | rights_type r; |
| 41 | |
| 42 | if(!q) |
| 43 | return 0; |
| 44 | if(q->submitter) |
| 45 | if(!strcmp(q->submitter, who)) |
| 46 | r = RIGHT_SCRATCH_MINE|RIGHT_SCRATCH_ANY; |
| 47 | else |
| 48 | r = RIGHT_SCRATCH_ANY; |
| 49 | else |
| 50 | r = RIGHT_SCRATCH_RANDOM|RIGHT_SCRATCH_ANY; |
| 51 | return !!(rights & r); |
| 52 | } |
| 53 | |
| 54 | /** @brief Test for movability |
| 55 | * @param rights User rights |
| 56 | * @param who Username |
| 57 | * @param q Queue entry or NULL |
| 58 | * @return non-0 if movable, else 0 |
| 59 | */ |
| 60 | int right_movable(rights_type rights, const char *who, |
| 61 | const struct queue_entry *q) { |
| 62 | rights_type r; |
| 63 | |
| 64 | if(!q) |
| 65 | return 0; |
| 66 | if(q->submitter) |
| 67 | if(!strcmp(q->submitter, who)) |
| 68 | r = RIGHT_MOVE_MINE|RIGHT_MOVE_ANY; |
| 69 | else |
| 70 | r = RIGHT_MOVE_ANY; |
| 71 | else |
| 72 | r = RIGHT_MOVE_RANDOM|RIGHT_MOVE_ANY; |
| 73 | return !!(rights & r); |
| 74 | } |
| 75 | |
| 76 | /** @brief Test for removability |
| 77 | * @param rights User rights |
| 78 | * @param who Username |
| 79 | * @param q Queue entry or NULL |
| 80 | * @return non-0 if removable, else 0 |
| 81 | */ |
| 82 | int right_removable(rights_type rights, const char *who, |
| 83 | const struct queue_entry *q) { |
| 84 | rights_type r; |
| 85 | |
| 86 | if(!q) |
| 87 | return 0; |
| 88 | if(q->submitter) |
| 89 | if(!strcmp(q->submitter, who)) |
| 90 | r = RIGHT_REMOVE_MINE|RIGHT_REMOVE_ANY; |
| 91 | else |
| 92 | r = RIGHT_REMOVE_ANY; |
| 93 | else |
| 94 | r = RIGHT_REMOVE_RANDOM|RIGHT_REMOVE_ANY; |
| 95 | return !!(rights & r); |
| 96 | } |
| 97 | |
| 98 | /* |
| 99 | Local Variables: |
| 100 | c-basic-offset:2 |
| 101 | comment-column:40 |
| 102 | fill-column:79 |
| 103 | indent-tabs-mode:nil |
| 104 | End: |
| 105 | */ |