Exemple #1
0
/*  ---------------------------------------------------------------------[<]-
    Function: init_resources

    Synopsis: stores needed parameters for the service and application
      - bin_name and appl_version will be used for display only. Can be NULL
      - init_fct: a function starting all the SMT agents needed for the service
      - term_fct: a function disposing resources allocated by init_fct

    Returns: 0 is everything is OK, negative error code otherwise
    ---------------------------------------------------------------------[>]-*/
static int 
init_resources(
    const char *binary_name,
    const char *appl_version,
    SMT_AGENTS_INIT_FCT *init_fct, 
    SMT_AGENTS_TERM_FCT *term_fct)
{
    if (!binary_name)
        return 1;

    application_name = mem_strdup (binary_name);
    if (application_name)
        strip_file_path (application_name);
    application_version = mem_strdup (appl_version ? appl_version : "???");
    application_config = service_get_config_filename (application_name);
    smt_agents_init_fct = init_fct;
    smt_agents_term_fct = term_fct;

    if (!application_name || !application_config || !application_version)
      {
        free_resources();
        return 1;
      }

    return 0;
}
Exemple #2
0
static setting_t *parse_setting(char *buf) {
    char *start = buf;
    char *end;
    setting_t *setting;
    setting_t *head = NULL;

    do{
        end = strchr(start, '\n');
        if(end)
            *end = 0;
        char **s = space_splite_str(start);
        if(s != NULL && s[0] != NULL && s[1] != NULL && s[0][0] != '#') {
            if(!(setting = (setting_t *)mem_malloc(sizeof(*setting))) ||
                    !(setting->key = mem_strdup(s[0])) ||
                    !(setting->value = mem_strdup(s[1]))
              ){
                abort();
            }
            setting->next = head;
            head = setting;
        }
        splite_str_free(s);

        if(end != NULL)
            start = end + 1;
    }while(end != NULL);

    return head;
}
Exemple #3
0
Bool load_config (const char *filename)
{
    int rc;
    XML_ITEM *config = NULL;
    XML_ITEM *root   = NULL;
    char fullname[FILE_NAME_MAX + 1];

    root = xml_create ("root", NULL);

    ASSERT (filename != NULL);
    ASSERT (strlen(filename) < FILE_NAME_MAX);
    default_extension (fullname, filename, "cfg");

    rc = xml_load_file (&root, ".", fullname, FALSE);

    if (rc != XML_NOERROR)
      {
        coprintf ("Error while loading \"%s\". Check file presence and consistence",
                   fullname);
        display_usage ();
        return FALSE;;
      }

    config = xml_first_child (root);
    ASSERT (config);

    /* default server is localhost */
    main_server =   mem_strdup (xml_get_attr (config, "smtp",    "127.0.0.1"));
    main_sender =   mem_strdup (xml_get_attr (config, "sender",  "admin@crjo"));
    main_dest   =   mem_strdup (xml_get_attr (config, "dest",    "user@crjo"));

    xml_free (root);

    return TRUE;
}
Exemple #4
0
int browsecb(const mTCHAR *Section, const mTCHAR *Key, const mTCHAR *Value, const void *UserData) {

  if (UserData != NULL) { //dumping a section, not entire file
    if (strcmp(UserData,Section)==0)
      printf("%s\n", Key);
    return 1;
  }
  //dumping entire file

  if (strcasecmp((char*)Section, (char*)lastSection)!=0 && strcmp(lastSection,"")!=0 && lastSection != NULL) {
    free(lastSection);
  }

  if (lastSection=="" || strcasecmp((char*)Section, (char*)lastSection)!=0 ) {
    printf("[%s]\n",Section);
    lastSection =  (char*)mem_strdup(Section);
  } else {
    if (strcasecmp((char*)Section, (char*)lastSection)!=0) {
      free(lastSection);
      lastSection = "";
      lastSection =  (char*)mem_strdup(Section);
    }
  }

  printf("%s=%s\n", Key, Value);
  //if (lastSection != "")

//  lastSection =  (char*)mem_strdup(Section);
  return 1;
}
Exemple #5
0
EE* ee_new(const char* type, const char* text)
{
  EE* ee = mem_new(EE);
  if (type != UNTYPED) ee->type = mem_strdup(type);
  ee->text = mem_strdup(text);
  return ee;
}
Exemple #6
0
static int config_serialize_calendar_view(char **buf, void *dummy)
{
	if (ui_calendar_get_view() == CAL_WEEK_VIEW)
		*buf = mem_strdup("weekly");
	else
		*buf = mem_strdup("monthly");

	return 1;
}
Exemple #7
0
static int config_serialize_todo_view(char **buf, void *dummy)
{
	if (ui_todo_get_view() == TODO_SHOW_COMPLETED_VIEW)
		*buf = mem_strdup("show-completed");
	else
		*buf = mem_strdup("hide-completed");

	return 1;
}
Exemple #8
0
char *find_alt_name(Env *env, char *name)
{
    char *alt = env_get(env, name);
    if(alt){
        return mem_strdup(alt);
    }

    return mem_strdup(name);
}
Exemple #9
0
static int config_serialize_first_day_of_week(char **buf, void *dummy)
{
	if (ui_calendar_week_begins_on_monday())
		*buf = mem_strdup("monday");
	else
		*buf = mem_strdup("sunday");

	return 1;
}
Exemple #10
0
static int config_serialize_default_panel(char **buf, void *dummy)
{
	if (conf.default_panel == CAL)
		*buf = mem_strdup("calendar");
	else if (conf.default_panel == APP)
		*buf = mem_strdup("appointments");
	else
		*buf = mem_strdup("todo");

	return 1;
}
Exemple #11
0
static void
apoint_dup (struct apoint *in, struct apoint *bkp)
{
  EXIT_IF (!in || !bkp, _("null pointer"));

  bkp->start = in->start;
  bkp->dur = in->dur;
  bkp->state = in->state;
  bkp->mesg = mem_strdup (in->mesg);
  if (in->note)
    bkp->note = mem_strdup (in->note);
}
Exemple #12
0
static int config_serialize_notifyall(char **buf, void *dummy)
{
	if (nbar.notify_all == NOTIFY_FLAGGED_ONLY)
		*buf = mem_strdup("flagged-only");
	else if (nbar.notify_all == NOTIFY_UNFLAGGED_ONLY)
		*buf = mem_strdup("unflagged-only");
	else if (nbar.notify_all == NOTIFY_ALL)
		*buf = mem_strdup("all");
	else
		return 0;
	return 1;
}
Exemple #13
0
static int
file_recover (FILEINFO *file_info)
{
    int
        rc = 0;
    char
        *origin_name,
        *origin_fullname,
        *backup_name,
        *backup_fullname;
    size_t
        backup_name_len;

    backup_name     = file_info-> dir. file_name;
    backup_name_len = strlen (backup_name);
    if (! streq (& backup_name [backup_name_len - strlen (BACKUP_SUFFIX)], 
                 BACKUP_SUFFIX))
        return HEAP_OK;

    origin_name = mem_alloc (backup_name_len - strlen (BACKUP_SUFFIX) + 1);
    strncpy (origin_name, backup_name, 
             backup_name_len - strlen (BACKUP_SUFFIX));
    origin_name [backup_name_len - strlen (BACKUP_SUFFIX)] = '\0';
    origin_fullname = NULL;

    backup_fullname = mem_strdup (heap_filename (backup_name));
    if (! file_exists (backup_fullname))
        rc = HEAP_MEMORY_ERROR;

    if (! rc)
      {
        origin_fullname = mem_strdup (heap_filename (origin_name));
        if (! origin_fullname)
            rc = HEAP_MEMORY_ERROR;
      }

    if (! rc)
        if (file_exists (origin_fullname))
            rc = file_delete (origin_fullname);
    
    if (! rc)
        rc = file_rename (backup_fullname, origin_fullname);

    if (rc)
        rc = HEAP_RECOVERY_ERROR;

    mem_free (origin_name);
    mem_free (origin_fullname);
    mem_free (backup_fullname);

    return rc;
}
Exemple #14
0
void
xml_modify_value  (XML_ITEM *item, const char *value)
{
    ASSERT (item);

    if (!item-> value)
        item-> value = mem_strdup (value);
    else
        if (! value || (strneq (value, item-> value)))
          {
            mem_free (item-> value);
            item-> value = mem_strdup (value);
          }
}
Exemple #15
0
char *filespecmultitilde(char *string)
{
    register char *p, *p2, *p3, *p4;

    string = filespectilde(string);     /* expand if first character is a '~' */

    if (string)
    {
       for (p = string; *p != '\0'; p++)
       {
           if (*p == '~')
           {
              *p = '\0';        /* terminate sub string */
              p2 = mem_strdup(string); /* get new sub string from old string */
              *p = '~'; /* reset ~ character */
              for (p3 = p + 1; *p3 != ' ' && *p3 != '\0'; p3++)
                  ; /* scan to next name, or end of the string */
              p4 = NULL;
              if (*p3 == ' ')
              {
                 p4 = mem_strdup(p3);  /* save reminder of the string */
                 *p3 = '\0';
              }
              p = mem_strdup(p);    /* get tilde string */
              mem_free(string);
              p = filespectilde(p);

              /* reconstruct the string from pieces */
              if (p4)
              {
                 string = (char *)
                       mem_calloc(strlen(p2) + strlen(p) + strlen(p4) + 1);
                 sprintf(string, "%s%s%s", p2, p, p4);
              }
              else
              {
                 string = (char *)
                       mem_calloc(strlen(p2) + strlen(p) + 1);
                 sprintf(string, "%s%s", p2, p);
              }
              mem_free(p);
              p = string + strlen(p2) + 2;
              mem_free(p2);
              if (p4)
                 mem_free(p4);
           }
       }
    }
    return string;
}
Exemple #16
0
MODULE get_answer_result (THREAD *thread)
{
    Bool
        host;

    tcb = thread-> tcb;                 /*  Point to thread's context        */

    host = rdns_read_answer (tcb-> query,
                             tcb-> readsize,
                             tcb-> cur_request,
                             tcb-> invalid_ns_tab,
                             tcb-> rr_result,
                             tcb-> rr_result_nbr);

    if (host)                           /*  Found a result                   */
      {
        if (tcb-> main_req_type == REQ_TYPE_HOST)
          {
            if (tcb-> cur_request-> host_address
            &&  streq (tcb-> cur_request-> host_address, tcb-> ip_value))
              {
                tcb-> host_name = mem_strdup (tcb-> cur_request-> host_name);
                the_next_event  = host_name_event;
              }
            else
                the_next_event   = ip_value_event;
          }
        else
          {
            if (tcb-> host_name
            &&  streq (tcb-> host_name, tcb-> cur_request-> host_name))
              {
                tcb-> ip_value = mem_strdup (tcb-> cur_request-> host_address);
                tcb-> ip_address = tcb-> cur_request-> host_ip;
                the_next_event = ip_value_event;
              }
            else
                the_next_event  = host_name_event;
          }
      }
    else
        the_next_event = name_server_event;

    if (tcb-> rr_result)
      {
        mem_free (tcb-> rr_result);
        tcb-> rr_result = NULL;
      }
}
Exemple #17
0
MODULE create_request_thread (THREAD *thread)
{
    THREAD
        *child;                         /*  Handle to child thread           */
    TCB
        *main_tcb;
    char
        *thread_name = NULL;

    main_tcb = thread-> tcb;

    if (main_tcb-> main_req_type == REQ_TYPE_HOST)
        thread_name = main_tcb-> ip_value;
    else
        thread_name = main_tcb-> host_name;
    if (thread_name == NULL)
        thread_name = "";
    if ((child = thread_create (AGENT_NAME, thread_name)) != NULL)
      {
        event_send (
            &child-> queue-> qid,       /*  Send to child thread queue       */
            &thread-> event-> sender,   /*  Queue for reply                  */
            "_CLIENT",                  /*  Name of event to send            */
            thread-> event-> body,      /*  Event body                       */
            thread-> event-> body_size, /*    and size                       */
            NULL, NULL, NULL,           /*  No response events               */
            0);                         /*  No timeout                       */
        tcb = (TCB *) child-> tcb;

        list_reset (&tcb-> reply);
        add_user_data (main_tcb, &tcb-> reply);
        tcb-> thread_type   = client_event;
        tcb-> main_req_type = main_tcb-> main_req_type;
        tcb-> host_name     = NULL;
        tcb-> ip_value      = NULL;
        if (tcb-> main_req_type == REQ_TYPE_HOST)
          {
            tcb-> ip_address = main_tcb-> ip_address;
            tcb-> ip_value   = mem_strdup (main_tcb-> ip_value);
            mem_strfree (&main_tcb-> ip_value);
          }
        else
          {
            tcb-> host_name = mem_strdup (main_tcb-> host_name);
            mem_strfree (&main_tcb-> host_name);
          }
      }
}
Exemple #18
0
static void
test_ttop (char *line)
{
    long
        time;
    int
        offset = 0;
    char
        *picture,
        *scan,
        *result;

    time    = atol       (get_token (line, &offset));
    picture = mem_strdup (get_token (line, &offset));
    result  = conv_time_pict (time, picture);
    if (result == NULL)
        result = "<Error>";

    /*  Replace spaces by underlines for visibility                          */
    for (scan = result; *scan; scan++)
        if (*scan == ' ')
            *scan = '_';

    printf (" dtop: %-55s", line);
    printf ("   => %s\n", result);

    if (conv_reason)
        printf ("Error: %s\n", conv_reason_text [conv_reason]);

    mem_free (picture);
}
Exemple #19
0
SYMTAB *
env2symb (void)
{
    SYMTAB
        *symtab;                        /*  Allocated symbol table           */
    char
        *next_entry,                    /*  Environment variable + value     */
        *equals;                        /*  Position of '=' in string        */
    int
        string_nbr;                     /*  Index into string table          */

    /*  We create the table here, instead of passing through strt2symb(),
        since we have to ensure that environment variable names are stored
        in uppercase.  Some systems (NT) return mixed-case names.            */

    symtab = sym_create_table ();
    if (symtab)
      {
        for (string_nbr = 0; environ [string_nbr]; string_nbr++)
          {
            next_entry = mem_strdup (environ [string_nbr]);
            equals = strchr (next_entry, '=');
            if (equals)
              {
                *equals = '\0';         /*  Cut into two strings             */
                strupc (next_entry);
                sym_assume_symbol (symtab, next_entry, equals + 1);
              }
            mem_free (next_entry);
          }
      }
    return (symtab);
}
Exemple #20
0
Bool load_body (const char *filename)
{
    FILE *file = NULL;
    char *fullname = NULL;
    size_t bytes_read, size;

    ASSERT (filename);

    fullname = mem_strdup (file_where ('s', NULL, filename, "txt"));
    ASSERT (fullname);


    file = file_locate (NULL, filename, "txt");
    if (!file)
      {
        coprintf ("ERROR : unable to open file %s", fullname);
        mem_free (fullname);
        return FALSE;
      }


    size = get_file_size (fullname);

    main_body = mem_alloc (size+1);
    ASSERT (main_body);

    bytes_read = fread (main_body, 1, size, file);
    ASSERT (bytes_read == size);

    main_body[size] = 0;

    mem_free (fullname);
    return TRUE;
}
Exemple #21
0
int
object_register (char *name, GSL_FUNCTION *gsl_functions, int size)
{
    GSL_OBJECT
        *object;
    int
        i;

    list_create (object, sizeof (GSL_OBJECT));
    ASSERT (object);
    list_relink_after (object, & object_list);

    object-> name     = mem_strdup (name);
    object-> function = gsl_functions;
    object-> size     = size;

    for (i = 1; i < size; i++)
        if (strcmp (gsl_functions [i-1]. name, gsl_functions [i]. name) >= 0)
          {
            mem_free (object-> name);
            mem_free (object);
            return -1;
          }
    return 0;
}
Exemple #22
0
MODULE get_current_request_type (THREAD *thread)
{
    NS_REQUEST
        *request;

    tcb = thread-> tcb;                 /*  Point to thread's context        */

    request = tcb-> cur_request;

    if (request-> host_address == NULL
    &&  request-> host_name    == NULL
    &&  request-> ns_ip != 0)
        request-> host_address = mem_strdup (tcb-> ip_value);

    if (request-> type == REQ_TYPE_HOST
    &&  streq (tcb-> ip_value, request-> host_address))
        the_next_event = host_name_event;
    else
    if (request-> type == REQ_TYPE_IP
    &&  request-> host_name != NULL
    &&  tcb-> host_name
    &&  streq (tcb-> host_name, request-> host_name))
        the_next_event = ip_value_event;
    else
        the_next_event = name_server_ip_event;
}
Exemple #23
0
int
get_smtssl_open (
    byte *_buffer,
    struct_smtssl_open **params)
{
    struct_smtssl_open
        *_struct_ptr;
    char
        *_ptr;

    _struct_ptr = (struct_smtssl_open *) _buffer;
    *params = mem_alloc (sizeof (struct_smtssl_open));
    if (*params)
      {
        _ptr = (char *) _struct_ptr + sizeof (struct_smtssl_open);
        if (_struct_ptr-> config)
          {
            (* params)-> config             = mem_strdup (_ptr);
            _ptr += strlen ((* params)-> config) + 1;
          }
        else
            (* params)-> config             = NULL;
        return 0;
      }
    else
        return -1;
}
Exemple #24
0
/*
 * Look in the appointment list if we have an item which starts before the item
 * stored in the notify_app structure (which is the next item to be notified).
 */
