* Macros and Typedefs
*****************************************************************************/
+#define INSTANCE_NAME_LEN 63
+#define SERVICE_TYPE_LEN 15
+#define PROTO_LEN 4
+#define KEY_LEN 9 /* http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt */
+#define KEY_MIN 0x20 /* RFC 20 */
+#define KEY_MAX 0x7E
+
+#define SERVICE_INFO_LEN 65000
+#define DEFERRED_LEN 144
+#define SESSION_INFO_LEN 144
+
/*****************************************************************************
* Global Variables
*****************************************************************************/
return ASP_ERROR_NONE;
}
+static bool __is_valid_instance_name(char *instance_name)
+{
+ if (strlen(instance_name) > INSTANCE_NAME_LEN)
+ return false;
+ else
+ return true;
+}
int asp_advert_create(char *instance_name, asp_advert_service_h *adv_service)
{
if (instance_name) {
ASP_LOGD("instance_name = [%s]", instance_name);
+ if (!__is_valid_instance_name(instance_name)) {
+ ASP_LOGE("Not valid instance_name");
+ __ASP_LOG_FUNC_END__;
+ return ASP_ERROR_INVALID_PARAMETER;
+ }
service->instance_name = g_strdup(instance_name);
if (!service->instance_name) {
ASP_LOGE("malloc() failed!!!.");
return ASP_ERROR_NONE;
}
+static bool __is_valid_service_name(char *service_name)
+{
+ int pos = 0;
+ while(service_name[pos] != 0) {
+ if (!g_ascii_isalpha(service_name[pos]) &&
+ !g_ascii_isdigit(service_name[pos]) &&
+ service_name[pos] != '.' &&
+ service_name[pos] != '-')
+ return false;
+ pos++;
+ }
+ return true;
+}
+
+static bool __is_valid_service_type(char *service_type)
+{
+ int type_len = strlen(service_type) - PROTO_LEN - 1;
+ char *proto = &(service_type[type_len + 1]);
+ int pos = 1;
+
+ if (strncmp(proto, "_udp", PROTO_LEN) != 0 && strncmp(proto, "_tcp", PROTO_LEN) != 0)
+ return __is_valid_service_name(service_type);
+
+ if (type_len > SERVICE_TYPE_LEN + 1)
+ return false;
+
+ while (pos < type_len) {
+ if (!g_ascii_isalpha(service_type[pos]) &&
+ !g_ascii_isdigit(service_type[pos]) &&
+ service_type[pos] != '-')
+ return false;
+ pos++;
+ }
+ return true;
+}
int asp_advert_set_service_type(asp_advert_service_h adv_service,
char *service_type)
}
ASP_LOGD("service [%p]", adv_service);
+ if (!__is_valid_service_type(service_type)) {
+ ASP_LOGE("invalid service_type");
+ __ASP_LOG_FUNC_END__;
+ return ASP_ERROR_INVALID_PARAMETER;
+ }
+
service = __get_advert((void *)adv_service);
if (service == NULL) {
ASP_LOGE("Service NOT registered");
return ASP_ERROR_NONE;
}
+
+static bool __is_valid_key(const char *key)
+{
+ int pos = 0;
+
+ if (strlen(key) > KEY_LEN)
+ return false;
+
+ while (key[pos] != 0) {
+ if (key[pos] < KEY_MIN || key[pos] > KEY_MAX)
+ return false;
+ pos++;
+ }
+ return true;
+}
+
int asp_advert_add_info(asp_advert_service_h adv_service,
const char *key, const char *value)
{
}
ASP_LOGD("service [%p]", adv_service);
+ if (__is_valid_key(key)) {
+ ASP_LOGE("invalid key!");
+ __ASP_LOG_FUNC_END__;
+ return ASP_ERROR_INVALID_PARAMETER;
+ }
+
service = __get_advert((void *)adv_service);
if (service == NULL) {
ASP_LOGE("Service NOT registered");
return ASP_ERROR_NOT_INITIALIZED;
}
/* TODO fit the rsp info for length */
- if (length <= 0 || length > 144) {
+ if (length <= 0 || length > DEFERRED_LEN) {
ASP_LOGE("invalid length!");
__ASP_LOG_FUNC_END__;
return ASP_ERROR_INVALID_PARAMETER;
return ASP_ERROR_NOT_INITIALIZED;
}
- if (!service_type || strlen(service_type) == 0) {
+ if (!service_type || strlen(service_type) == 0 || !__is_valid_service_type(service_type)) {
ASP_LOGE("NULL Param [service_type]!");
__ASP_LOG_FUNC_END__;
return ASP_ERROR_INVALID_PARAMETER;
}
+
ASP_LOGD("service_type = [%s]", service_type);
if (!seek_service) {
return ASP_ERROR_NOT_INITIALIZED;
}
- if (!seek_service) {
+ if (!seek_service || !key || strlen(key) == 0) {
ASP_LOGE("NULL handler!");
__ASP_LOG_FUNC_END__;
return ASP_ERROR_INVALID_PARAMETER;
}
+
ASP_LOGD("service [%p]", seek_service);
service = __get_seek((void *)seek_service);
return ASP_ERROR_NOT_INITIALIZED;
}
- if (!seek_service) {
+ if (!seek_service || !key || strlen(key) == 0) {
ASP_LOGE("NULL handler!");
__ASP_LOG_FUNC_END__;
return ASP_ERROR_INVALID_PARAMETER;
return ASP_ERROR_NOT_INITIALIZED;
}
- if (!service_info || !session) {
+ if (!service_info || !session || strlen(service_info) > SESSION_INFO_LEN) {
ASP_LOGE("NULL Param!");
__ASP_LOG_FUNC_END__;
return ASP_ERROR_INVALID_PARAMETER;