2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo 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 OGo 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 OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #import <Foundation/Foundation.h>
24 #include <NGStreams/NGDatagramPacket.h>
25 #include <NGStreams/NGDatagramSocket.h>
26 #include <NGStreams/NGInternetSocketAddress.h>
27 #include <NGStreams/NGInternetSocketDomain.h>
29 static void run(void) {
33 NGDatagramSocket *socket = nil;
34 NGInternetSocketAddress *address;
35 NGDatagramPacket *packet;
39 ud = [NSUserDefaults standardUserDefaults];
40 sid = [ud stringForKey:@"sid"];
41 observer = [NSURL URLWithString:[ud stringForKey:@"url"]];
43 if (observer == nil) {
44 NSLog(@"missing observer ! (use -url to specify one !)");
48 /* construct HTTP-over-UDP request */
50 ms = [NSMutableString stringWithCapacity:16];
51 [ms appendString:@"NOTIFY "];
52 [ms appendString:[observer absoluteString]];
53 [ms appendString:@" HTTP/1.1\r\n"];
55 /* notifications without sid are "teardown's" */
56 if ([sid length] > 0) {
57 [ms appendString:@"Subscription-id: "];
58 [ms appendString:sid];
59 [ms appendString:@"\r\n"];
64 data = [ms dataUsingEncoding:NSUTF8StringEncoding];
65 packet = [NGDatagramPacket packetWithData:data];
66 address = [NGInternetSocketAddress addressWithPort:
67 [[observer port] intValue]
71 socket = [[NGDatagramSocket alloc] initWithDomain:
72 [NGInternetSocketDomain domain]];
73 [packet setReceiver:address];
75 if (![socket sendPacket:packet timeout:3.0]) {
76 NSLog(@"could not send packet %@ on socket %@ !");
81 int main(int argc, char **argv, char **env) {
82 NSAutoreleasePool *pool;
84 pool = [[NSAutoreleasePool alloc] init];
85 #if LIB_FOUNDATION_LIBRARY
86 [NSProcessInfo initializeWithArguments:argv count:argc environment:env];