Example #1
0
bool MtpDeviceInfo::read(MtpDataPacket& packet) {
    MtpStringBuffer string;

    // read the device info
    if (!packet.getUInt16(mStandardVersion)) return false;
    if (!packet.getUInt32(mVendorExtensionID)) return false;
    if (!packet.getUInt16(mVendorExtensionVersion)) return false;

    if (!packet.getString(string)) return false;
    mVendorExtensionDesc = strdup((const char *)string);

    if (!packet.getUInt16(mFunctionalMode)) return false;
    mOperations = packet.getAUInt16();
    if (!mOperations) return false;
    mEvents = packet.getAUInt16();
    if (!mEvents) return false;
    mDeviceProperties = packet.getAUInt16();
    if (!mDeviceProperties) return false;
    mCaptureFormats = packet.getAUInt16();
    if (!mCaptureFormats) return false;
    mPlaybackFormats = packet.getAUInt16();
    if (!mCaptureFormats) return false;

    if (!packet.getString(string)) return false;
    mManufacturer = strdup((const char *)string);
    if (!packet.getString(string)) return false;
    mModel = strdup((const char *)string);
    if (!packet.getString(string)) return false;
    mVersion = strdup((const char *)string);
    if (!packet.getString(string)) return false;
    mSerial = strdup((const char *)string);

    return true;
}
Example #2
0
static int xmp_unlink(const char *path) {
  //log_msg("in xmp_unlink");
  //TODO: handle in vold somehow
  int res;
  string fileid=database_getval("name",basename(strdup(path)));

    string fromext=database_getval(fileid,"ext");
    string file=append_path2(basename(strdup(path)));
    string attrs=database_getval(fromext,"attrs");
    //cout << fromext <<  fileid << endl;
    //cout<<"HERE!"<<endl;
    database_remove_val(fileid,"attrs","all_"+fromext+"s");
    //cout<<"THERE!"<<endl;
    //database_remove_val("all_"+fromext+"s",strdup(basename(strdup(from))),fileid);
    //cout<<"WHERE!"<<endl;
    string token="";
    stringstream ss2(attrs.c_str());
    while(getline(ss2,token,':')){
      if(strcmp(token.c_str(),"null")!=0){
        string cmd=database_getval(token+"gen","command");
        string msg2=(cmd+" "+file).c_str();
        FILE* stream=popen(msg2.c_str(),"r");
        if(fgets(msg,200,stream)!=0){
          database_remove_val(fileid,token,msg);
        }
                                pclose(stream);
      }
    }

        path=append_path2(basename(strdup(path)));
        res = unlink(path);
  if (res == -1)
    return -errno;
  return 0;
}
Example #3
0
static int
__pmSetUserGroupAttributes(const char *username, __pmHashCtl *attrs)
{
    char name[32];
    char *namep;
    uid_t uid;
    gid_t gid;

    if (__pmGetUserIdentity(username, &uid, &gid, PM_RECOV_ERR) == 0) {
	pmsprintf(name, sizeof(name), "%u", uid);
	name[sizeof(name)-1] = '\0';
	if ((namep = strdup(name)) != NULL)
	    __pmHashAdd(PCP_ATTR_USERID, namep, attrs);
	else
	    return -ENOMEM;

	pmsprintf(name, sizeof(name), "%u", gid);
	name[sizeof(name)-1] = '\0';
	if ((namep = strdup(name)) != NULL)
	    __pmHashAdd(PCP_ATTR_GROUPID, namep, attrs);
	else
	    return -ENOMEM;
	return 0;
    }
    pmNotifyErr(LOG_ERR, "Authenticated user %s not found\n", username);
    return -ESRCH;
}
Example #4
0
File: sys.c Project: futex/radare2
R_API char *r_sys_pid_to_path(int pid) {
#if __WINDOWS__
	// TODO: implement r_sys_pid_to_path on W32
	return NULL;
#elif __APPLE__
	char pathbuf[PROC_PIDPATHINFO_MAXSIZE];
	int ret = proc_pidpath (pid, pathbuf, sizeof (pathbuf));
	if (ret <= 0)
		return NULL;
	return strdup (pathbuf);
#else
	int ret;
	char buf[128], pathbuf[1024];
#if __FreeBSD__
	snprintf (buf, sizeof (buf), "/proc/%d/file", pid);
#else
	snprintf (buf, sizeof (buf), "/proc/%d/exe", pid);
#endif
	ret = readlink (buf, pathbuf, sizeof (pathbuf)-1);
	if (ret<1)
		return NULL;
	pathbuf[ret] = 0;
	return strdup (pathbuf);
#endif
}
Example #5
0
int httpauth_keyvalue_buffer_append(httpauth_keyvalue_buffer *kvb, const char *key, const char *realm, httpauth_type type) {
	size_t i;
	if (kvb->size == 0) {
		kvb->size = 4;

		kvb->kv = malloc(kvb->size * sizeof(*kvb->kv));

		for(i = 0; i < kvb->size; i++) {
			kvb->kv[i] = calloc(1, sizeof(**kvb->kv));
		}
	} else if (kvb->used == kvb->size) {
		kvb->size += 4;

		kvb->kv = realloc(kvb->kv, kvb->size * sizeof(*kvb->kv));

		for(i = kvb->used; i < kvb->size; i++) {
			kvb->kv[i] = calloc(1, sizeof(**kvb->kv));
		}
	}

	kvb->kv[kvb->used]->key = strdup(key);
	kvb->kv[kvb->used]->realm = strdup(realm);
	kvb->kv[kvb->used]->type = type;

	kvb->used++;

	return 0;
}
Example #6
0
static struct newsnntp_distrib_value_meaning *
distrib_value_meaning_new(char * value, char * meaning)
{
  struct newsnntp_distrib_value_meaning * n;
  
  n = malloc(sizeof(* n));

  if (n == NULL)
    return NULL;
  
  n->dst_value = strdup(value);
  if (n->dst_value == NULL) {
    free(n);
    return NULL;
  }

  n->dst_meaning = strdup(meaning);
  if (n->dst_meaning == NULL) {
    free(n->dst_value);
    free(n);
    return NULL;
  }

  return n;
}
rfbCredential *VncClientThread::credentialHandler(rfbClient *cl, int credentialType)
{
    kDebug(5011) << "credential request" << credentialType;

    VncClientThread *t = (VncClientThread*)rfbClientGetClientData(cl, 0);
    Q_ASSERT(t);

    rfbCredential *cred = 0;

    switch (credentialType) {
        case rfbCredentialTypeUser:
            t->passwordRequest(true);
            t->m_passwordError = true;

            cred = new rfbCredential;
            cred->userCredential.username = strdup(t->username().toUtf8());
            cred->userCredential.password = strdup(t->password().toUtf8());
            break;
        default:
            kError(5011) << "credential request failed, unspported credentialType:" << credentialType;
            t->outputErrorMessage(i18n("VNC authentication type is not supported."));
            break;
    }
    return cred;
}
Example #8
0
/*
 * Copy a file from the disk.
 *
 * fosfat       handle
 * path         where in the tree
 * dst          where in local
 * return true if it is ok
 */
