void Register(SLPToolCommandLine * cmdline) { SLPError result; SLPHandle hslp; char srvtype[80] = "", * s; size_t len = 0; unsigned int lt = 0; if (cmdline->time) { lt = atoi(cmdline->time); } if (strncasecmp(cmdline->cmdparam1, "service:", 8) == 0) len = 8; s = strchr(cmdline->cmdparam1 + len, ':'); if (!s) { printf("Invalid URL: %s\n", cmdline->cmdparam1); return; } len = s - cmdline->cmdparam1; strncpy(srvtype, cmdline->cmdparam1, len); srvtype[len] = 0; /* Clear property (if set), otherwise the register function is quite useless */ SLPSetProperty("net.slp.watchRegistrationPID", 0); if ((cmdline->scopes != 0) && (*cmdline->scopes != 0)) SLPSetProperty("net.slp.useScopes", cmdline->scopes); if (SLPOpen(cmdline->lang, SLP_FALSE, &hslp) == SLP_OK) { if (!lt || lt > SLP_LIFETIME_MAXIMUM) result = SLPReg(hslp, cmdline->cmdparam1, SLP_LIFETIME_MAXIMUM, srvtype, cmdline->cmdparam2, SLP_TRUE, mySLPRegReport, 0); else result = SLPReg(hslp, cmdline->cmdparam1, (unsigned short)lt, srvtype, cmdline->cmdparam2, SLP_TRUE, mySLPRegReport, 0); if (result != SLP_OK) printf("errorcode: %i\n", result); SLPClose(hslp); } }
/* * assign_defaults * * Initialization routine for all state specific to the mslpd. * This is the routine which processes the command line inputs * as well. After basic properties are set, the configuration * file is read in (if one is specified on the command line.) * */ static int assign_defaults(SAState *psa, struct sockaddr_in *psin, int argc, char *argv[]) { char* daScopeListTemp = NULL; SLPBoolean needToSetOverflow = SLP_FALSE; psa->tvTimeout.tv_sec = 1L; psa->tvTimeout.tv_usec = 0L; memset(psin,0,sizeof(struct sockaddr_in)); /* set up default configuration */ SLPSetProperty("com.sun.slp.isSA","true"); #ifdef MAC_OS_X SLPSetProperty("com.apple.slp.isDA", "false"); #endif SLPSetProperty("net.slp.useScopes",SLP_DEFAULT_SCOPE); // this is our current list of scopes SLPSetProperty("com.apple.slp.defaultRegistrationScope",SLP_DEFAULT_SCOPE); // use this for registrations SLPSetProperty("com.apple.slp.daScopeList", SLP_DEFAULT_SCOPE); // this only get's used if we are a da SLPSetProperty("net.slp.multicastTTL",MCAST_TTL); SLPSetProperty("net.slp.MTU",SENDMTU); if (!SLPGetProperty("com.apple.slp.port")) SLPSetProperty("com.apple.slp.port","427"); SLPSetProperty("net.slp.locale","en"); SLPSetProperty("com.sun.slp.minRefreshInterval","10800"); SLPSetProperty("com.apple.slp.logfile",LOG_FILE); SLPSetProperty("com.apple.slp.identity", "slpd"); /* * If there is a configuration file on the command line, read it in. * Ensure that net.slp.serializedRegURL is set properly at the end. */ if (argc == 4 && !strcmp(argv[2], "-f")) { char buf[1029]; SLPReadConfigFile(argv[3]); sprintf(buf,"file:%s",argv[1]); /* the command line takes precedence over the property file. */ SLPSetProperty("net.slp.serializedRegURL",buf); } else if (argc == 3 && !strcmp(argv[1],"-f")) { SLPReadConfigFile(argv[2]); } // Now we need to check if our scope list is too long and needs to be trimmed if ( SLPGetProperty( "com.apple.slp.daScopeList" ) && strlen(SLPGetProperty( "com.apple.slp.daScopeList" ) ) > kMaxScopeListLenForUDP ) { daScopeListTemp = (char*)malloc( strlen(SLPGetProperty( "com.apple.slp.daScopeList" ) ) +1 ); strcpy( daScopeListTemp, SLPGetProperty( "com.apple.slp.daScopeList" ) ); while ( strlen( daScopeListTemp ) > kMaxScopeListLenForUDP ) // as long as we have a scope list that is too long { // message is too long char* tempPtr = strrchr( daScopeListTemp, ',' ); needToSetOverflow = SLP_TRUE; if ( !tempPtr ) { free( daScopeListTemp ); SLP_LOG( SLP_LOG_FAIL, "we can't fit a single scope in our advertisement!" ); // bad error break; } if ( tempPtr && *tempPtr == ',' ) *tempPtr = '\0'; // chop off here and try again } } if ( needToSetOverflow == SLP_TRUE ) { SLPSetProperty( "com.apple.slp.daPrunedScopeList", daScopeListTemp ); #ifdef ENABLE_SLP_LOGGING SLP_LOG( SLP_LOG_RADMIN, "We have a scope list that is longer than can be advertised via multicasting. Some SLP implementations may see a truncated list." ); #endif } else SLPSetProperty( "com.apple.slp.daPrunedScopeList", NULL ); if ( daScopeListTemp ) free( daScopeListTemp ); #ifndef NDEBUG #ifdef ENABLE_SLP_LOGGING if ( AreWeADirectoryAgent() ) mslplog(SLP_LOG_DEBUG,"slpd as a DA started with scopes", SLPGetProperty("com.apple.slp.daScopeList")); else mslplog(SLP_LOG_DEBUG,"slpd as an SA started with scopes", SLPGetProperty("net.slp.useScopes")); #endif #endif /* NDEBUG */ /* set up the address for da discovery */ psin->sin_family = AF_INET; psin->sin_port = htons(SLP_PORT); if (SLPGetProperty("net.slp.isBroadcastOnly") != NULL && !(SDstrcasecmp(SLPGetProperty("net.slp.isBroadcastOnly"),"true"))) { psin->sin_addr.s_addr = BROADCAST; } else { psin->sin_addr.s_addr = SLP_MCAST; } psa->pdat = GetGlobalDATable(); #ifdef EXTRA_MSGS if (!SLPGetProperty("com.sun.slp.regfile")) SLPSetProperty("com.sun.slp.regfile",SDDefaultRegfile()); if (!SLPGetProperty("com.sun.slp.tempfile")) SLPSetProperty("com.sun.slp.tempfile",SDDefaultTempfile()); #endif /* EXTRA_MSGS */ return SLP_OK; }