/*=========================================================================*/ SLPError SLPAPI SLPParseSrvURL(const char *pcSrvURL, SLPSrvURL** ppSrvURL) /* */ /* Parses the URL passed in as the argument into a service URL structure */ /* and returns it in the ppSrvURL pointer. If a parse error occurs, */ /* returns SLP_PARSE_ERROR. The input buffer pcSrvURL is destructively */ /* modified during the parse and used to fill in the fields of the */ /* return structure. The structure returned in ppSrvURL should be freed */ /* with SLPFreeURL(). If the URL has no service part, the s_pcSrvPart */ /* string is the empty string, "", i.e. not NULL. If pcSrvURL is not a */ /* service: URL, then the s_pcSrvType field in the returned data */ /* structure is the URL's scheme, which might not be the same as the */ /* service type under which the URL was registered. If the transport is */ /* IP, the s_pcTransport field is the empty string. If the transport is */ /* not IP or there is no port number, the s_iPort field is zero. */ /* */ /* pcSrvURL A pointer to a character buffer containing the null terminated */ /* URL string to parse. */ /* */ /* ppSrvURL A pointer to a pointer for the SLPSrvURL structure to receive */ /* the parsed URL. The memory should be freed by a call to */ /* SLPFree() when no longer needed. */ /* */ /* Returns: If no error occurs, the return value is SLP_OK. Otherwise, the */ /* appropriate error code is returned. */ /*=========================================================================*/ { int result = SLPParseSrvUrl(strlen(pcSrvURL), pcSrvURL, (SLPParsedSrvUrl**) ppSrvURL); switch(result) { case ENOMEM: return SLP_MEMORY_ALLOC_FAILED; case EINVAL: return SLP_PARSE_ERROR; } return SLP_OK; }
int main(int argc, char* argv[]) { SLPParsedSrvUrl* parsedurl; printf("Testing srvurl: %s\n",TESTURL1); if(SLPParseSrvUrl(strlen(TESTURL1), TESTURL1, &parsedurl) != 0) { printf("FAILURE: SLPParseSrvUrl returned error\n"); return -1; } if(strcmp(parsedurl->srvtype,TESTSRVTYPE1)) { printf("FAILURE: wrong srvtype\n"); } else if(strcmp(parsedurl->host,TESTHOST1)) { printf("FAILURE: wrong host\n"); } else if(parsedurl->port != atoi(TESTPORT1)) { printf("FAILURE: wrong port\n"); } else if(strcmp(parsedurl->remainder,TESTREMAINDER1)) { printf("FAILURE: wrong remainder\n"); } else if(*(parsedurl->family)) { printf("FAILURE: wrong family\n"); } else { printf("Success!\n"); } if(parsedurl) xfree(parsedurl); /* TESTURL2 */ printf("Testing srvurl: %s\n",TESTURL2); if(SLPParseSrvUrl(strlen(TESTURL2), TESTURL2, &parsedurl) != 0) { printf("FAILURE: SLPParseSrvUrl returned error\n"); return -1; } if(strcmp(parsedurl->srvtype,TESTSRVTYPE1)) { printf("FAILURE: wrong srvtype\n"); } else if(strcmp(parsedurl->host,TESTHOST1)) { printf("FAILURE: wrong host\n"); } else if(parsedurl->port != atoi(TESTPORT1)) { printf("FAILURE: wrong port\n"); } /* else if(strcmp(parsedurl->remainder,TESTREMAINDER1)) { printf("FAILURE: wrong remainder\n"); } */ else if(*(parsedurl->family)) { printf("FAILURE: wrong family\n"); } else { printf("Success!\n"); } if(parsedurl) xfree(parsedurl); /* TESTURL3 */ printf("Testing srvurl: %s\n",TESTURL3); if(SLPParseSrvUrl(strlen(TESTURL3), TESTURL3, &parsedurl) != 0) { printf("FAILURE: SLPParseSrvUrl returned error\n"); return -1; } if(strcmp(parsedurl->srvtype,TESTSRVTYPE1)) { printf("FAILURE: wrong srvtype\n"); } else if(strcmp(parsedurl->host,TESTHOST1)) { printf("FAILURE: wrong host\n"); } /* else if(parsedurl->port != atoi(TESTPORT1)) { printf("FAILURE: wrong port\n"); } else if(strcmp(parsedurl->remainder,TESTREMAINDER1)) { printf("FAILURE: wrong remainder\n"); } */ else if(*(parsedurl->family)) { printf("FAILURE: wrong family\n"); } else { printf("Success!\n"); } if(parsedurl) xfree(parsedurl); /* TESTURL4 */ printf("Testing srvurl: %s\n",TESTURL4); if(SLPParseSrvUrl(strlen(TESTURL4), TESTURL4, &parsedurl) == 0) { printf("FAILURE: SLPParseSrvUrl should have returned an error\n"); } else { printf("Success!\n"); } if(parsedurl) xfree(parsedurl); /* TESTURL5 */ printf("Testing srvurl: %s\n",TESTURL5); if(SLPParseSrvUrl(strlen(TESTURL5), TESTURL5, &parsedurl) != 0) { printf("FAILURE: SLPParseSrvUrl returned error\n"); return -1; } if(strcmp(parsedurl->srvtype,TESTSRVTYPE1)) { printf("FAILURE: wrong srvtype\n"); } else if(strcmp(parsedurl->host,TESTHOST2_PARSED)) /* host should be different */ { printf("FAILURE: wrong host\n"); } else if(parsedurl->port != atoi(TESTPORT1)) { printf("FAILURE: wrong port\n"); } else if(strcmp(parsedurl->remainder,TESTREMAINDER1)) { printf("FAILURE: wrong remainder\n"); } else if(*(parsedurl->family)) { printf("FAILURE: wrong family\n"); } else { printf("Success!\n"); } if(parsedurl) xfree(parsedurl); /* TESTURL6 - invalid ipv6 host */ printf("Testing srvurl: %s\n",TESTURL6); if(SLPParseSrvUrl(strlen(TESTURL6), TESTURL6, &parsedurl) != 0) { printf("FAILURE: SLPParseSrvUrl returned error\n"); return -1; } if(strcmp(parsedurl->srvtype,TESTSRVTYPE1)) { printf("FAILURE: wrong srvtype\n"); } if(parsedurl) xfree(parsedurl); return 0; }