struct notify_app *
apoint_check_next (struct notify_app *app, long start)
{
  llist_item_t *i;

  LLIST_TS_LOCK (&alist_p);
  i = LLIST_TS_FIND_FIRST (&alist_p, start, apoint_starts_after);

  if (i)
    {
      struct apoint *apt = LLIST_TS_GET_DATA (i);

      if (apt->start <= app->time)
        {
          app->time = apt->start;
          app->txt = mem_strdup (apt->mesg);
          app->state = apt->state;
          app->got_app = 1;
        }
    }

  LLIST_TS_UNLOCK (&alist_p);

  return (app);
}
Exemple #25
0
MYSQLHANDLE *
alloc_mysql_handle    (char *table_name, void *context)
{
    MYSQLHANDLE
        *handle = NULL;                 /* mysql Context handle                */
    MYSQL_CONNECT_CTX
        *temp_ctx,
        *ctx;
    if (context)
      {
        ctx = (MYSQL_CONNECT_CTX *)context;
        temp_ctx = dbio_mysql_connect (ctx-> dbname, ctx-> user, ctx->password,
                                       ctx->host);
        if (temp_ctx)
          {
            handle = mem_alloc (sizeof (MYSQLHANDLE));
            if (handle)
              {
                memset (handle, 0, sizeof (MYSQLHANDLE));
                handle-> db_handle = temp_ctx-> db_handle;
                if (table_name && strused (table_name))
                    handle-> table_name = mem_strdup (table_name);
                mem_free (temp_ctx);
              }
            else
              {
                coprintf ("DBIO MYSQL: Error in alloc_mysql_handle (Memory Allocation)");
                dbio_mysql_disconnect (temp_ctx);
              }
          }
      }
    return (handle);
}
Exemple #26
0
char * filespecaddpath(const char *path,const char *filename)
{   register char *filespec;
    register unsigned pathlen;

    if (!path || (pathlen = strlen(path)) == 0)
        filespec = mem_strdup(filename);
    else
    {
        filespec = (char *) mem_malloc(pathlen + 1 + strlen(filename) + 1);
        if (filespec)
        {   strcpy(filespec,path);
#if MSDOS || __OS2__ || __NT__ || _WIN32
            if (!ispathdelim(filespec[pathlen - 1]))
                strcat(filespec,"\\");
#else
#if VMS
#else
#if MPW
            if (!ispathdelim(filespec[pathlen - 1]))
                strcat(filespec,":");
#else
            if (!ispathdelim(filespec[pathlen - 1]))
                strcat(filespec,"/");
#endif /* MPW   */
#endif /* VMS   */
#endif
            strcat(filespec,filename);
        }
    }
    return filespec;
}
Exemple #27
0
int
heap_get (
    const char   *key,
          DESCR **data)
{
    int
        rc = 0;
    char
        *filename = NULL;
    
    filename = mem_strdup (heap_filename (key));
    if (filename == NULL)
        rc = HEAP_IO_FAILED;

    if (!rc)
      {
        if (!file_exists (filename))
            rc = HEAP_DATA_NOT_FOUND;
      }

    if (!rc)
      {
        *data = file_slurpl (filename);
        if (*data == NULL)
            rc = HEAP_IO_FAILED;
      }
        
    mem_free (filename);

    return rc;
}
Exemple #28
0
int
heap_init (
    const char *heappath)
{
    int
        rc = HEAP_OK;

    if (file_exists (heappath))
      {
        if (!file_is_directory (heappath))
            rc = HEAP_INVALID_PATH;
      }
    else
      {
        if (make_dir (heappath) != 0)
            rc = HEAP_CANNOT_CREATE_PATH;
      }

    if (! rc)
      {
        path = mem_strdup (heappath);
        if (!path)
            rc = HEAP_MEMORY_ERROR;
      }

    return rc;
}
Exemple #29
0
int
get_smtssl_put_slice (
    byte *_buffer,
    struct_smtssl_put_slice **params)
{
    struct_smtssl_put_slice
        *_struct_ptr;
    char
        *_ptr;

    _struct_ptr = (struct_smtssl_put_slice *) _buffer;
    *params = mem_alloc (sizeof (struct_smtssl_put_slice));
    if (*params)
      {
        _ptr = (char *) _struct_ptr + sizeof (struct_smtssl_put_slice);
        (* params)-> socket             = _struct_ptr-> socket;
        if (_struct_ptr-> filename)
          {
            (* params)-> filename           = mem_strdup (_ptr);
            _ptr += strlen ((* params)-> filename) + 1;
          }
        else
            (* params)-> filename           = NULL;
        (* params)-> start              = _struct_ptr-> start;
        (* params)-> end                = _struct_ptr-> end;
        return 0;
      }
    else
        return -1;
}
Exemple #30
0
static void console_loghook(char *str)
{
	if(hConsole) {
		char newline[3] = "\r\n";
		char *tmp = mem_strdup(str);
		char *p,*p2 = tmp;

		//break up all lines
		for(p=tmp;*p;p++) {
			if(*p == '\n') {
				*p = 0;
				console_addline(p2);
				console_addline(newline);
				p2 = p + 1;
			}
		}

		//output text after the last newline
		if(*p2) {
			console_addline(p2);
		}

		//free the temp string
		mem_free(tmp);
	}
}