summaryrefslogtreecommitdiff
authorkorovkin <korovkin>2007-01-24 18:38:04 (UTC)
committer korovkin <korovkin>2007-01-24 18:38:04 (UTC)
commita4a7bd22feb060a80e20c81cded43cc24f5cd423 (patch) (unidiff)
tree5d92d27b96ad235f3815014f98d49c766461a678
parent8644340455a433f4d6e3b31b329479f1e7983f78 (diff)
downloadopie-a4a7bd22feb060a80e20c81cded43cc24f5cd423.zip
opie-a4a7bd22feb060a80e20c81cded43cc24f5cd423.tar.gz
opie-a4a7bd22feb060a80e20c81cded43cc24f5cd423.tar.bz2
OBEX push server has a more common description.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/obex/obexserver.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/core/obex/obexserver.cpp b/core/obex/obexserver.cpp
index 25d8224..f1fb205 100644
--- a/core/obex/obexserver.cpp
+++ b/core/obex/obexserver.cpp
@@ -244,193 +244,193 @@ static void obex_event (obex_t* handle, obex_object_t* object, int mode,
244 * @param session SDP session 244 * @param session SDP session
245 * @param chan channel to listen 245 * @param chan channel to listen
246 * @name name to show 246 * @name name to show
247 */ 247 */
248sdp_session_t* ObexServer::addOpushSvc(uint8_t chan, const char* name) 248sdp_session_t* ObexServer::addOpushSvc(uint8_t chan, const char* name)
249{ 249{
250 sdp_list_t *svclass_id, *pfseq, *apseq, *root; 250 sdp_list_t *svclass_id, *pfseq, *apseq, *root;
251 uuid_t root_uuid, opush_uuid, l2cap_uuid, rfcomm_uuid, obex_uuid; 251 uuid_t root_uuid, opush_uuid, l2cap_uuid, rfcomm_uuid, obex_uuid;
252 sdp_profile_desc_t profile[1]; 252 sdp_profile_desc_t profile[1];
253 sdp_list_t *aproto, *proto[3]; 253 sdp_list_t *aproto, *proto[3];
254 sdp_record_t record; 254 sdp_record_t record;
255 sdp_data_t *channel; 255 sdp_data_t *channel;
256 uint8_t formats[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 }; 256 uint8_t formats[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
257 //uint8_t formats[] = { 0xff }; 257 //uint8_t formats[] = { 0xff };
258 void *dtds[sizeof(formats)], *values[sizeof(formats)]; 258 void *dtds[sizeof(formats)], *values[sizeof(formats)];
259 unsigned int i; 259 unsigned int i;
260 uint8_t dtd = SDP_UINT8; 260 uint8_t dtd = SDP_UINT8;
261 sdp_data_t *sflist; 261 sdp_data_t *sflist;
262 int err = 0; 262 int err = 0;
263 sdp_session_t* lsession = 0; 263 sdp_session_t* lsession = 0;
264 264
265 memset((void *)&record, 0, sizeof(sdp_record_t)); 265 memset((void *)&record, 0, sizeof(sdp_record_t));
266 record.handle = 0xffffffff; 266 record.handle = 0xffffffff;
267 sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP); 267 sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP);
268 root = sdp_list_append(0, &root_uuid); 268 root = sdp_list_append(0, &root_uuid);
269 sdp_set_browse_groups(&record, root); 269 sdp_set_browse_groups(&record, root);
270 270
271 sdp_uuid16_create(&opush_uuid, OBEX_OBJPUSH_SVCLASS_ID); 271 sdp_uuid16_create(&opush_uuid, OBEX_OBJPUSH_SVCLASS_ID);
272 svclass_id = sdp_list_append(0, &opush_uuid); 272 svclass_id = sdp_list_append(0, &opush_uuid);
273 sdp_set_service_classes(&record, svclass_id); 273 sdp_set_service_classes(&record, svclass_id);
274 274
275 sdp_uuid16_create(&profile[0].uuid, OBEX_OBJPUSH_PROFILE_ID); 275 sdp_uuid16_create(&profile[0].uuid, OBEX_OBJPUSH_PROFILE_ID);
276 profile[0].version = 0x0100; 276 profile[0].version = 0x0100;
277 pfseq = sdp_list_append(0, profile); 277 pfseq = sdp_list_append(0, profile);
278 sdp_set_profile_descs(&record, pfseq); 278 sdp_set_profile_descs(&record, pfseq);
279 279
280 sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID); 280 sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID);
281 proto[0] = sdp_list_append(0, &l2cap_uuid); 281 proto[0] = sdp_list_append(0, &l2cap_uuid);
282 apseq = sdp_list_append(0, proto[0]); 282 apseq = sdp_list_append(0, proto[0]);
283 283
284 sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID); 284 sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID);
285 proto[1] = sdp_list_append(0, &rfcomm_uuid); 285 proto[1] = sdp_list_append(0, &rfcomm_uuid);
286 channel = sdp_data_alloc(SDP_UINT8, &chan); 286 channel = sdp_data_alloc(SDP_UINT8, &chan);
287 proto[1] = sdp_list_append(proto[1], channel); 287 proto[1] = sdp_list_append(proto[1], channel);
288 apseq = sdp_list_append(apseq, proto[1]); 288 apseq = sdp_list_append(apseq, proto[1]);
289 289
290 sdp_uuid16_create(&obex_uuid, OBEX_UUID); 290 sdp_uuid16_create(&obex_uuid, OBEX_UUID);
291 proto[2] = sdp_list_append(0, &obex_uuid); 291 proto[2] = sdp_list_append(0, &obex_uuid);
292 apseq = sdp_list_append(apseq, proto[2]); 292 apseq = sdp_list_append(apseq, proto[2]);
293 293
294 aproto = sdp_list_append(0, apseq); 294 aproto = sdp_list_append(0, apseq);
295 sdp_set_access_protos(&record, aproto); 295 sdp_set_access_protos(&record, aproto);
296 296
297 for (i = 0; i < sizeof(formats); i++) 297 for (i = 0; i < sizeof(formats); i++)
298 { 298 {
299 dtds[i] = &dtd; 299 dtds[i] = &dtd;
300 values[i] = &formats[i]; 300 values[i] = &formats[i];
301 } 301 }
302 sflist = sdp_seq_alloc(dtds, values, sizeof(formats)); 302 sflist = sdp_seq_alloc(dtds, values, sizeof(formats));
303 sdp_attr_add(&record, SDP_ATTR_SUPPORTED_FORMATS_LIST, sflist); 303 sdp_attr_add(&record, SDP_ATTR_SUPPORTED_FORMATS_LIST, sflist);
304 304
305 sdp_set_info_attr(&record, name, 0, 0); 305 sdp_set_info_attr(&record, name, 0, 0);
306 306
307 // connect to the local SDP server, register the service record, and 307 // connect to the local SDP server, register the service record, and
308 // disconnect 308 // disconnect
309 lsession = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY); 309 lsession = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY);
310 if (lsession == NULL) 310 if (lsession == NULL)
311 goto errout; 311 goto errout;
312 err = sdp_record_register(lsession, &record, 0); 312 err = sdp_record_register(lsession, &record, 0);
313 if (err) { 313 if (err) {
314 sdp_close(lsession); 314 sdp_close(lsession);
315 lsession = NULL; 315 lsession = NULL;
316 } 316 }
317errout: 317errout:
318 sdp_data_free(channel); 318 sdp_data_free(channel);
319 sdp_list_free(proto[0], 0); 319 sdp_list_free(proto[0], 0);
320 sdp_list_free(proto[1], 0); 320 sdp_list_free(proto[1], 0);
321 sdp_list_free(proto[2], 0); 321 sdp_list_free(proto[2], 0);
322 sdp_list_free(apseq, 0); 322 sdp_list_free(apseq, 0);
323 sdp_list_free(aproto, 0); 323 sdp_list_free(aproto, 0);
324 324
325 return lsession; 325 return lsession;
326} 326}
327 327
328int ObexServer::initObex(void) 328int ObexServer::initObex(void)
329{ 329{
330 int channel = 10; //Channel on which we do listen 330 int channel = 10; //Channel on which we do listen
331 if (m_obex) 331 if (m_obex)
332 return 0; 332 return 0;
333 m_obex = ::OBEX_Init(transport, obex_event, 0); 333 m_obex = ::OBEX_Init(transport, obex_event, 0);
334 if (!m_obex) { 334 if (!m_obex) {
335 printf("OBEX initialization error %d\n", errno); 335 printf("OBEX initialization error %d\n", errno);
336 return -1; 336 return -1;
337 } 337 }
338 if (transport == OBEX_TRANS_BLUETOOTH) { 338 if (transport == OBEX_TRANS_BLUETOOTH) {
339 ::BtOBEX_ServerRegister(m_obex, NULL, channel); 339 ::BtOBEX_ServerRegister(m_obex, NULL, channel);
340 m_session = addOpushSvc(channel, "OBEX push service"); 340 m_session = addOpushSvc(channel, "OBEX Object Push");
341 if (!m_session) { 341 if (!m_session) {
342 printf("OBEX registration error %d\n", errno); 342 printf("OBEX registration error %d\n", errno);
343 ::OBEX_Cleanup(m_obex); 343 ::OBEX_Cleanup(m_obex);
344 m_obex = NULL; 344 m_obex = NULL;
345 return -1; 345 return -1;
346 } 346 }
347 } else if (transport == OBEX_TRANS_IRDA) 347 } else if (transport == OBEX_TRANS_IRDA)
348 ::IrOBEX_ServerRegister(m_obex, "OBEX"); 348 ::IrOBEX_ServerRegister(m_obex, "OBEX");
349 return 0; 349 return 0;
350} 350}
351 351
352bool ObexServer::start(RunMode runmode, Communication comm) 352bool ObexServer::start(RunMode runmode, Communication comm)
353{ 353{
354 if ( runs ) 354 if ( runs )
355 { 355 {
356 return false; // cannot start a process that is already running 356 return false; // cannot start a process that is already running
357 // or if no executable has been assigned 357 // or if no executable has been assigned
358 } 358 }
359 run_mode = runmode; 359 run_mode = runmode;
360 status = 0; 360 status = 0;
361 361
362 if ( !setupCommunication( comm ) ) 362 if ( !setupCommunication( comm ) )
363 qWarning( "Could not setup Communication!" ); 363 qWarning( "Could not setup Communication!" );
364 364
365 // We do this in the parent because if we do it in the child process 365 // We do this in the parent because if we do it in the child process
366 // gdb gets confused when the application runs from gdb. 366 // gdb gets confused when the application runs from gdb.
367 uid_t uid = getuid(); 367 uid_t uid = getuid();
368 gid_t gid = getgid(); 368 gid_t gid = getgid();
369#ifdef HAVE_INITGROUPS 369#ifdef HAVE_INITGROUPS
370 370
371 struct passwd *pw = getpwuid( uid ); 371 struct passwd *pw = getpwuid( uid );
372#endif 372#endif
373 373
374 int fd[ 2 ]; 374 int fd[ 2 ];
375 if ( 0 > pipe( fd ) ) 375 if ( 0 > pipe( fd ) )
376 { 376 {
377 fd[ 0 ] = fd[ 1 ] = 0; // Pipe failed.. continue 377 fd[ 0 ] = fd[ 1 ] = 0; // Pipe failed.. continue
378 } 378 }
379 379
380 runs = true; 380 runs = true;
381 381
382 QApplication::flushX(); 382 QApplication::flushX();
383 383
384 // WABA: Note that we use fork() and not vfork() because 384 // WABA: Note that we use fork() and not vfork() because
385 // vfork() has unclear semantics and is not standardized. 385 // vfork() has unclear semantics and is not standardized.
386 pid_ = fork(); 386 pid_ = fork();
387 387
388 if ( 0 == pid_ ) 388 if ( 0 == pid_ )
389 { 389 {
390 if ( fd[ 0 ] ) 390 if ( fd[ 0 ] )
391 close( fd[ 0 ] ); 391 close( fd[ 0 ] );
392 if ( !runPrivileged() ) 392 if ( !runPrivileged() )
393 { 393 {
394 setgid( gid ); 394 setgid( gid );
395#if defined( HAVE_INITGROUPS) 395#if defined( HAVE_INITGROUPS)
396 396
397 if ( pw ) 397 if ( pw )
398 initgroups( pw->pw_name, pw->pw_gid ); 398 initgroups( pw->pw_name, pw->pw_gid );
399#endif 399#endif
400 400
401 setuid( uid ); 401 setuid( uid );
402 } 402 }
403 // The child process 403 // The child process
404 if ( !commSetupDoneC() ) 404 if ( !commSetupDoneC() )
405 qWarning( "Could not finish comm setup in child!" ); 405 qWarning( "Could not finish comm setup in child!" );
406 406
407 setupEnvironment(); 407 setupEnvironment();
408 408
409 // Matthias 409 // Matthias
410 if ( run_mode == DontCare ) 410 if ( run_mode == DontCare )
411 setpgid( 0, 0 ); 411 setpgid( 0, 0 );
412 // restore default SIGPIPE handler (Harri) 412 // restore default SIGPIPE handler (Harri)
413 struct sigaction act; 413 struct sigaction act;
414 sigemptyset( &( act.sa_mask ) ); 414 sigemptyset( &( act.sa_mask ) );
415 sigaddset( &( act.sa_mask ), SIGPIPE ); 415 sigaddset( &( act.sa_mask ), SIGPIPE );
416 act.sa_handler = SIG_DFL; 416 act.sa_handler = SIG_DFL;
417 act.sa_flags = 0; 417 act.sa_flags = 0;
418 sigaction( SIGPIPE, &act, 0L ); 418 sigaction( SIGPIPE, &act, 0L );
419 419
420 // We set the close on exec flag. 420 // We set the close on exec flag.
421 // Closing of fd[1] indicates that the execvp succeeded! 421 // Closing of fd[1] indicates that the execvp succeeded!
422 if ( fd[ 1 ] ) 422 if ( fd[ 1 ] )
423 fcntl( fd[ 1 ], F_SETFD, FD_CLOEXEC ); 423 fcntl( fd[ 1 ], F_SETFD, FD_CLOEXEC );
424 424
425 if (initObex() == 0) { 425 if (initObex() == 0) {
426 do { 426 do {
427 int result; //Connection result 427 int result; //Connection result
428 if ( fd[ 1 ] ) { 428 if ( fd[ 1 ] ) {
429 ::close(fd[1]); 429 ::close(fd[1]);
430 fd[1] = 0; 430 fd[1] = 0;
431 } 431 }
432 if ((result = OBEX_HandleInput(m_obex, 60)) < 0) { 432 if ((result = OBEX_HandleInput(m_obex, 60)) < 0) {
433 if (errno != ECONNRESET) { 433 if (errno != ECONNRESET) {
434 printf("OBEX_HandleInput error %d\n", errno); 434 printf("OBEX_HandleInput error %d\n", errno);
435 fflush(stdout); 435 fflush(stdout);
436 _exit(-1); 436 _exit(-1);