+/** Registers a service mapping to the pseudocommand handler.
+ * @param[in] map Service mapping to add.
+ * @return Non-zero on success; zero if a command already used the name.
+ */
+int register_mapping(struct s_map *map)
+{
+ struct Message *msg;
+
+ if (msg_tree_parse(map->command, &msg_tree))
+ return 0;
+
+ msg = (struct Message *)MyMalloc(sizeof(struct Message));
+ msg->cmd = map->command;
+ msg->tok = map->command;
+ msg->count = 0;
+ msg->parameters = 2;
+ msg->flags = MFLG_EXTRA;
+ if (!(map->flags & SMAP_FAST))
+ msg->flags |= MFLG_SLOW;
+ msg->bytes = 0;
+ msg->extra = map;
+
+ msg->handlers[UNREGISTERED_HANDLER] = m_ignore;
+ msg->handlers[CLIENT_HANDLER] = m_pseudo;
+ msg->handlers[SERVER_HANDLER] = m_ignore;
+ msg->handlers[OPER_HANDLER] = m_pseudo;
+ msg->handlers[SERVICE_HANDLER] = m_ignore;
+
+ add_msg_element(&msg_tree, msg, msg->cmd);
+ map->msg = msg;
+
+ return 1;
+}
+
+/** Removes a service mapping.
+ * @param[in] map Service mapping to remove.
+ * @return Non-zero on success; zero if no command used the name.
+ */
+int unregister_mapping(struct s_map *map)
+{
+ if (!msg_tree_parse(map->command, &msg_tree))
+ {
+ /* This simply should never happen. */
+ assert(0);
+ return 0;
+ }
+
+ del_msg_element(&msg_tree, map->msg->cmd);
+
+ map->msg->extra = NULL;
+ MyFree(map->msg);
+ map->msg = NULL;
+
+ return 1;
+}
+
+/** Parse a line of data from a user.
+ * NOTE: parse_*() should not be called recursively by any other
+ * functions!
+ * @param[in] cptr Client that sent the data.
+ * @param[in] buffer Start of input line.
+ * @param[in] bufend End of input line.
+ * @return 0 on success, -1 on parse error, or CPTR_KILLED if message
+ * handler returns it.