2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #import <Foundation/Foundation.h>
23 #include <NGStreams/NGDatagramPacket.h>
24 #include <NGStreams/NGDatagramSocket.h>
25 #include <NGStreams/NGInternetSocketAddress.h>
26 #include <NGStreams/NGInternetSocketDomain.h>
28 static void run(void) {
32 NGDatagramSocket *socket = nil;
33 NGInternetSocketAddress *address;
34 NGDatagramPacket *packet;
38 ud = [NSUserDefaults standardUserDefaults];
39 sid = [ud stringForKey:@"sid"];
40 observer = [NSURL URLWithString:[ud stringForKey:@"url"]];
42 if (observer == nil) {
43 NSLog(@"missing observer ! (use -url to specify one !)");
47 /* construct HTTP-over-UDP request */
49 ms = [NSMutableString stringWithCapacity:16];
50 [ms appendString:@"NOTIFY "];
51 [ms appendString:[observer absoluteString]];
52 [ms appendString:@" HTTP/1.1\r\n"];
54 /* notifications without sid are "teardown's" */
55 if ([sid length] > 0) {
56 [ms appendString:@"Subscription-id: "];
57 [ms appendString:sid];
58 [ms appendString:@"\r\n"];
63 data = [ms dataUsingEncoding:NSUTF8StringEncoding];
64 packet = [NGDatagramPacket packetWithData:data];
65 address = [NGInternetSocketAddress addressWithPort:
66 [[observer port] intValue]
70 socket = [[NGDatagramSocket alloc] initWithDomain:
71 [NGInternetSocketDomain domain]];
72 [packet setReceiver:address];
74 if (![socket sendPacket:packet timeout:3.0]) {
75 NSLog(@"could not send packet %@ on socket %@ !");
80 int main(int argc, char **argv, char **env) {
81 NSAutoreleasePool *pool;
83 pool = [[NSAutoreleasePool alloc] init];
84 #if LIB_FOUNDATION_LIBRARY
85 [NSProcessInfo initializeWithArguments:argv count:argc environment:env];