예제 #1
0
int doCopy(int argc, char **argv){
  struct location *dest, *src;
  int i;
  int r;
  if(opts(argc,argv)<0)
    return EXIT_FAILURE;
  dest=parse_location(destination);
  if(open_location(dest,WRITE)<0)
    return EXIT_FAILURE;
  for(i=0;i<nsources;++i){
    src=parse_location(sources[i]);
    if(open_location(src,READ)<0){
      return EXIT_FAILURE;
    }
    if(do_copy(src,dest,0) < 0){
        break;
    }
  }
  if(dest->is_ssh){
          r=ssh_scp_close(dest->scp);
          if(r == SSH_ERROR){
                  fprintf(stderr,"Error closing scp: %s\n",ssh_get_error(dest->session));
                  ssh_scp_free(dest->scp);
                  dest->scp=NULL;
                  return -1;
          }
  } else {
          fclose(dest->file);
          dest->file=NULL;
  }
  ssh_disconnect(dest->session);
  ssh_finalize();
  return 0;
}
예제 #2
0
파일: node.c 프로젝트: DylanWalseth/tis-100
static void parse_mov(Node *n, const char *s) {
  const int len = strlen(s+4);
  char *rem = (char *) malloc(sizeof(char) * (len + 1));
  strcpy(rem, s+4);

  Instruction *i = node_create_instruction(n, MOV);
  parse_location(strtok(rem, " ,"), &i->src, &i->src_type);
  parse_location(strtok(NULL, " ,\n"), &i->dest, &i->dest_type);

  free(rem);
}
예제 #3
0
int main(int argc, char **argv) {
    struct location *dest, *src;
    int i;
    int r;
    if (opts(argc, argv) < 0) {
        r = EXIT_FAILURE;
        goto end;
    }

    dest = parse_location(destination);
    if (dest == NULL) {
        r = EXIT_FAILURE;
        goto end;
    }

    if (open_location(dest, WRITE) < 0) {
        location_free(dest);
        r = EXIT_FAILURE;
        goto end;
    }

    for (i = 0; i < nsources; ++i) {
        src = parse_location(sources[i]);
        if (src == NULL) {
            r = EXIT_FAILURE;
            goto close_dest;
        }

        if (open_location(src, READ) < 0) {
            location_free(src);
            r = EXIT_FAILURE;
            goto close_dest;
        }

        if (do_copy(src, dest, 0) < 0) {
            close_location(src);
            location_free(src);
            break;
        }

        close_location(src);
        location_free(src);
    }

    r = 0;

close_dest:
    close_location(dest);
    location_free(dest);
end:
    return r;
}
예제 #4
0
파일: node.c 프로젝트: DylanWalseth/tis-100
static void parse_onearg(Node *n, InputCode *ic, const char *s, Operation op) {
  const int len = strlen(s+4);
  char *rem = (char *) malloc(sizeof(char) * (len + 1));
  strcpy(rem, s+4);

  Instruction *ins = node_create_instruction(n, op);

  switch(op) {
    case JEZ:
    case JMP:
    case JNZ:
    case JGZ:
    case JLZ:
      for (int i=0; i<ic->label_count; i++) {
        const char *label = ic->labels[i];
        if (strcmp(label, rem) == 0) {
          ins->src_type = NUMBER;
          ins->src.number = ic->label_address[i];
          goto finally;
        }
      }
    default:
      parse_location(rem, &ins->src, &ins->src_type);
  }
finally:
  free(rem);
}
예제 #5
0
int argparse::parse_arguments(char* arg, options_t& options) {
    std::string argument = arg, option, value;

    if (argument.compare(0, 8, "--macpo:") != 0)
        return -1;

    size_t start_position = -1, end_position;
    if ((start_position = argument.find(":")) == std::string::npos)
        return -1;

    end_position = argument.find("=", start_position + 1);
    if (end_position == std::string::npos) {
        option = argument.substr(start_position + 1);
        value = "";
    } else {
        option = argument.substr(start_position + 1,
            end_position - start_position - 1);
        value = argument.substr(end_position + 1);
    }

    if (option == "instrument") {
        if (!value.size())
            return -1;

        options.action = ACTION_INSTRUMENT;
        parse_location(value, options.function_name, options.line_number);
    } else if (option == "check-alignment") {
        if (!value.size())
            return -1;

        options.action = ACTION_ALIGNCHECK;
        parse_location(value, options.function_name, options.line_number);
    } else if (option == "backup-filename") {
        if (!value.size())
            return -1;

        options.backup_filename = value;
    } else if (option == "no-compile") {
        options.no_compile = true;
    } else
        return -1;

    return 0;
}
예제 #6
0
void on_debug_list_source(GArray *nodes)
{
	ParseLocation loc;

	parse_location(nodes, &loc);

	iff (loc.line, "no line or abs file")
		debug_send_format(N, "02-break-insert -t %s:%d\n05", loc.file, loc.line);

	parse_location_free(&loc);
}
예제 #7
0
/* Visit the next location in the history list. */
void
on_forward_clicked (GtkToolButton *item)
{
  GtkWidget *treeview;
  GString *str;

  if (history_pos + 1 < history->len)
  {
    history_pos++;
    treeview = glade_xml_get_widget (xml, "treeview");
    str = g_string_new ((gchar*) g_ptr_array_index (history, history_pos));
    parse_location (str);
    populate_tree_model (GTK_WIDGET (treeview));
  }
}
예제 #8
0
파일: keyfile.c 프로젝트: ryanolson/Spindle
void get_keyfile_path(char *pathname, int pathname_len, int number)
{
#if defined(KEYFILE)
   debug_printf("Turning pathname %s and number %d to key file location\n",
                SEC_KEYDIR, number);

   char *demangled_loc = parse_location(SEC_KEYDIR);
   if (demangled_loc == NULL)
      abort();
   snprintf(pathname, pathname_len, "%s/spindle_key.%d.%d", demangled_loc, getuid(), number);
   pathname[pathname_len-1] = '\0';
#else
   assert(0 && "Tried to use keyfile when not compiled with keyfile.");
#endif
}
예제 #9
0
/* Visit the previous location in the history list. */
void 
on_back_clicked (GtkToolButton *item)
{
  GtkWidget *treeview;

  if (history_pos >= 0)
  {
    /* Store the current location at the end of the list. */
    if (history_pos + 1 == history->len)
      store_history();

    treeview = glade_xml_get_widget (xml, "treeview");
    parse_location (g_string_new ((gchar*) history->pdata[history_pos]));
    populate_tree_model (GTK_WIDGET (treeview));

    if (history_pos > 0)
      history_pos--;
  }
}
예제 #10
0
/* Go to the address bar location when the button is clicked. */
void 
on_go_clicked (GtkButton *button) 
{
  GtkWidget *entry, *treeview;
  GString *location;
  
  entry = glade_xml_get_widget (xml, "location");
  treeview = glade_xml_get_widget (xml, "treeview");
  location = g_string_new (gtk_entry_get_text (GTK_ENTRY (entry)));
  
  /* If the directory exists, visit the entered location. */
  if (g_file_test (location->str, G_FILE_TEST_IS_DIR))
  {
    store_history ();
    parse_location (location);
    populate_tree_model (GTK_WIDGET (treeview));
  }
  else
    file_manager_error ("The location does not exist!");
  
  g_string_free (location, TRUE);
}
예제 #11
0
파일: aprs_tt.c 프로젝트: glneo/direwolf
static int parse_fields (char *msg)
{
	char stemp[MAX_MSG_LEN+1];
	char *e;
	char *save;

	strcpy (stemp, msg);
	e = strtok_r (stemp, "*#", &save);
	while (e != NULL) {

	  switch (*e) {

	    case 'A': 
	      
	      switch (e[1]) {
	        case 'A':
	          parse_object_name (e);
	          break;
	        case 'B':
	          parse_symbol (e);
	          break;
	        case 'C':
	          /*
	           * New in 1.2: test for 10 digit callsign.
	           */
	          if (tt_call10_to_text(e+2,1,stemp) == 0) {
	             strcpy(m_callsign, stemp);
	          }
	          break;
	        default:
	          parse_callsign (e);
	          break;
	      }
	      break;

	    case 'B': 
	      parse_location (e);
	      break;

	    case 'C': 
	      parse_comment (e);
	      break;

	    case '0': 
	    case '1': 
	    case '2': 
	    case '3': 
	    case '4': 
	    case '5': 
	    case '6': 
	    case '7': 
	    case '8': 
	    case '9': 
	      expand_macro (e);
	      break;

	    case '\0':
	      /* Empty field.  Just ignore it. */
	      /* This would happen if someone uses a leading *. */
	      break;

	    default:

	      text_color_set(DW_COLOR_ERROR);
	      dw_printf ("Entry does not start with A, B, C, or digit: \"%s\"\n", msg);
	      return (TT_ERROR_D_MSG);

	  }
	
	  e = strtok_r (NULL, "*#", &save);
	}

	return (0);

} /* end parse_fields */
예제 #12
0
파일: client.c 프로젝트: hpc/Spindle
static int init_server_connection()
{
   char *connection, *rankinfo_s, *opts_s, *cachesize_s;

   debug_printf("Initializing connection to server\n");

   if (ldcsid != -1)
      return 0;
   if (!use_ldcs)
      return 0;

   location = getenv("LDCS_LOCATION");
   number = atoi(getenv("LDCS_NUMBER"));
   connection = getenv("LDCS_CONNECTION");
   rankinfo_s = getenv("LDCS_RANKINFO");
   opts_s = getenv("LDCS_OPTIONS");
   cachesize_s = getenv("LDCS_CACHESIZE");
   opts = atol(opts_s);
   shm_cachesize = atoi(cachesize_s) * 1024;

   if (strchr(location, '$')) {
      location = parse_location(location);
   }

   if (!(opts & OPT_FOLLOWFORK)) {
      debug_printf("Disabling environment variables because we're not following forks\n");
      unsetenv("LD_AUDIT");
      unsetenv("LDCS_LOCATION");
      unsetenv("LDCS_NUMBER");
      unsetenv("LDCS_CONNECTION");
      unsetenv("LDCS_RANKINFO");
      unsetenv("LDCS_OPTIONS");
   }

   if (opts & OPT_SHMCACHE) {
      assert(shm_cachesize);
#if defined(COMM_BITER)
      shm_cache_limit = shm_cachesize > 512*1024 ? shm_cachesize - 512*1024 : 0;
#else
      shm_cache_limit = shm_cachesize;
#endif
      shmcache_init(location, number, shm_cachesize, shm_cache_limit);
   }

   if (connection) {
      /* boostrapper established the connection for us.  Reuse it. */
      debug_printf("Recreating existing connection to server\n");
      debug_printf3("location = %s, number = %d, connection = %s, rankinfo = %s\n",
                    location, number, connection, rankinfo_s);
      ldcsid  = client_register_connection(connection);
      if (ldcsid == -1)
         return -1;
      assert(rankinfo_s);
      sscanf(rankinfo_s, "%d %d %d %d", rankinfo+0, rankinfo+1, rankinfo+2, rankinfo+3);
      unsetenv("LDCS_CONNECTION");
   }
   else {
      /* Establish a new connection */
      debug_printf("open connection to ldcs %s %d\n", location, number);
      ldcsid = client_open_connection(location, number);
      if (ldcsid == -1)
         return -1;

      send_pid(ldcsid);
      send_location(ldcsid, location);
      send_rankinfo_query(ldcsid, rankinfo+0, rankinfo+1, rankinfo+2, rankinfo+3);
   }
   
   snprintf(debugging_name, 32, "Client.%d", rankinfo[0]);
   LOGGING_INIT(debugging_name);

   sync_cwd();

   if (opts & OPT_RELOCPY)
      parse_python_prefixes(ldcsid);
   return 0;
}
예제 #13
0
static int cmd_dsync_prerun(struct doveadm_mail_cmd_context *_ctx,
			    struct mail_storage_service_user *service_user,
			    const char **error_r)
{
	struct dsync_cmd_context *ctx = (struct dsync_cmd_context *)_ctx;
	const char *const *remote_cmd_args = NULL;
	const struct mail_user_settings *user_set;
	const struct mail_storage_settings *mail_set;
	const char *username = "";

	user_set = mail_storage_service_user_get_set(service_user)[0];
	mail_set = mail_storage_service_user_get_mail_set(service_user);

	ctx->fd_in = -1;
	ctx->fd_out = -1;
	ctx->fd_err = -1;
	ctx->run_type = DSYNC_RUN_TYPE_LOCAL;
	ctx->remote_name = "remote";

	if (ctx->default_replica_location) {
		ctx->local_location =
			mail_user_set_plugin_getenv(user_set, "mail_replica");
		if (ctx->local_location == NULL ||
		    *ctx->local_location == '\0') {
			*error_r = "User has no mail_replica in userdb";
			_ctx->exit_code = DOVEADM_EX_NOTFOUND;
			return -1;
		}
	} else {
		/* if we're executing remotely, give -u parameter if we also
		   did a userdb lookup. */
		if ((_ctx->service_flags & MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP) != 0)
			username = _ctx->cur_username;

		if (!mirror_get_remote_cmd(ctx, username, &remote_cmd_args)) {
			/* it's a mail_location */
			if (_ctx->args[1] != NULL)
				doveadm_mail_help_name(_ctx->cmd->name);
			ctx->local_location = _ctx->args[0];
			ctx->local_location_from_arg = TRUE;
		}
	}

	if (remote_cmd_args == NULL && ctx->local_location != NULL) {
		if (parse_location(ctx, mail_set, ctx->local_location,
				   &remote_cmd_args, error_r) < 0)
			return -1;
	}

	if (remote_cmd_args != NULL) {
		/* do this before mail_storage_service_next() in case it
		   drops process privileges */
		run_cmd(ctx, remote_cmd_args);
		ctx->run_type = DSYNC_RUN_TYPE_CMD;
	}

	if (ctx->sync_visible_namespaces &&
	    ctx->run_type == DSYNC_RUN_TYPE_LOCAL)
		i_fatal("-N parameter requires syncing with remote host");
	return 0;
}
예제 #14
0
파일: http.c 프로젝트: 309746069/FFmpeg
static int process_line(URLContext *h, char *line, int line_count,
                        int *new_location)
{
    HTTPContext *s = h->priv_data;
    const char *auto_method =  h->flags & AVIO_FLAG_READ ? "POST" : "GET";
    char *tag, *p, *end, *method, *resource, *version;
    int ret;

    /* end of header */
    if (line[0] == '\0') {
        s->end_header = 1;
        return 0;
    }

    p = line;
    if (line_count == 0) {
        if (s->listen) {
            // HTTP method
            method = p;
            while (!av_isspace(*p))
                p++;
            *(p++) = '\0';
            av_log(h, AV_LOG_TRACE, "Received method: %s\n", method);
            if (s->method) {
                if (av_strcasecmp(s->method, method)) {
                    av_log(h, AV_LOG_ERROR, "Received and expected HTTP method do not match. (%s expected, %s received)\n",
                           s->method, method);
                    return ff_http_averror(400, AVERROR(EIO));
                }
            } else {
                // use autodetected HTTP method to expect
                av_log(h, AV_LOG_TRACE, "Autodetected %s HTTP method\n", auto_method);
                if (av_strcasecmp(auto_method, method)) {
                    av_log(h, AV_LOG_ERROR, "Received and autodetected HTTP method did not match "
                           "(%s autodetected %s received)\n", auto_method, method);
                    return ff_http_averror(400, AVERROR(EIO));
                }
            }

            // HTTP resource
            while (av_isspace(*p))
                p++;
            resource = p;
            while (!av_isspace(*p))
                p++;
            *(p++) = '\0';
            av_log(h, AV_LOG_TRACE, "Requested resource: %s\n", resource);

            // HTTP version
            while (av_isspace(*p))
                p++;
            version = p;
            while (!av_isspace(*p))
                p++;
            *p = '\0';
            if (av_strncasecmp(version, "HTTP/", 5)) {
                av_log(h, AV_LOG_ERROR, "Malformed HTTP version string.\n");
                return ff_http_averror(400, AVERROR(EIO));
            }
            av_log(h, AV_LOG_TRACE, "HTTP version string: %s\n", version);
        } else {
            while (!av_isspace(*p) && *p != '\0')
                p++;
            while (av_isspace(*p))
                p++;
            s->http_code = strtol(p, &end, 10);

            av_log(h, AV_LOG_TRACE, "http_code=%d\n", s->http_code);

            if ((ret = check_http_code(h, s->http_code, end)) < 0)
                return ret;
        }
    } else {
        while (*p != '\0' && *p != ':')
            p++;
        if (*p != ':')
            return 1;

        *p  = '\0';
        tag = line;
        p++;
        while (av_isspace(*p))
            p++;
        if (!av_strcasecmp(tag, "Location")) {
            if ((ret = parse_location(s, p)) < 0)
                return ret;
            *new_location = 1;
        } else if (!av_strcasecmp(tag, "Content-Length") && s->filesize == -1) {
            s->filesize = strtoll(p, NULL, 10);
        } else if (!av_strcasecmp(tag, "Content-Range")) {
            parse_content_range(h, p);
        } else if (!av_strcasecmp(tag, "Accept-Ranges") &&
                   !strncmp(p, "bytes", 5) &&
                   s->seekable == -1) {
            h->is_streamed = 0;
        } else if (!av_strcasecmp(tag, "Transfer-Encoding") &&
                   !av_strncasecmp(p, "chunked", 7)) {
            s->filesize  = -1;
            s->chunksize = 0;
        } else if (!av_strcasecmp(tag, "WWW-Authenticate")) {
            ff_http_auth_handle_header(&s->auth_state, tag, p);
        } else if (!av_strcasecmp(tag, "Authentication-Info")) {
            ff_http_auth_handle_header(&s->auth_state, tag, p);
        } else if (!av_strcasecmp(tag, "Proxy-Authenticate")) {
            ff_http_auth_handle_header(&s->proxy_auth_state, tag, p);
        } else if (!av_strcasecmp(tag, "Connection")) {
            if (!strcmp(p, "close"))
                s->willclose = 1;
        } else if (!av_strcasecmp(tag, "Server")) {
            if (!av_strcasecmp(p, "AkamaiGHost")) {
                s->is_akamai = 1;
            } else if (!av_strncasecmp(p, "MediaGateway", 12)) {
                s->is_mediagateway = 1;
            }
        } else if (!av_strcasecmp(tag, "Content-Type")) {
            av_free(s->mime_type);
            s->mime_type = av_strdup(p);
        } else if (!av_strcasecmp(tag, "Set-Cookie")) {
            if (parse_cookie(s, p, &s->cookie_dict))
                av_log(h, AV_LOG_WARNING, "Unable to parse '%s'\n", p);
        } else if (!av_strcasecmp(tag, "Icy-MetaInt")) {
            s->icy_metaint = strtoll(p, NULL, 10);
        } else if (!av_strncasecmp(tag, "Icy-", 4)) {
            if ((ret = parse_icy(s, tag, p)) < 0)
                return ret;
        } else if (!av_strcasecmp(tag, "Content-Encoding")) {
            if ((ret = parse_content_encoding(h, p)) < 0)
                return ret;
        }
    }
    return 1;
}
예제 #15
0
int argparse::parse_arguments(char* arg, options_t& options) {
    std::string argument = arg, option, value;

    if (argument.compare(0, 8, "--macpo:") != 0)
        return -1;

    size_t start_position = -1, end_position;
    if ((start_position = argument.find(":")) == std::string::npos)
        return -1;

    end_position = argument.find("=", start_position + 1);
    if (end_position == std::string::npos) {
        option = argument.substr(start_position + 1);
        value = "";
    } else {
        option = argument.substr(start_position + 1,
            end_position - start_position - 1);
        value = argument.substr(end_position + 1);
    }

    location_t location;
    if (option == "instrument") {
        if (!value.size())
            return -1;

        parse_location(value, location);
        options.add_location(ACTION_INSTRUMENT, location);
    } else if (option == "check-alignment") {
        if (!value.size())
            return -1;

        parse_location(value, location);
        options.add_location(ACTION_ALIGNCHECK, location);
    } else if (option == "record-tripcount") {
        if (!value.size())
            return -1;

        parse_location(value, location);
        options.add_location(ACTION_TRIPCOUNT, location);
    } else if (option == "record-branchpath") {
        if (!value.size())
            return -1;

        parse_location(value, location);
        options.add_location(ACTION_BRANCHPATH, location);
    } else if (option == "gen-trace") {
        if (!value.size())
            return -1;

        parse_location(value, location);
        options.add_location(ACTION_GENTRACE, location);
    } else if (option == "vector-strides") {
        if (!value.size())
            return -1;

        parse_location(value, location);
        options.add_location(ACTION_VECTORSTRIDES, location);
    } else if (option == "overlap-check") {
        if (!value.size())
            return -1;

        parse_location(value, location);
        options.add_location(ACTION_OVERLAPCHECK, location);
    } else if (option == "stride-check") {
        if (!value.size())
            return -1;

        parse_location(value, location);
        options.add_location(ACTION_STRIDECHECK, location);
    } else if (option == "reuse-distance") {
        if (!value.size())
            return -1;

        parse_location(value, location);
        options.add_location(ACTION_REUSEDISTANCE, location);
    } else if (option == "backup-filename") {
        if (!value.size())
            return -1;

        options.backup_filename = value;
    } else if (option == "no-compile") {
        options.no_compile = true;
    } else if (option == "enable-sampling") {
        options.disable_sampling = false;
    } else if (option == "disable-sampling") {
        options.disable_sampling = true;
    } else if (option == "profile-analysis") {
        options.profile_analysis = true;
    } else if (option == "compiler") {
        // Check if we were passed a valid executable.
        if (!value.size()) {
            return -1;
        }

        options.base_compiler = value;
    } else {
        return -1;
    }

    return 0;
}
예제 #16
0
파일: http.c 프로젝트: OS2World/LIB-libav
static int process_line(URLContext *h, char *line, int line_count,
                        int *new_location)
{
    HTTPContext *s = h->priv_data;
    char *tag, *p, *end;
    int ret;

    /* end of header */
    if (line[0] == '\0') {
        s->end_header = 1;
        return 0;
    }

    p = line;
    if (line_count == 0) {
        while (!av_isspace(*p) && *p != '\0')
            p++;
        while (av_isspace(*p))
            p++;
        s->http_code = strtol(p, &end, 10);

        av_log(NULL, AV_LOG_TRACE, "http_code=%d\n", s->http_code);

        if ((ret = check_http_code(h, s->http_code, end)) < 0)
            return ret;
    } else {
        while (*p != '\0' && *p != ':')
            p++;
        if (*p != ':')
            return 1;

        *p  = '\0';
        tag = line;
        p++;
        while (av_isspace(*p))
            p++;
        if (!av_strcasecmp(tag, "Location")) {
            if ((ret = parse_location(s, p)) < 0)
                return ret;
            *new_location = 1;
        } else if (!av_strcasecmp(tag, "Content-Length") && s->filesize == -1) {
            s->filesize = strtoll(p, NULL, 10);
        } else if (!av_strcasecmp(tag, "Content-Range")) {
            parse_content_range(h, p);
        } else if (!av_strcasecmp(tag, "Accept-Ranges") &&
                   !strncmp(p, "bytes", 5)) {
            h->is_streamed = 0;
        } else if (!av_strcasecmp(tag, "Transfer-Encoding") &&
                   !av_strncasecmp(p, "chunked", 7)) {
            s->filesize  = -1;
            s->chunksize = 0;
        } else if (!av_strcasecmp(tag, "WWW-Authenticate")) {
            ff_http_auth_handle_header(&s->auth_state, tag, p);
        } else if (!av_strcasecmp(tag, "Authentication-Info")) {
            ff_http_auth_handle_header(&s->auth_state, tag, p);
        } else if (!av_strcasecmp(tag, "Proxy-Authenticate")) {
            ff_http_auth_handle_header(&s->proxy_auth_state, tag, p);
        } else if (!av_strcasecmp(tag, "Connection")) {
            if (!strcmp(p, "close"))
                s->willclose = 1;
        } else if (!av_strcasecmp(tag, "Content-Type")) {
            av_free(s->mime_type);
            s->mime_type = av_strdup(p);
        } else if (!av_strcasecmp(tag, "Icy-MetaInt")) {
            s->icy_metaint = strtoll(p, NULL, 10);
        } else if (!av_strncasecmp(tag, "Icy-", 4)) {
            if ((ret = parse_icy(s, tag, p)) < 0)
                return ret;
        } else if (!av_strcasecmp(tag, "Content-Encoding")) {
            if ((ret = parse_content_encoding(h, p)) < 0)
                return ret;
        }
    }
    return 1;
}