+/*
+ * Add or replace a new script.
+ * NOTE: after this function returns, "u" owns the memory that "script_content"
+ * was pointing to.
+ */
+void msiv_putscript(struct sdm_userdata *u, char *script_name, char *script_content) {
+ int replaced = 0;
+ struct sdm_script *s, *sptr;
+
+ for (s=u->first_script; s!=NULL; s=s->next) {
+ if (!strcasecmp(s->script_name, script_name)) {
+ if (s->script_content != NULL) {
+ free(s->script_content);
+ }
+ s->script_content = script_content;
+ replaced = 1;
+ }
+ }
+
+ if (replaced == 0) {
+ sptr = malloc(sizeof(struct sdm_script));
+ safestrncpy(sptr->script_name, script_name, sizeof sptr->script_name);
+ sptr->script_content = script_content;
+ sptr->next = u->first_script;
+ u->first_script = sptr;
+ }
+}
+
+