static int
get_file (fosfat_t *fosfat, const char *path, const char *dst)
{
  int res = 0;
  char *new_file;

  if (!strcasecmp (dst, "./"))
    new_file = strdup ((strrchr (path, '/') ? strrchr (path, '/') + 1 : path));
  else
    new_file = strdup (dst);

  if (!fosfat_islink (fosfat, path) && !fosfat_isdir (fosfat, path))
  {
    printf ("File \"%s\" is copying ...\n", path);

    if (fosfat_get_file (fosfat, path, new_file, 1))
    {
      res = 1;
      printf ("Okay..\n");
    }
    else
      fprintf (stderr, "ERROR: I can't copy the file!\n");
  }
  else
    fprintf (stderr, "ERROR: I can't copy a directory or a link!\n");

  free (new_file);
  return res;
}
Example #9
0
Node *getListOfReservedWords(char *fptrw){//fptrw= file path to reserved words
	Node *lrw=NULL;//list reserved words
	char *word,*token;
	if((el=fopen(fptrw,"r"))==NULL){
		return NULL;
	}
	sl=fopen(fptrw,"r");
	while((cr=fgetc(el))!=EOF){
		while(cr!='\n' && cr!=EOF){
			cr=fgetc(el);
		}
		fseek(el,-1,SEEK_CUR);
		setLexema();//set lexema reconocido on global variable lexema
		fgetc(el);
		fseek(sl,ftell(el),SEEK_SET);
		word=strdup(strtok(lexema,"|"));
		token=strdup(strtok(NULL,"|"));
		//printf("word= |%s|\n",word);
		//printf("token= |%s|\n",token);
		addNode(&lrw,getNode(word,token,NULL,NULL));
	}
	fclose(sl);
	fclose(el);
	return lrw;
}
Example #10
0
char *selfs(char *dev)
{
#ifndef ARCH_PPC
	int fsnum=7;
#else
	int fsnum=4;
#endif
	char *fss[] =
	{
		"ext2", _("Standard Linux ext2fs filesystem"),
		"ext3", _("Journaling version of the ext2 filesystem"),
		"ext4", _("The evolution of the ext3 filesystem"),
#ifndef ARCH_PPC
		"reiserfs", _("Hans Reiser's journaling filesystem"),
#endif
		"jfs", _("Journaled File System"),
		"xfs", _("SGI's journaling filesystem"),
		"btrfs", _("B-tree file system (EXPERIMENTAL)")
	};

	dialog_vars.backtitle=gen_backtitle(_("Formatting partitions"));
	dlg_put_backtitle();
	dlg_clear();
	dialog_vars.default_item=strdup("ext4");
	if(fw_menu(g_strdup_printf(_("Selecting filesystem for %s"), dev),
		g_strdup_printf(_("Please select the type of filesystem to "
		"use for %s."), dev), 0, 0, 0, fsnum, fss) == -1)
		return(NULL);
	FREE(dialog_vars.default_item);

	return(strdup(dialog_vars.input_result));
}
Example #11
0
int partdetails(PedPartition *part, int noswap)
{
	char *pname, *ptype, *ptr;
	PedFileSystemType *type;

	if ((type = ped_file_system_probe (&part->geom)) == NULL)
		// prevent a nice segfault
		ptype = strdup("unknown");
	else
		ptype = (char*)type->name;

	if(noswap && !strncmp("linux-swap", ptype, 10))
		return(0);

	pname = ped_partition_get_path(part);

	// remove the unnecessary "p-1" suffix from sw raid device names
	if((ptr = strstr(pname, "p-1"))!=NULL)
		*ptr='\0';

	// for dialog menus
	parts = g_list_append(parts, pname);
	ptr = fsize(part->geom.length);
	parts = g_list_append(parts, g_strdup_printf("%s\t%s", ptr, ptype));
	// for dialog checklists
	partschk = g_list_append(partschk, pname);
	partschk = g_list_append(partschk, g_strdup_printf("%s %s", ptr, ptype));
	FREE(ptr);
	partschk = g_list_append(partschk, strdup("Off"));

	return(0);
}
Example #12
0
int
show_undolist_menu(FileView *view, int with_details)
{
	char **p;
	size_t len;

	static menu_info m;
	init_menu_info(&m, UNDOLIST_MENU, strdup("Undolist is empty"));
	m.current = get_undolist_pos(with_details) + 1;
	m.pos = m.current - 1;
	m.title = strdup(" Undolist ");

	m.items = undolist(with_details);
	p = m.items;
	while(*p++ != NULL)
		m.len++;

	if(m.len > 0)
	{
		m.len = add_to_string_array(&m.items, m.len, 1, "list end");

		/* Add current position mark to menu item. */
		len = (m.items[m.pos] != NULL) ? strlen(m.items[m.pos]) : 0;
		m.items[m.pos] = realloc(m.items[m.pos], len + 1 + 1);
		memmove(m.items[m.pos] + 1, m.items[m.pos], len + 1);
		m.items[m.pos][0] = '*';
	}

	return display_menu(&m, view);
}
Example #13
0
static int ntlm2_makechal(krb5_context context, struct kcrap_chal_req_data *req,
                          krb5_data *chal, int *errnum, krb5_data *error_data)
{
	int retval;

	chal->length = 8;
	chal->data = malloc(chal->length);

	if (chal->data == 0) {
		perror("malloc");
		*errnum = errno;
		error_data->data = strdup(error_message(errno));
		error_data->length = strlen(error_data->data);
		return errno;
	} else {
		if ((retval = krb5_c_random_make_octets(context, chal))) {
			*errnum = retval;
			error_data->data = strdup(error_message(retval));
			error_data->length = strlen(error_data->data);
			free(chal->data);
			return retval;
		}
	}

	*errnum = 0;
	return 0;
}
Example #14
0
void quickplay_preinvite(const char *online_id,
                         const char *profile_id,
                         const char *nickname)
{
    if (online_id == NULL || profile_id == NULL || nickname == NULL)
        return;

    if (session.quickplay.pre_uid == NULL)
    {
        eprintf("No pending quickplay\n");
        return;
    }

    if (session.quickplay.group == NULL)
    {
        session.quickplay.group = list_new(
            (f_list_cmp) qp_player_cmp,
            (f_list_free) qp_player_free);
    }

    s_qp_player *p = calloc(1, sizeof (s_qp_player));

    p->online_id = strdup(online_id);
    p->profile_id = strdup(profile_id);
    p->nickname = strdup(nickname);
    p->accepted = 0;

    list_add(session.quickplay.group, p);

    xmpp_iq_preinvite_invite(online_id,
                             session.quickplay.pre_uid,
                             NULL, NULL);
}
Example #15
0
/* gets base file name from path or original file name if no path is supplied */
void get_file_name(char *namebuf, int bufsize, const char *pathname)
{
    int idx = strlen(pathname) - 1;
    char *path = strdup(pathname);

    if (path == NULL)
        exit_toxic_err("failed in get_file_name", FATALERR_MEMORY);

    while (idx >= 0 && pathname[idx] == '/')
        path[idx--] = '\0';

    char *finalname = strdup(path);

    if (finalname == NULL)
        exit_toxic_err("failed in get_file_name", FATALERR_MEMORY);

    const char *basenm = strrchr(path, '/');

    if (basenm != NULL) {
        if (basenm[1])
            strcpy(finalname, &basenm[1]);
    }

    snprintf(namebuf, bufsize, "%s", finalname);
    free(finalname);
    free(path);
}
Example #16
0
struct repolist *parse_cvsup(char *path, struct repolist *r)
{
	FILE *file;
	char *line = NULL;
	size_t n = 0;
	ssize_t nread;

