## SLPReg

### Declaration

`#include <slp.h>`

`SLPError SLPReg( SLPHandle hslp,`
`const char* srvurl,`
`unsigned short lifetime,`
`const char* srvtype,`
`const char* attrs,`
`SLPBoolean fresh,`
`SLPRegReport callback,`
`void* cookie )`

### Description

Registers the URL in `srvurl` having the lifetime `lifetime` with the attribute list in `attrs`. The `attrs` list is a comma separated list of attribute assignments in the wire format (including escaping of reserved characters). The `lifetime` parameter must be nonzero and less than or equal to `SLP_LIFETIME_MAXIMUM`. If the `fresh` flag is `SLP_TRUE`, then the registration is new (the SLP protocol FRESH flag is set) and the registration replaces any existing registrations. The `srvtype` parameter is a service type name and can be included for service URLs that are not in the service: scheme. If the URL is in the service: scheme, the `srvtype` parameter is ignored. If the fresh flag is `SLP`_FALSE, then an existing registration is updated. Registrations and updates take place in the language locale of the `hslp` handle.

### Parameters

`hslp` | The language specific `SLPHandle` on which to register the service.
`srvurl` | The service URL to register. May not be the empty string. May not be NULL. Must conform to SLP Service URL syntax. `SLP_INVALID_REGISTRATION` will be returned if srvurl is not a SLP Service URL. See Syntax for more information on Service URL syntax.
`lifetime` | An unsigned short giving the lifetime of the service in seconds. The value must be an unsigned integer less than or equal to `SLP_LIFETIME_MAXIMUM` and greater than zero. If lifetime is set to `SLP_LIFETIME_MAXIMUM`, it will remain registered for the life of the calling process.
srvtype | This parameter is always ignored because the Service URL syntax required for the `srvurl` parameter encapsulates the service-type. See Syntax for more information on Service URL syntax.
attrs | A list of attribute assignment expressions for the attributes of the registered service. Use the empty string, "" for no attributes. Example: "(attr1=val1),(attr2=val2),(attr3=val3)"
`fresh` | An SLPBoolean that is `SLP_TRUE` if the registration is new or `SLP_FALSE` for a re-registration. Currently, OpenSLP does not support incremental registrations. If `fresh` is `SLP_FALSE`, `SLPReg()` will return `SLP_NOT_IMPLEMENTED`.
`callback` | The address of an `SLPRegReport` function that will be called to report the operation completion status. Man not be NULL. See Callbacks for more information on how callbacks are used by the SLPAPI.
`cookie` | Pointer to memory that gets passed to the callback code. May be NULL.

### Returns

SLP_OK | Indicates that the no error occurred during the operation.
SLP_INVALID_REGISTRATION | The deregistered service url does not conform to valid service url syntax. The service url being deregistered is not registered this means that either it was never registered via a call to SLPReg() or that the registration lifetime has expired. SLP_INVALID_REGISTRATION is commonly returned when an attempt is made to deregister a service that was registered by a call to SLPReg() on a different host.
SLP_PARSE_ERROR | The SLP message was rejected by a remote SLP agent. The API returns this error only when no information was retrieved, and at least one SA or DA indicated a protocol error. The data supplied through the API may be malformed or a may have been damaged in transit.
SLP_AUTHENTICATION_ABSENT | If the SLP framework supports authentication, this error arises when the UA or SA failed to send an authenticator for requests or registrations.
SLP_AUTHENTICATION_FAILED | If the SLP framework supports authentication, this error arises when a authentication on an SLP message failed.
SLP_NETWORK_TIMED_OUT | When no reply can be obtained in the time specified by the configured timeout interval for a unicast request, this error is returned. In other words, slpd is running, but something is wrong with it
SLP_NETWORK_INIT_FAILED | If the network cannot initialize properly, this error is returned. Will also be returned if an SA or DA agent (slpd) can not be contacted. slpd must be running in order to call SLPReg() or SLPDereg().
SLP_MEMORY_ALLOC_FAILED | Out of memory error
SLP_PARAMETER_BAD | If a parameter passed into a function is bad, this error is returned.
SLP_NETWORK_ERROR | The failure of networking during normal operations causes this error to be returned. In OpenSLP, this is the error you'll get if an underlying socket() call failed.
SLP_INTERNAL_SYSTEM_ERROR | A basic failure of the API causes this error to be returned. This occurs when a system call or library fails. The operation could not recover.
SLP_HANDLE_IN_USE | Callback functions are not permitted to recursively call into the API on the same SLPHandle, either directly or indirectly. If an attempt is made to do so, this error is returned from the called API function.

Be aware, especially if the call is async, of error codes that may be passed to the SLPRegReport() callback function.

### Status

OpenSLP 0.8.0 | Fully implemented as specified by RFC 2614

### See Also

SLPDeReg(), Syntax, Callbacks

### Example Code

> `#include <slp.h>`

> `void MySLPRegReport(SLPHandle hslp, SLPError errcode, void* cookie)`
> `{`
> `/* return the error code in the cookie */`
> `*(SLPError*)cookie = errcode;`

> `/* You could do something else here like print out */`
> `/* the errcode, etc. Remember, as a general rule, */`
> `/* do not try to do too much in a callback because */`
> `/* it is being executed by the same thread that is */`
> `/* reading slp packets from the wire. */`
> `}`

> `int main(int argc, char* argv[])`
> `{`
> `SLPError err;`
> `SLPError callbackerr;`
> `SLPHandle hslp;`

> `err = SLPOpen("en",SLP_FALSE,&hslp);`
> `if(err != SLP_OK)`
> `{`
> `printf("Error opening slp handle %i\n",err);`
> `return err;`
> `}`

> `/* Register a service with SLP */`
> `err = SLPReg( hslp,`
> `"service:myservice.myorg://hostname.domain.com:6672",`
> `SLP_LIFETIME_MAXIMUM,`
> `0,`
> `"(public_key=......my_pgp_key.......)",`
> `SLP_TRUE,`
> `MySLPRegReport,`
> `&callbackerr );`

> `/* err may contain an error code that occurred as the slp library */`
> `/* _prepared_ to make the call. */`
> `if(( err != SLP_OK) || (callbackerr != SLP_OK))`
> `{`
> `printf("Error registering service with slp %i\n",err);`
> `return err;`
> `}`

> `/* callbackerr may contain an error code (that was assigned through */`
> `/* the callback cookie) that occurred as slp packets were sent on */`
> `/* the wire */`
> `if( callbackerr != SLP_OK)`
> `{`
> `printf("Error registering service with slp %i\n",callbackerr);`
> `return callbackerr;`
> `}`

> `/* Now that we're done using slp, close the slp handle */`
> `SLPClose(hslp);`

> `/* rest of program */`
> `}`
> ``