8 /* SunOS 4.x Blargh.... */
10 #define NULL ((void*)0)
15 # define WMAX(a,b) ((a)>(b) ? (a) : (b))
18 # define WMIN(a,b) ((a)<(b) ? (a) : (b))
22 #ifndef __ASSERT_FUNCTION
23 # if (!defined (__GNUC__) || (__GNUC__ < 2 && \
24 __GNUC_MINOR__ < (defined (__cplusplus) ? 6 : 4)))
25 # define __ASSERT_FUNCTION ((char *) 0)
27 # define __ASSERT_FUNCTION __PRETTY_FUNCTION__
32 #define __attribute__(x) /*NOTHING*/
37 #define wassertr(expr) {}
38 #define wassertrv(expr, val) {}
46 #define wassertr(expr) assert(expr)
48 #define wassertrv(expr, val) assert(expr)
52 #define wassertr(expr) \
54 wwarning("%s line %i (%s): assertion %s failed",\
55 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
59 #define wassertrv(expr, val) \
61 wwarning("%s line %i (%s): assertion %s failed",\
62 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
72 #endif /* __cplusplus */
86 } WMNotificationCoalescing
;
89 /* The possible states for connections */
102 /* The possible states for connection timeouts */
107 } WMConnectionTimeoutState
;
112 WBNotFound
= INT_MIN
, /* element was not found in WMBag */
113 WANotFound
= -1 /* element was not found in WMArray */
117 typedef struct W_Array WMArray
;
118 typedef struct W_Bag WMBag
;
119 typedef struct W_Data WMData
;
120 typedef struct W_TreeNode WMTreeNode
;
121 typedef struct W_HashTable WMHashTable
;
122 typedef struct W_UserDefaults WMUserDefaults
;
123 typedef struct W_Notification WMNotification
;
124 typedef struct W_NotificationQueue WMNotificationQueue
;
125 typedef struct W_Host WMHost
;
126 typedef struct W_Connection WMConnection
;
127 typedef struct W_PropList WMPropList
;
131 /* Some typedefs for the handler stuff */
132 typedef void *WMHandlerID
;
134 typedef void WMCallback(void *data
);
136 typedef void WMInputProc(int fd
, int mask
, void *clientData
);
140 typedef int WMCompareDataProc(const void *item1
, const void *item2
);
142 typedef void WMFreeDataProc(void *data
);
144 /* Used by WMBag or WMArray for matching data */
145 typedef int WMMatchDataProc(const void *item
, const void *cdata
);
156 /* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */
165 /* NULL is pointer hash */
166 unsigned (*hash
)(const void *);
167 /* NULL is pointer compare */
168 Bool (*keyIsEqual
)(const void *, const void *);
169 /* NULL does nothing */
170 void* (*retainKey
)(const void *);
171 /* NULL does nothing */
172 void (*releaseKey
)(const void *);
173 } WMHashTableCallbacks
;
176 typedef int WMArrayIterator
;
177 typedef void *WMBagIterator
;
182 char character
; /* the escape character */
183 char *value
; /* value to place */
188 /* The connection callbacks */
189 typedef struct ConnectionDelegate
{
192 void (*canResumeSending
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
194 void (*didCatchException
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
196 void (*didDie
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
198 void (*didInitialize
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
200 void (*didReceiveInput
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
202 void (*didTimeout
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
204 } ConnectionDelegate
;
207 typedef void WMNotificationObserverAction(void *observerData
,
208 WMNotification
*notification
);
212 /*......................................................................*/
214 typedef void waborthandler(int);
216 waborthandler
* wsetabort(waborthandler
* handler
);
219 /* don't free the returned string */
220 char* wstrerror(int errnum
);
223 WMESSAGE_TYPE_MESSAGE
,
224 WMESSAGE_TYPE_WARNING
,
226 WMESSAGE_TYPE_WSYSERROR
,
227 WMESSAGE_TYPE_WSYSERRORWITHCODE
230 #define wmessage(fmt, args...) __wmessage( WMESSAGE_TYPE_MESSAGE, NULL, fmt, ## args)
231 #define wwarning(fmt, args...) __wmessage( WMESSAGE_TYPE_WARNING, NULL, fmt, ## args)
232 #define wfatal(fmt, args...) __wmessage( WMESSAGE_TYPE_FATAL, NULL, fmt, ## args)
233 #define wsyserror(fmt, args...) __wmessage( WMESSAGE_TYPE_WSYSERROR, NULL, fmt, ## args)
234 #define wsyserrorwithcode(errno, fmt, args...) \
235 __wmessage( WMESSAGE_TYPE_WSYSERRORWITHCODE, &errno, fmt, ## args)
237 void __wmessage(int type
, void *extra
, const char *msg
, ...) __attribute__((__format__(printf
,3,4)));
239 char* wfindfile(char *paths
, char *file
);
241 char* wfindfileinlist(char **path_list
, char *file
);
243 char* wfindfileinarray(WMPropList
* array
, char *file
);
245 char* wexpandpath(char *path
);
247 int wmkdirhier(const char *path
);
248 int wrmdirhier(const char *path
);
250 /* don't free the returned string */
253 void* wmalloc(size_t size
);
254 void* wrealloc(void *ptr
, size_t newsize
);
255 void wfree(void *ptr
);
257 #define wnew(type, count) wmalloc(sizeof(type)*count)
259 void wrelease(void *ptr
);
260 void* wretain(void *ptr
);
262 char *wstrdup(const char *str
);
263 char* wstrndup(const char *str
, size_t len
);
265 /* Concatenate str1 with str2 and return that in a newly malloc'ed string.
266 * str1 and str2 can be any strings including static and constant strings.
267 * str1 and str2 will not be modified.
268 * Free the returned string when you're done with it. */
269 char* wstrconcat(char *str1
, char *str2
);
271 /* This will append src to dst, and return dst. dst MUST be either NULL
272 * or a string that was a result of a dynamic allocation (malloc, realloc
273 * wmalloc, wrealloc, ...). dst CANNOT be a static or a constant string!
274 * Modifies dst (no new string is created except if dst==NULL in which case
275 * it is equivalent to calling wstrdup(src) ).
276 * The returned address may be different from the original address of dst,
277 * so always assign the returned address to avoid dangling pointers. */
278 char* wstrappend(char *dst
, char *src
);
281 void wtokensplit(char *command
, char ***argv
, int *argc
);
283 char* wtokennext(char *word
, char **next
);
285 char* wtokenjoin(char **list
, int count
);
287 void wtokenfree(char **tokens
, int count
);
289 char* wtrimspace(const char *s
);
292 WMRange
wmkrange(int start
, int count
);
293 #ifdef ANSI_C_DOESNT_LIKE_IT_THIS_WAY
294 #define wmkrange(position, count) (WMRange){(position), (count)}
298 char* wusergnusteppath();
300 char* wdefaultspathfordomain(char *domain
);
301 char* wglobaldefaultspathfordomain(const char *domain
);
303 void wusleep(unsigned int microsec
);
306 int wsprintesc(char *buffer
, int length
, char *format
, WMSEscapes
**escapes
,
310 /*......................................................................*/
312 /* Event handlers: timer, idle, input */
314 WMHandlerID
WMAddTimerHandler(int milliseconds
, WMCallback
*callback
,
317 WMHandlerID
WMAddPersistentTimerHandler(int milliseconds
, WMCallback
*callback
,
320 void WMDeleteTimerWithClientData(void *cdata
);
322 void WMDeleteTimerHandler(WMHandlerID handlerID
);
324 WMHandlerID
WMAddIdleHandler(WMCallback
*callback
, void *cdata
);
326 void WMDeleteIdleHandler(WMHandlerID handlerID
);
328 WMHandlerID
WMAddInputHandler(int fd
, int condition
, WMInputProc
*proc
,
331 void WMDeleteInputHandler(WMHandlerID handlerID
);
334 /* This function is used _only_ if you create a non-GUI program.
335 * For GUI based programs use WMNextEvent()/WMHandleEvent() instead.
336 * This function will handle all input/timer/idle events, then return.
339 void WHandleEvents();
341 /*......................................................................*/
344 WMHashTable
* WMCreateHashTable(WMHashTableCallbacks callbacks
);
346 void WMFreeHashTable(WMHashTable
*table
);
348 void WMResetHashTable(WMHashTable
*table
);
350 unsigned WMCountHashTable(WMHashTable
*table
);
352 void* WMHashGet(WMHashTable
*table
, const void *key
);
354 /* Returns True if there is a value associated with <key> in the table, in
355 * which case <retKey> and <retItem> will contain the item's internal key
356 * address and the item's value respectively.
357 * If there is no value associated with <key> it will return False and in
358 * this case <retKey> and <retItem> will be undefined.
359 * Use this when you need to perform your own custom retain/release mechanism
360 * which requires access to the keys too.
362 Bool
WMHashGetItemAndKey(WMHashTable
*table
, const void *key
,
363 void **retItem
, void **retKey
);
365 /* put data in table, replacing already existing data and returning
367 void* WMHashInsert(WMHashTable
*table
, const void *key
, const void *data
);
369 void WMHashRemove(WMHashTable
*table
, const void *key
);
371 /* warning: do not manipulate the table while using the enumerator functions */
372 WMHashEnumerator
WMEnumerateHashTable(WMHashTable
*table
);
374 void* WMNextHashEnumeratorItem(WMHashEnumerator
*enumerator
);
376 void* WMNextHashEnumeratorKey(WMHashEnumerator
*enumerator
);
378 /* Returns True if there is a next element, in which case key and item
379 * will contain the next element's key and value respectively.
380 * If there is no next element available it will return False and in this
381 * case key and item will be undefined.
383 Bool
WMNextHashEnumeratorItemAndKey(WMHashEnumerator
*enumerator
,
384 void **item
, void **key
);
389 /* some predefined callback sets */
391 extern const WMHashTableCallbacks WMIntHashCallbacks
;
392 /* sizeof(keys) are <= sizeof(void*) */
394 extern const WMHashTableCallbacks WMStringHashCallbacks
;
395 /* keys are strings. Strings will be copied with wstrdup()
396 * and freed with wfree() */
398 extern const WMHashTableCallbacks WMStringPointerHashCallbacks
;
399 /* keys are strings, but they are not copied */
402 /*......................................................................*/
405 * WMArray use an array to store the elements.
406 * Item indexes may be only positive integer numbers.
407 * The array cannot contain holes in it.
410 * Fast [O(1)] access to elements
411 * Fast [O(1)] push/pop
414 * A little slower [O(n)] for insertion/deletion of elements that
418 WMArray
* WMCreateArray(int initialSize
);
420 WMArray
* WMCreateArrayWithDestructor(int initialSize
, WMFreeDataProc
*destructor
);
422 WMArray
* WMCreateArrayWithArray(WMArray
*array
);
424 #define WMDuplicateArray(array) WMCreateArrayWithArray(array)
426 void WMEmptyArray(WMArray
*array
);
428 void WMFreeArray(WMArray
*array
);
430 int WMGetArrayItemCount(WMArray
*array
);
432 /* appends other to array. other remains unchanged */
433 void WMAppendArray(WMArray
*array
, WMArray
*other
);
435 /* add will place the element at the end of the array */
436 void WMAddToArray(WMArray
*array
, void *item
);
438 #define WMPushInArray(array, item) WMAddToArray(array, item)
440 /* insert will increment the index of elements after it by 1 */
441 void WMInsertInArray(WMArray
*array
, int index
, void *item
);
443 /* replace and set will return the old item WITHOUT calling the
444 * destructor on it even if its available. Free the returned item yourself.
446 void* WMReplaceInArray(WMArray
*array
, int index
, void *item
);
448 #define WMSetInArray(array, index, item) WMReplaceInArray(array, index, item)
450 /* delete and remove will remove the elements and cause the elements
451 * after them to decrement their indexes by 1. Also will call the
452 * destructor on the deleted element if there's one available.
454 int WMDeleteFromArray(WMArray
*array
, int index
);
456 #define WMRemoveFromArray(array, item) WMRemoveFromArrayMatching(array, NULL, item)
458 int WMRemoveFromArrayMatching(WMArray
*array
, WMMatchDataProc
*match
, void *cdata
);
460 void* WMGetFromArray(WMArray
*array
, int index
);
462 #define WMGetFirstInArray(array, item) WMFindInArray(array, NULL, item)
464 /* pop will return the last element from the array, also removing it
465 * from the array. The destructor is NOT called, even if available.
466 * Free the returned element if needed by yourself
468 void* WMPopFromArray(WMArray
*array
);
470 int WMFindInArray(WMArray
*array
, WMMatchDataProc
*match
, void *cdata
);
472 int WMCountInArray(WMArray
*array
, void *item
);
474 /* comparer must return:
479 void WMSortArray(WMArray
*array
, WMCompareDataProc
*comparer
);
481 void WMMapArray(WMArray
*array
, void (*function
)(void*, void*), void *data
);
483 WMArray
* WMGetSubarrayWithRange(WMArray
* array
, WMRange aRange
);
485 void* WMArrayFirst(WMArray
*array
, WMArrayIterator
*iter
);
487 void* WMArrayLast(WMArray
*array
, WMArrayIterator
*iter
);
489 /* The following 2 functions assume that the array doesn't change between calls */
490 void* WMArrayNext(WMArray
*array
, WMArrayIterator
*iter
);
492 void* WMArrayPrevious(WMArray
*array
, WMArrayIterator
*iter
);
495 /* The following 2 macros assume that the array doesn't change in the for loop */
496 #define WM_ITERATE_ARRAY(array, var, i) \
497 for (var = WMArrayFirst(array, &(i)); (i) != WANotFound; \
498 var = WMArrayNext(array, &(i)))
500 #define WM_ETARETI_ARRAY(array, var, i) \
501 for (var = WMArrayLast(array, &(i)); (i) != WANotFound; \
502 var = WMArrayPrevious(array, &(i)))
504 /*..........................................................................*/
507 * Tree bags use a red-black tree for storage.
508 * Item indexes may be any integer number.
511 * O(lg n) insertion/deletion/search
512 * Good for large numbers of elements with sparse indexes
515 * O(lg n) insertion/deletion/search
516 * Slow for storing small numbers of elements
519 #define WMCreateBag(size) WMCreateTreeBag()
521 #define WMCreateBagWithDestructor(size, d) WMCreateTreeBagWithDestructor(d)
523 WMBag
* WMCreateTreeBag(void);
525 WMBag
* WMCreateTreeBagWithDestructor(WMFreeDataProc
*destructor
);
527 int WMGetBagItemCount(WMBag
*bag
);
529 void WMAppendBag(WMBag
*bag
, WMBag
*other
);
531 void WMPutInBag(WMBag
*bag
, void *item
);
533 /* insert will increment the index of elements after it by 1 */
534 void WMInsertInBag(WMBag
*bag
, int index
, void *item
);
536 /* erase will remove the element from the bag,
537 * but will keep the index of the other elements unchanged */
538 int WMEraseFromBag(WMBag
*bag
, int index
);
540 /* delete and remove will remove the elements and cause the elements
541 * after them to decrement their indexes by 1 */
542 int WMDeleteFromBag(WMBag
*bag
, int index
);
544 int WMRemoveFromBag(WMBag
*bag
, void *item
);
546 void* WMGetFromBag(WMBag
*bag
, int index
);
548 void* WMReplaceInBag(WMBag
*bag
, int index
, void *item
);
550 #define WMSetInBag(bag, index, item) WMReplaceInBag(bag, index, item)
552 /* comparer must return:
557 void WMSortBag(WMBag
*bag
, WMCompareDataProc
*comparer
);
559 void WMEmptyBag(WMBag
*bag
);
561 void WMFreeBag(WMBag
*bag
);
563 void WMMapBag(WMBag
*bag
, void (*function
)(void*, void*), void *data
);
565 int WMGetFirstInBag(WMBag
*bag
, void *item
);
567 int WMCountInBag(WMBag
*bag
, void *item
);
569 int WMFindInBag(WMBag
*bag
, WMMatchDataProc
*match
, void *cdata
);
571 void* WMBagFirst(WMBag
*bag
, WMBagIterator
*ptr
);
573 void* WMBagLast(WMBag
*bag
, WMBagIterator
*ptr
);
575 /* The following 4 functions assume that the bag doesn't change between calls */
576 void* WMBagNext(WMBag
*bag
, WMBagIterator
*ptr
);
578 void* WMBagPrevious(WMBag
*bag
, WMBagIterator
*ptr
);
580 void* WMBagIteratorAtIndex(WMBag
*bag
, int index
, WMBagIterator
*ptr
);
582 int WMBagIndexForIterator(WMBag
*bag
, WMBagIterator ptr
);
585 /* The following 2 macros assume that the bag doesn't change in the for loop */
586 #define WM_ITERATE_BAG(bag, var, i) \
587 for (var = WMBagFirst(bag, &(i)); (i) != NULL; \
588 var = WMBagNext(bag, &(i)))
590 #define WM_ETARETI_BAG(bag, var, i) \
591 for (var = WMBagLast(bag, &(i)); (i) != NULL; \
592 var = WMBagPrevious(bag, &(i)))
596 /*-------------------------------------------------------------------------*/
598 /* WMData handling */
600 /* Creating/destroying data */
602 WMData
* WMCreateDataWithCapacity(unsigned capacity
);
604 WMData
* WMCreateDataWithLength(unsigned length
);
606 WMData
* WMCreateDataWithBytes(void *bytes
, unsigned length
);
608 /* destructor is a function called to free the data when releasing the data
609 * object, or NULL if no freeing of data is necesary. */
610 WMData
* WMCreateDataWithBytesNoCopy(void *bytes
, unsigned length
,
611 WMFreeDataProc
*destructor
);
613 WMData
* WMCreateDataWithData(WMData
*aData
);
615 WMData
* WMRetainData(WMData
*aData
);
617 void WMReleaseData(WMData
*aData
);
619 /* Adjusting capacity */
621 void WMSetDataCapacity(WMData
*aData
, unsigned capacity
);
623 void WMSetDataLength(WMData
*aData
, unsigned length
);
625 void WMIncreaseDataLengthBy(WMData
*aData
, unsigned extraLength
);
629 const void* WMDataBytes(WMData
*aData
);
631 void WMGetDataBytes(WMData
*aData
, void *buffer
);
633 void WMGetDataBytesWithLength(WMData
*aData
, void *buffer
, unsigned length
);
635 void WMGetDataBytesWithRange(WMData
*aData
, void *buffer
, WMRange aRange
);
637 WMData
* WMGetSubdataWithRange(WMData
*aData
, WMRange aRange
);
641 Bool
WMIsDataEqualToData(WMData
*aData
, WMData
*anotherData
);
643 unsigned WMGetDataLength(WMData
*aData
);
647 void WMAppendDataBytes(WMData
*aData
, void *bytes
, unsigned length
);
649 void WMAppendData(WMData
*aData
, WMData
*anotherData
);
653 void WMReplaceDataBytesInRange(WMData
*aData
, WMRange aRange
, void *bytes
);
655 void WMResetDataBytesInRange(WMData
*aData
, WMRange aRange
);
657 void WMSetData(WMData
*aData
, WMData
*anotherData
);
660 void WMSetDataFormat(WMData
*aData
, unsigned format
);
662 unsigned WMGetDataFormat(WMData
*aData
);
666 /*--------------------------------------------------------------------------*/
668 /* Generic Tree and TreeNode */
670 WMTreeNode
* WMCreateTreeNode(void *data
);
672 WMTreeNode
* WMCreateTreeNodeWithDestructor(void *data
, WMFreeDataProc
*destructor
);
674 WMTreeNode
* WMInsertItemInTree(WMTreeNode
*parent
, int index
, void *item
);
676 #define WMAddItemToTree(parent, item) WMInsertItemInTree(parent, -1, item)
678 WMTreeNode
* WMInsertNodeInTree(WMTreeNode
*parent
, int index
, WMTreeNode
*aNode
);
680 #define WMAddNodeToTree(parent, aNode) WMInsertNodeInTree(parent, -1, aNode)
682 void WMDestroyTreeNode(WMTreeNode
*aNode
);
684 void WMDeleteLeafForTreeNode(WMTreeNode
*aNode
, int index
);
686 void WMRemoveLeafForTreeNode(WMTreeNode
*aNode
, void *leaf
);
688 void* WMReplaceDataForTreeNode(WMTreeNode
*aNode
, void *newData
);
690 void* WMGetDataForTreeNode(WMTreeNode
*aNode
);
692 int WMGetTreeNodeDepth(WMTreeNode
*aNode
);
694 WMTreeNode
* WMGetParentForTreeNode(WMTreeNode
*aNode
);
696 /* Sort only the leaves of the passed node */
697 void WMSortLeavesForTreeNode(WMTreeNode
*aNode
, WMCompareDataProc
*comparer
);
699 /* Sort all tree recursively starting from the passed node */
700 void WMSortTree(WMTreeNode
*aNode
, WMCompareDataProc
*comparer
);
702 /* Returns the first node which matches node's data with cdata by 'match' */
703 WMTreeNode
* WMFindInTree(WMTreeNode
*aTree
, WMMatchDataProc
*match
, void *cdata
);
705 /* Returns first tree node that has data == cdata */
706 #define WMGetFirstInTree(aTree, cdata) WMFindInTree(aTree, NULL, cdata)
709 /*--------------------------------------------------------------------------*/
712 WMNotification
* WMCreateNotification(const char *name
, void *object
, void *clientData
);
714 void WMReleaseNotification(WMNotification
*notification
);
716 WMNotification
* WMRetainNotification(WMNotification
*notification
);
718 void* WMGetNotificationClientData(WMNotification
*notification
);
720 void* WMGetNotificationObject(WMNotification
*notification
);
722 const char* WMGetNotificationName(WMNotification
*notification
);
725 void WMAddNotificationObserver(WMNotificationObserverAction
*observerAction
,
726 void *observer
, const char *name
, void *object
);
728 void WMPostNotification(WMNotification
*notification
);
730 void WMRemoveNotificationObserver(void *observer
);
732 void WMRemoveNotificationObserverWithName(void *observer
, const char *name
,
735 void WMPostNotificationName(const char *name
, void *object
, void *clientData
);
737 WMNotificationQueue
* WMGetDefaultNotificationQueue(void);
739 WMNotificationQueue
* WMCreateNotificationQueue(void);
741 void WMDequeueNotificationMatching(WMNotificationQueue
*queue
,
742 WMNotification
*notification
,
745 void WMEnqueueNotification(WMNotificationQueue
*queue
,
746 WMNotification
*notification
,
747 WMPostingStyle postingStyle
);
749 void WMEnqueueCoalesceNotification(WMNotificationQueue
*queue
,
750 WMNotification
*notification
,
751 WMPostingStyle postingStyle
,
752 unsigned coalesceMask
);
755 /*......................................................................*/
757 /* Property Lists handling */
759 void WMPLSetCaseSensitive(Bool caseSensitive
);
761 WMPropList
* WMCreatePLString(char *str
);
763 WMPropList
* WMCreatePLData(WMData
*data
);
765 WMPropList
* WMCreatePLDataWithBytes(unsigned char *bytes
, unsigned int length
);
767 WMPropList
* WMCreatePLDataWithBytesNoCopy(unsigned char *bytes
,
769 WMFreeDataProc
*destructor
);
771 WMPropList
* WMCreatePLArray(WMPropList
*elem
, ...);
773 WMPropList
* WMCreatePLDictionary(WMPropList
*key
, WMPropList
*value
, ...);
775 WMPropList
* WMRetainPropList(WMPropList
*plist
);
777 void WMReleasePropList(WMPropList
*plist
);
779 /* Objects inserted in arrays and dictionaries will be retained,
780 * so you can safely release them after insertion.
781 * For dictionaries both the key and value are retained.
782 * Objects removed from arrays or dictionaries are released */
783 void WMInsertInPLArray(WMPropList
*plist
, int index
, WMPropList
*item
);
785 void WMAddToPLArray(WMPropList
*plist
, WMPropList
*item
);
787 void WMDeleteFromPLArray(WMPropList
*plist
, int index
);
789 void WMRemoveFromPLArray(WMPropList
*plist
, WMPropList
*item
);
791 void WMPutInPLDictionary(WMPropList
*plist
, WMPropList
*key
, WMPropList
*value
);
793 void WMRemoveFromPLDictionary(WMPropList
*plist
, WMPropList
*key
);
795 /* It will insert all key/value pairs from source into dest, overwriting
796 * the values with the same keys from dest, keeping all values with keys
797 * only present in dest unchanged */
798 WMPropList
* WMMergePLDictionaries(WMPropList
*dest
, WMPropList
*source
,
801 /* It will remove all key/value pairs from dest for which there is an
802 * identical key/value present in source. Entires only present in dest, or
803 * which have different values in dest than in source will be preserved. */
804 WMPropList
* WMSubtractPLDictionaries(WMPropList
*dest
, WMPropList
*source
,
807 int WMGetPropListItemCount(WMPropList
*plist
);
809 Bool
WMIsPLString(WMPropList
*plist
);
811 Bool
WMIsPLData(WMPropList
*plist
);
813 Bool
WMIsPLArray(WMPropList
*plist
);
815 Bool
WMIsPLDictionary(WMPropList
*plist
);
817 Bool
WMIsPropListEqualTo(WMPropList
*plist
, WMPropList
*other
);
819 /* Returns a reference. Do not free it! */
820 char* WMGetFromPLString(WMPropList
*plist
);
822 /* Returns a reference. Do not free it! */
823 WMData
* WMGetFromPLData(WMPropList
*plist
);
825 /* Returns a reference. Do not free it! */
826 const unsigned char* WMGetPLDataBytes(WMPropList
*plist
);
828 int WMGetPLDataLength(WMPropList
*plist
);
830 /* Returns a reference. */
831 WMPropList
* WMGetFromPLArray(WMPropList
*plist
, int index
);
833 /* Returns a reference. */
834 WMPropList
* WMGetFromPLDictionary(WMPropList
*plist
, WMPropList
*key
);
836 /* Returns a PropList array with all the dictionary keys. Release it when
837 * you're done. Keys in array are retained from the original dictionary
838 * not copied and need NOT to be released individually. */
839 WMPropList
* WMGetPLDictionaryKeys(WMPropList
*plist
);
841 /* Creates only the first level deep object. All the elements inside are
842 * retained from the original */
843 WMPropList
* WMShallowCopyPropList(WMPropList
*plist
);
845 /* Makes a completely separate replica of the original proplist */
846 WMPropList
* WMDeepCopyPropList(WMPropList
*plist
);
848 WMPropList
* WMCreatePropListFromDescription(char *desc
);
850 /* Free the returned string when you no longer need it */
851 char* WMGetPropListDescription(WMPropList
*plist
, Bool indented
);
853 WMPropList
* WMReadPropListFromFile(char *file
);
855 Bool
WMWritePropListToFile(WMPropList
*plist
, char *path
);
857 /*......................................................................*/
859 WMUserDefaults
* WMGetStandardUserDefaults(void);
861 WMUserDefaults
* WMGetDefaultsFromPath(char *path
);
863 void WMSynchronizeUserDefaults(WMUserDefaults
*database
);
865 void WMSaveUserDefaults(WMUserDefaults
*database
);
867 void WMEnableUDPeriodicSynchronization(WMUserDefaults
*database
, Bool enable
);
869 /* Returns a WMPropList array with all the keys in the user defaults database.
870 * Free the array with WMReleasePropList() when no longer needed.
871 * Keys in array are just retained references to the original keys */
872 WMPropList
* WMGetUDKeys(WMUserDefaults
*database
);
874 WMPropList
* WMGetUDObjectForKey(WMUserDefaults
*database
, char *defaultName
);
876 void WMSetUDObjectForKey(WMUserDefaults
*database
, WMPropList
*object
,
879 void WMRemoveUDObjectForKey(WMUserDefaults
*database
, char *defaultName
);
881 char* WMGetUDStringForKey(WMUserDefaults
*database
, char *defaultName
);
883 int WMGetUDIntegerForKey(WMUserDefaults
*database
, char *defaultName
);
885 float WMGetUDFloatForKey(WMUserDefaults
*database
, char *defaultName
);
887 Bool
WMGetUDBoolForKey(WMUserDefaults
*database
, char *defaultName
);
889 void WMSetUDStringForKey(WMUserDefaults
*database
, char *value
,
892 void WMSetUDIntegerForKey(WMUserDefaults
*database
, int value
,
895 void WMSetUDFloatForKey(WMUserDefaults
*database
, float value
,
898 void WMSetUDBoolForKey(WMUserDefaults
*database
, Bool value
,
901 WMPropList
* WMGetUDSearchList(WMUserDefaults
*database
);
903 void WMSetUDSearchList(WMUserDefaults
*database
, WMPropList
*list
);
905 extern char *WMUserDefaultsDidChangeNotification
;
908 /*-------------------------------------------------------------------------*/
910 /* WMHost: host handling */
912 WMHost
* WMGetCurrentHost();
914 WMHost
* WMGetHostWithName(char* name
);
916 WMHost
* WMGetHostWithAddress(char* address
);
918 WMHost
* WMRetainHost(WMHost
*hPtr
);
920 void WMReleaseHost(WMHost
*hPtr
);
923 * Host cache management
924 * If enabled, only one object representing each host will be created, and
925 * a shared instance will be returned by all methods that return a host.
926 * Enabled by default.
928 void WMSetHostCacheEnabled(Bool flag
);
930 Bool
WMIsHostCacheEnabled();
932 void WMFlushHostCache();
935 * Compare hosts: Hosts are equal if they share at least one address
937 Bool
WMIsHostEqualToHost(WMHost
* hPtr
, WMHost
* anotherHost
);
941 * WMGetHostName() will return first name (official) if a host has several.
942 * WMGetHostNames() will return a R/O WMArray with all the names of the host.
944 char* WMGetHostName(WMHost
* hPtr
);
946 /* The returned array is R/O. Do not modify it, and do not free it! */
947 WMArray
* WMGetHostNames(WMHost
* hPtr
);
951 * Addresses are represented as "Dotted Decimal" strings, e.g. "192.42.172.1"
952 * WMGetHostAddress() will return an arbitrary address if a host has several.
953 * WMGetHostAddresses() will return a R/O WMArray with all addresses of the host.
955 char* WMGetHostAddress(WMHost
* hPtr
);
957 /* The returned array is R/O. Do not modify it, and do not free it! */
958 WMArray
* WMGetHostAddresses(WMHost
* hPtr
);
961 /*-------------------------------------------------------------------------*/
963 /* WMConnection functions */
965 WMConnection
* WMCreateConnectionAsServerAtAddress(char *host
, char *service
,
968 WMConnection
* WMCreateConnectionToAddress(char *host
, char *service
,
971 WMConnection
* WMCreateConnectionToAddressAndNotify(char *host
, char *service
,
974 void WMCloseConnection(WMConnection
*cPtr
);
976 void WMDestroyConnection(WMConnection
*cPtr
);
978 WMConnection
* WMAcceptConnection(WMConnection
*listener
);
980 /* Release the returned data! */
981 WMData
* WMGetConnectionAvailableData(WMConnection
*cPtr
);
983 int WMSendConnectionData(WMConnection
*cPtr
, WMData
*data
);
985 Bool
WMEnqueueConnectionData(WMConnection
*cPtr
, WMData
*data
);
987 #define WMFlushConnection(cPtr) WMSendConnectionData((cPtr), NULL)
989 void WMSetConnectionDelegate(WMConnection
*cPtr
, ConnectionDelegate
*delegate
);
991 /* Connection info */
993 char* WMGetConnectionAddress(WMConnection
*cPtr
);
995 char* WMGetConnectionService(WMConnection
*cPtr
);
997 char* WMGetConnectionProtocol(WMConnection
*cPtr
);
999 Bool
WMSetConnectionNonBlocking(WMConnection
*cPtr
, Bool flag
);
1001 Bool
WMSetConnectionCloseOnExec(WMConnection
*cPtr
, Bool flag
);
1003 void WMSetConnectionShutdownOnClose(WMConnection
*cPtr
, Bool flag
);
1005 void* WMGetConnectionClientData(WMConnection
*cPtr
);
1007 void WMSetConnectionClientData(WMConnection
*cPtr
, void *data
);
1009 unsigned int WMGetConnectionFlags(WMConnection
*cPtr
);
1011 void WMSetConnectionFlags(WMConnection
*cPtr
, unsigned int flags
);
1013 int WMGetConnectionSocket(WMConnection
*cPtr
);
1015 WMConnectionState
WMGetConnectionState(WMConnection
*cPtr
);
1017 WMConnectionTimeoutState
WMGetConnectionTimeoutState(WMConnection
*cPtr
);
1019 WMArray
* WMGetConnectionUnsentData(WMConnection
*cPtr
);
1021 #define WMGetConnectionQueuedData(cPtr) WMGetConnectionUnsentData(cPtr)
1025 * Passing timeout==0 in the SetTimeout functions below, will reset that
1026 * timeout to its default value.
1029 /* The default timeout inherited by all WMConnection operations, if none set */
1030 void WMSetConnectionDefaultTimeout(unsigned int timeout
);
1032 /* Global timeout for all WMConnection objects, for opening a new connection */
1033 void WMSetConnectionOpenTimeout(unsigned int timeout
);
1035 /* Connection specific timeout for sending out data */
1036 void WMSetConnectionSendTimeout(WMConnection
*cPtr
, unsigned int timeout
);
1039 /* Global variables */
1041 extern int WCErrorCode
;
1044 /*-------------------------------------------------------------------------*/
1050 #endif /* __cplusplus */