	file = fopen(path, "r");
	if (file == NULL)
		return (r);

	char *prefix = NULL;
	char *mad_prefix = NULL;
	char *repo;

	while ((nread = getline(&line, &n, file)) != -1) {
		line[strlen(line) - 1] = '\0';
		trim(line);
		if (line[0] == '#' || strlen(line) == 0)
			continue;

		if (strstr(line, "*default prefix")) {
			prefix = get_value(line, "*default prefix");
			if (prefix == NULL)
				continue;
			if (strlen(prefix) <= strlen(PORTS_LOCATION))
				continue;
			if (strncmp
			    (prefix, PORTS_LOCATION,
			     strlen(PORTS_LOCATION)))
				continue;
			mad_prefix =
			    mid(prefix, strlen(PORTS_LOCATION) + 1, END);
			trim(mad_prefix);
			strcat(mad_prefix, "/");
			prefix = strdup(PORTS_LOCATION);

		}

		if (line[0] == '*')
			continue;

		if (strlen(line)) {
			if (mad_prefix) {
				repo = strdup(mad_prefix);
				strcat(repo, line);
				sed(repo, "//", "/");
			} else
				repo = strdup(line);

			strtok(repo, " ");
			r = repolist_add(repo, prefix, path, r);
		}
	}

	if (line)
		free(line);
	fclose(file);
	return (r);
}
Example #17
0
static struct newsnntp_group_time *
group_time_new(char * group_name, time_t date, char * email)
{
  struct newsnntp_group_time * n;
  
  n = malloc(sizeof(* n));

  if (n == NULL)
    return NULL;
  
  n->grp_name = strdup(group_name);
  if (n->grp_name == NULL) {
    free(n);
    return NULL;
  }

  n->grp_email = strdup(email);
  if (n->grp_email == NULL) {
    free(n->grp_name);
    free(n);
    return NULL;
  }

  n->grp_date = date;

  return n;
}
Example #18
0
struct repolist *parse_local(char *path, struct repolist *r)
{
	FILE *file;

