PageRenderTime 55ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/OpenSLP_1-1-5/openslp/slptool/slptool.c

#
C | 1065 lines | 839 code | 124 blank | 102 comment | 160 complexity | 966217b053644a2e6edd97bf18c80728 MD5 | raw file
Possible License(s): BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-2.1
  1. /***************************************************************************/
  2. /* */
  3. /* Project: OpenSLP command line UA wrapper */
  4. /* */
  5. /* File: slptool.c */
  6. /* */
  7. /* Abstract: Command line wrapper for OpenSLP */
  8. /* */
  9. /* Requires: OpenSLP installation */
  10. /* */
  11. /* Author(s): Matt Peterson <mpeterson@caldera.com> */
  12. /* */
  13. /* Copyright (c) 1995, 1999 Caldera Systems, Inc. */
  14. /* */
  15. /* This program is free software; you can redistribute it and/or modify it */
  16. /* under the terms of the GNU Lesser General Public License as published */
  17. /* by the Free Software Foundation; either version 2.1 of the License, or */
  18. /* (at your option) any later version. */
  19. /* */
  20. /* This program is distributed in the hope that it will be useful, */
  21. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  22. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  23. /* GNU Lesser General Public License for more details. */
  24. /* */
  25. /* You should have received a copy of the GNU Lesser General Public */
  26. /* License along with this program; see the file COPYING. If not, */
  27. /* please obtain a copy from http://www.gnu.org/copyleft/lesser.html */
  28. /* */
  29. /*-------------------------------------------------------------------------*/
  30. /* */
  31. /* Please submit patches to maintainer of http://www.openslp.org */
  32. /* */
  33. /***************************************************************************/
  34. #include "slptool.h"
  35. #ifdef WIN32
  36. #define strncasecmp(String1, String2, Num) strnicmp(String1, String2, Num)
  37. #define strcasecmp(String1, String2) stricmp(String1, String2)
  38. #define inet_aton(opt,bind) ((bind)->s_addr = inet_addr(opt))
  39. #else
  40. #ifndef HAVE_STRNCASECMP
  41. int
  42. strncasecmp(const char *s1, const char *s2, size_t len);
  43. #endif
  44. #ifndef HAVE_STRCASECMP
  45. int
  46. strcasecmp(const char *s1, const char *s2);
  47. #endif
  48. #endif
  49. /*=========================================================================*/
  50. SLPBoolean mySrvTypeCallback( SLPHandle hslp,
  51. const char* srvtypes,
  52. SLPError errcode,
  53. void* cookie )
  54. /*=========================================================================*/
  55. {
  56. char* cpy;
  57. char* slider1;
  58. char* slider2;
  59. if(errcode == SLP_OK && *srvtypes)
  60. {
  61. cpy = strdup(srvtypes);
  62. if(cpy)
  63. {
  64. slider1 = slider2 = cpy;
  65. slider1 = strchr(slider2,',');
  66. while(slider1)
  67. {
  68. *slider1 = 0;
  69. printf("%s\n",slider2);
  70. slider1 ++;
  71. slider2 = slider1;
  72. slider1 = strchr(slider2,',');
  73. }
  74. /* print the final itam */
  75. printf("%s\n",slider2);
  76. free(cpy);
  77. }
  78. }
  79. return SLP_TRUE;
  80. }
  81. /*=========================================================================*/
  82. void FindSrvTypes(SLPToolCommandLine* cmdline)
  83. /*=========================================================================*/
  84. {
  85. SLPError result;
  86. SLPHandle hslp;
  87. if(SLPOpen(cmdline->lang,SLP_FALSE,&hslp) == SLP_OK)
  88. {
  89. if(cmdline->cmdparam1)
  90. {
  91. result = SLPFindSrvTypes(hslp,
  92. cmdline->cmdparam1,
  93. cmdline->scopes,
  94. mySrvTypeCallback,
  95. 0);
  96. }
  97. else
  98. {
  99. result = SLPFindSrvTypes(hslp,
  100. "*",
  101. cmdline->scopes,
  102. mySrvTypeCallback,
  103. 0);
  104. }
  105. if(result != SLP_OK)
  106. {
  107. printf("errorcode: %i\n",result);
  108. }
  109. SLPClose(hslp);
  110. }
  111. }
  112. #ifndef UNICAST_NOT_SUPPORTED
  113. /*=========================================================================*/
  114. void UnicastFindSrvTypes(SLPToolCommandLine* cmdline)
  115. /*=========================================================================*/
  116. {
  117. SLPError result;
  118. SLPHandle hslp;
  119. if(SLPOpen(cmdline->lang,SLP_FALSE,&hslp) == SLP_OK) {
  120. if((result = SLPAssociateIP(hslp, cmdline->cmdparam3)) != SLP_OK)
  121. {
  122. printf("errorcode: %i\n",result);
  123. SLPClose(hslp);
  124. return;
  125. }
  126. if(cmdline->cmdparam1)
  127. {
  128. result = SLPFindSrvTypes(hslp,
  129. cmdline->cmdparam1,
  130. cmdline->scopes,
  131. mySrvTypeCallback,
  132. 0);
  133. }
  134. else
  135. {
  136. result = SLPFindSrvTypes(hslp,
  137. "*",
  138. cmdline->scopes,
  139. mySrvTypeCallback,
  140. 0);
  141. }
  142. if(result != SLP_OK)
  143. {
  144. printf("errorcode: %i\n",result);
  145. }
  146. SLPClose(hslp);
  147. }
  148. }
  149. #endif
  150. #ifndef MI_NOT_SUPPORTED
  151. /*=========================================================================*/
  152. void FindSrvTypesUsingIFList(SLPToolCommandLine* cmdline)
  153. /*=========================================================================*/
  154. {
  155. SLPError result;
  156. SLPHandle hslp;
  157. if(SLPOpen(cmdline->lang,SLP_FALSE,&hslp) == SLP_OK)
  158. {
  159. if((result = SLPAssociateIFList(hslp, cmdline->cmdparam3)) != SLP_OK)
  160. {
  161. printf("errorcode: %i\n",result);
  162. SLPClose(hslp);
  163. return;
  164. }
  165. if(cmdline->cmdparam1)
  166. {
  167. result = SLPFindSrvTypes(hslp,
  168. cmdline->cmdparam1,
  169. cmdline->scopes,
  170. mySrvTypeCallback,
  171. 0);
  172. }
  173. else
  174. {
  175. result = SLPFindSrvTypes(hslp,
  176. "*",
  177. cmdline->scopes,
  178. mySrvTypeCallback,
  179. 0);
  180. }
  181. if(result != SLP_OK)
  182. {
  183. printf("errorcode: %i\n",result);
  184. }
  185. SLPClose(hslp);
  186. }
  187. }
  188. #endif /* MI_NOT_SUPPORTED */
  189. /*=========================================================================*/
  190. SLPBoolean myAttrCallback(SLPHandle hslp,
  191. const char* attrlist,
  192. SLPError errcode,
  193. void* cookie )
  194. /*=========================================================================*/
  195. {
  196. if(errcode == SLP_OK)
  197. {
  198. printf("%s\n",attrlist);
  199. }
  200. return SLP_TRUE;
  201. }
  202. /*=========================================================================*/
  203. void FindAttrs(SLPToolCommandLine* cmdline)
  204. /*=========================================================================*/
  205. {
  206. SLPError result;
  207. SLPHandle hslp;
  208. if(SLPOpen(cmdline->lang,SLP_FALSE,&hslp) == SLP_OK)
  209. {
  210. result = SLPFindAttrs(hslp,
  211. cmdline->cmdparam1,
  212. cmdline->scopes,
  213. cmdline->cmdparam2,
  214. myAttrCallback,
  215. 0);
  216. if(result != SLP_OK)
  217. {
  218. printf("errorcode: %i\n",result);
  219. }
  220. SLPClose(hslp);
  221. }
  222. }
  223. #ifndef UNICAST_NOT_SUPPORTED
  224. /*=========================================================================*/
  225. void UnicastFindAttrs(SLPToolCommandLine* cmdline)
  226. /*=========================================================================*/
  227. {
  228. SLPError result;
  229. SLPHandle hslp;
  230. if(SLPOpen(cmdline->lang,SLP_FALSE,&hslp) == SLP_OK) {
  231. if((result = SLPAssociateIP(hslp, cmdline->cmdparam3)) != SLP_OK)
  232. {
  233. printf("errorcode: %i\n",result);
  234. SLPClose(hslp);
  235. return;
  236. }
  237. result = SLPFindAttrs(hslp,
  238. cmdline->cmdparam1,
  239. cmdline->scopes,
  240. cmdline->cmdparam2,
  241. myAttrCallback,
  242. 0);
  243. if(result != SLP_OK)
  244. {
  245. printf("errorcode: %i\n",result);
  246. }
  247. SLPClose(hslp);
  248. }
  249. }
  250. #endif
  251. #ifndef MI_NOT_SUPPORTED
  252. /*=========================================================================*/
  253. void FindAttrsUsingIFList(SLPToolCommandLine* cmdline)
  254. /*=========================================================================*/
  255. {
  256. SLPError result;
  257. SLPHandle hslp;
  258. if(SLPOpen(cmdline->lang,SLP_FALSE,&hslp) == SLP_OK)
  259. {
  260. if((result = SLPAssociateIFList(hslp, cmdline->cmdparam3)) != SLP_OK)
  261. {
  262. printf("errorcode: %i\n",result);
  263. SLPClose(hslp);
  264. return;
  265. }
  266. result = SLPFindAttrs(hslp,
  267. cmdline->cmdparam1,
  268. cmdline->scopes,
  269. cmdline->cmdparam2,
  270. myAttrCallback,
  271. 0);
  272. if(result != SLP_OK)
  273. {
  274. printf("errorcode: %i\n",result);
  275. }
  276. SLPClose(hslp);
  277. }
  278. }
  279. #endif /* MI_NOT_SUPPORTED */
  280. /*=========================================================================*/
  281. SLPBoolean mySrvUrlCallback( SLPHandle hslp,
  282. const char* srvurl,
  283. unsigned short lifetime,
  284. SLPError errcode,
  285. void* cookie )
  286. /*=========================================================================*/
  287. {
  288. if(errcode == SLP_OK)
  289. {
  290. printf("%s,%i\n",srvurl,lifetime);
  291. }
  292. return SLP_TRUE;
  293. }
  294. /*=========================================================================*/
  295. void FindSrvs(SLPToolCommandLine* cmdline)
  296. /*=========================================================================*/
  297. {
  298. SLPError result;
  299. SLPHandle hslp;
  300. if(SLPOpen(cmdline->lang,SLP_FALSE,&hslp) == SLP_OK)
  301. {
  302. result = SLPFindSrvs(hslp,
  303. cmdline->cmdparam1,
  304. cmdline->scopes,
  305. cmdline->cmdparam2,
  306. mySrvUrlCallback,
  307. 0);
  308. if(result != SLP_OK)
  309. {
  310. printf("errorcode: %i\n",result);
  311. }
  312. SLPClose(hslp);
  313. }
  314. }
  315. #ifndef MI_NOT_SUPPORTED
  316. /*=========================================================================*/
  317. void FindSrvsUsingIFList(SLPToolCommandLine* cmdline)
  318. /*=========================================================================*/
  319. {
  320. SLPError result;
  321. SLPHandle hslp;
  322. if(SLPOpen(cmdline->lang,SLP_FALSE,&hslp) == SLP_OK)
  323. {
  324. if((result = SLPAssociateIFList(hslp, cmdline->cmdparam3)) != SLP_OK)
  325. {
  326. printf("errorcode: %i\n",result);
  327. SLPClose(hslp);
  328. return;
  329. }
  330. result = SLPFindSrvs(hslp,
  331. cmdline->cmdparam1,
  332. cmdline->scopes,
  333. cmdline->cmdparam2,
  334. mySrvUrlCallback,
  335. 0);
  336. if(result != SLP_OK)
  337. {
  338. printf("errorcode: %i\n",result);
  339. }
  340. SLPClose(hslp);
  341. }
  342. }
  343. #endif /* MI_NOT_SUPPORTED */
  344. #ifndef UNICAST_NOT_SUPPORTED
  345. /*=========================================================================*/
  346. void UnicastFindSrvs(SLPToolCommandLine* cmdline)
  347. /*=========================================================================*/
  348. {
  349. SLPError result;
  350. SLPHandle hslp;
  351. if(SLPOpen(cmdline->lang,SLP_FALSE,&hslp) == SLP_OK) {
  352. if((result = SLPAssociateIP(hslp, cmdline->cmdparam3)) != SLP_OK)
  353. {
  354. printf("errorcode: %i\n",result);
  355. SLPClose(hslp);
  356. return;
  357. }
  358. result = SLPFindSrvs(hslp,
  359. cmdline->cmdparam1,
  360. cmdline->scopes,
  361. cmdline->cmdparam2,
  362. mySrvUrlCallback,
  363. 0);
  364. if(result != SLP_OK)
  365. {
  366. printf("errorcode: %i\n",result);
  367. }
  368. SLPClose(hslp);
  369. }
  370. }
  371. #endif
  372. /*=========================================================================*/
  373. void FindScopes(SLPToolCommandLine* cmdline)
  374. /*=========================================================================*/
  375. {
  376. SLPError result;
  377. SLPHandle hslp;
  378. char* scopes;
  379. if(SLPOpen(cmdline->lang,SLP_FALSE,&hslp) == SLP_OK)
  380. {
  381. result = SLPFindScopes(hslp,&scopes);
  382. if(result == SLP_OK)
  383. {
  384. printf("%s\n",scopes);
  385. SLPFree(scopes);
  386. }
  387. SLPClose(hslp);
  388. }
  389. }
  390. /*-------------------------------------------------------------------------*/
  391. void mySLPRegReport(SLPHandle hslp, SLPError errcode, void* cookie)
  392. {
  393. if (errcode)
  394. printf("(de)registration errorcode %d\n", errcode);
  395. }
  396. /*=========================================================================*/
  397. void Register(SLPToolCommandLine* cmdline)
  398. /*=========================================================================*/
  399. {
  400. SLPError result;
  401. SLPHandle hslp;
  402. char srvtype[80] = "", *s;
  403. int len = 0;
  404. if (strncasecmp(cmdline->cmdparam1, "service:", 8) == 0)
  405. len = 8;
  406. s = strchr(cmdline->cmdparam1 + len, ':');
  407. if (!s)
  408. {
  409. printf("Invalid URL: %s\n", cmdline->cmdparam1);
  410. return;
  411. }
  412. len = s - cmdline->cmdparam1;
  413. strncpy(srvtype, cmdline->cmdparam1, len);
  414. srvtype[len] = 0;
  415. if(SLPOpen(cmdline->lang,SLP_FALSE,&hslp) == SLP_OK)
  416. {
  417. result = SLPReg(hslp,
  418. cmdline->cmdparam1,
  419. SLP_LIFETIME_DEFAULT,
  420. srvtype,
  421. cmdline->cmdparam2,
  422. SLP_TRUE,
  423. mySLPRegReport,
  424. 0);
  425. if(result != SLP_OK)
  426. {
  427. printf("errorcode: %i\n",result);
  428. }
  429. SLPClose(hslp);
  430. }
  431. }
  432. /*=========================================================================*/
  433. void Deregister(SLPToolCommandLine* cmdline)
  434. /*=========================================================================*/
  435. {
  436. SLPError result;
  437. SLPHandle hslp;
  438. if(SLPOpen(cmdline->lang,SLP_FALSE,&hslp) == SLP_OK)
  439. {
  440. result = SLPDereg(hslp,
  441. cmdline->cmdparam1,
  442. mySLPRegReport,
  443. 0);
  444. if(result != SLP_OK)
  445. {
  446. printf("errorcode: %i\n",result);
  447. }
  448. SLPClose(hslp);
  449. }
  450. }
  451. /*=========================================================================*/
  452. void PrintVersion(SLPToolCommandLine* cmdline)
  453. /*=========================================================================*/
  454. {
  455. #ifdef WIN32
  456. printf("slptool version = %s\n",SLP_VERSION);
  457. #else
  458. printf("slptool version = %s\n",VERSION);
  459. #endif
  460. printf("libslp version = %s\n",
  461. SLPGetProperty("net.slp.OpenSLPVersion"));
  462. printf("libslp configuration file = %s\n",
  463. SLPGetProperty("net.slp.OpenSLPConfigFile"));
  464. }
  465. /*=========================================================================*/
  466. void GetProperty(SLPToolCommandLine* cmdline)
  467. /*=========================================================================*/
  468. {
  469. const char* propertyValue;
  470. propertyValue = SLPGetProperty(cmdline->cmdparam1);
  471. printf("%s = %s\n",
  472. cmdline->cmdparam1,
  473. propertyValue == 0 ? "" : propertyValue);
  474. }
  475. /*=========================================================================*/
  476. int ParseCommandLine(int argc,char* argv[], SLPToolCommandLine* cmdline)
  477. /* Returns Zero on success. Non-zero on error. */
  478. /*=========================================================================*/
  479. {
  480. int i;
  481. if(argc < 2)
  482. {
  483. /* not enough arguments */
  484. return 1;
  485. }
  486. for (i=1;i<argc;i++)
  487. {
  488. if( strcasecmp(argv[i],"-v") == 0 ||
  489. strcasecmp(argv[i],"--version") == 0 )
  490. {
  491. if(i < argc)
  492. {
  493. cmdline->cmd = PRINT_VERSION;
  494. return 0;
  495. }
  496. else
  497. {
  498. return 1;
  499. }
  500. }
  501. else if( strcasecmp(argv[i],"-s") == 0 ||
  502. strcasecmp(argv[i],"--scopes") == 0 )
  503. {
  504. i++;
  505. if(i < argc)
  506. {
  507. cmdline->scopes = argv[i];
  508. }
  509. else
  510. {
  511. return 1;
  512. }
  513. }
  514. else if( strcasecmp(argv[i],"-l") == 0 ||
  515. strcasecmp(argv[i],"--lang") == 0 )
  516. {
  517. i++;
  518. if(i < argc)
  519. {
  520. cmdline->lang = argv[i];
  521. }
  522. else
  523. {
  524. return 1;
  525. }
  526. }
  527. else if(strcasecmp(argv[i],"findsrvs") == 0)
  528. {
  529. cmdline->cmd = FINDSRVS;
  530. /* service type */
  531. i++;
  532. if(i < argc)
  533. {
  534. cmdline->cmdparam1 = argv[i];
  535. }
  536. else
  537. {
  538. return 1;
  539. }
  540. /* (optional) filter */
  541. i++;
  542. if(i < argc)
  543. {
  544. cmdline->cmdparam2 = argv[i];
  545. }
  546. break;
  547. }
  548. #ifndef MI_NOT_SUPPORTED
  549. else if(strcasecmp(argv[i],"findsrvsusingiflist") == 0)
  550. {
  551. cmdline->cmd = FINDSRVSUSINGIFLIST;
  552. /* (required) IFList */
  553. i++;
  554. if(i < argc)
  555. {
  556. cmdline->cmdparam3 = argv[i];
  557. }
  558. else
  559. {
  560. return 1;
  561. }
  562. /* service type */
  563. i++;
  564. if(i < argc)
  565. {
  566. cmdline->cmdparam1 = argv[i];
  567. }
  568. else
  569. {
  570. return 1;
  571. }
  572. /* (optional) filter */
  573. i++;
  574. if(i < argc)
  575. {
  576. cmdline->cmdparam2 = argv[i];
  577. }
  578. break;
  579. }
  580. #endif /* MI_NOT_SUPPORTED */
  581. #ifndef UNICAST_NOT_SUPPORTED
  582. else if(strcasecmp(argv[i],"unicastfindsrvs") == 0)
  583. {
  584. cmdline->cmd = UNICASTFINDSRVS;
  585. i++;
  586. if(i < argc)
  587. {
  588. cmdline->cmdparam3 = argv[i];
  589. }
  590. else
  591. {
  592. return 1;
  593. }
  594. /* service type */
  595. i++;
  596. if(i < argc)
  597. {
  598. cmdline->cmdparam1 = argv[i];
  599. } else {
  600. return 1;
  601. }
  602. /* optional filter */
  603. i++;
  604. if(i < argc)
  605. {
  606. cmdline->cmdparam2 = argv[i];
  607. }
  608. break;
  609. }
  610. #endif
  611. else if(strcasecmp(argv[i],"findattrs") == 0)
  612. {
  613. cmdline->cmd = FINDATTRS;
  614. /* url or service type */
  615. i++;
  616. if(i < argc)
  617. {
  618. cmdline->cmdparam1 = argv[i];
  619. }
  620. else
  621. {
  622. return 1;
  623. }
  624. /* (optional) attrids */
  625. i++;
  626. if(i < argc)
  627. {
  628. cmdline->cmdparam2 = argv[i];
  629. }
  630. }
  631. #ifndef UNICAST_NOT_SUPPORTED
  632. else if(strcasecmp(argv[i],"unicastfindattrs") == 0)
  633. {
  634. cmdline->cmd = UNICASTFINDATTRS;
  635. /* unicast IP address */
  636. i++;
  637. if(i < argc)
  638. {
  639. cmdline->cmdparam3 = argv[i];
  640. }
  641. else
  642. {
  643. return 1;
  644. }
  645. /* url or service type */
  646. i++;
  647. if(i < argc)
  648. {
  649. cmdline->cmdparam1 = argv[i];
  650. } else {
  651. return 1;
  652. }
  653. /* optional filter */
  654. i++;
  655. if(i < argc)
  656. {
  657. cmdline->cmdparam2 = argv[i];
  658. }
  659. break;
  660. }
  661. #endif
  662. #ifndef MI_NOT_SUPPORTED
  663. else if(strcasecmp(argv[i],"findattrsusingiflist") == 0)
  664. {
  665. cmdline->cmd = FINDATTRSUSINGIFLIST;
  666. /* (required) IFList */
  667. i++;
  668. if(i < argc)
  669. {
  670. cmdline->cmdparam3 = argv[i];
  671. }
  672. else
  673. {
  674. return 1;
  675. }
  676. /* url or service type */
  677. i++;
  678. if(i < argc)
  679. {
  680. cmdline->cmdparam1 = argv[i];
  681. }
  682. else
  683. {
  684. return 1;
  685. }
  686. /* (optional) attrids */
  687. i++;
  688. if(i < argc)
  689. {
  690. cmdline->cmdparam2 = argv[i];
  691. }
  692. }
  693. #endif /* MI_NOT_SUPPORTED */
  694. else if(strcasecmp(argv[i],"findsrvtypes") == 0)
  695. {
  696. cmdline->cmd = FINDSRVTYPES;
  697. /* (optional) naming authority */
  698. i++;
  699. if(i < argc)
  700. {
  701. cmdline->cmdparam1 = argv[i];
  702. }
  703. }
  704. #ifndef UNICAST_NOT_SUPPORTED
  705. else if(strcasecmp(argv[i],"unicastfindsrvtypes") == 0)
  706. {
  707. cmdline->cmd = UNICASTFINDSRVTYPES;
  708. /* unicast IP address */
  709. i++;
  710. if(i < argc)
  711. {
  712. cmdline->cmdparam3 = argv[i];
  713. }
  714. else
  715. {
  716. return 1;
  717. }
  718. /* (optional) naming authority */
  719. i++;
  720. if(i < argc)
  721. {
  722. cmdline->cmdparam1 = argv[i];
  723. }
  724. }
  725. #endif
  726. #ifndef MI_NOT_SUPPORTED
  727. else if(strcasecmp(argv[i],"findsrvtypesusingiflist") == 0)
  728. {
  729. cmdline->cmd = FINDSRVTYPESUSINGIFLIST;
  730. /* (required) IFList */
  731. i++;
  732. if(i < argc)
  733. {
  734. cmdline->cmdparam3 = argv[i];
  735. }
  736. else
  737. {
  738. return 1;
  739. }
  740. /* (optional) naming authority */
  741. i++;
  742. if(i < argc)
  743. {
  744. cmdline->cmdparam1 = argv[i];
  745. }
  746. }
  747. #endif /* MI_NOT_SUPPORTED */
  748. else if(strcasecmp(argv[i],"findscopes") == 0)
  749. {
  750. cmdline->cmd = FINDSCOPES;
  751. }
  752. else if(strcasecmp(argv[i],"register") == 0)
  753. {
  754. cmdline->cmd = REGISTER;
  755. /* url */
  756. i++;
  757. if(i < argc)
  758. {
  759. cmdline->cmdparam1 = argv[i];
  760. }
  761. else
  762. {
  763. return 1;
  764. }
  765. /* Optional attrids */
  766. i++;
  767. if(i < argc)
  768. {
  769. cmdline->cmdparam2 = argv[i];
  770. }
  771. else
  772. {
  773. cmdline->cmdparam2 = cmdline->cmdparam1 + strlen(cmdline->cmdparam1);
  774. }
  775. break;
  776. }
  777. else if(strcasecmp(argv[i],"deregister") == 0)
  778. {
  779. cmdline->cmd = DEREGISTER;
  780. /* url */
  781. i++;
  782. if(i < argc)
  783. {
  784. cmdline->cmdparam1 = argv[i];
  785. }
  786. else
  787. {
  788. return 1;
  789. }
  790. }
  791. else if(strcasecmp(argv[i],"getproperty") == 0)
  792. {
  793. cmdline->cmd = GETPROPERTY;
  794. i++;
  795. if(i < argc)
  796. {
  797. cmdline->cmdparam1 = argv[i];
  798. }
  799. else
  800. {
  801. return 1;
  802. }
  803. }
  804. else
  805. {
  806. return 1;
  807. }
  808. }
  809. return 0;
  810. }
  811. /*=========================================================================*/
  812. void DisplayUsage()
  813. /*=========================================================================*/
  814. {
  815. printf("Usage: slptool [options] command-and-arguments \n");
  816. printf(" options may be:\n");
  817. printf(" -v (or --version) displays version of slptool and OpenSLP\n");
  818. printf(" -s (or --scope) followed by a comma separated list of scopes\n");
  819. printf(" -l (or --language) followed by a language tag\n");
  820. printf(" command-and-arguments may be:\n");
  821. printf(" findsrvs service-type [filter]\n");
  822. #ifndef MI_NOT_SUPPORTED
  823. printf(" findsrvsusingiflist interface-list service-type [filter]\n");
  824. #endif /* MI_NOT_SUPPORTED */
  825. #ifndef UNICAST_NOT_SUPPORTED
  826. printf(" unicastfindsrvs ip-address service-type [filter]\n");
  827. #endif
  828. printf(" findattrs url [attrids]\n");
  829. #ifndef UNICAST_NOT_SUPPORTED
  830. printf(" unicastfindattrs ip-address url [attrids]\n");
  831. #endif
  832. #ifndef MI_NOT_SUPPORTED
  833. printf(" findattrsusingiflist interface-list url [attrids]\n");
  834. #endif /* MI_NOT_SUPPORTED */
  835. printf(" findsrvtypes [authority]\n");
  836. #ifndef UNICAST_NOT_SUPPORTED
  837. printf(" unicastfindsrvtypes [authority]\n");
  838. #endif
  839. #ifndef MI_NOT_SUPPORTED
  840. printf(" findsrvtypesusingiflist interface-list [authority]\n");
  841. #endif /* MI_NOT_SUPPORTED */
  842. printf(" findscopes\n");
  843. printf(" register url [attrs]\n");
  844. printf(" deregister url\n");
  845. printf(" getproperty propertyname\n");
  846. printf("Examples:\n");
  847. printf(" slptool register service:myserv.x://myhost.com \"(attr1=val1),(attr2=val2)\"\n");
  848. printf(" slptool findsrvs service:myserv.x\n");
  849. printf(" slptool findsrvs service:myserv.x \"(attr1=val1)\"\n");
  850. #ifndef MI_NOT_SUPPORTED
  851. printf(" slptool findsrvsusingiflist 10.77.13.240,192.168.250.240 service:myserv.x\n");
  852. printf(" slptool findsrvsusingiflist 10.77.13.243 service:myserv.x \"(attr1=val1)\"\n");
  853. #endif /* MI_NOT_SUPPORTED */
  854. #ifndef UNICAST_NOT_SUPPORTED
  855. printf(" slptool unicastfindsrvs 10.77.13.237 service:myserv.x\n");
  856. printf(" slptool unicastfindsrvs 10.77.13.237 service:myserv.x \"(attr1=val1)\"\n");
  857. #endif
  858. printf(" slptool findattrs service:myserv.x://myhost.com\n");
  859. printf(" slptool findattrs service:myserv.x://myhost.com attr1\n");
  860. #ifndef UNICAST_NOT_SUPPORTED
  861. printf(" slptool unicastfindattrs 10.77.13.237 service:myserv.x\n");
  862. printf(" slptool unicastfindattrs 10.77.13.237 service:myserv.x://myhost.com attr1 \n");
  863. #endif
  864. #ifndef MI_NOT_SUPPORTED
  865. printf(" slptool findattrsusingiflist 10.77.13.240,192.168.250.240 service:myserv.x://myhost.com\n");
  866. printf(" slptool findattrsusingiflist 10.77.13.243 service:myserv.x://myhost.com attr1\n");
  867. #endif /* MI_NOT_SUPPORTED */
  868. printf(" slptool deregister service:myserv.x://myhost.com\n");
  869. printf(" slptool getproperty net.slp.useScopes\n");
  870. }
  871. /*=========================================================================*/
  872. int main(int argc, char* argv[])
  873. /*=========================================================================*/
  874. {
  875. int result;
  876. SLPToolCommandLine cmdline;
  877. /* zero out the cmdline */
  878. memset(&cmdline,0,sizeof(cmdline));
  879. /* Parse the command line */
  880. if(ParseCommandLine(argc,argv,&cmdline) == 0)
  881. {
  882. switch(cmdline.cmd)
  883. {
  884. case FINDSRVS:
  885. FindSrvs(&cmdline);
  886. break;
  887. #ifndef UNICAST_NOT_SUPPORTED
  888. case UNICASTFINDSRVS:
  889. UnicastFindSrvs(&cmdline);
  890. break;
  891. #endif
  892. case FINDATTRS:
  893. FindAttrs(&cmdline);
  894. break;
  895. #ifndef UNICAST_NOT_SUPPORTED
  896. case UNICASTFINDATTRS:
  897. UnicastFindAttrs(&cmdline);
  898. break;
  899. #endif
  900. case FINDSRVTYPES:
  901. FindSrvTypes(&cmdline);
  902. break;
  903. #ifndef UNICAST_NOT_SUPPORTED
  904. case UNICASTFINDSRVTYPES:
  905. UnicastFindSrvTypes(&cmdline);
  906. break;
  907. #endif
  908. case FINDSCOPES:
  909. FindScopes(&cmdline);
  910. break;
  911. case GETPROPERTY:
  912. GetProperty(&cmdline);
  913. break;
  914. case REGISTER:
  915. Register(&cmdline);
  916. break;
  917. case DEREGISTER:
  918. Deregister(&cmdline);
  919. break;
  920. #ifndef MI_NOT_SUPPORTED
  921. case FINDSRVSUSINGIFLIST:
  922. FindSrvsUsingIFList(&cmdline);
  923. break;
  924. case FINDATTRSUSINGIFLIST:
  925. FindAttrsUsingIFList(&cmdline);
  926. break;
  927. case FINDSRVTYPESUSINGIFLIST:
  928. FindSrvTypesUsingIFList(&cmdline);
  929. break;
  930. #endif /* MI_NOT_SUPPORTED */
  931. case PRINT_VERSION:
  932. PrintVersion(&cmdline);
  933. }
  934. }
  935. else
  936. {
  937. DisplayUsage();
  938. result = 1;
  939. }
  940. return 0;
  941. }