Single-photon switch: Controllable scattering of photons inside a one-dimensional resonator waveguide