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__
34 #define wassertr(expr) {}
35 #define wassertrv(expr, val) {}
43 #define wassertr(expr) assert(expr)
45 #define wassertrv(expr, val) assert(expr)
49 #define wassertr(expr) \
51 wwarning("%s line %i (%s): assertion %s failed",\
52 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
56 #define wassertrv(expr, val) \
58 wwarning("%s line %i (%s): assertion %s failed",\
59 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
69 #endif /* __cplusplus */
83 } WMNotificationCoalescing
;
86 /* The possible states for connections */
99 /* The possible states for connection timeouts */
104 } WMConnectionTimeoutState
;
109 WBNotFound
= INT_MIN
, /* element was not found in WMBag */
110 WANotFound
= -1 /* element was not found in WMArray */
114 typedef struct W_Array WMArray
;
115 typedef struct W_Bag WMBag
;
116 typedef struct W_Data WMData
;
117 typedef struct W_TreeNode WMTreeNode
;
118 typedef struct W_HashTable WMHashTable
;
119 typedef struct W_UserDefaults WMUserDefaults
;
120 typedef struct W_Notification WMNotification
;
121 typedef struct W_NotificationQueue WMNotificationQueue
;
122 typedef struct W_Host WMHost
;
123 typedef struct W_Connection WMConnection
;
124 typedef struct W_PropList WMPropList
;
128 /* Some typedefs for the handler stuff */
129 typedef void *WMHandlerID
;
131 typedef void WMCallback(void *data
);
133 typedef void WMInputProc(int fd
, int mask
, void *clientData
);
137 typedef int WMCompareDataProc(const void *item1
, const void *item2
);
139 typedef void WMFreeDataProc(void *data
);
141 /* Used by WMBag or WMArray for matching data */
142 typedef int WMMatchDataProc(void *item
, void *cdata
);
153 /* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */
162 /* NULL is pointer hash */
163 unsigned (*hash
)(const void *);
164 /* NULL is pointer compare */
165 Bool (*keyIsEqual
)(const void *, const void *);
166 /* NULL does nothing */
167 void* (*retainKey
)(const void *);
168 /* NULL does nothing */
169 void (*releaseKey
)(const void *);
170 } WMHashTableCallbacks
;
173 typedef int WMArrayIterator
;
174 typedef void *WMBagIterator
;
179 char character
; /* the escape character */
180 char *value
; /* value to place */
185 /* The connection callbacks */
186 typedef struct ConnectionDelegate
{
189 void (*canResumeSending
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
191 void (*didCatchException
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
193 void (*didDie
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
195 void (*didInitialize
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
197 void (*didReceiveInput
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
199 void (*didTimeout
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
201 } ConnectionDelegate
;
204 typedef void WMNotificationObserverAction(void *observerData
,
205 WMNotification
*notification
);
209 /*......................................................................*/
211 typedef void waborthandler(int);
213 waborthandler
* wsetabort(waborthandler
* handler
);
216 /* don't free the returned string */
217 char* wstrerror(int errnum
);
219 void wmessage(const char *msg
, ...);
220 void wwarning(const char *msg
, ...);
221 void wfatal(const char *msg
, ...);
222 void wsyserror(const char *msg
, ...);
223 void wsyserrorwithcode(int error
, const char *msg
, ...);
225 char* wfindfile(char *paths
, char *file
);
227 char* wfindfileinlist(char **path_list
, char *file
);
229 char* wfindfileinarray(WMPropList
* array
, char *file
);
231 char* wexpandpath(char *path
);
233 /* don't free the returned string */
236 void* wmalloc(size_t size
);
237 void* wrealloc(void *ptr
, size_t newsize
);
238 void wfree(void *ptr
);
241 void wrelease(void *ptr
);
242 void* wretain(void *ptr
);
244 char* wstrdup(char *str
);
246 /* Concatenate str1 with str2 and return that in a newly malloc'ed string.
247 * str1 and str2 can be any strings including static and constant strings.
248 * str1 and str2 will not be modified.
249 * Free the returned string when you're done with it. */
250 char* wstrconcat(char *str1
, char *str2
);
252 /* This will append src to dst, and return dst. dst MUST be either NULL
253 * or a string that was a result of a dynamic allocation (malloc, realloc
254 * wmalloc, wrealloc, ...). dst CANNOT be a static or a constant string!
255 * Modifies dst (no new string is created except if dst==NULL in which case
256 * it is equivalent to calling wstrdup(src) ).
257 * The returned address may be different from the original address of dst,
258 * so always assign the returned address to avoid dangling pointers. */
259 char* wstrappend(char *dst
, char *src
);
262 void wtokensplit(char *command
, char ***argv
, int *argc
);
264 char* wtokennext(char *word
, char **next
);
266 char* wtokenjoin(char **list
, int count
);
268 void wtokenfree(char **tokens
, int count
);
270 char* wtrimspace(char *s
);
273 WMRange
wmkrange(int start
, int count
);
274 #ifdef ANSI_C_DOESNT_LIKE_IT_THIS_WAY
275 #define wmkrange(position, count) (WMRange){(position), (count)}
279 char* wusergnusteppath();
281 char* wdefaultspathfordomain(char *domain
);
283 void wusleep(unsigned int microsec
);
286 int wsprintesc(char *buffer
, int length
, char *format
, WMSEscapes
**escapes
,
290 /*......................................................................*/
292 /* Event handlers: timer, idle, input */
294 WMHandlerID
WMAddTimerHandler(int milliseconds
, WMCallback
*callback
,
297 WMHandlerID
WMAddPersistentTimerHandler(int milliseconds
, WMCallback
*callback
,
300 void WMDeleteTimerWithClientData(void *cdata
);
302 void WMDeleteTimerHandler(WMHandlerID handlerID
);
304 WMHandlerID
WMAddIdleHandler(WMCallback
*callback
, void *cdata
);
306 void WMDeleteIdleHandler(WMHandlerID handlerID
);
308 WMHandlerID
WMAddInputHandler(int fd
, int condition
, WMInputProc
*proc
,
311 void WMDeleteInputHandler(WMHandlerID handlerID
);
314 /* This function is used _only_ if you create a non-GUI program.
315 * For GUI based programs use WMNextEvent()/WMHandleEvent() instead.
316 * This function will handle all input/timer/idle events, then return.
319 void WHandleEvents();
321 /*......................................................................*/
324 WMHashTable
* WMCreateHashTable(WMHashTableCallbacks callbacks
);
326 void WMFreeHashTable(WMHashTable
*table
);
328 void WMResetHashTable(WMHashTable
*table
);
330 unsigned WMCountHashTable(WMHashTable
*table
);
332 void* WMHashGet(WMHashTable
*table
, const void *key
);
334 /* Returns True if there is a value associated with <key> in the table, in
335 * which case <retKey> and <retItem> will contain the item's internal key
336 * address and the item's value respectively.
337 * If there is no value associated with <key> it will return False and in
338 * this case <retKey> and <retItem> will be undefined.
339 * Use this when you need to perform your own custom retain/release mechanism
340 * which requires access to the keys too.
342 Bool
WMHashGetItemAndKey(WMHashTable
*table
, const void *key
,
343 void **retItem
, void **retKey
);
345 /* put data in table, replacing already existing data and returning
347 void* WMHashInsert(WMHashTable
*table
, const void *key
, const void *data
);
349 void WMHashRemove(WMHashTable
*table
, const void *key
);
351 /* warning: do not manipulate the table while using the enumerator functions */
352 WMHashEnumerator
WMEnumerateHashTable(WMHashTable
*table
);
354 void* WMNextHashEnumeratorItem(WMHashEnumerator
*enumerator
);
356 void* WMNextHashEnumeratorKey(WMHashEnumerator
*enumerator
);
358 /* Returns True if there is a next element, in which case key and item
359 * will contain the next element's key and value respectively.
360 * If there is no next element available it will return False and in this
361 * case key and item will be undefined.
363 Bool
WMNextHashEnumeratorItemAndKey(WMHashEnumerator
*enumerator
,
364 void **item
, void **key
);
369 /* some predefined callback sets */
371 extern const WMHashTableCallbacks WMIntHashCallbacks
;
372 /* sizeof(keys) are <= sizeof(void*) */
374 extern const WMHashTableCallbacks WMStringHashCallbacks
;
375 /* keys are strings. Strings will be copied with wstrdup()
376 * and freed with wfree() */
378 extern const WMHashTableCallbacks WMStringPointerHashCallbacks
;
379 /* keys are strings, but they are not copied */
382 /*......................................................................*/
385 * WMArray use an array to store the elements.
386 * Item indexes may be only positive integer numbers.
387 * The array cannot contain holes in it.
390 * Fast [O(1)] access to elements
391 * Fast [O(1)] push/pop
394 * A little slower [O(n)] for insertion/deletion of elements that
398 WMArray
* WMCreateArray(int initialSize
);
400 WMArray
* WMCreateArrayWithDestructor(int initialSize
, WMFreeDataProc
*destructor
);
402 WMArray
* WMCreateArrayWithArray(WMArray
*array
);
404 #define WMDuplicateArray(array) WMCreateArrayWithArray(array)
406 void WMEmptyArray(WMArray
*array
);
408 void WMFreeArray(WMArray
*array
);
410 int WMGetArrayItemCount(WMArray
*array
);
412 /* appends other to array. other remains unchanged */
413 void WMAppendArray(WMArray
*array
, WMArray
*other
);
415 /* add will place the element at the end of the array */
416 void WMAddToArray(WMArray
*array
, void *item
);
418 #define WMPushInArray(array, item) WMAddToArray(array, item)
420 /* insert will increment the index of elements after it by 1 */
421 void WMInsertInArray(WMArray
*array
, int index
, void *item
);
423 /* replace and set will return the old item WITHOUT calling the
424 * destructor on it even if its available. Free the returned item yourself.
426 void* WMReplaceInArray(WMArray
*array
, int index
, void *item
);
428 #define WMSetInArray(array, index, item) WMReplaceInArray(array, index, item)
430 /* delete and remove will remove the elements and cause the elements
431 * after them to decrement their indexes by 1. Also will call the
432 * destructor on the deleted element if there's one available.
434 int WMDeleteFromArray(WMArray
*array
, int index
);
436 #define WMRemoveFromArray(array, item) WMRemoveFromArrayMatching(array, NULL, item)
438 int WMRemoveFromArrayMatching(WMArray
*array
, WMMatchDataProc
*match
, void *cdata
);
440 void* WMGetFromArray(WMArray
*array
, int index
);
442 #define WMGetFirstInArray(array, item) WMFindInArray(array, NULL, item)
444 /* pop will return the last element from the array, also removing it
445 * from the array. The destructor is NOT called, even if available.
446 * Free the returned element if needed by yourself
448 void* WMPopFromArray(WMArray
*array
);
450 int WMFindInArray(WMArray
*array
, WMMatchDataProc
*match
, void *cdata
);
452 int WMCountInArray(WMArray
*array
, void *item
);
454 /* comparer must return:
459 void WMSortArray(WMArray
*array
, WMCompareDataProc
*comparer
);
461 void WMMapArray(WMArray
*array
, void (*function
)(void*, void*), void *data
);
463 WMArray
* WMGetSubarrayWithRange(WMArray
* array
, WMRange aRange
);
465 void* WMArrayFirst(WMArray
*array
, WMArrayIterator
*iter
);
467 void* WMArrayLast(WMArray
*array
, WMArrayIterator
*iter
);
469 /* The following 2 functions assume that the array doesn't change between calls */
470 void* WMArrayNext(WMArray
*array
, WMArrayIterator
*iter
);
472 void* WMArrayPrevious(WMArray
*array
, WMArrayIterator
*iter
);
475 /* The following 2 macros assume that the array doesn't change in the for loop */
476 #define WM_ITERATE_ARRAY(array, var, i) \
477 for (var = WMArrayFirst(array, &(i)); (i) != WANotFound; \
478 var = WMArrayNext(array, &(i)))
480 #define WM_ETARETI_ARRAY(array, var, i) \
481 for (var = WMArrayLast(array, &(i)); (i) != WANotFound; \
482 var = WMArrayPrevious(array, &(i)))
484 /*..........................................................................*/
487 * Tree bags use a red-black tree for storage.
488 * Item indexes may be any integer number.
491 * O(lg n) insertion/deletion/search
492 * Good for large numbers of elements with sparse indexes
495 * O(lg n) insertion/deletion/search
496 * Slow for storing small numbers of elements
499 #define WMCreateBag(size) WMCreateTreeBag()
501 #define WMCreateBagWithDestructor(size, d) WMCreateTreeBagWithDestructor(d)
503 WMBag
* WMCreateTreeBag(void);
505 WMBag
* WMCreateTreeBagWithDestructor(WMFreeDataProc
*destructor
);
507 int WMGetBagItemCount(WMBag
*bag
);
509 void WMAppendBag(WMBag
*bag
, WMBag
*other
);
511 void WMPutInBag(WMBag
*bag
, void *item
);
513 /* insert will increment the index of elements after it by 1 */
514 void WMInsertInBag(WMBag
*bag
, int index
, void *item
);
516 /* erase will remove the element from the bag,
517 * but will keep the index of the other elements unchanged */
518 int WMEraseFromBag(WMBag
*bag
, int index
);
520 /* delete and remove will remove the elements and cause the elements
521 * after them to decrement their indexes by 1 */
522 int WMDeleteFromBag(WMBag
*bag
, int index
);
524 int WMRemoveFromBag(WMBag
*bag
, void *item
);
526 void* WMGetFromBag(WMBag
*bag
, int index
);
528 void* WMReplaceInBag(WMBag
*bag
, int index
, void *item
);
530 #define WMSetInBag(bag, index, item) WMReplaceInBag(bag, index, item)
532 /* comparer must return:
537 void WMSortBag(WMBag
*bag
, WMCompareDataProc
*comparer
);
539 void WMEmptyBag(WMBag
*bag
);
541 void WMFreeBag(WMBag
*bag
);
543 void WMMapBag(WMBag
*bag
, void (*function
)(void*, void*), void *data
);
545 int WMGetFirstInBag(WMBag
*bag
, void *item
);
547 int WMCountInBag(WMBag
*bag
, void *item
);
549 int WMFindInBag(WMBag
*bag
, WMMatchDataProc
*match
, void *cdata
);
551 void* WMBagFirst(WMBag
*bag
, WMBagIterator
*ptr
);
553 void* WMBagLast(WMBag
*bag
, WMBagIterator
*ptr
);
555 /* The following 4 functions assume that the bag doesn't change between calls */
556 void* WMBagNext(WMBag
*bag
, WMBagIterator
*ptr
);
558 void* WMBagPrevious(WMBag
*bag
, WMBagIterator
*ptr
);
560 void* WMBagIteratorAtIndex(WMBag
*bag
, int index
, WMBagIterator
*ptr
);
562 int WMBagIndexForIterator(WMBag
*bag
, WMBagIterator ptr
);
565 /* The following 2 macros assume that the bag doesn't change in the for loop */
566 #define WM_ITERATE_BAG(bag, var, i) \
567 for (var = WMBagFirst(bag, &(i)); (i) != NULL; \
568 var = WMBagNext(bag, &(i)))
570 #define WM_ETARETI_BAG(bag, var, i) \
571 for (var = WMBagLast(bag, &(i)); (i) != NULL; \
572 var = WMBagPrevious(bag, &(i)))
576 /*-------------------------------------------------------------------------*/
578 /* WMData handling */
580 /* Creating/destroying data */
582 WMData
* WMCreateDataWithCapacity(unsigned capacity
);
584 WMData
* WMCreateDataWithLength(unsigned length
);
586 WMData
* WMCreateDataWithBytes(void *bytes
, unsigned length
);
588 /* destructor is a function called to free the data when releasing the data
589 * object, or NULL if no freeing of data is necesary. */
590 WMData
* WMCreateDataWithBytesNoCopy(void *bytes
, unsigned length
,
591 WMFreeDataProc
*destructor
);
593 WMData
* WMCreateDataWithData(WMData
*aData
);
595 WMData
* WMRetainData(WMData
*aData
);
597 void WMReleaseData(WMData
*aData
);
599 /* Adjusting capacity */
601 void WMSetDataCapacity(WMData
*aData
, unsigned capacity
);
603 void WMSetDataLength(WMData
*aData
, unsigned length
);
605 void WMIncreaseDataLengthBy(WMData
*aData
, unsigned extraLength
);
609 const void* WMDataBytes(WMData
*aData
);
611 void WMGetDataBytes(WMData
*aData
, void *buffer
);
613 void WMGetDataBytesWithLength(WMData
*aData
, void *buffer
, unsigned length
);
615 void WMGetDataBytesWithRange(WMData
*aData
, void *buffer
, WMRange aRange
);
617 WMData
* WMGetSubdataWithRange(WMData
*aData
, WMRange aRange
);
621 Bool
WMIsDataEqualToData(WMData
*aData
, WMData
*anotherData
);
623 unsigned WMGetDataLength(WMData
*aData
);
627 void WMAppendDataBytes(WMData
*aData
, void *bytes
, unsigned length
);
629 void WMAppendData(WMData
*aData
, WMData
*anotherData
);
633 void WMReplaceDataBytesInRange(WMData
*aData
, WMRange aRange
, void *bytes
);
635 void WMResetDataBytesInRange(WMData
*aData
, WMRange aRange
);
637 void WMSetData(WMData
*aData
, WMData
*anotherData
);
640 void WMSetDataFormat(WMData
*aData
, unsigned format
);
642 unsigned WMGetDataFormat(WMData
*aData
);
646 /*--------------------------------------------------------------------------*/
648 /* Generic Tree and TreeNode */
650 WMTreeNode
* WMCreateTreeNode(void *data
);
652 WMTreeNode
* WMCreateTreeNodeWithDestructor(void *data
, WMFreeDataProc
*destructor
);
654 WMTreeNode
* WMInsertItemInTree(WMTreeNode
*parent
, int index
, void *item
);
656 #define WMAddItemToTree(parent, item) WMInsertItemInTree(parent, -1, item)
658 WMTreeNode
* WMInsertNodeInTree(WMTreeNode
*parent
, int index
, WMTreeNode
*aNode
);
660 #define WMAddNodeToTree(parent, aNode) WMInsertNodeInTree(parent, -1, aNode)
662 void WMDestroyTreeNode(WMTreeNode
*aNode
);
664 void WMDeleteLeafForTreeNode(WMTreeNode
*aNode
, int index
);
666 void WMRemoveLeafForTreeNode(WMTreeNode
*aNode
, void *leaf
);
668 void* WMReplaceDataForTreeNode(WMTreeNode
*aNode
, void *newData
);
670 void* WMGetDataForTreeNode(WMTreeNode
*aNode
);
672 int WMGetTreeNodeDepth(WMTreeNode
*aNode
);
674 WMTreeNode
* WMGetParentForTreeNode(WMTreeNode
*aNode
);
676 /* Sort only the leaves of the passed node */
677 void WMSortLeavesForTreeNode(WMTreeNode
*aNode
, WMCompareDataProc
*comparer
);
679 /* Sort all tree recursively starting from the passed node */
680 void WMSortTree(WMTreeNode
*aNode
, WMCompareDataProc
*comparer
);
682 /* Returns the first node which matches node's data with cdata by 'match' */
683 WMTreeNode
* WMFindInTree(WMTreeNode
*aTree
, WMMatchDataProc
*match
, void *cdata
);
685 /* Returns first tree node that has data == cdata */
686 #define WMGetFirstInTree(aTree, cdata) WMFindInTree(aTree, NULL, cdata)
689 /*--------------------------------------------------------------------------*/
692 WMNotification
* WMCreateNotification(const char *name
, void *object
, void *clientData
);
694 void WMReleaseNotification(WMNotification
*notification
);
696 WMNotification
* WMRetainNotification(WMNotification
*notification
);
698 void* WMGetNotificationClientData(WMNotification
*notification
);
700 void* WMGetNotificationObject(WMNotification
*notification
);
702 const char* WMGetNotificationName(WMNotification
*notification
);
705 void WMAddNotificationObserver(WMNotificationObserverAction
*observerAction
,
706 void *observer
, const char *name
, void *object
);
708 void WMPostNotification(WMNotification
*notification
);
710 void WMRemoveNotificationObserver(void *observer
);
712 void WMRemoveNotificationObserverWithName(void *observer
, const char *name
,
715 void WMPostNotificationName(const char *name
, void *object
, void *clientData
);
717 WMNotificationQueue
* WMGetDefaultNotificationQueue(void);
719 WMNotificationQueue
* WMCreateNotificationQueue(void);
721 void WMDequeueNotificationMatching(WMNotificationQueue
*queue
,
722 WMNotification
*notification
,
725 void WMEnqueueNotification(WMNotificationQueue
*queue
,
726 WMNotification
*notification
,
727 WMPostingStyle postingStyle
);
729 void WMEnqueueCoalesceNotification(WMNotificationQueue
*queue
,
730 WMNotification
*notification
,
731 WMPostingStyle postingStyle
,
732 unsigned coalesceMask
);
735 /*......................................................................*/
737 /* Property Lists handling */
739 void WMPLSetCaseSensitive(Bool caseSensitive
);
741 WMPropList
* WMCreatePLString(char *str
);
743 WMPropList
* WMCreatePLData(WMData
*data
);
745 WMPropList
* WMCreatePLDataWithBytes(unsigned char *bytes
, unsigned int length
);
747 WMPropList
* WMCreatePLDataWithBytesNoCopy(unsigned char *bytes
,
749 WMFreeDataProc
*destructor
);
751 WMPropList
* WMCreatePLArray(WMPropList
*elem
, ...);
753 WMPropList
* WMCreatePLDictionary(WMPropList
*key
, WMPropList
*value
, ...);
755 WMPropList
* WMRetainPropList(WMPropList
*plist
);
757 void WMReleasePropList(WMPropList
*plist
);
759 /* Objects inserted in arrays and dictionaries will be retained,
760 * so you can safely release them after insertion.
761 * For dictionaries both the key and value are retained.
762 * Objects removed from arrays or dictionaries are released */
763 void WMInsertInPLArray(WMPropList
*plist
, int index
, WMPropList
*item
);
765 void WMAddToPLArray(WMPropList
*plist
, WMPropList
*item
);
767 void WMDeleteFromPLArray(WMPropList
*plist
, int index
);
769 void WMRemoveFromPLArray(WMPropList
*plist
, WMPropList
*item
);
771 void WMPutInPLDictionary(WMPropList
*plist
, WMPropList
*key
, WMPropList
*value
);
773 void WMRemoveFromPLDictionary(WMPropList
*plist
, WMPropList
*key
);
775 /* It will insert all key/value pairs from source into dest, overwriting
776 * the values with the same keys from dest, keeping all values with keys
777 * only present in dest unchanged */
778 WMPropList
* WMMergePLDictionaries(WMPropList
*dest
, WMPropList
*source
,
781 /* It will remove all key/value pairs from dest for which there is an
782 * identical key/value present in source. Entires only present in dest, or
783 * which have different values in dest than in source will be preserved. */
784 WMPropList
* WMSubtractPLDictionaries(WMPropList
*dest
, WMPropList
*source
,
787 int WMGetPropListItemCount(WMPropList
*plist
);
789 Bool
WMIsPLString(WMPropList
*plist
);
791 Bool
WMIsPLData(WMPropList
*plist
);
793 Bool
WMIsPLArray(WMPropList
*plist
);
795 Bool
WMIsPLDictionary(WMPropList
*plist
);
797 Bool
WMIsPropListEqualTo(WMPropList
*plist
, WMPropList
*other
);
799 /* Returns a reference. Do not free it! */
800 char* WMGetFromPLString(WMPropList
*plist
);
802 /* Returns a reference. Do not free it! */
803 WMData
* WMGetFromPLData(WMPropList
*plist
);
805 /* Returns a reference. Do not free it! */
806 const unsigned char* WMGetPLDataBytes(WMPropList
*plist
);
808 int WMGetPLDataLength(WMPropList
*plist
);
810 /* Returns a reference. */
811 WMPropList
* WMGetFromPLArray(WMPropList
*plist
, int index
);
813 /* Returns a reference. */
814 WMPropList
* WMGetFromPLDictionary(WMPropList
*plist
, WMPropList
*key
);
816 /* Returns a PropList array with all the dictionary keys. Release it when
817 * you're done. Keys in array are retained from the original dictionary
818 * not copied and need NOT to be released individually. */
819 WMPropList
* WMGetPLDictionaryKeys(WMPropList
*plist
);
821 /* Creates only the first level deep object. All the elements inside are
822 * retained from the original */
823 WMPropList
* WMShallowCopyPropList(WMPropList
*plist
);
825 /* Makes a completely separate replica of the original proplist */
826 WMPropList
* WMDeepCopyPropList(WMPropList
*plist
);
828 WMPropList
* WMCreatePropListFromDescription(char *desc
);
830 /* Free the returned string when you no longer need it */
831 char* WMGetPropListDescription(WMPropList
*plist
, Bool indented
);
833 WMPropList
* WMReadPropListFromFile(char *file
);
835 Bool
WMWritePropListToFile(WMPropList
*plist
, char *path
, Bool atomically
);
837 /*......................................................................*/
839 WMUserDefaults
* WMGetStandardUserDefaults(void);
841 WMUserDefaults
* WMGetDefaultsFromPath(char *path
);
843 void WMSynchronizeUserDefaults(WMUserDefaults
*database
);
845 void WMSaveUserDefaults(WMUserDefaults
*database
);
847 void WMEnableUDPeriodicSynchronization(WMUserDefaults
*database
, Bool enable
);
849 /* Returns a WMPropList array with all the keys in the user defaults database.
850 * Free the array with WMReleasePropList() when no longer needed.
851 * Keys in array are just retained references to the original keys */
852 WMPropList
* WMGetUDKeys(WMUserDefaults
*database
);
854 WMPropList
* WMGetUDObjectForKey(WMUserDefaults
*database
, char *defaultName
);
856 void WMSetUDObjectForKey(WMUserDefaults
*database
, WMPropList
*object
,
859 void WMRemoveUDObjectForKey(WMUserDefaults
*database
, char *defaultName
);
861 char* WMGetUDStringForKey(WMUserDefaults
*database
, char *defaultName
);
863 int WMGetUDIntegerForKey(WMUserDefaults
*database
, char *defaultName
);
865 float WMGetUDFloatForKey(WMUserDefaults
*database
, char *defaultName
);
867 Bool
WMGetUDBoolForKey(WMUserDefaults
*database
, char *defaultName
);
869 void WMSetUDStringForKey(WMUserDefaults
*database
, char *value
,
872 void WMSetUDIntegerForKey(WMUserDefaults
*database
, int value
,
875 void WMSetUDFloatForKey(WMUserDefaults
*database
, float value
,
878 void WMSetUDBoolForKey(WMUserDefaults
*database
, Bool value
,
881 WMPropList
* WMGetUDSearchList(WMUserDefaults
*database
);
883 void WMSetUDSearchList(WMUserDefaults
*database
, WMPropList
*list
);
885 extern char *WMUserDefaultsDidChangeNotification
;
888 /*-------------------------------------------------------------------------*/
890 /* WMHost: host handling */
892 WMHost
* WMGetCurrentHost();
894 WMHost
* WMGetHostWithName(char* name
);
896 WMHost
* WMGetHostWithAddress(char* address
);
898 WMHost
* WMRetainHost(WMHost
*hPtr
);
900 void WMReleaseHost(WMHost
*hPtr
);
903 * Host cache management
904 * If enabled, only one object representing each host will be created, and
905 * a shared instance will be returned by all methods that return a host.
906 * Enabled by default.
908 void WMSetHostCacheEnabled(Bool flag
);
910 Bool
WMIsHostCacheEnabled();
912 void WMFlushHostCache();
915 * Compare hosts: Hosts are equal if they share at least one address
917 Bool
WMIsHostEqualToHost(WMHost
* hPtr
, WMHost
* anotherHost
);
921 * WMGetHostName() will return first name (official) if a host has several.
922 * WMGetHostNames() will return a R/O WMArray with all the names of the host.
924 char* WMGetHostName(WMHost
* hPtr
);
926 /* The returned array is R/O. Do not modify it, and do not free it! */
927 WMArray
* WMGetHostNames(WMHost
* hPtr
);
931 * Addresses are represented as "Dotted Decimal" strings, e.g. "192.42.172.1"
932 * WMGetHostAddress() will return an arbitrary address if a host has several.
933 * WMGetHostAddresses() will return a R/O WMArray with all addresses of the host.
935 char* WMGetHostAddress(WMHost
* hPtr
);
937 /* The returned array is R/O. Do not modify it, and do not free it! */
938 WMArray
* WMGetHostAddresses(WMHost
* hPtr
);
941 /*-------------------------------------------------------------------------*/
943 /* WMConnection functions */
945 WMConnection
* WMCreateConnectionAsServerAtAddress(char *host
, char *service
,
948 WMConnection
* WMCreateConnectionToAddress(char *host
, char *service
,
951 WMConnection
* WMCreateConnectionToAddressAndNotify(char *host
, char *service
,
954 void WMCloseConnection(WMConnection
*cPtr
);
956 void WMDestroyConnection(WMConnection
*cPtr
);
958 WMConnection
* WMAcceptConnection(WMConnection
*listener
);
960 /* Release the returned data! */
961 WMData
* WMGetConnectionAvailableData(WMConnection
*cPtr
);
963 int WMSendConnectionData(WMConnection
*cPtr
, WMData
*data
);
965 Bool
WMEnqueueConnectionData(WMConnection
*cPtr
, WMData
*data
);
967 #define WMFlushConnection(cPtr) WMSendConnectionData((cPtr), NULL)
969 void WMSetConnectionDelegate(WMConnection
*cPtr
, ConnectionDelegate
*delegate
);
971 /* Connection info */
973 char* WMGetConnectionAddress(WMConnection
*cPtr
);
975 char* WMGetConnectionService(WMConnection
*cPtr
);
977 char* WMGetConnectionProtocol(WMConnection
*cPtr
);
979 Bool
WMSetConnectionNonBlocking(WMConnection
*cPtr
, Bool flag
);
981 Bool
WMSetConnectionCloseOnExec(WMConnection
*cPtr
, Bool flag
);
983 void WMSetConnectionShutdownOnClose(WMConnection
*cPtr
, Bool flag
);
985 void* WMGetConnectionClientData(WMConnection
*cPtr
);
987 void WMSetConnectionClientData(WMConnection
*cPtr
, void *data
);
989 unsigned int WMGetConnectionFlags(WMConnection
*cPtr
);
991 void WMSetConnectionFlags(WMConnection
*cPtr
, unsigned int flags
);
993 int WMGetConnectionSocket(WMConnection
*cPtr
);
995 WMConnectionState
WMGetConnectionState(WMConnection
*cPtr
);
997 WMConnectionTimeoutState
WMGetConnectionTimeoutState(WMConnection
*cPtr
);
999 WMArray
* WMGetConnectionUnsentData(WMConnection
*cPtr
);
1001 #define WMGetConnectionQueuedData(cPtr) WMGetConnectionUnsentData(cPtr)
1005 * Passing timeout==0 in the SetTimeout functions below, will reset that
1006 * timeout to its default value.
1009 /* The default timeout inherited by all WMConnection operations, if none set */
1010 void WMSetConnectionDefaultTimeout(unsigned int timeout
);
1012 /* Global timeout for all WMConnection objects, for opening a new connection */
1013 void WMSetConnectionOpenTimeout(unsigned int timeout
);
1015 /* Connection specific timeout for sending out data */
1016 void WMSetConnectionSendTimeout(WMConnection
*cPtr
, unsigned int timeout
);
1019 /* Global variables */
1021 extern int WCErrorCode
;
1024 /*-------------------------------------------------------------------------*/
1030 #endif /* __cplusplus */