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 #if (!defined (__GNUC__) || __GNUC__ < 2 || \
23 __GNUC_MINOR__ < (defined (__cplusplus) ? 6 : 4))
24 #define __ASSERT_FUNCTION ((char *) 0)
26 #define __ASSERT_FUNCTION __PRETTY_FUNCTION__
32 #define wassertr(expr) {}
33 #define wassertrv(expr, val) {}
41 #define wassertr(expr) assert(expr)
43 #define wassertrv(expr, val) assert(expr)
47 #define wassertr(expr) \
49 wwarning("%s line %i (%s): assertion %s failed",\
50 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
54 #define wassertrv(expr, val) \
56 wwarning("%s line %i (%s): assertion %s failed",\
57 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
67 #endif /* __cplusplus */
81 } WMNotificationCoalescing
;
84 /* The possible states for connections */
97 /* The possible states for connection timeouts */
102 } WMConnectionTimeoutState
;
107 WBNotFound
= INT_MIN
, /* element was not found in WMBag */
108 WANotFound
= -1 /* element was not found in WMArray */
112 typedef struct W_Array WMArray
;
113 typedef struct W_Bag WMBag
;
114 typedef struct W_Data WMData
;
115 typedef struct W_TreeNode WMTreeNode
;
116 typedef struct W_HashTable WMHashTable
;
117 typedef struct W_UserDefaults WMUserDefaults
;
118 typedef struct W_Notification WMNotification
;
119 typedef struct W_NotificationQueue WMNotificationQueue
;
120 typedef struct W_Host WMHost
;
121 typedef struct W_Connection WMConnection
;
122 typedef struct W_PropList WMPropList
;
126 /* Some typedefs for the handler stuff */
127 typedef void *WMHandlerID
;
129 typedef void WMCallback(void *data
);
131 typedef void WMInputProc(int fd
, int mask
, void *clientData
);
135 typedef int WMCompareDataProc(const void *item1
, const void *item2
);
137 typedef void WMFreeDataProc(void *data
);
139 /* Used by WMBag or WMArray for matching data */
140 typedef int WMMatchDataProc(void *item
, void *cdata
);
151 /* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */
160 /* NULL is pointer hash */
161 unsigned (*hash
)(const void *);
162 /* NULL is pointer compare */
163 Bool (*keyIsEqual
)(const void *, const void *);
164 /* NULL does nothing */
165 void* (*retainKey
)(const void *);
166 /* NULL does nothing */
167 void (*releaseKey
)(const void *);
168 } WMHashTableCallbacks
;
171 typedef int WMArrayIterator
;
172 typedef void *WMBagIterator
;
177 char character
; /* the escape character */
178 char *value
; /* value to place */
183 /* The connection callbacks */
184 typedef struct ConnectionDelegate
{
187 void (*canResumeSending
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
189 void (*didCatchException
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
191 void (*didDie
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
193 void (*didInitialize
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
195 void (*didReceiveInput
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
197 void (*didTimeout
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
199 } ConnectionDelegate
;
202 typedef void WMNotificationObserverAction(void *observerData
,
203 WMNotification
*notification
);
207 /*......................................................................*/
209 typedef void waborthandler(int);
211 waborthandler
* wsetabort(waborthandler
* handler
);
214 /* don't free the returned string */
215 char* wstrerror(int errnum
);
217 void wmessage(const char *msg
, ...);
218 void wwarning(const char *msg
, ...);
219 void wfatal(const char *msg
, ...);
220 void wsyserror(const char *msg
, ...);
221 void wsyserrorwithcode(int error
, const char *msg
, ...);
223 char* wfindfile(char *paths
, char *file
);
225 char* wfindfileinlist(char **path_list
, char *file
);
227 char* wfindfileinarray(WMPropList
* array
, char *file
);
229 char* wexpandpath(char *path
);
231 /* don't free the returned string */
234 void* wmalloc(size_t size
);
235 void* wrealloc(void *ptr
, size_t newsize
);
236 void wfree(void *ptr
);
239 void wrelease(void *ptr
);
240 void* wretain(void *ptr
);
242 char* wstrdup(char *str
);
244 /* Concatenate str1 with str2 and return that in a newly malloc'ed string.
245 * str1 and str2 can be any strings including static and constant strings.
246 * str1 and str2 will not be modified.
247 * Free the returned string when you're done with it. */
248 char* wstrconcat(char *str1
, char *str2
);
250 /* This will append src to dst, and return dst. dst MUST be either NULL
251 * or a string that was a result of a dynamic allocation (malloc, realloc
252 * wmalloc, wrealloc, ...). dst CANNOT be a static or a constant string!
253 * Modifies dst (no new string is created except if dst==NULL in which case
254 * it is equivalent to calling wstrdup(src) ).
255 * The returned address may be different from the original address of dst,
256 * so always assign the returned address to avoid dangling pointers. */
257 char* wstrappend(char *dst
, char *src
);
260 void wtokensplit(char *command
, char ***argv
, int *argc
);
262 char* wtokennext(char *word
, char **next
);
264 char* wtokenjoin(char **list
, int count
);
266 void wtokenfree(char **tokens
, int count
);
268 char* wtrimspace(char *s
);
271 WMRange
wmkrange(int start
, int count
);
272 #ifdef ANSI_C_DOESNT_LIKE_IT_THIS_WAY
273 #define wmkrange(position, count) (WMRange){(position), (count)}
277 char* wusergnusteppath();
279 char* wdefaultspathfordomain(char *domain
);
281 void wusleep(unsigned int microsec
);
284 int wsprintesc(char *buffer
, int length
, char *format
, WMSEscapes
**escapes
,
288 /*......................................................................*/
290 /* Event handlers: timer, idle, input */
292 WMHandlerID
WMAddTimerHandler(int milliseconds
, WMCallback
*callback
,
295 WMHandlerID
WMAddPersistentTimerHandler(int milliseconds
, WMCallback
*callback
,
298 void WMDeleteTimerWithClientData(void *cdata
);
300 void WMDeleteTimerHandler(WMHandlerID handlerID
);
302 WMHandlerID
WMAddIdleHandler(WMCallback
*callback
, void *cdata
);
304 void WMDeleteIdleHandler(WMHandlerID handlerID
);
306 WMHandlerID
WMAddInputHandler(int fd
, int condition
, WMInputProc
*proc
,
309 void WMDeleteInputHandler(WMHandlerID handlerID
);
312 /* This function is used _only_ if you create a non-GUI program.
313 * For GUI based programs use WMNextEvent()/WMHandleEvent() instead.
314 * This function will handle all input/timer/idle events, then return.
317 void WHandleEvents();
319 /*......................................................................*/
322 WMHashTable
* WMCreateHashTable(WMHashTableCallbacks callbacks
);
324 void WMFreeHashTable(WMHashTable
*table
);
326 void WMResetHashTable(WMHashTable
*table
);
328 unsigned WMCountHashTable(WMHashTable
*table
);
330 void* WMHashGet(WMHashTable
*table
, const void *key
);
332 /* Returns True if there is a value associated with <key> in the table, in
333 * which case <retKey> and <retItem> will contain the item's internal key
334 * address and the item's value respectively.
335 * If there is no value associated with <key> it will return False and in
336 * this case <retKey> and <retItem> will be undefined.
337 * Use this when you need to perform your own custom retain/release mechanism
338 * which requires access to the keys too.
340 Bool
WMHashGetItemAndKey(WMHashTable
*table
, const void *key
,
341 void **retItem
, void **retKey
);
343 /* put data in table, replacing already existing data and returning
345 void* WMHashInsert(WMHashTable
*table
, const void *key
, const void *data
);
347 void WMHashRemove(WMHashTable
*table
, const void *key
);
349 /* warning: do not manipulate the table while using the enumerator functions */
350 WMHashEnumerator
WMEnumerateHashTable(WMHashTable
*table
);
352 void* WMNextHashEnumeratorItem(WMHashEnumerator
*enumerator
);
354 void* WMNextHashEnumeratorKey(WMHashEnumerator
*enumerator
);
356 /* Returns True if there is a next element, in which case key and item
357 * will contain the next element's key and value respectively.
358 * If there is no next element available it will return False and in this
359 * case key and item will be undefined.
361 Bool
WMNextHashEnumeratorItemAndKey(WMHashEnumerator
*enumerator
,
362 void **item
, void **key
);
367 /* some predefined callback sets */
369 extern const WMHashTableCallbacks WMIntHashCallbacks
;
370 /* sizeof(keys) are <= sizeof(void*) */
372 extern const WMHashTableCallbacks WMStringHashCallbacks
;
373 /* keys are strings. Strings will be copied with wstrdup()
374 * and freed with wfree() */
376 extern const WMHashTableCallbacks WMStringPointerHashCallbacks
;
377 /* keys are strings, but they are not copied */
380 /*......................................................................*/
383 * WMArray use an array to store the elements.
384 * Item indexes may be only positive integer numbers.
385 * The array cannot contain holes in it.
388 * Fast [O(1)] access to elements
389 * Fast [O(1)] push/pop
392 * A little slower [O(n)] for insertion/deletion of elements that
396 WMArray
* WMCreateArray(int initialSize
);
398 WMArray
* WMCreateArrayWithDestructor(int initialSize
, WMFreeDataProc
*destructor
);
400 WMArray
* WMCreateArrayWithArray(WMArray
*array
);
402 #define WMDuplicateArray(array) WMCreateArrayWithArray(array)
404 void WMEmptyArray(WMArray
*array
);
406 void WMFreeArray(WMArray
*array
);
408 int WMGetArrayItemCount(WMArray
*array
);
410 /* appends other to array. other remains unchanged */
411 void WMAppendArray(WMArray
*array
, WMArray
*other
);
413 /* add will place the element at the end of the array */
414 void WMAddToArray(WMArray
*array
, void *item
);
416 #define WMPushInArray(array, item) WMAddToArray(array, item)
418 /* insert will increment the index of elements after it by 1 */
419 void WMInsertInArray(WMArray
*array
, int index
, void *item
);
421 /* replace and set will return the old item WITHOUT calling the
422 * destructor on it even if its available. Free the returned item yourself.
424 void* WMReplaceInArray(WMArray
*array
, int index
, void *item
);
426 #define WMSetInArray(array, index, item) WMReplaceInArray(array, index, item)
428 /* delete and remove will remove the elements and cause the elements
429 * after them to decrement their indexes by 1. Also will call the
430 * destructor on the deleted element if there's one available.
432 int WMDeleteFromArray(WMArray
*array
, int index
);
434 #define WMRemoveFromArray(array, item) WMRemoveFromArrayMatching(array, NULL, item)
436 int WMRemoveFromArrayMatching(WMArray
*array
, WMMatchDataProc
*match
, void *cdata
);
438 void* WMGetFromArray(WMArray
*array
, int index
);
440 #define WMGetFirstInArray(array, item) WMFindInArray(array, NULL, item)
442 /* pop will return the last element from the array, also removing it
443 * from the array. The destructor is NOT called, even if available.
444 * Free the returned element if needed by yourself
446 void* WMPopFromArray(WMArray
*array
);
448 int WMFindInArray(WMArray
*array
, WMMatchDataProc
*match
, void *cdata
);
450 int WMCountInArray(WMArray
*array
, void *item
);
452 /* comparer must return:
457 void WMSortArray(WMArray
*array
, WMCompareDataProc
*comparer
);
459 void WMMapArray(WMArray
*array
, void (*function
)(void*, void*), void *data
);
461 WMArray
* WMGetSubarrayWithRange(WMArray
* array
, WMRange aRange
);
463 void* WMArrayFirst(WMArray
*array
, WMArrayIterator
*iter
);
465 void* WMArrayLast(WMArray
*array
, WMArrayIterator
*iter
);
467 /* The following 2 functions assume that the array doesn't change between calls */
468 void* WMArrayNext(WMArray
*array
, WMArrayIterator
*iter
);
470 void* WMArrayPrevious(WMArray
*array
, WMArrayIterator
*iter
);
473 /* The following 2 macros assume that the array doesn't change in the for loop */
474 #define WM_ITERATE_ARRAY(array, var, i) \
475 for (var = WMArrayFirst(array, &(i)); (i) != WANotFound; \
476 var = WMArrayNext(array, &(i)))
478 #define WM_ETARETI_ARRAY(array, var, i) \
479 for (var = WMArrayLast(array, &(i)); (i) != WANotFound; \
480 var = WMArrayPrevious(array, &(i)))
482 /*..........................................................................*/
485 * Tree bags use a red-black tree for storage.
486 * Item indexes may be any integer number.
489 * O(lg n) insertion/deletion/search
490 * Good for large numbers of elements with sparse indexes
493 * O(lg n) insertion/deletion/search
494 * Slow for storing small numbers of elements
497 #define WMCreateBag(size) WMCreateTreeBag()
499 #define WMCreateBagWithDestructor(size, d) WMCreateTreeBagWithDestructor(d)
501 WMBag
* WMCreateTreeBag(void);
503 WMBag
* WMCreateTreeBagWithDestructor(WMFreeDataProc
*destructor
);
505 int WMGetBagItemCount(WMBag
*bag
);
507 void WMAppendBag(WMBag
*bag
, WMBag
*other
);
509 void WMPutInBag(WMBag
*bag
, void *item
);
511 /* insert will increment the index of elements after it by 1 */
512 void WMInsertInBag(WMBag
*bag
, int index
, void *item
);
514 /* erase will remove the element from the bag,
515 * but will keep the index of the other elements unchanged */
516 int WMEraseFromBag(WMBag
*bag
, int index
);
518 /* delete and remove will remove the elements and cause the elements
519 * after them to decrement their indexes by 1 */
520 int WMDeleteFromBag(WMBag
*bag
, int index
);
522 int WMRemoveFromBag(WMBag
*bag
, void *item
);
524 void* WMGetFromBag(WMBag
*bag
, int index
);
526 void* WMReplaceInBag(WMBag
*bag
, int index
, void *item
);
528 #define WMSetInBag(bag, index, item) WMReplaceInBag(bag, index, item)
530 /* comparer must return:
535 void WMSortBag(WMBag
*bag
, WMCompareDataProc
*comparer
);
537 void WMEmptyBag(WMBag
*bag
);
539 void WMFreeBag(WMBag
*bag
);
541 void WMMapBag(WMBag
*bag
, void (*function
)(void*, void*), void *data
);
543 int WMGetFirstInBag(WMBag
*bag
, void *item
);
545 int WMCountInBag(WMBag
*bag
, void *item
);
547 int WMFindInBag(WMBag
*bag
, WMMatchDataProc
*match
, void *cdata
);
549 void* WMBagFirst(WMBag
*bag
, WMBagIterator
*ptr
);
551 void* WMBagLast(WMBag
*bag
, WMBagIterator
*ptr
);
553 /* The following 4 functions assume that the bag doesn't change between calls */
554 void* WMBagNext(WMBag
*bag
, WMBagIterator
*ptr
);
556 void* WMBagPrevious(WMBag
*bag
, WMBagIterator
*ptr
);
558 void* WMBagIteratorAtIndex(WMBag
*bag
, int index
, WMBagIterator
*ptr
);
560 int WMBagIndexForIterator(WMBag
*bag
, WMBagIterator ptr
);
563 /* The following 2 macros assume that the bag doesn't change in the for loop */
564 #define WM_ITERATE_BAG(bag, var, i) \
565 for (var = WMBagFirst(bag, &(i)); (i) != NULL; \
566 var = WMBagNext(bag, &(i)))
568 #define WM_ETARETI_BAG(bag, var, i) \
569 for (var = WMBagLast(bag, &(i)); (i) != NULL; \
570 var = WMBagPrevious(bag, &(i)))
574 /*-------------------------------------------------------------------------*/
576 /* WMData handling */
578 /* Creating/destroying data */
580 WMData
* WMCreateDataWithCapacity(unsigned capacity
);
582 WMData
* WMCreateDataWithLength(unsigned length
);
584 WMData
* WMCreateDataWithBytes(void *bytes
, unsigned length
);
586 /* destructor is a function called to free the data when releasing the data
587 * object, or NULL if no freeing of data is necesary. */
588 WMData
* WMCreateDataWithBytesNoCopy(void *bytes
, unsigned length
,
589 WMFreeDataProc
*destructor
);
591 WMData
* WMCreateDataWithData(WMData
*aData
);
593 WMData
* WMRetainData(WMData
*aData
);
595 void WMReleaseData(WMData
*aData
);
597 /* Adjusting capacity */
599 void WMSetDataCapacity(WMData
*aData
, unsigned capacity
);
601 void WMSetDataLength(WMData
*aData
, unsigned length
);
603 void WMIncreaseDataLengthBy(WMData
*aData
, unsigned extraLength
);
607 const void* WMDataBytes(WMData
*aData
);
609 void WMGetDataBytes(WMData
*aData
, void *buffer
);
611 void WMGetDataBytesWithLength(WMData
*aData
, void *buffer
, unsigned length
);
613 void WMGetDataBytesWithRange(WMData
*aData
, void *buffer
, WMRange aRange
);
615 WMData
* WMGetSubdataWithRange(WMData
*aData
, WMRange aRange
);
619 Bool
WMIsDataEqualToData(WMData
*aData
, WMData
*anotherData
);
621 unsigned WMGetDataLength(WMData
*aData
);
625 void WMAppendDataBytes(WMData
*aData
, void *bytes
, unsigned length
);
627 void WMAppendData(WMData
*aData
, WMData
*anotherData
);
631 void WMReplaceDataBytesInRange(WMData
*aData
, WMRange aRange
, void *bytes
);
633 void WMResetDataBytesInRange(WMData
*aData
, WMRange aRange
);
635 void WMSetData(WMData
*aData
, WMData
*anotherData
);
638 void WMSetDataFormat(WMData
*aData
, unsigned format
);
640 unsigned WMGetDataFormat(WMData
*aData
);
644 /*--------------------------------------------------------------------------*/
646 /* Generic Tree and TreeNode */
648 WMTreeNode
* WMCreateTreeNode(void *data
);
650 WMTreeNode
* WMCreateTreeNodeWithDestructor(void *data
, WMFreeDataProc
*destructor
);
652 WMTreeNode
* WMInsertItemInTree(WMTreeNode
*parent
, int index
, void *item
);
654 #define WMAddItemToTree(parent, item) WMInsertItemInTree(parent, -1, item)
656 WMTreeNode
* WMInsertNodeInTree(WMTreeNode
*parent
, int index
, WMTreeNode
*aNode
);
658 #define WMAddNodeToTree(parent, aNode) WMInsertNodeInTree(parent, -1, aNode)
660 void WMDestroyTreeNode(WMTreeNode
*aNode
);
662 void WMDeleteLeafForTreeNode(WMTreeNode
*aNode
, int index
);
664 void WMRemoveLeafForTreeNode(WMTreeNode
*aNode
, void *leaf
);
666 void* WMReplaceDataForTreeNode(WMTreeNode
*aNode
, void *newData
);
668 void* WMGetDataForTreeNode(WMTreeNode
*aNode
);
670 int WMGetTreeNodeDepth(WMTreeNode
*aNode
);
672 WMTreeNode
* WMGetParentForTreeNode(WMTreeNode
*aNode
);
674 /* Sort only the leaves of the passed node */
675 void WMSortLeavesForTreeNode(WMTreeNode
*aNode
, WMCompareDataProc
*comparer
);
677 /* Sort all tree recursively starting from the passed node */
678 void WMSortTree(WMTreeNode
*aNode
, WMCompareDataProc
*comparer
);
680 /* Returns the first node which matches node's data with cdata by 'match' */
681 WMTreeNode
* WMFindInTree(WMTreeNode
*aTree
, WMMatchDataProc
*match
, void *cdata
);
683 /* Returns first tree node that has data == cdata */
684 #define WMGetFirstInTree(aTree, cdata) WMFindInTree(aTree, NULL, cdata)
687 /*--------------------------------------------------------------------------*/
690 WMNotification
* WMCreateNotification(const char *name
, void *object
, void *clientData
);
692 void WMReleaseNotification(WMNotification
*notification
);
694 WMNotification
* WMRetainNotification(WMNotification
*notification
);
696 void* WMGetNotificationClientData(WMNotification
*notification
);
698 void* WMGetNotificationObject(WMNotification
*notification
);
700 const char* WMGetNotificationName(WMNotification
*notification
);
703 void WMAddNotificationObserver(WMNotificationObserverAction
*observerAction
,
704 void *observer
, const char *name
, void *object
);
706 void WMPostNotification(WMNotification
*notification
);
708 void WMRemoveNotificationObserver(void *observer
);
710 void WMRemoveNotificationObserverWithName(void *observer
, const char *name
,
713 void WMPostNotificationName(const char *name
, void *object
, void *clientData
);
715 WMNotificationQueue
* WMGetDefaultNotificationQueue(void);
717 WMNotificationQueue
* WMCreateNotificationQueue(void);
719 void WMDequeueNotificationMatching(WMNotificationQueue
*queue
,
720 WMNotification
*notification
,
723 void WMEnqueueNotification(WMNotificationQueue
*queue
,
724 WMNotification
*notification
,
725 WMPostingStyle postingStyle
);
727 void WMEnqueueCoalesceNotification(WMNotificationQueue
*queue
,
728 WMNotification
*notification
,
729 WMPostingStyle postingStyle
,
730 unsigned coalesceMask
);
733 /*......................................................................*/
735 /* Property Lists handling */
737 void WMPLSetCaseSensitive(Bool caseSensitive
);
739 WMPropList
* WMCreatePLString(char *str
);
741 WMPropList
* WMCreatePLData(WMData
*data
);
743 WMPropList
* WMCreatePLDataWithBytes(unsigned char *bytes
, unsigned int length
);
745 WMPropList
* WMCreatePLDataWithBytesNoCopy(unsigned char *bytes
,
747 WMFreeDataProc
*destructor
);
749 WMPropList
* WMCreatePLArray(WMPropList
*elem
, ...);
751 WMPropList
* WMCreatePLDictionary(WMPropList
*key
, WMPropList
*value
, ...);
753 WMPropList
* WMRetainPropList(WMPropList
*plist
);
755 void WMReleasePropList(WMPropList
*plist
);
757 /* Objects inserted in arrays and dictionaries will be retained,
758 * so you can safely release them after insertion.
759 * For dictionaries both the key and value are retained.
760 * Objects removed from arrays or dictionaries are released */
761 void WMInsertInPLArray(WMPropList
*plist
, int index
, WMPropList
*item
);
763 void WMAddToPLArray(WMPropList
*plist
, WMPropList
*item
);
765 void WMDeleteFromPLArray(WMPropList
*plist
, int index
);
767 void WMRemoveFromPLArray(WMPropList
*plist
, WMPropList
*item
);
769 void WMPutInPLDictionary(WMPropList
*plist
, WMPropList
*key
, WMPropList
*value
);
771 void WMRemoveFromPLDictionary(WMPropList
*plist
, WMPropList
*key
);
773 /* It will insert all key/value pairs from source into dest, overwriting
774 * the values with the same keys from dest, keeping all values with keys
775 * only present in dest unchanged */
776 WMPropList
* WMMergePLDictionaries(WMPropList
*dest
, WMPropList
*source
,
779 /* It will remove all key/value pairs from dest for which there is an
780 * identical key/value present in source. Entires only present in dest, or
781 * which have different values in dest than in source will be preserved. */
782 WMPropList
* WMSubtractPLDictionaries(WMPropList
*dest
, WMPropList
*source
,
785 int WMGetPropListItemCount(WMPropList
*plist
);
787 Bool
WMIsPLString(WMPropList
*plist
);
789 Bool
WMIsPLData(WMPropList
*plist
);
791 Bool
WMIsPLArray(WMPropList
*plist
);
793 Bool
WMIsPLDictionary(WMPropList
*plist
);
795 Bool
WMIsPropListEqualTo(WMPropList
*plist
, WMPropList
*other
);
797 /* Returns a reference. Do not free it! */
798 char* WMGetFromPLString(WMPropList
*plist
);
800 /* Returns a reference. Do not free it! */
801 WMData
* WMGetFromPLData(WMPropList
*plist
);
803 /* Returns a reference. Do not free it! */
804 const unsigned char* WMGetPLDataBytes(WMPropList
*plist
);
806 int WMGetPLDataLength(WMPropList
*plist
);
808 /* Returns a reference. */
809 WMPropList
* WMGetFromPLArray(WMPropList
*plist
, int index
);
811 /* Returns a reference. */
812 WMPropList
* WMGetFromPLDictionary(WMPropList
*plist
, WMPropList
*key
);
814 /* Returns a PropList array with all the dictionary keys. Release it when
815 * you're done. Keys in array are retained from the original dictionary
816 * not copied and need NOT to be released individually. */
817 WMPropList
* WMGetPLDictionaryKeys(WMPropList
*plist
);
819 /* Creates only the first level deep object. All the elements inside are
820 * retained from the original */
821 WMPropList
* WMShallowCopyPropList(WMPropList
*plist
);
823 /* Makes a completely separate replica of the original proplist */
824 WMPropList
* WMDeepCopyPropList(WMPropList
*plist
);
826 WMPropList
* WMCreatePropListFromDescription(char *desc
);
828 /* Free the returned string when you no longer need it */
829 char* WMGetPropListDescription(WMPropList
*plist
, Bool indented
);
831 WMPropList
* WMReadPropListFromFile(char *file
);
833 Bool
WMWritePropListToFile(WMPropList
*plist
, char *path
, Bool atomically
);
835 /*......................................................................*/
837 WMUserDefaults
* WMGetStandardUserDefaults(void);
839 WMUserDefaults
* WMGetDefaultsFromPath(char *path
);
841 void WMSynchronizeUserDefaults(WMUserDefaults
*database
);
843 void WMSaveUserDefaults(WMUserDefaults
*database
);
845 void WMEnableUDPeriodicSynchronization(WMUserDefaults
*database
, Bool enable
);
847 /* Returns a WMPropList array with all the keys in the user defaults database.
848 * Free the array with WMReleasePropList() when no longer needed.
849 * Keys in array are just retained references to the original keys */
850 WMPropList
* WMGetUDKeys(WMUserDefaults
*database
);
852 WMPropList
* WMGetUDObjectForKey(WMUserDefaults
*database
, char *defaultName
);
854 void WMSetUDObjectForKey(WMUserDefaults
*database
, WMPropList
*object
,
857 void WMRemoveUDObjectForKey(WMUserDefaults
*database
, char *defaultName
);
859 char* WMGetUDStringForKey(WMUserDefaults
*database
, char *defaultName
);
861 int WMGetUDIntegerForKey(WMUserDefaults
*database
, char *defaultName
);
863 float WMGetUDFloatForKey(WMUserDefaults
*database
, char *defaultName
);
865 Bool
WMGetUDBoolForKey(WMUserDefaults
*database
, char *defaultName
);
867 void WMSetUDStringForKey(WMUserDefaults
*database
, char *value
,
870 void WMSetUDIntegerForKey(WMUserDefaults
*database
, int value
,
873 void WMSetUDFloatForKey(WMUserDefaults
*database
, float value
,
876 void WMSetUDBoolForKey(WMUserDefaults
*database
, Bool value
,
879 WMPropList
* WMGetUDSearchList(WMUserDefaults
*database
);
881 void WMSetUDSearchList(WMUserDefaults
*database
, WMPropList
*list
);
883 extern char *WMUserDefaultsDidChangeNotification
;
886 /*-------------------------------------------------------------------------*/
888 /* WMHost: host handling */
890 WMHost
* WMGetCurrentHost();
892 WMHost
* WMGetHostWithName(char* name
);
894 WMHost
* WMGetHostWithAddress(char* address
);
896 WMHost
* WMRetainHost(WMHost
*hPtr
);
898 void WMReleaseHost(WMHost
*hPtr
);
901 * Host cache management
902 * If enabled, only one object representing each host will be created, and
903 * a shared instance will be returned by all methods that return a host.
904 * Enabled by default.
906 void WMSetHostCacheEnabled(Bool flag
);
908 Bool
WMIsHostCacheEnabled();
910 void WMFlushHostCache();
913 * Compare hosts: Hosts are equal if they share at least one address
915 Bool
WMIsHostEqualToHost(WMHost
* hPtr
, WMHost
* anotherHost
);
919 * WMGetHostName() will return first name (official) if a host has several.
920 * WMGetHostNames() will return a R/O WMArray with all the names of the host.
922 char* WMGetHostName(WMHost
* hPtr
);
924 /* The returned array is R/O. Do not modify it, and do not free it! */
925 WMArray
* WMGetHostNames(WMHost
* hPtr
);
929 * Addresses are represented as "Dotted Decimal" strings, e.g. "192.42.172.1"
930 * WMGetHostAddress() will return an arbitrary address if a host has several.
931 * WMGetHostAddresses() will return a R/O WMArray with all addresses of the host.
933 char* WMGetHostAddress(WMHost
* hPtr
);
935 /* The returned array is R/O. Do not modify it, and do not free it! */
936 WMArray
* WMGetHostAddresses(WMHost
* hPtr
);
939 /*-------------------------------------------------------------------------*/
941 /* WMConnection functions */
943 WMConnection
* WMCreateConnectionAsServerAtAddress(char *host
, char *service
,
946 WMConnection
* WMCreateConnectionToAddress(char *host
, char *service
,
949 WMConnection
* WMCreateConnectionToAddressAndNotify(char *host
, char *service
,
952 void WMCloseConnection(WMConnection
*cPtr
);
954 void WMDestroyConnection(WMConnection
*cPtr
);
956 WMConnection
* WMAcceptConnection(WMConnection
*listener
);
958 /* Release the returned data! */
959 WMData
* WMGetConnectionAvailableData(WMConnection
*cPtr
);
961 int WMSendConnectionData(WMConnection
*cPtr
, WMData
*data
);
963 Bool
WMEnqueueConnectionData(WMConnection
*cPtr
, WMData
*data
);
965 #define WMFlushConnection(cPtr) WMSendConnectionData((cPtr), NULL)
967 void WMSetConnectionDelegate(WMConnection
*cPtr
, ConnectionDelegate
*delegate
);
969 /* Connection info */
971 char* WMGetConnectionAddress(WMConnection
*cPtr
);
973 char* WMGetConnectionService(WMConnection
*cPtr
);
975 char* WMGetConnectionProtocol(WMConnection
*cPtr
);
977 Bool
WMSetConnectionNonBlocking(WMConnection
*cPtr
, Bool flag
);
979 Bool
WMSetConnectionCloseOnExec(WMConnection
*cPtr
, Bool flag
);
981 void WMSetConnectionShutdownOnClose(WMConnection
*cPtr
, Bool flag
);
983 void* WMGetConnectionClientData(WMConnection
*cPtr
);
985 void WMSetConnectionClientData(WMConnection
*cPtr
, void *data
);
987 unsigned int WMGetConnectionFlags(WMConnection
*cPtr
);
989 void WMSetConnectionFlags(WMConnection
*cPtr
, unsigned int flags
);
991 int WMGetConnectionSocket(WMConnection
*cPtr
);
993 WMConnectionState
WMGetConnectionState(WMConnection
*cPtr
);
995 WMConnectionTimeoutState
WMGetConnectionTimeoutState(WMConnection
*cPtr
);
997 WMArray
* WMGetConnectionUnsentData(WMConnection
*cPtr
);
999 #define WMGetConnectionQueuedData(cPtr) WMGetConnectionUnsentData(cPtr)
1003 * Passing timeout==0 in the SetTimeout functions below, will reset that
1004 * timeout to its default value.
1007 /* The default timeout inherited by all WMConnection operations, if none set */
1008 void WMSetConnectionDefaultTimeout(unsigned int timeout
);
1010 /* Global timeout for all WMConnection objects, for opening a new connection */
1011 void WMSetConnectionOpenTimeout(unsigned int timeout
);
1013 /* Connection specific timeout for sending out data */
1014 void WMSetConnectionSendTimeout(WMConnection
*cPtr
, unsigned int timeout
);
1017 /* Global variables */
1019 extern int WCErrorCode
;
1022 /*-------------------------------------------------------------------------*/
1028 #endif /* __cplusplus */