	file = fopen(path, "r");
	if (file == NULL)
		return (r);

	char *line = NULL;
	char *repo;
	char *prefix = NULL;
	char *mad_prefix;
	char *c_path = NULL;
	c_path = strdup(path);
	size_t n = 0;
	ssize_t nread;

	while ((nread = getline(&line, &n, file)) != -1) {
		line[strlen(line) - 1] = '\0';
		trim(line);
		if (line[0] == '#')
			continue;
		if (strstr(line, "PATH"))
			prefix = get_value(line, "PATH");
	}
	if (line)
		free(line);
	repo = rindex(c_path, '/');
	repo = mid(repo, 1, strlen(repo) - strlen(index(repo, '.')) - 1);
	mad_prefix = strdup("local/");
	repo = strcat(mad_prefix, repo);
	r = repolist_add(repo, prefix, path, r);
	fclose(file);
	return (r);
}
Example #19
0
static struct newsnntp_distrib_default_value *
distrib_default_value_new(uint32_t weight, char * group_pattern, char * value)
{
  struct newsnntp_distrib_default_value * n;

  n = malloc(sizeof(* n));
  if (n == NULL)
    return NULL;
  
  n->dst_group_pattern = strdup(group_pattern);
  if (n->dst_group_pattern == NULL) {
    free(n);
    return NULL;
  }

  n->dst_value = strdup(value);
  if (n->dst_value == NULL) {
    free(n->dst_group_pattern);
    free(n);
    return NULL;
  }

  n->dst_weight = weight;

  return n;
}
Example #20
0
File: io.c Project: m403/radare2
static inline RList *__getioplugin_many(RIO *io, const char *_uri, int flags, int mode) {
	RIOPlugin *plugin, *iop = NULL;
	RList *list_fds = NULL;
	RListIter *iter;
	RIODesc *desc;
	char *uri = strdup (_uri);
	for (;;) {
		// resolve
		plugin = r_io_plugin_resolve (io, uri, 1);
		if (plugin && plugin->open_many) {
			// open
			list_fds = plugin->open_many (io, uri, flags, mode);
			if (io->redirect) {
				free (uri);
				uri = strdup (io->redirect);
				r_io_redirect (io, NULL);
				continue;
			}
		}
		break;
	}

	if (!list_fds) {
		free (uri);
		return NULL;
	}

	r_list_foreach (list_fds, iter, desc) {
		desc->uri = strdup (uri);
	}
Example #21
0
/*****************************************************************************
 * HTTPClose: Stop the internal HTTP server
 *****************************************************************************/
void E_(HTTPClose)( access_t *p_access )
{
    access_sys_t *p_sys = p_access->p_sys;

    if ( p_sys->p_httpd_host != NULL )
    {
        if ( p_sys->p_httpd_file != NULL )
        {
            /* Unlock the thread if it is stuck in HttpCallback */
            vlc_mutex_lock( &p_sys->httpd_mutex );
            if ( p_sys->b_request_frontend_info == VLC_TRUE )
            {
                p_sys->b_request_frontend_info = VLC_FALSE;
                p_sys->psz_frontend_info = strdup("");
            }
            if ( p_sys->b_request_mmi_info == VLC_TRUE )
            {
                p_sys->b_request_mmi_info = VLC_FALSE;
                p_sys->psz_mmi_info = strdup("");
            }
            vlc_cond_signal( &p_sys->httpd_cond );
            vlc_mutex_unlock( &p_sys->httpd_mutex );

            httpd_FileDelete( p_sys->p_httpd_file->p_file );
            httpd_RedirectDelete( p_sys->p_httpd_redir );
        }

        httpd_HostDelete( p_sys->p_httpd_host );
    }

    vlc_mutex_destroy( &p_sys->httpd_mutex );
    vlc_cond_destroy( &p_sys->httpd_cond );
}
Example #22
0
bool NiceConnection::setRemoteCandidates(
    std::vector<CandidateInfo> &candidates) {

    ELOG_DEBUG("Setting remote candidates %d", candidates.size());


    for (unsigned int compId = 1; compId <= iceComponents_; compId++) {

        GSList* candList = NULL;

        for (unsigned int it = 0; it < candidates.size(); it++) {
            NiceCandidateType nice_cand_type;
            CandidateInfo cinfo = candidates[it];
            if (cinfo.mediaType != this->mediaType
                    || this->transportName->compare(cinfo.transProtocol)
                    || cinfo.componentId != compId)
                continue;

            switch (cinfo.hostType) {
            case HOST:
                nice_cand_type = NICE_CANDIDATE_TYPE_HOST;
                break;
            case SRLFX:
                nice_cand_type = NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE;
                break;
            case PRFLX:
                nice_cand_type = NICE_CANDIDATE_TYPE_PEER_REFLEXIVE;
                break;
            case RELAY:
                nice_cand_type = NICE_CANDIDATE_TYPE_RELAYED;
                break;
            default:
                nice_cand_type = NICE_CANDIDATE_TYPE_HOST;
                break;
            }

            NiceCandidate* thecandidate = nice_candidate_new(nice_cand_type);
            NiceAddress* naddr = nice_address_new();
            nice_address_set_from_string(naddr, cinfo.hostAddress.c_str());
            nice_address_set_port(naddr, cinfo.hostPort);
            thecandidate->addr = *naddr;
            sprintf(thecandidate->foundation, "%s", cinfo.foundation.c_str());

            thecandidate->username = strdup(cinfo.username.c_str());
            thecandidate->password = strdup(cinfo.password.c_str());
            thecandidate->stream_id = (guint) 1;
            thecandidate->component_id = cinfo.componentId;
            thecandidate->priority = cinfo.priority;
            thecandidate->transport = NICE_CANDIDATE_TRANSPORT_UDP;
            candList = g_slist_append(candList, thecandidate);
            ELOG_DEBUG("New Candidate SET %s %d", cinfo.hostAddress.c_str(), cinfo.hostPort);

        }
        nice_agent_set_remote_candidates(agent_, (guint) 1, compId, candList);
    }

    ELOG_DEBUG("Candidates SET");
    this->updateIceState(NICE_CANDIDATES_RECEIVED);
    return true;
}
Example #23
0
int s_keyvalue_buffer_append(s_keyvalue_buffer *kvb, const char *key, const char *value) {
	size_t i;
	if (kvb->size == 0) {
		kvb->size = 4;
		kvb->used = 0;

		kvb->kv = malloc(kvb->size * sizeof(*kvb->kv));

		for(i = 0; i < kvb->size; i++) {
			kvb->kv[i] = calloc(1, sizeof(**kvb->kv));
		}
	} else if (kvb->used == kvb->size) {
		kvb->size += 4;

		kvb->kv = realloc(kvb->kv, kvb->size * sizeof(*kvb->kv));

		for(i = kvb->used; i < kvb->size; i++) {
			kvb->kv[i] = calloc(1, sizeof(**kvb->kv));
		}
	}

	kvb->kv[kvb->used]->key = key ? strdup(key) : NULL;
	kvb->kv[kvb->used]->value = strdup(value);

	kvb->used++;

	return 0;
}
Example #24
0
static int gw_parse_line( const char *line, const char *pattern , char **return_msg )
{
    int  found = 0;
    char *pline, *token, *lasts;
    char delimiters[] = GW_FIELD_DELIMITERS;
    
    *return_msg = NULL;
    
    pline  = strdup(line);
    
    token = strtok_r(pline, delimiters, &lasts);
   
    if ( token != NULL )
    {
        if ( strcasecmp(pattern, token) == 0 )
        {
            token = strchr(line, '=');   

            if (token != NULL)
            {
                *return_msg = strdup(token+1);
            }
            else
                *return_msg = NULL;
   
            found = 1;
        }
    }

    free(pline);
        
    return found;
}
char*
nsMimeBaseEmitter::GetLocalizedDateString(const char * dateString)
{
  char *i18nValue = nullptr;

  bool displayOriginalDate = false;
  nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));

  if (prefBranch)
    prefBranch->GetBoolPref("mailnews.display.original_date",
                            &displayOriginalDate);

  if (!displayOriginalDate)
  {
    nsAutoCString convertedDateString;
    nsresult rv = GenerateDateString(dateString, convertedDateString, true);
    if (NS_SUCCEEDED(rv))
      i18nValue = strdup(convertedDateString.get());
    else
      i18nValue = strdup(dateString);
  }
  else
    i18nValue = strdup(dateString);

  return i18nValue;
}
Example #26
0
static void silc_client_ftp_ask_name(const char *filepath,
				     void *context)
{
  SilcClientFtpSession session = (SilcClientFtpSession)context;
  SilcSFTPAttributesStruct attr;
  char *remote_file = NULL;

  SILC_LOG_DEBUG(("Start"));

  if (filepath) {
    remote_file = session->filepath;
    session->filepath = NULL;
    silc_free(session->path);
    session->path = NULL;
    session->filepath = strdup(filepath);
  } else {
    remote_file = strdup(session->filepath);
  }

  /* Now open the file */
  memset(&attr, 0, sizeof(attr));
  silc_sftp_open(session->sftp, remote_file, SILC_SFTP_FXF_READ, &attr,
		 silc_client_ftp_open_handle, session);

  /* Close the directory handle */
  silc_sftp_close(session->sftp, session->dir_handle, NULL, NULL);
  session->dir_handle = NULL;

  silc_free(remote_file);
}
Example #27
0
static help_node_t *			/* O - Node pointer or NULL on error */
help_new_node(const char   *filename,	/* I - Filename */
              const char   *anchor,	/* I - Anchor */
	      const char   *section,	/* I - Section */
	      const char   *text,	/* I - Text */
	      time_t       mtime,	/* I - Modification time */
              off_t        offset,	/* I - Offset in file */
	      size_t       length)	/* I - Length in bytes */
{
  help_node_t	*n;			/* Node */


  DEBUG_printf(("2help_new_node(filename=\"%s\", anchor=\"%s\", text=\"%s\", "
                "mtime=%ld, offset=%ld, length=%ld)", filename, anchor, text,
                (long)mtime, (long)offset, (long)length));

  n = (help_node_t *)calloc(1, sizeof(help_node_t));
  if (!n)
    return (NULL);

  n->filename = strdup(filename);
  n->anchor   = anchor ? strdup(anchor) : NULL;
  n->section  = (section && *section) ? strdup(section) : NULL;
  n->text     = strdup(text);
  n->mtime    = mtime;
  n->offset   = offset;
  n->length   = length;

  return (n);
}
Example #28
0
void options_parse(int argc, char *argv[])
{
  int option_index= 0;
  int option_rv;

  memcached_programs_help_st help_options[]=
  {
    {0},
  };

  static struct option long_options[]=
    {
      {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION},
      {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP},
      {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
      {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG},
      {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS},
      {(OPTIONSTRING)"flag", no_argument, &opt_displayflag, OPT_FLAG},
      {(OPTIONSTRING)"hash", required_argument, NULL, OPT_HASH},
      {(OPTIONSTRING)"binary", no_argument, NULL, OPT_BINARY},
      {0, 0, 0, 0},
    };

  while (1) 
  {
    option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
    if (option_rv == -1) break;
    switch (option_rv)
    {
    case 0:
      break;
    case OPT_BINARY:
      opt_binary = 1;
      break;
    case OPT_VERBOSE: /* --verbose or -v */
      opt_verbose = OPT_VERBOSE;
      break;
    case OPT_DEBUG: /* --debug or -d */
      opt_verbose = OPT_DEBUG;
      break;
    case OPT_VERSION: /* --version or -V */
      version_command(PROGRAM_NAME);
      break;
    case OPT_HELP: /* --help or -h */
      help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options);
      break;
    case OPT_SERVERS: /* --servers or -s */
      opt_servers= strdup(optarg);
      break;
    case OPT_HASH:
      opt_hash= strdup(optarg);
      break;
    case '?':
      /* getopt_long already printed an error message. */
      exit(1);
    default:
      abort();
    }
  }
}
Example #29
0
void royparse_getopt(int* argc, char** argv[])
{
    int c;

    while ((c = getopt(*argc, *argv, "?q:r:")) != EOF) {
        switch (c) {
        case '?':
            royparse_usage();
            exit(1);
            break;
        case 'q':
            if (opt_q)
                free(opt_q);
            opt_q = strdup(optarg);
            break;
        case 'r':
            if (opt_r)
                free(opt_r);
            opt_r = strdup(optarg);
            break;
        default:
            royparse_usage();
            exit(1);
        }
    }
}
Example #30
0
static int tt_config(const char *key, const char *value) {
  if (strcasecmp("Host", key) == 0) {
    char *temp;

    temp = strdup(value);
    if (temp == NULL) {
      ERROR("tokyotyrant plugin: Host strdup failed.");
      return 1;
    }
    sfree(config_host);
    config_host = temp;
  } else if (strcasecmp("Port", key) == 0) {
    char *temp;

    temp = strdup(value);
    if (temp == NULL) {
      ERROR("tokyotyrant plugin: Port strdup failed.");
      return 1;
    }
    sfree(config_port);
    config_port = temp;
  } else {
    ERROR("tokyotyrant plugin: error: unrecognized configuration key %s", key);
    return -1;
  }

  return 0;
}