Implemented smack_label_set_get() and smack_label_set_remove().
authorJarkko Sakkinen <ext-jarkko.2.sakkinen@nokia.com>
Wed, 24 Nov 2010 16:12:10 +0000 (08:12 -0800)
committerJarkko Sakkinen <ext-jarkko.2.sakkinen@nokia.com>
Wed, 24 Nov 2010 16:12:10 +0000 (08:12 -0800)
src/smack.h
src/smack_labels.c

index 776ff36..f0b8c13 100644 (file)
@@ -235,7 +235,6 @@ void smack_label_set_delete(SmackLabelSet handle);
  */
 extern int smack_label_set_save_to_file(SmackLabelSet handle, const char *path);
 
-
 /*!
  * Add new label to a label set.
  *
@@ -246,6 +245,23 @@ extern int smack_label_set_save_to_file(SmackLabelSet handle, const char *path);
 extern int smack_label_set_add(SmackLabelSet handle, const char *long_name);
 
 /*!
+ * Remove a label from a label set.
+ *
+ * @param handle handle to a label set
+ * @param long_name long label
+ * @return 0 on success
+ */
+extern int smack_label_set_remove(SmackLabelSet handle, const char *long_name);
+
+/*!
+ * Get pointer to the instance of a given long label inside label set.
+ *
+ * @param handle handle to a label set
+ * @param long_name long name of the label
+ */
+extern const char *smack_label_set_get(SmackLabelSet handle, const char *long_name);
+
+/*!
  * Get short label.
  *
  * @param handle handle to a label set
@@ -263,8 +279,6 @@ extern const char *smack_label_set_to_short_name(SmackLabelSet handle,
 extern const char *smack_label_set_to_long_name(SmackLabelSet handle,
                                                const char *short_name);
 
-
-
 #ifdef __cplusplus
 }
 #endif
index a284502..31a2a19 100644 (file)
@@ -133,8 +133,38 @@ int smack_label_set_add(SmackLabelSet handle, const char *long_name)
        return ret == 0 ? 0  : -1;
 }
 
+int smack_label_set_remove(SmackLabelSet handle, const char *long_name)
+{
+       struct smack_label *l;
+
+       HASH_FIND(long_name_hh, handle->label_by_long_name, long_name, strlen(long_name), l);
+
+       if (l == NULL)
+               return -1;
+
+       HASH_DELETE(long_name_hh, handle->label_by_long_name, l);
+       HASH_DELETE(short_name_hh, handle->label_by_short_name, l);
+       free(l->long_name);
+       free(l->short_name);
+       free(l);
+
+       return 0;
+}
+
+const char *smack_label_set_get(SmackLabelSet handle, const char *long_name)
+{
+       struct smack_label *l;
+
+       HASH_FIND(long_name_hh, handle->label_by_long_name, long_name, strlen(long_name), l);
+
+       if (l == NULL)
+               return NULL;
+
+       return l->long_name;
+}
+
 const char *smack_label_set_to_short_name(SmackLabelSet handle,
-                                          const char *long_name)
+                                         const char *long_name)
 {
        struct smack_label *l;
 
@@ -147,7 +177,7 @@ const char *smack_label_set_to_short_name(SmackLabelSet handle,
 }
 
 const char *smack_label_set_to_long_name(SmackLabelSet handle,
-                                         const char *short_name)
+                                        const char *short_name)
 {
        struct smack_label *l;