| 1 /* |
|
| 2 * nmfield.h |
|
| 3 * |
|
| 4 * Copyright (c) 2004 Novell, Inc. All Rights Reserved. |
|
| 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; version 2 of the License. |
|
| 9 * |
|
| 10 * This program is distributed in the hope that it will be useful, |
|
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 13 * GNU 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 USA |
|
| 18 * |
|
| 19 */ |
|
| 20 |
|
| 21 #ifndef NMFIELD_H |
|
| 22 #define NMFIELD_H |
|
| 23 |
|
| 24 #include <glib.h> |
|
| 25 |
|
| 26 typedef struct NMField_t |
|
| 27 { |
|
| 28 char *tag; /* Field tag */ |
|
| 29 guint8 method; /* Method of the field */ |
|
| 30 guint8 flags; /* Flags */ |
|
| 31 guint8 type; /* Type of value */ |
|
| 32 guint32 size; /* Size of value if binary */ |
|
| 33 guint32 value; /* Value of a numeric field */ |
|
| 34 gpointer ptr_value; /* Value of a string or sub array field */ |
|
| 35 guint32 len; /* Length of the array */ |
|
| 36 } NMField; |
|
| 37 |
|
| 38 /* Field types */ |
|
| 39 #define NMFIELD_TYPE_INVALID 0 |
|
| 40 #define NMFIELD_TYPE_NUMBER 1 |
|
| 41 #define NMFIELD_TYPE_BINARY 2 |
|
| 42 #define NMFIELD_TYPE_BYTE 3 |
|
| 43 #define NMFIELD_TYPE_UBYTE 4 |
|
| 44 #define NMFIELD_TYPE_WORD 5 |
|
| 45 #define NMFIELD_TYPE_UWORD 6 |
|
| 46 #define NMFIELD_TYPE_DWORD 7 |
|
| 47 #define NMFIELD_TYPE_UDWORD 8 |
|
| 48 #define NMFIELD_TYPE_ARRAY 9 |
|
| 49 #define NMFIELD_TYPE_UTF8 10 |
|
| 50 #define NMFIELD_TYPE_BOOL 11 |
|
| 51 #define NMFIELD_TYPE_MV 12 |
|
| 52 #define NMFIELD_TYPE_DN 13 |
|
| 53 |
|
| 54 /* Field methods */ |
|
| 55 #define NMFIELD_METHOD_VALID 0 |
|
| 56 #define NMFIELD_METHOD_IGNORE 1 |
|
| 57 #define NMFIELD_METHOD_DELETE 2 |
|
| 58 #define NMFIELD_METHOD_DELETE_ALL 3 |
|
| 59 #define NMFIELD_METHOD_EQUAL 4 |
|
| 60 #define NMFIELD_METHOD_ADD 5 |
|
| 61 #define NMFIELD_METHOD_UPDATE 6 |
|
| 62 #define NMFIELD_METHOD_GTE 10 |
|
| 63 #define NMFIELD_METHOD_LTE 12 |
|
| 64 #define NMFIELD_METHOD_NE 14 |
|
| 65 #define NMFIELD_METHOD_EXIST 15 |
|
| 66 #define NMFIELD_METHOD_NOTEXIST 16 |
|
| 67 #define NMFIELD_METHOD_SEARCH 17 |
|
| 68 #define NMFIELD_METHOD_MATCHBEGIN 19 |
|
| 69 #define NMFIELD_METHOD_MATCHEND 20 |
|
| 70 #define NMFIELD_METHOD_NOT_ARRAY 40 |
|
| 71 #define NMFIELD_METHOD_OR_ARRAY 41 |
|
| 72 #define NMFIELD_METHOD_AND_ARRAY 42 |
|
| 73 |
|
| 74 /* Attribute Names (field tags) */ |
|
| 75 #define NM_A_IP_ADDRESS "nnmIPAddress" |
|
| 76 #define NM_A_PORT "nnmPort" |
|
| 77 #define NM_A_FA_FOLDER "NM_A_FA_FOLDER" |
|
| 78 #define NM_A_FA_CONTACT "NM_A_FA_CONTACT" |
|
| 79 #define NM_A_FA_CONVERSATION "NM_A_FA_CONVERSATION" |
|
| 80 #define NM_A_FA_MESSAGE "NM_A_FA_MESSAGE" |
|
| 81 #define NM_A_FA_CONTACT_LIST "NM_A_FA_CONTACT_LIST" |
|
| 82 #define NM_A_FA_RESULTS "NM_A_FA_RESULTS" |
|
| 83 #define NM_A_FA_INFO_DISPLAY_ARRAY "NM_A_FA_INFO_DISPLAY_ARRAY" |
|
| 84 #define NM_A_FA_USER_DETAILS "NM_A_FA_USER_DETAILS" |
|
| 85 #define NM_A_SZ_OBJECT_ID "NM_A_SZ_OBJECT_ID" |
|
| 86 #define NM_A_SZ_PARENT_ID "NM_A_SZ_PARENT_ID" |
|
| 87 #define NM_A_SZ_SEQUENCE_NUMBER "NM_A_SZ_SEQUENCE_NUMBER" |
|
| 88 #define NM_A_SZ_TYPE "NM_A_SZ_TYPE" |
|
| 89 #define NM_A_SZ_STATUS "NM_A_SZ_STATUS" |
|
| 90 #define NM_A_SZ_STATUS_TEXT "NM_A_SZ_STATUS_TEXT" |
|
| 91 #define NM_A_SZ_DN "NM_A_SZ_DN" |
|
| 92 #define NM_A_SZ_DISPLAY_NAME "NM_A_SZ_DISPLAY_NAME" |
|
| 93 #define NM_A_SZ_USERID "NM_A_SZ_USERID" |
|
| 94 #define NM_A_SZ_CREDENTIALS "NM_A_SZ_CREDENTIALS" |
|
| 95 #define NM_A_SZ_MESSAGE_BODY "NM_A_SZ_MESSAGE_BODY" |
|
| 96 #define NM_A_SZ_MESSAGE_TEXT "NM_A_SZ_MESSAGE_TEXT" |
|
| 97 #define NM_A_UD_MESSAGE_TYPE "NM_A_UD_MESSAGE_TYPE" |
|
| 98 #define NM_A_FA_PARTICIPANTS "NM_A_FA_PARTICIPANTS" |
|
| 99 #define NM_A_FA_INVITES "NM_A_FA_INVITES" |
|
| 100 #define NM_A_FA_EVENT "NM_A_FA_EVENT" |
|
| 101 #define NM_A_UD_COUNT "NM_A_UD_COUNT" |
|
| 102 #define NM_A_UD_DATE "NM_A_UD_DATE" |
|
| 103 #define NM_A_UD_EVENT "NM_A_UD_EVENT" |
|
| 104 #define NM_A_B_NO_CONTACTS "NM_A_B_NO_CONTACTS" |
|
| 105 #define NM_A_B_NO_CUSTOMS "NM_A_B_NO_CUSTOMS" |
|
| 106 #define NM_A_B_NO_PRIVACY "NM_A_B_NO_PRIVACY" |
|
| 107 #define NM_A_UW_STATUS "NM_A_UW_STATUS" |
|
| 108 #define NM_A_UD_OBJECT_ID "NM_A_UD_OBJECT_ID" |
|
| 109 #define NM_A_SZ_TRANSACTION_ID "NM_A_SZ_TRANSACTION_ID" |
|
| 110 #define NM_A_SZ_RESULT_CODE "NM_A_SZ_RESULT_CODE" |
|
| 111 #define NM_A_UD_BUILD "NM_A_UD_BUILD" |
|
| 112 #define NM_A_SZ_AUTH_ATTRIBUTE "NM_A_SZ_AUTH_ATTRIBUTE" |
|
| 113 #define NM_A_UD_KEEPALIVE "NM_A_UD_KEEPALIVE" |
|
| 114 #define NM_A_SZ_USER_AGENT "NM_A_SZ_USER_AGENT" |
|
| 115 #define NM_A_BLOCKING "nnmBlocking" |
|
| 116 #define NM_A_BLOCKING_DENY_LIST "nnmBlockingDenyList" |
|
| 117 #define NM_A_BLOCKING_ALLOW_LIST "nnmBlockingAllowList" |
|
| 118 #define NM_A_SZ_BLOCKING_ALLOW_ITEM "NM_A_SZ_BLOCKING_ALLOW_ITEM" |
|
| 119 #define NM_A_SZ_BLOCKING_DENY_ITEM "NM_A_SZ_BLOCKING_DENY_ITEM" |
|
| 120 #define NM_A_LOCKED_ATTR_LIST "nnmLockedAttrList" |
|
| 121 |
|
| 122 #define NM_PROTOCOL_VERSION 2 |
|
| 123 |
|
| 124 #define NM_FIELD_TRUE "1" |
|
| 125 #define NM_FIELD_FALSE "0" |
|
| 126 |
|
| 127 #define NMFIELD_MAX_STR_LENGTH 32768 |
|
| 128 |
|
| 129 /** |
|
| 130 * Count the number of fields |
|
| 131 * |
|
| 132 * @param fields Field array |
|
| 133 * |
|
| 134 * @return The number of fields in the array. |
|
| 135 * |
|
| 136 */ |
|
| 137 guint32 nm_count_fields(NMField * fields); |
|
| 138 |
|
| 139 /** |
|
| 140 * Add a field to the field array. The field should be of type NMFIELD_TYPE_UTF8, |
|
| 141 * NMFIELD_TYPE_DN, NMFIELD_TYPE_ARRAY, or NMFIELD_TYPE_MV |
|
| 142 * |
|
| 143 * NOTE: field array that is passed in may be realloc'd so you should use |
|
| 144 * the returned field array pointer not the passed in pointer after calling |
|
| 145 * this function. |
|
| 146 * |
|
| 147 * @param fields Field array |
|
| 148 * @param tag Tag for the new field |
|
| 149 * @param size Size of the field value (if type = binary) |
|
| 150 * @param method Field method (see method defines above) |
|
| 151 * @param flags Flags for new field |
|
| 152 * @param value The value of the field |
|
| 153 * @param type The type of the field value |
|
| 154 * |
|
| 155 * @return Pointer to the updated field array |
|
| 156 * |
|
| 157 */ |
|
| 158 NMField *nm_field_add_pointer(NMField *fields, const char *tag, guint32 size, guint8 method, |
|
| 159 guint8 flags, gpointer value, guint8 type); |
|
| 160 |
|
| 161 /** |
|
| 162 * Add a numeric field to the field array. |
|
| 163 * |
|
| 164 * NOTE: field array that is passed in may be realloc'd so you should use |
|
| 165 * the returned field array pointer not the passed in pointer after calling |
|
| 166 * this function. |
|
| 167 * |
|
| 168 * @param fields Field array |
|
| 169 * @param tag Tag for the new field |
|
| 170 * @param size Size of the field value (if type = binary) |
|
| 171 * @param method Field method (see method defines above) |
|
| 172 * @param flags Flags for new field |
|
| 173 * @param value The value of the field |
|
| 174 * @param type The type of the field value |
|
| 175 * |
|
| 176 * @return Pointer to the updated field array |
|
| 177 * |
|
| 178 */ |
|
| 179 NMField *nm_field_add_number(NMField *fields, const char *tag, guint32 size, guint8 method, |
|
| 180 guint8 flags, guint32 value, guint8 type); |
|
| 181 |
|
| 182 /** |
|
| 183 * Recursively free an array of fields and set pointer to NULL. |
|
| 184 * |
|
| 185 * @param fields Pointer to a field array |
|
| 186 * |
|
| 187 */ |
|
| 188 void nm_free_fields(NMField ** fields); |
|
| 189 |
|
| 190 /** |
|
| 191 * Find first field with given tag in field array. |
|
| 192 * |
|
| 193 * Note: this will only work for 7-bit ascii tags (which is all that |
|
| 194 * we use currently). |
|
| 195 * |
|
| 196 * @param tag Tag to search for |
|
| 197 * @param fields Field array |
|
| 198 * |
|
| 199 * @return The first matching field, or NULL if no fields match. |
|
| 200 * |
|
| 201 */ |
|
| 202 NMField *nm_locate_field(char *tag, NMField * fields); |
|
| 203 |
|
| 204 /** |
|
| 205 * Make a deep copy of a field array |
|
| 206 * |
|
| 207 * @param src The array to copy |
|
| 208 * |
|
| 209 * @return The new (copied) array, which must be freed. |
|
| 210 * |
|
| 211 */ |
|
| 212 NMField *nm_copy_field_array(NMField * src); |
|
| 213 |
|
| 214 /** |
|
| 215 * Remove a field and move other fields up to fill the gap |
|
| 216 * |
|
| 217 * @param field The field to remove |
|
| 218 * |
|
| 219 */ |
|
| 220 void nm_remove_field(NMField * field); |
|
| 221 |
|
| 222 /* Print a field array (for debugging purposes) */ |
|
| 223 void nm_print_fields(NMField * fields); |
|
| 224 |
|
| 225 #endif |
|