text:
/**
 * Autogenerated by Thrift Compiler (0.11.0)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
#include "Channels_types.h"

#include <algorithm>
#include <ostream>

#include <thrift/TToString.h>

namespace aroma { namespace thrift { namespace channels {

IOSDevice::~IOSDevice() throw() {
}

void IOSDevice::__set_deviceToken(const std::string& val) {
  this->deviceToken = val;
}
std::ostream& operator<<(std::ostream& out, const IOSDevice& obj)
{
  obj.printTo(out);
  return out;
}

uint32_t IOSDevice::read(::apache::thrift::protocol::TProtocol* iprot) {

  ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot);
  uint32_t xfer = 0;
  std::string fname;
  ::apache::thrift::protocol::TType ftype;
  int16_t fid;

  xfer += iprot->readStructBegin(fname);

  using ::apache::thrift::protocol::TProtocolException;

  while (true)
  {
    xfer += iprot->readFieldBegin(fname, ftype, fid);
    if (ftype == ::apache::thrift::protocol::T_STOP) {
      break;
    }
    switch (fid)
    {
      case 1:
        if (ftype == ::apache::thrift::protocol::T_STRING) {
          xfer += iprot->readBinary(this->deviceToken);
          this->__isset.deviceToken = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      default:
        xfer += iprot->skip(ftype);
        break;
    }
    xfer += iprot->readFieldEnd();
  }

  xfer += iprot->readStructEnd();

  return xfer;
}

uint32_t IOSDevice::write(::apache::thrift::protocol::TProtocol* oprot) const {
  uint32_t xfer = 0;
  ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot);
  xfer += oprot->writeStructBegin("IOSDevice");

  xfer += oprot->writeFieldBegin("deviceToken", ::apache::thrift::protocol::T_STRING, 1);
  xfer += oprot->writeBinary(this->deviceToken);
  xfer += oprot->writeFieldEnd();

  xfer += oprot->writeFieldStop();
  xfer += oprot->writeStructEnd();
  return xfer;
}

void swap(IOSDevice &a, IOSDevice &b) {
  using ::std::swap;
  swap(a.deviceToken, b.deviceToken);
  swap(a.__isset, b.__isset);
}

IOSDevice::IOSDevice(const IOSDevice& other0) {
  deviceToken = other0.deviceToken;
  __isset = other0.__isset;
}
IOSDevice& IOSDevice::operator=(const IOSDevice& other1) {
  deviceToken = other1.deviceToken;
  __isset = other1.__isset;
  return *this;
}
void IOSDevice::printTo(std::ostream& out) const {
  using ::apache::thrift::to_string;
  out << "IOSDevice(";
  out << "deviceToken=" << to_string(deviceToken);
  out << ")";
}

AndroidDevice::~AndroidDevice() throw() {
}

void AndroidDevice::__set_registrationId(const std::string& val) {
  this->registrationId = val;
}
std::ostream& operator<<(std::ostream& out, const AndroidDevice& obj)
{
  obj.printTo(out);
  return out;
}

uint32_t AndroidDevice::read(::apache::thrift::protocol::TProtocol* iprot) {

  ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot);
  uint32_t xfer = 0;
  std::string fname;
  ::apache::thrift::protocol::TType ftype;
  int16_t fid;

  xfer += iprot->readStructBegin(fname);

  using ::apache::thrift::protocol::TProtocolException;

  while (true)
  {
    xfer += iprot->readFieldBegin(fname, ftype, fid);
    if (ftype == ::apache::thrift::protocol::T_STOP) {
      break;
    }
    switch (fid)
    {
      case 1:
        if (ftype == ::apache::thrift::protocol::T_STRING) {
          xfer += iprot->readString(this->registrationId);
          this->__isset.registrationId = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      default:
        xfer += iprot->skip(ftype);
        break;
    }
    xfer += iprot->readFieldEnd();
  }

  xfer += iprot->readStructEnd();

  return xfer;
}

uint32_t AndroidDevice::write(::apache::thrift::protocol::TProtocol* oprot) const {
  uint32_t xfer = 0;
  ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot);
  xfer += oprot->writeStructBegin("AndroidDevice");

  xfer += oprot->writeFieldBegin("registrationId", ::apache::thrift::protocol::T_STRING, 1);
  xfer += oprot->writeString(this->registrationId);
  xfer += oprot->writeFieldEnd();

  xfer += oprot->writeFieldStop();
  xfer += oprot->writeStructEnd();
  return xfer;
}

void swap(AndroidDevice &a, AndroidDevice &b) {
  using ::std::swap;
  swap(a.registrationId, b.registrationId);
  swap(a.__isset, b.__isset);
}

AndroidDevice::AndroidDevice(const AndroidDevice& other2) {
  registrationId = other2.registrationId;
  __isset = other2.__isset;
}
AndroidDevice& AndroidDevice::operator=(const AndroidDevice& other3) {
  registrationId = other3.registrationId;
  __isset = other3.__isset;
  return *this;
}
void AndroidDevice::printTo(std::ostream& out) const {
  using ::apache::thrift::to_string;
  out << "AndroidDevice(";
  out << "registrationId=" << to_string(registrationId);
  out << ")";
}

WindowsPhoneDevice::~WindowsPhoneDevice() throw() {
}

std::ostream& operator<<(std::ostream& out, const WindowsPhoneDevice& obj)
{
  obj.printTo(out);
  return out;
}

uint32_t WindowsPhoneDevice::read(::apache::thrift::protocol::TProtocol* iprot) {

  ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot);
  uint32_t xfer = 0;
  std::string fname;
  ::apache::thrift::protocol::TType ftype;
  int16_t fid;

  xfer += iprot->readStructBegin(fname);

  using ::apache::thrift::protocol::TProtocolException;

  while (true)
  {
    xfer += iprot->readFieldBegin(fname, ftype, fid);
    if (ftype == ::apache::thrift::protocol::T_STOP) {
      break;
    }
    xfer += iprot->skip(ftype);
    xfer += iprot->readFieldEnd();
  }

  xfer += iprot->readStructEnd();

  return xfer;
}

uint32_t WindowsPhoneDevice::write(::apache::thrift::protocol::TProtocol* oprot) const {
  uint32_t xfer = 0;
  ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot);
  xfer += oprot->writeStructBegin("WindowsPhoneDevice");

  xfer += oprot->writeFieldStop();
  xfer += oprot->writeStructEnd();
  return xfer;
}

void swap(WindowsPhoneDevice &a, WindowsPhoneDevice &b) {
  using ::std::swap;
  (void) a;
  (void) b;
}

WindowsPhoneDevice::WindowsPhoneDevice(const WindowsPhoneDevice& other4) {
  (void) other4;
}
WindowsPhoneDevice& WindowsPhoneDevice::operator=(const WindowsPhoneDevice& other5) {
  (void) other5;
  return *this;
}
void WindowsPhoneDevice::printTo(std::ostream& out) const {
  using ::apache::thrift::to_string;
  out << "WindowsPhoneDevice(";
  out << ")";
}

MobileDevice::~MobileDevice() throw() {
}

void MobileDevice::__set_iosDevice(const IOSDevice& val) {
  this->iosDevice = val;
__isset.iosDevice = true;
}

void MobileDevice::__set_androidDevice(const AndroidDevice& val) {
  this->androidDevice = val;
__isset.androidDevice = true;
}

void MobileDevice::__set_windowsPhoneDevice(const WindowsPhoneDevice& val) {
  this->windowsPhoneDevice = val;
__isset.windowsPhoneDevice = true;
}
std::ostream& operator<<(std::ostream& out, const MobileDevice& obj)
{
  obj.printTo(out);
  return out;
}

uint32_t MobileDevice::read(::apache::thrift::protocol::TProtocol* iprot) {

  ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot);
  uint32_t xfer = 0;
  std::string fname;
  ::apache::thrift::protocol::TType ftype;
  int16_t fid;

  xfer += iprot->readStructBegin(fname);

  using ::apache::thrift::protocol::TProtocolException;

  while (true)
  {
    xfer += iprot->readFieldBegin(fname, ftype, fid);
    if (ftype == ::apache::thrift::protocol::T_STOP) {
      break;
    }
    switch (fid)
    {
      case 1:
        if (ftype == ::apache::thrift::protocol::T_STRUCT) {
          xfer += this->iosDevice.read(iprot);
          this->__isset.iosDevice = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      case 2:
        if (ftype == ::apache::thrift::protocol::T_STRUCT) {
          xfer += this->androidDevice.read(iprot);
          this->__isset.androidDevice = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      case 3:
        if (ftype == ::apache::thrift::protocol::T_STRUCT) {
          xfer += this->windowsPhoneDevice.read(iprot);
          this->__isset.windowsPhoneDevice = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      default:
        xfer += iprot->skip(ftype);
        break;
    }
    xfer += iprot->readFieldEnd();
  }

  xfer += iprot->readStructEnd();

  return xfer;
}

uint32_t MobileDevice::write(::apache::thrift::protocol::TProtocol* oprot) const {
  uint32_t xfer = 0;
  ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot);
  xfer += oprot->writeStructBegin("MobileDevice");

  if (this->__isset.iosDevice) {
    xfer += oprot->writeFieldBegin("iosDevice", ::apache::thrift::protocol::T_STRUCT, 1);
    xfer += this->iosDevice.write(oprot);
    xfer += oprot->writeFieldEnd();
  }
  if (this->__isset.androidDevice) {
    xfer += oprot->writeFieldBegin("androidDevice", ::apache::thrift::protocol::T_STRUCT, 2);
    xfer += this->androidDevice.write(oprot);
    xfer += oprot->writeFieldEnd();
  }
  if (this->__isset.windowsPhoneDevice) {
    xfer += oprot->writeFieldBegin("windowsPhoneDevice", ::apache::thrift::protocol::T_STRUCT, 3);
    xfer += this->windowsPhoneDevice.write(oprot);
    xfer += oprot->writeFieldEnd();
  }
  xfer += oprot->writeFieldStop();
  xfer += oprot->writeStructEnd();
  return xfer;
}

void swap(MobileDevice &a, MobileDevice &b) {
  using ::std::swap;
  swap(a.iosDevice, b.iosDevice);
  swap(a.androidDevice, b.androidDevice);
  swap(a.windowsPhoneDevice, b.windowsPhoneDevice);
  swap(a.__isset, b.__isset);
}

MobileDevice::MobileDevice(const MobileDevice& other6) {
  iosDevice = other6.iosDevice;
  androidDevice = other6.androidDevice;
  windowsPhoneDevice = other6.windowsPhoneDevice;
  __isset = other6.__isset;
}
MobileDevice& MobileDevice::operator=(const MobileDevice& other7) {
  iosDevice = other7.iosDevice;
  androidDevice = other7.androidDevice;
  windowsPhoneDevice = other7.windowsPhoneDevice;
  __isset = other7.__isset;
  return *this;
}
void MobileDevice::printTo(std::ostream& out) const {
  using ::apache::thrift::to_string;
  out << "MobileDevice(";
  out << "iosDevice="; (__isset.iosDevice ? (out << to_string(iosDevice)) : (out << "<null>"));
  out << ", " << "androidDevice="; (__isset.androidDevice ? (out << to_string(androidDevice)) : (out << "<null>"));
  out << ", " << "windowsPhoneDevice="; (__isset.windowsPhoneDevice ? (out << to_string(windowsPhoneDevice)) : (out << "<null>"));
  out << ")";
}

PushNotificationPayload::~PushNotificationPayload() throw() {
}

void PushNotificationPayload::__set_messageId(const uuid& val) {
  this->messageId = val;
}

void PushNotificationPayload::__set_applicationId(const uuid& val) {
  this->applicationId = val;
}
std::ostream& operator<<(std::ostream& out, const PushNotificationPayload& obj)
{
  obj.printTo(out);
  return out;
}

uint32_t PushNotificationPayload::read(::apache::thrift::protocol::TProtocol* iprot) {

  ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot);
  uint32_t xfer = 0;
  std::string fname;
  ::apache::thrift::protocol::TType ftype;
  int16_t fid;

  xfer += iprot->readStructBegin(fname);

  using ::apache::thrift::protocol::TProtocolException;

  while (true)
  {
    xfer += iprot->readFieldBegin(fname, ftype, fid);
    if (ftype == ::apache::thrift::protocol::T_STOP) {
      break;
    }
    switch (fid)
    {
      case 1:
        if (ftype == ::apache::thrift::protocol::T_STRING) {
          xfer += iprot->readString(this->messageId);
          this->__isset.messageId = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      case 2:
        if (ftype == ::apache::thrift::protocol::T_STRING) {
          xfer += iprot->readString(this->applicationId);
          this->__isset.applicationId = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      default:
        xfer += iprot->skip(ftype);
        break;
    }
    xfer += iprot->readFieldEnd();
  }

  xfer += iprot->readStructEnd();

  return xfer;
}

uint32_t PushNotificationPayload::write(::apache::thrift::protocol::TProtocol* oprot) const {
  uint32_t xfer = 0;
  ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot);
  xfer += oprot->writeStructBegin("PushNotificationPayload");

  xfer += oprot->writeFieldBegin("messageId", ::apache::thrift::protocol::T_STRING, 1);
  xfer += oprot->writeString(this->messageId);
  xfer += oprot->writeFieldEnd();

  xfer += oprot->writeFieldBegin("applicationId", ::apache::thrift::protocol::T_STRING, 2);
  xfer += oprot->writeString(this->applicationId);
  xfer += oprot->writeFieldEnd();

  xfer += oprot->writeFieldStop();
  xfer += oprot->writeStructEnd();
  return xfer;
}

void swap(PushNotificationPayload &a, PushNotificationPayload &b) {
  using ::std::swap;
  swap(a.messageId, b.messageId);
  swap(a.applicationId, b.applicationId);
  swap(a.__isset, b.__isset);
}

PushNotificationPayload::PushNotificationPayload(const PushNotificationPayload& other8) {
  messageId = other8.messageId;
  applicationId = other8.applicationId;
  __isset = other8.__isset;
}
PushNotificationPayload& PushNotificationPayload::operator=(const PushNotificationPayload& other9) {
  messageId = other9.messageId;
  applicationId = other9.applicationId;
  __isset = other9.__isset;
  return *this;
}
void PushNotificationPayload::printTo(std::ostream& out) const {
  using ::apache::thrift::to_string;
  out << "PushNotificationPayload(";
  out << "messageId=" << to_string(messageId);
  out << ", " << "applicationId=" << to_string(applicationId);
  out << ")";
}

SlackChannel::~SlackChannel() throw() {
}

void SlackChannel::__set_domainName(const std::string& val) {
  this->domainName = val;
}

void SlackChannel::__set_channelName(const std::string& val) {
  this->channelName = val;
}

void SlackChannel::__set_slackToken(const std::string& val) {
  this->slackToken = val;
}
std::ostream& operator<<(std::ostream& out, const SlackChannel& obj)
{
  obj.printTo(out);
  return out;
}

uint32_t SlackChannel::read(::apache::thrift::protocol::TProtocol* iprot) {

  ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot);
  uint32_t xfer = 0;
  std::string fname;
  ::apache::thrift::protocol::TType ftype;
  int16_t fid;

  xfer += iprot->readStructBegin(fname);

  using ::apache::thrift::protocol::TProtocolException;

  while (true)
  {
    xfer += iprot->readFieldBegin(fname, ftype, fid);
    if (ftype == ::apache::thrift::protocol::T_STOP) {
      break;
    }
    switch (fid)
    {
      case 1:
        if (ftype == ::apache::thrift::protocol::T_STRING) {
          xfer += iprot->readString(this->domainName);
          this->__isset.domainName = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      case 2:
        if (ftype == ::apache::thrift::protocol::T_STRING) {
          xfer += iprot->readString(this->channelName);
          this->__isset.channelName = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      case 3:
        if (ftype == ::apache::thrift::protocol::T_STRING) {
          xfer += iprot->readString(this->slackToken);
          this->__isset.slackToken = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      default:
        xfer += iprot->skip(ftype);
        break;
    }
    xfer += iprot->readFieldEnd();
  }

  xfer += iprot->readStructEnd();

  return xfer;
}

uint32_t SlackChannel::write(::apache::thrift::protocol::TProtocol* oprot) const {
  uint32_t xfer = 0;
  ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot);
  xfer += oprot->writeStructBegin("SlackChannel");

  xfer += oprot->writeFieldBegin("domainName", ::apache::thrift::protocol::T_STRING, 1);
  xfer += oprot->writeString(this->domainName);
  xfer += oprot->writeFieldEnd();

  xfer += oprot->writeFieldBegin("channelName", ::apache::thrift::protocol::T_STRING, 2);
  xfer += oprot->writeString(this->channelName);
  xfer += oprot->writeFieldEnd();

  xfer += oprot->writeFieldBegin("slackToken", ::apache::thrift::protocol::T_STRING, 3);
  xfer += oprot->writeString(this->slackToken);
  xfer += oprot->writeFieldEnd();

  xfer += oprot->writeFieldStop();
  xfer += oprot->writeStructEnd();
  return xfer;
}

void swap(SlackChannel &a, SlackChannel &b) {
  using ::std::swap;
  swap(a.domainName, b.domainName);
  swap(a.channelName, b.channelName);
  swap(a.slackToken, b.slackToken);
  swap(a.__isset, b.__isset);
}

SlackChannel::SlackChannel(const SlackChannel& other10) {
  domainName = other10.domainName;
  channelName = other10.channelName;
  slackToken = other10.slackToken;
  __isset = other10.__isset;
}
SlackChannel& SlackChannel::operator=(const SlackChannel& other11) {
  domainName = other11.domainName;
  channelName = other11.channelName;
  slackToken = other11.slackToken;
  __isset = other11.__isset;
  return *this;
}
void SlackChannel::printTo(std::ostream& out) const {
  using ::apache::thrift::to_string;
  out << "SlackChannel(";
  out << "domainName=" << to_string(domainName);
  out << ", " << "channelName=" << to_string(channelName);
  out << ", " << "slackToken=" << to_string(slackToken);
  out << ")";
}

SlackUsername::~SlackUsername() throw() {
}

void SlackUsername::__set_domainName(const std::string& val) {
  this->domainName = val;
}

void SlackUsername::__set_username(const std::string& val) {
  this->username = val;
}

void SlackUsername::__set_slackToken(const std::string& val) {
  this->slackToken = val;
}
std::ostream& operator<<(std::ostream& out, const SlackUsername& obj)
{
  obj.printTo(out);
  return out;
}

uint32_t SlackUsername::read(::apache::thrift::protocol::TProtocol* iprot) {

  ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot);
  uint32_t xfer = 0;
  std::string fname;
  ::apache::thrift::protocol::TType ftype;
  int16_t fid;

  xfer += iprot->readStructBegin(fname);

  using ::apache::thrift::protocol::TProtocolException;

  while (true)
  {
    xfer += iprot->readFieldBegin(fname, ftype, fid);
    if (ftype == ::apache::thrift::protocol::T_STOP) {
      break;
    }
    switch (fid)
    {
      case 1:
        if (ftype == ::apache::thrift::protocol::T_STRING) {
          xfer += iprot->readString(this->domainName);
          this->__isset.domainName = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      case 2:
        if (ftype == ::apache::thrift::protocol::T_STRING) {
          xfer += iprot->readString(this->username);
          this->__isset.username = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      case 3:
        if (ftype == ::apache::thrift::protocol::T_STRING) {
          xfer += iprot->readString(this->slackToken);
          this->__isset.slackToken = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      default:
        xfer += iprot->skip(ftype);
        break;
    }
    xfer += iprot->readFieldEnd();
  }

  xfer += iprot->readStructEnd();

  return xfer;
}

uint32_t SlackUsername::write(::apache::thrift::protocol::TProtocol* oprot) const {
  uint32_t xfer = 0;
  ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot);
  xfer += oprot->writeStructBegin("SlackUsername");

  xfer += oprot->writeFieldBegin("domainName", ::apache::thrift::protocol::T_STRING, 1);
  xfer += oprot->writeString(this->domainName);
  xfer += oprot->writeFieldEnd();

  xfer += oprot->writeFieldBegin("username", ::apache::thrift::protocol::T_STRING, 2);
  xfer += oprot->writeString(this->username);
  xfer += oprot->writeFieldEnd();

  xfer += oprot->writeFieldBegin("slackToken", ::apache::thrift::protocol::T_STRING, 3);
  xfer += oprot->writeString(this->slackToken);
  xfer += oprot->writeFieldEnd();

  xfer += oprot->writeFieldStop();
  xfer += oprot->writeStructEnd();
  return xfer;
}

void swap(SlackUsername &a, SlackUsername &b) {
  using ::std::swap;
  swap(a.domainName, b.domainName);
  swap(a.username, b.username);
  swap(a.slackToken, b.slackToken);
  swap(a.__isset, b.__isset);
}

SlackUsername::SlackUsername(const SlackUsername& other12) {
  domainName = other12.domainName;
  username = other12.username;
  slackToken = other12.slackToken;
  __isset = other12.__isset;
}
SlackUsername& SlackUsername::operator=(const SlackUsername& other13) {
  domainName = other13.domainName;
  username = other13.username;
  slackToken = other13.slackToken;
  __isset = other13.__isset;
  return *this;
}
void SlackUsername::printTo(std::ostream& out) const {
  using ::apache::thrift::to_string;
  out << "SlackUsername(";
  out << "domainName=" << to_string(domainName);
  out << ", " << "username=" << to_string(username);
  out << ", " << "slackToken=" << to_string(slackToken);
  out << ")";
}

Email::~Email() throw() {
}

void Email::__set_emailAddress(const std::string& val) {
  this->emailAddress = val;
}

void Email::__set_subject(const std::string& val) {
  this->subject = val;
__isset.subject = true;
}
std::ostream& operator<<(std::ostream& out, const Email& obj)
{
  obj.printTo(out);
  return out;
}

uint32_t Email::read(::apache::thrift::protocol::TProtocol* iprot) {

  ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot);
  uint32_t xfer = 0;
  std::string fname;
  ::apache::thrift::protocol::TType ftype;
  int16_t fid;

  xfer += iprot->readStructBegin(fname);

  using ::apache::thrift::protocol::TProtocolException;

  while (true)
  {
    xfer += iprot->readFieldBegin(fname, ftype, fid);
    if (ftype == ::apache::thrift::protocol::T_STOP) {
      break;
    }
    switch (fid)
    {
      case 1:
        if (ftype == ::apache::thrift::protocol::T_STRING) {
          xfer += iprot->readString(this->emailAddress);
          this->__isset.emailAddress = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      case 2:
        if (ftype == ::apache::thrift::protocol::T_STRING) {
          xfer += iprot->readString(this->subject);
          this->__isset.subject = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      default:
        xfer += iprot->skip(ftype);
        break;
    }
    xfer += iprot->readFieldEnd();
  }

  xfer += iprot->readStructEnd();

  return xfer;
}

uint32_t Email::write(::apache::thrift::protocol::TProtocol* oprot) const {
  uint32_t xfer = 0;
  ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot);
  xfer += oprot->writeStructBegin("Email");

  xfer += oprot->writeFieldBegin("emailAddress", ::apache::thrift::protocol::T_STRING, 1);
  xfer += oprot->writeString(this->emailAddress);
  xfer += oprot->writeFieldEnd();

  if (this->__isset.subject) {
    xfer += oprot->writeFieldBegin("subject", ::apache::thrift::protocol::T_STRING, 2);
    xfer += oprot->writeString(this->subject);
    xfer += oprot->writeFieldEnd();
  }
  xfer += oprot->writeFieldStop();
  xfer += oprot->writeStructEnd();
  return xfer;
}

void swap(Email &a, Email &b) {
  using ::std::swap;
  swap(a.emailAddress, b.emailAddress);
  swap(a.subject, b.subject);
  swap(a.__isset, b.__isset);
}

Email::Email(const Email& other14) {
  emailAddress = other14.emailAddress;
  subject = other14.subject;
  __isset = other14.__isset;
}
Email& Email::operator=(const Email& other15) {
  emailAddress = other15.emailAddress;
  subject = other15.subject;
  __isset = other15.__isset;
  return *this;
}
void Email::printTo(std::ostream& out) const {
  using ::apache::thrift::to_string;
  out << "Email(";
  out << "emailAddress=" << to_string(emailAddress);
  out << ", " << "subject="; (__isset.subject ? (out << to_string(subject)) : (out << "<null>"));
  out << ")";
}

CustomChannel::~CustomChannel() throw() {
}

void CustomChannel::__set_endpoint(const  ::aroma::thrift::endpoint::Endpoint& val) {
  this->endpoint = val;
}
std::ostream& operator<<(std::ostream& out, const CustomChannel& obj)
{
  obj.printTo(out);
  return out;
}

uint32_t CustomChannel::read(::apache::thrift::protocol::TProtocol* iprot) {

  ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot);
  uint32_t xfer = 0;
  std::string fname;
  ::apache::thrift::protocol::TType ftype;
  int16_t fid;

  xfer += iprot->readStructBegin(fname);

  using ::apache::thrift::protocol::TProtocolException;

  while (true)
  {
    xfer += iprot->readFieldBegin(fname, ftype, fid);
    if (ftype == ::apache::thrift::protocol::T_STOP) {
      break;
    }
    switch (fid)
    {
      case 1:
        if (ftype == ::apache::thrift::protocol::T_STRUCT) {
          xfer += this->endpoint.read(iprot);
          this->__isset.endpoint = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      default:
        xfer += iprot->skip(ftype);
        break;
    }
    xfer += iprot->readFieldEnd();
  }

  xfer += iprot->readStructEnd();

  return xfer;
}

uint32_t CustomChannel::write(::apache::thrift::protocol::TProtocol* oprot) const {
  uint32_t xfer = 0;
  ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot);
  xfer += oprot->writeStructBegin("CustomChannel");

  xfer += oprot->writeFieldBegin("endpoint", ::apache::thrift::protocol::T_STRUCT, 1);
  xfer += this->endpoint.write(oprot);
  xfer += oprot->writeFieldEnd();

  xfer += oprot->writeFieldStop();
  xfer += oprot->writeStructEnd();
  return xfer;
}

void swap(CustomChannel &a, CustomChannel &b) {
  using ::std::swap;
  swap(a.endpoint, b.endpoint);
  swap(a.__isset, b.__isset);
}

CustomChannel::CustomChannel(const CustomChannel& other16) {
  endpoint = other16.endpoint;
  __isset = other16.__isset;
}
CustomChannel& CustomChannel::operator=(const CustomChannel& other17) {
  endpoint = other17.endpoint;
  __isset = other17.__isset;
  return *this;
}
void CustomChannel::printTo(std::ostream& out) const {
  using ::apache::thrift::to_string;
  out << "CustomChannel(";
  out << "endpoint=" << to_string(endpoint);
  out << ")";
}

AromaChannel::~AromaChannel() throw() {
}

void AromaChannel::__set_slackChannel(const SlackChannel& val) {
  this->slackChannel = val;
__isset.slackChannel = true;
}

void AromaChannel::__set_slackUsername(const SlackUsername& val) {
  this->slackUsername = val;
__isset.slackUsername = true;
}

void AromaChannel::__set_email(const Email& val) {
  this->email = val;
__isset.email = true;
}

void AromaChannel::__set_customChannel(const CustomChannel& val) {
  this->customChannel = val;
__isset.customChannel = true;
}

void AromaChannel::__set_iosDevice(const IOSDevice& val) {
  this->iosDevice = val;
__isset.iosDevice = true;
}

void AromaChannel::__set_androidDevice(const AndroidDevice& val) {
  this->androidDevice = val;
__isset.androidDevice = true;
}

void AromaChannel::__set_windowsPhoneDevice(const WindowsPhoneDevice& val) {
  this->windowsPhoneDevice = val;
__isset.windowsPhoneDevice = true;
}
std::ostream& operator<<(std::ostream& out, const AromaChannel& obj)
{
  obj.printTo(out);
  return out;
}

uint32_t AromaChannel::read(::apache::thrift::protocol::TProtocol* iprot) {

  ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot);
  uint32_t xfer = 0;
  std::string fname;
  ::apache::thrift::protocol::TType ftype;
  int16_t fid;

  xfer += iprot->readStructBegin(fname);

  using ::apache::thrift::protocol::TProtocolException;

  while (true)
  {
    xfer += iprot->readFieldBegin(fname, ftype, fid);
    if (ftype == ::apache::thrift::protocol::T_STOP) {
      break;
    }
    switch (fid)
    {
      case 1:
        if (ftype == ::apache::thrift::protocol::T_STRUCT) {
          xfer += this->slackChannel.read(iprot);
          this->__isset.slackChannel = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      case 2:
        if (ftype == ::apache::thrift::protocol::T_STRUCT) {
          xfer += this->slackUsername.read(iprot);
          this->__isset.slackUsername = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      case 3:
        if (ftype == ::apache::thrift::protocol::T_STRUCT) {
          xfer += this->email.read(iprot);
          this->__isset.email = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      case 4:
        if (ftype == ::apache::thrift::protocol::T_STRUCT) {
          xfer += this->customChannel.read(iprot);
          this->__isset.customChannel = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      case 5:
        if (ftype == ::apache::thrift::protocol::T_STRUCT) {
          xfer += this->iosDevice.read(iprot);
          this->__isset.iosDevice = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      case 6:
        if (ftype == ::apache::thrift::protocol::T_STRUCT) {
          xfer += this->androidDevice.read(iprot);
          this->__isset.androidDevice = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      case 7:
        if (ftype == ::apache::thrift::protocol::T_STRUCT) {
          xfer += this->windowsPhoneDevice.read(iprot);
          this->__isset.windowsPhoneDevice = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      default:
        xfer += iprot->skip(ftype);
        break;
    }
    xfer += iprot->readFieldEnd();
  }

  xfer += iprot->readStructEnd();

  return xfer;
}

uint32_t AromaChannel::write(::apache::thrift::protocol::TProtocol* oprot) const {
  uint32_t xfer = 0;
  ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot);
  xfer += oprot->writeStructBegin("AromaChannel");

  if (this->__isset.slackChannel) {
    xfer += oprot->writeFieldBegin("slackChannel", ::apache::thrift::protocol::T_STRUCT, 1);
    xfer += this->slackChannel.write(oprot);
    xfer += oprot->writeFieldEnd();
  }
  if (this->__isset.slackUsername) {
    xfer += oprot->writeFieldBegin("slackUsername", ::apache::thrift::protocol::T_STRUCT, 2);
    xfer += this->slackUsername.write(oprot);
    xfer += oprot->writeFieldEnd();
  }
  if (this->__isset.email) {
    xfer += oprot->writeFieldBegin("email", ::apache::thrift::protocol::T_STRUCT, 3);
    xfer += this->email.write(oprot);
    xfer += oprot->writeFieldEnd();
  }
  if (this->__isset.customChannel) {
    xfer += oprot->writeFieldBegin("customChannel", ::apache::thrift::protocol::T_STRUCT, 4);
    xfer += this->customChannel.write(oprot);
    xfer += oprot->writeFieldEnd();
  }
  if (this->__isset.iosDevice) {
    xfer += oprot->writeFieldBegin("iosDevice", ::apache::thrift::protocol::T_STRUCT, 5);
    xfer += this->iosDevice.write(oprot);
    xfer += oprot->writeFieldEnd();
  }
  if (this->__isset.androidDevice) {
    xfer += oprot->writeFieldBegin("androidDevice", ::apache::thrift::protocol::T_STRUCT, 6);
    xfer += this->androidDevice.write(oprot);
    xfer += oprot->writeFieldEnd();
  }
  if (this->__isset.windowsPhoneDevice) {
    xfer += oprot->writeFieldBegin("windowsPhoneDevice", ::apache::thrift::protocol::T_STRUCT, 7);
    xfer += this->windowsPhoneDevice.write(oprot);
    xfer += oprot->writeFieldEnd();
  }
  xfer += oprot->writeFieldStop();
  xfer += oprot->writeStructEnd();
  return xfer;
}

void swap(AromaChannel &a, AromaChannel &b) {
  using ::std::swap;
  swap(a.slackChannel, b.slackChannel);
  swap(a.slackUsername, b.slackUsername);
  swap(a.email, b.email);
  swap(a.customChannel, b.customChannel);
  swap(a.iosDevice, b.iosDevice);
  swap(a.androidDevice, b.androidDevice);
  swap(a.windowsPhoneDevice, b.windowsPhoneDevice);
  swap(a.__isset, b.__isset);
}

AromaChannel::AromaChannel(const AromaChannel& other18) {
  slackChannel = other18.slackChannel;
  slackUsername = other18.slackUsername;
  email = other18.email;
  customChannel = other18.customChannel;
  iosDevice = other18.iosDevice;
  androidDevice = other18.androidDevice;
  windowsPhoneDevice = other18.windowsPhoneDevice;
  __isset = other18.__isset;
}
AromaChannel& AromaChannel::operator=(const AromaChannel& other19) {
  slackChannel = other19.slackChannel;
  slackUsername = other19.slackUsername;
  email = other19.email;
  customChannel = other19.customChannel;
  iosDevice = other19.iosDevice;
  androidDevice = other19.androidDevice;
  windowsPhoneDevice = other19.windowsPhoneDevice;
  __isset = other19.__isset;
  return *this;
}
void AromaChannel::printTo(std::ostream& out) const {
  using ::apache::thrift::to_string;
  out << "AromaChannel(";
  out << "slackChannel="; (__isset.slackChannel ? (out << to_string(slackChannel)) : (out << "<null>"));
  out << ", " << "slackUsername="; (__isset.slackUsername ? (out << to_string(slackUsername)) : (out << "<null>"));
  out << ", " << "email="; (__isset.email ? (out << to_string(email)) : (out << "<null>"));
  out << ", " << "customChannel="; (__isset.customChannel ? (out << to_string(customChannel)) : (out << "<null>"));
  out << ", " << "iosDevice="; (__isset.iosDevice ? (out << to_string(iosDevice)) : (out << "<null>"));
  out << ", " << "androidDevice="; (__isset.androidDevice ? (out << to_string(androidDevice)) : (out << "<null>"));
  out << ", " << "windowsPhoneDevice="; (__isset.windowsPhoneDevice ? (out << to_string(windowsPhoneDevice)) : (out << "<null>"));
  out << ")";
}

ChannelInfo::~ChannelInfo() throw() {
}

void ChannelInfo::__set_channel(const AromaChannel& val) {
  this->channel = val;
}

void ChannelInfo::__set_timeRegistered(const timestamp val) {
  this->timeRegistered = val;
}

void ChannelInfo::__set_channelId(const uuid& val) {
  this->channelId = val;
__isset.channelId = true;
}
std::ostream& operator<<(std::ostream& out, const ChannelInfo& obj)
{
  obj.printTo(out);
  return out;
}

uint32_t ChannelInfo::read(::apache::thrift::protocol::TProtocol* iprot) {

  ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot);
  uint32_t xfer = 0;
  std::string fname;
  ::apache::thrift::protocol::TType ftype;
  int16_t fid;

  xfer += iprot->readStructBegin(fname);

  using ::apache::thrift::protocol::TProtocolException;

  while (true)
  {
    xfer += iprot->readFieldBegin(fname, ftype, fid);
    if (ftype == ::apache::thrift::protocol::T_STOP) {
      break;
    }
    switch (fid)
    {
      case 1:
        if (ftype == ::apache::thrift::protocol::T_STRUCT) {
          xfer += this->channel.read(iprot);
          this->__isset.channel = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      case 2:
        if (ftype == ::apache::thrift::protocol::T_I64) {
          xfer += iprot->readI64(this->timeRegistered);
          this->__isset.timeRegistered = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      case 3:
        if (ftype == ::apache::thrift::protocol::T_STRING) {
          xfer += iprot->readString(this->channelId);
          this->__isset.channelId = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      default:
        xfer += iprot->skip(ftype);
        break;
    }
    xfer += iprot->readFieldEnd();
  }

  xfer += iprot->readStructEnd();

  return xfer;
}

uint32_t ChannelInfo::write(::apache::thrift::protocol::TProtocol* oprot) const {
  uint32_t xfer = 0;
  ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot);
  xfer += oprot->writeStructBegin("ChannelInfo");

  xfer += oprot->writeFieldBegin("channel", ::apache::thrift::protocol::T_STRUCT, 1);
  xfer += this->channel.write(oprot);
  xfer += oprot->writeFieldEnd();

  xfer += oprot->writeFieldBegin("timeRegistered", ::apache::thrift::protocol::T_I64, 2);
  xfer += oprot->writeI64(this->timeRegistered);
  xfer += oprot->writeFieldEnd();

  if (this->__isset.channelId) {
    xfer += oprot->writeFieldBegin("channelId", ::apache::thrift::protocol::T_STRING, 3);
    xfer += oprot->writeString(this->channelId);
    xfer += oprot->writeFieldEnd();
  }
  xfer += oprot->writeFieldStop();
  xfer += oprot->writeStructEnd();
  return xfer;
}

void swap(ChannelInfo &a, ChannelInfo &b) {
  using ::std::swap;
  swap(a.channel, b.channel);
  swap(a.timeRegistered, b.timeRegistered);
  swap(a.channelId, b.channelId);
  swap(a.__isset, b.__isset);
}

ChannelInfo::ChannelInfo(const ChannelInfo& other20) {
  channel = other20.channel;
  timeRegistered = other20.timeRegistered;
  channelId = other20.channelId;
  __isset = other20.__isset;
}
ChannelInfo& ChannelInfo::operator=(const ChannelInfo& other21) {
  channel = other21.channel;
  timeRegistered = other21.timeRegistered;
  channelId = other21.channelId;
  __isset = other21.__isset;
  return *this;
}
void ChannelInfo::printTo(std::ostream& out) const {
  using ::apache::thrift::to_string;
  out << "ChannelInfo(";
  out << "channel=" << to_string(channel);
  out << ", " << "timeRegistered=" << to_string(timeRegistered);
  out << ", " << "channelId="; (__isset.channelId ? (out << to_string(channelId)) : (out << "<null>"));
  out << ")";
}

ReceiveMessageRequest::~ReceiveMessageRequest() throw() {
}

void ReceiveMessageRequest::__set_message(const  ::tech::aroma::thrift::Message& val) {
  this->message = val;
}
std::ostream& operator<<(std::ostream& out, const ReceiveMessageRequest& obj)
{
  obj.printTo(out);
  return out;
}

uint32_t ReceiveMessageRequest::read(::apache::thrift::protocol::TProtocol* iprot) {

  ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot);
  uint32_t xfer = 0;
  std::string fname;
  ::apache::thrift::protocol::TType ftype;
  int16_t fid;

  xfer += iprot->readStructBegin(fname);

  using ::apache::thrift::protocol::TProtocolException;

  while (true)
  {
    xfer += iprot->readFieldBegin(fname, ftype, fid);
    if (ftype == ::apache::thrift::protocol::T_STOP) {
      break;
    }
    switch (fid)
    {
      case 1:
        if (ftype == ::apache::thrift::protocol::T_STRUCT) {
          xfer += this->message.read(iprot);
          this->__isset.message = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      default:
        xfer += iprot->skip(ftype);
        break;
    }
    xfer += iprot->readFieldEnd();
  }

  xfer += iprot->readStructEnd();

  return xfer;
}

uint32_t ReceiveMessageRequest::write(::apache::thrift::protocol::TProtocol* oprot) const {
  uint32_t xfer = 0;
  ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot);
  xfer += oprot->writeStructBegin("ReceiveMessageRequest");

  xfer += oprot->writeFieldBegin("message", ::apache::thrift::protocol::T_STRUCT, 1);
  xfer += this->message.write(oprot);
  xfer += oprot->writeFieldEnd();

  xfer += oprot->writeFieldStop();
  xfer += oprot->writeStructEnd();
  return xfer;
}

void swap(ReceiveMessageRequest &a, ReceiveMessageRequest &b) {
  using ::std::swap;
  swap(a.message, b.message);
  swap(a.__isset, b.__isset);
}

ReceiveMessageRequest::ReceiveMessageRequest(const ReceiveMessageRequest& other22) {
  message = other22.message;
  __isset = other22.__isset;
}
ReceiveMessageRequest& ReceiveMessageRequest::operator=(const ReceiveMessageRequest& other23) {
  message = other23.message;
  __isset = other23.__isset;
  return *this;
}
void ReceiveMessageRequest::printTo(std::ostream& out) const {
  using ::apache::thrift::to_string;
  out << "ReceiveMessageRequest(";
  out << "message=" << to_string(message);
  out << ")";
}

}}} // namespace


text:
// Copyright 2010-2021, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// OS_LINUX only. Note that OS_ANDROID/OS_WASM don't reach here.
#include <cstdint>
#if defined(OS_LINUX)

#include <arpa/inet.h>
#include <fcntl.h>
#include <libgen.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <unistd.h>

#include <cerrno>
#include <cstdlib>
#include <cstring>
#include <string>

#include "base/file_util.h"
#include "base/logging.h"
#include "base/thread.h"
#include "ipc/ipc.h"
#include "ipc/ipc_path_manager.h"
#include "absl/status/status.h"

#ifndef UNIX_PATH_MAX
#define UNIX_PATH_MAX 108
#endif  // UNIX_PATH_MAX

namespace mozc {
namespace {

constexpr int kInvalidSocket = -1;

absl::Status mkdir_p(const std::string &dirname) {
  const std::string parent_dir = FileUtil::Dirname(dirname);
  struct stat st;
  if (!parent_dir.empty() && ::stat(parent_dir.c_str(), &st) < 0) {
    if (absl::Status s = mkdir_p(parent_dir); !s.ok()) {
      return s;
    }
  }
  return FileUtil::CreateDirectory(dirname);
}

bool IsReadTimeout(int socket, int timeout) {
  if (timeout < 0) {
    return false;
  }
  fd_set fds;
  struct timeval tv;
  FD_ZERO(&fds);
  FD_SET(socket, &fds);
  tv.tv_sec = timeout / 1000;
  tv.tv_usec = 1000 * (timeout % 1000);
  if (select(socket + 1, &fds, nullptr, nullptr, &tv) < 0) {
    // Mac OS X and glibc implementations of strerror() return a pointer to a
    // string literal whenever errno is in a valid range, and thus thread-safe.
    // Probably we don't have to use the cumbersome strerror_r() function.
    LOG(WARNING) << "select() failed: " << strerror(errno);
    return true;
  }
  if (FD_ISSET(socket, &fds)) {
    return false;
  }

  LOG(ERROR) << "FD_ISSET failed";
  return true;
}

bool IsWriteTimeout(int socket, int timeout) {
  if (timeout < 0) {
    return false;
  }
  fd_set fds;
  struct timeval tv;
  FD_ZERO(&fds);
  FD_SET(socket, &fds);
  tv.tv_sec = timeout / 1000;
  tv.tv_usec = 1000 * (timeout % 1000);
  if (select(socket + 1, nullptr, &fds, nullptr, &tv) < 0) {
    LOG(WARNING) << "select() failed: " << strerror(errno);
    return true;
  }
  if (FD_ISSET(socket, &fds)) {
    return false;
  }

  LOG(ERROR) << "FD_ISSET failed";
  return true;
}

bool IsPeerValid(int socket, pid_t *pid) {
  *pid = 0;

  // On ARM Linux, we do nothing and just return true since the platform
  // sometimes doesn't support the getsockopt(sock, SOL_SOCKET, SO_PEERCRED)
  // system call.
  // TODO(yusukes): Add implementation for ARM Linux.
#ifndef __arm__
  struct ucred peer_cred;
  int peer_cred_len = sizeof(peer_cred);
  if (getsockopt(socket, SOL_SOCKET, SO_PEERCRED,
                 reinterpret_cast<void *>(&peer_cred),
                 reinterpret_cast<socklen_t *>(&peer_cred_len)) < 0) {
    LOG(ERROR) << "cannot get peer credential. Not a Unix socket?";
    return false;
  }

  if (peer_cred.uid != ::geteuid()) {
    LOG(WARNING) << "uid mismatch." << peer_cred.uid << "!=" << ::geteuid();
    return false;
  }

  *pid = peer_cred.pid;
#endif  // __arm__

  return true;
}

IPCErrorType SendMessage(int socket, const std::string &msg, int timeout) {
  int offset = 0;
  while (msg.size() != offset) {
    if (IsWriteTimeout(socket, timeout)) {
      LOG(WARNING) << "Write timeout " << timeout;
      return IPC_TIMEOUT_ERROR;
    }
    const ssize_t l =
        ::send(socket, msg.data() + offset, msg.size() - offset, MSG_NOSIGNAL);
    if (l < 0) {
      // An error occurs.
      LOG(ERROR) << "an error occurred during sending \"" << msg.substr(offset)
                 << "\": " << strerror(errno);
      return IPC_WRITE_ERROR;
    }
    offset += l;
  }
  VLOG(1) << offset << " bytes sent";
  return IPC_NO_ERROR;
}

IPCErrorType RecvMessage(int socket, std::string *msg, int timeout) {
  if (!msg) {
    LOG(WARNING) << "msg is nullptr";
    return IPC_UNKNOWN_ERROR;
  }
  msg->resize(IPC_RESPONSESIZE);
  ssize_t read_length = 0;
  int offset = 0;
  do {
    if (IsReadTimeout(socket, timeout)) {
      LOG(WARNING) << "Read timeout " << timeout;
      msg->clear();
      return IPC_TIMEOUT_ERROR;
    }
    read_length = ::recv(socket, msg->data() + offset, msg->size() - offset,
                         /* flags */ 0);
    if (read_length < 0) {
      LOG(ERROR) << "an error occurred during recv(): " << strerror(errno);
      msg->clear();
      return IPC_READ_ERROR;
    }
    offset += read_length;
    if (msg->size() == offset) {
      msg->resize(msg->size() * 2);
    }
  } while (read_length != 0);
  VLOG(1) << offset << " bytes received";
  msg->resize(offset);
  return IPC_NO_ERROR;
}

void SetCloseOnExecFlag(int fd) {
  int flags = ::fcntl(fd, F_GETFD, 0);
  if (flags < 0) {
    LOG(WARNING) << "fcntl(F_GETFD) for fd " << fd
                 << " failed: " << strerror(errno);
    return;
  }
  flags |= FD_CLOEXEC;
  if (::fcntl(fd, F_SETFD, flags) != 0) {
    LOG(WARNING) << "fcntl(F_SETFD) for fd " << fd
                 << " failed: " << strerror(errno);
  }
}

// Returns true if address is in abstract namespace. See unix(7) on Linux for
// details.
bool IsAbstractSocket(const std::string &address) {
  return (!address.empty()) && (address[0] == '\0');
}
}  // namespace

// Client
IPCClient::IPCClient(const std::string &name)
    : socket_(kInvalidSocket),
      connected_(false),
      ipc_path_manager_(nullptr),
      last_ipc_error_(IPC_NO_ERROR) {
  Init(name, "");
}

IPCClient::IPCClient(const std::string &name, const std::string &server_path)
    : socket_(kInvalidSocket),
      connected_(false),
      ipc_path_manager_(nullptr),
      last_ipc_error_(IPC_NO_ERROR) {
  Init(name, server_path);
}

void IPCClient::Init(const std::string &name, const std::string &server_path) {
  last_ipc_error_ = IPC_NO_CONNECTION;

  // Try twice, because key may be changed.
  IPCPathManager *manager = IPCPathManager::GetIPCPathManager(name);
  if (manager == nullptr) {
    LOG(ERROR) << "IPCPathManager::GetIPCPathManager failed";
    return;
  }

  ipc_path_manager_ = manager;

  for (size_t trial = 0; trial < 2; ++trial) {
    std::string server_address;
    if (!manager->LoadPathName() || !manager->GetPathName(&server_address)) {
      continue;
    }
    sockaddr_un address;
    ::memset(&address, 0, sizeof(address));
    const size_t server_address_length =
        (server_address.size() >= UNIX_PATH_MAX) ? UNIX_PATH_MAX - 1
                                                 : server_address.size();
    if (server_address.size() >= UNIX_PATH_MAX) {
      LOG(WARNING) << "too long path: " << server_address;
    }
    socket_ = socket(PF_UNIX, SOCK_STREAM, 0);
    if (socket_ < 0) {
      LOG(WARNING) << "socket failed: " << strerror(errno);
      continue;
    }
    SetCloseOnExecFlag(socket_);
    address.sun_family = AF_UNIX;
    ::memcpy(address.sun_path, server_address.data(), server_address_length);
    address.sun_path[server_address_length] = '\0';
    const size_t sun_len = sizeof(address.sun_family) + server_address_length;
    pid_t pid = 0;
    if (::connect(socket_, reinterpret_cast<const sockaddr *>(&address),
                  sun_len) != 0 ||
        !IsPeerValid(socket_, &pid)) {
      if ((errno == ENOTSOCK || errno == ECONNREFUSED) &&
          !IsAbstractSocket(server_address)) {
        // If abstract namepace is not enabled, recreate server_addresss path.
        ::unlink(server_address.c_str());
      }
      LOG(WARNING) << "connect failed: " << strerror(errno);
      connected_ = false;
      manager->Clear();
      continue;
    } else {
      if (!manager->IsValidServer(static_cast<uint32_t>(pid), server_path)) {
        LOG(ERROR) << "Connecting to invalid server";
        last_ipc_error_ = IPC_INVALID_SERVER;
        break;
      }
      last_ipc_error_ = IPC_NO_ERROR;
      connected_ = true;
      break;
    }
  }
}

IPCClient::~IPCClient() {
  if (socket_ != kInvalidSocket) {
    if (::close(socket_) < 0) {
      LOG(WARNING) << "close failed: " << strerror(errno);
    }
    socket_ = kInvalidSocket;
  }
  connected_ = false;
  VLOG(1) << "connection closed (IPCClient destructed)";
}

// RPC call
bool IPCClient::Call(const std::string &request, std::string *response,
                     int32_t timeout) {
  last_ipc_error_ = SendMessage(socket_, request, timeout);
  if (last_ipc_error_ != IPC_NO_ERROR) {
    LOG(ERROR) << "SendMessage failed";
    return false;
  }

  // Half-close the socket so that mozc_server could know the length of the
  // request data. Without this, RecvMessage() in mozc_server would fail with
  // timeout.
  // TODO(yusukes): It would be also possible to modify Send and RecvMessage()
  // so that they send/recv the payload size explicitly together with the actual
  // data. Will revisit later.
  ::shutdown(socket_, SHUT_WR);

  last_ipc_error_ = RecvMessage(socket_, response, timeout);
  if (last_ipc_error_ != IPC_NO_ERROR) {
    LOG(ERROR) << "RecvMessage failed";
    return false;
  }
  VLOG(1) << "Call succeeded";
  return true;
}

bool IPCClient::Connected() const { return connected_; }

// Server
IPCServer::IPCServer(const std::string &name, int32_t num_connections,
                     int32_t timeout)
    : connected_(false), socket_(kInvalidSocket), timeout_(timeout) {
  IPCPathManager *manager = IPCPathManager::GetIPCPathManager(name);
  if (!manager->CreateNewPathName() && !manager->LoadPathName()) {
    LOG(ERROR) << "Cannot prepare IPC path name";
    return;
  }

  if (!manager->GetPathName(&server_address_)) {
    LOG(ERROR) << "Cannot make IPC path name";
    return;
  }
  DCHECK(!server_address_.empty());
  if (server_address_.size() >= UNIX_PATH_MAX) {
    LOG(WARNING) << "server address is too long";
    return;
  }

  const bool is_file_socket = !IsAbstractSocket(server_address_);
  if (is_file_socket) {
    // Linux does not use files for IPC.
    const std::string dirname = FileUtil::Dirname(server_address_);
    if (absl::Status s = mkdir_p(dirname); !s.ok()) {
      LOG(ERROR) << s << ": Cannot create " << dirname;
    }
  }

  sockaddr_un addr;
  ::memset(&addr, 0, sizeof(addr));
  socket_ = ::socket(PF_UNIX, SOCK_STREAM, 0);
  if (socket_ < 0) {
    LOG(WARNING) << "socket failed: " << strerror(errno);
    return;
  }
  SetCloseOnExecFlag(socket_);

  addr.sun_family = AF_UNIX;
  server_address_.copy(addr.sun_path, server_address_.size());
  addr.sun_path[server_address_.size()] = '\0';

  int on = 1;
  ::setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<char *>(&on),
               sizeof(on));
  const size_t sun_len = sizeof(addr.sun_family) + server_address_.size();
  if (is_file_socket) {
    // Linux does not use files for IPC.
    ::chmod(server_address_.c_str(), 0600);
  }
  if (::bind(socket_, reinterpret_cast<sockaddr *>(&addr), sun_len) != 0) {
    // The UNIX domain socket file (server_address_) already exists?
    LOG(FATAL) << "bind() failed: " << strerror(errno);
    return;
  }

  if (::listen(socket_, num_connections) < 0) {
    LOG(FATAL) << "listen() failed: " << strerror(errno);
    return;
  }

  if (!manager->SavePathName()) {
    LOG(ERROR) << "Cannot save IPC path name";
    return;
  }

  connected_ = true;
  VLOG(1) << "IPCServer ready";
}

IPCServer::~IPCServer() {
  if (server_thread_ != nullptr) {
    server_thread_->Terminate();
  }
  ::shutdown(socket_, SHUT_RDWR);
  ::close(socket_);
  if (!IsAbstractSocket(server_address_)) {
    // When abstract namespace is used, unlink() is not necessary.
    ::unlink(server_address_.c_str());
  }
  connected_ = false;
  socket_ = kInvalidSocket;
  VLOG(1) << "IPCServer destructed";
}

bool IPCServer::Connected() const { return connected_; }

void IPCServer::Loop() {
  // The most portable and straightforward single-thread server
  bool error = false;
  pid_t pid = 0;
  std::string request;
  std::string response;
  while (!error) {
    const int new_sock = ::accept(socket_, nullptr, nullptr);
    if (new_sock < 0) {
      LOG(FATAL) << "accept() failed: " << strerror(errno);
      return;
    }
    if (!IsPeerValid(new_sock, &pid)) {
      continue;
    }

    if (RecvMessage(new_sock, &request, timeout_) != IPC_NO_ERROR) {
      LOG(WARNING) << "RecvMessage() failed";
      ::close(new_sock);
      continue;
    }

    if (!Process(request, &response)) {
      LOG(WARNING) << "Process() failed";
      ::close(new_sock);
      error = true;
      continue;
    }

    if (response.empty()) {
      LOG(WARNING) << "response is empty";
      ::close(new_sock);
      continue;
    }

    if (SendMessage(new_sock, response, timeout_) != IPC_NO_ERROR) {
      LOG(WARNING) << "SendMessage() failed";
    }
    ::close(new_sock);
  }

  ::shutdown(socket_, SHUT_RDWR);
  ::close(socket_);
  if (!IsAbstractSocket(server_address_)) {
    // When abstract namespace is used, unlink() is not necessary.
    ::unlink(server_address_.c_str());
  }
  connected_ = false;
  socket_ = kInvalidSocket;
}

void IPCServer::Terminate() { server_thread_->Terminate(); }

}  // namespace mozc

#endif  // OS_LINUX

redpajama_set_name: RedPajamaGithub


text:
<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Dashboard extends MY_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model(['company/Company_employees_model', 'company/Company_properties_model']);
    }

    /**
     * function use to display company dashboard.(HPA)
     */
    public function index() {
//        $this->login_data = array('name' => "sdfjkl",
//                            'user_name' => "dgmdfl",
//                            'password' => "dnknk" );
//        $this->email_data['content'] = $this->load->view('email_templates/login_content', $this->login_data , true);
//        $message = $this->load->view('email_templates/welcome_email', $this->email_data, true);
//        echo $message;
//        die;
//        pr(MY_Controller::$company_id);
//        if ($this->data['user_data']['role_id'] == 2 || $this->data['user_data']['role_id'] == 11) {
        $this->data['total_properties'] = $this->Company_properties_model->get_prop_details(null, 1);
        $this->data['total_emps'] = $this->Company_employees_model->get_company_employees(MY_Controller::$company_id, 1, null, array(3, 11));
        $this->data['total_agents'] = $this->Company_employees_model->get_company_employees(MY_Controller::$company_id, 1, null, 5);
//        $this->data['total_agents'] = $this->CMS_model->get_result(TBL_USERS, array('is_deleted' => 0, 'role_id' => 5, 'com_id' => MY_Controller::$company_id), null, null, 1);
        $property = $this->Company_properties_model->get_prop_details()->result_array();
        $rented = 0;
        $vacant = 0;
        foreach ($property as $key => $val) {
            if ($val['is_active'] == 1 && $val['tenant'] == 1) {
                $rented++;
            } else if ($val['tenant'] == 0) {
                $vacant++;
            }
        }
//        pr($this->data['user_data']);
        $this->data['total_vacant'] = $vacant;
        $this->data['total_rented'] = $rented;
        $ticket_status = $this->CMS_model->get_tickets_status();
        $this->data['ticket_open_status'] = $ticket_status;
        $this->data['total_open_tickets'] = $this->CMS_model->get_tickets($ticket_status, null, null, null, 1);
//        pr($this->data
//        }
        $this->template->load('front_main', 'company/dashboard', $this->data);
//        $this->email_data = array('head1' => 'New',
//            'head2' => 'Ticket');
//        $this->email_data['content'] = 'Thank you for recently contacting us, We have recieved your request and someone will be on it right away, please note your ticket number ' . 'fngjkn' . ' and use it for all follow ups.';
//       $message = $this->load->view('email_templates/common_email', $this->email_data, true);
//       echo $message; die;
//        $this->load->view('email_templates/common_email');
    }

    /**
     * function use for logout from company panel.(HDA)
     */
    public function log_out() {
        $this->session->sess_destroy();
//        $this->session->unset_userdata('admin');
        delete_cookie('Remember_me');
        $this->session->set_flashdata('message', array('message' => 'Log out Successfully.', 'class' => 'alert alert-success'));
        redirect('/');
    }

    /**
     * This function is used to Change company profile.
     * @author : HPA
     * @return boolean
     */
    public function edit() {
        $email = $this->session_data['email'];
        $post_email = htmlentities($this->input->post('email'));
        $email_unique_str = '';
        if ($email != $post_email) {
            $email_unique_str = '|callback_check_user';
        }

        if ($this->data['user_data']['role_id'] == 2) {
            if ($this->input->post('company_type') == 'business') {
                $this->form_validation->set_rules('company_name', 'Company Name', 'trim|required', array('required' => 'Please fill the field' . ' %s.'));
            }
            $this->data['plans'] = $this->CMS_model->get_result(TBL_MEMBERSHIP, array('is_deleted' => 0), 'id,title');
            $this->data['cities'] = $this->CMS_model->get_result(TBL_PROP_CITIES, array('is_delete' => 0));
        }
//        if ($this->data['user_data']['role_id'] == 11) {
//            $check_mem = $this->CMS_model->get_result('memberships', ['id' => $this->data['user_data']['membership_id']], 'No_of_emp', 1);
//            if (!empty($check_mem)) {
//                if ($check_mem['No_of_emp'] != '') {
//                    if ($total_employees >= $check_mem['No_of_emp']) {
//                        $this->session->set_flashdata('error', 'You may add maximum <b>' . $check_mem['No_of_emp'] . '</b> Employees Only.');
//                        redirect('employees/list');
//                    }
//                }
//            }
//        }
        $this->form_validation->set_rules('fname', 'First Name', 'trim|required', array('required' => 'Please fill the field' . ' %s.', 'regex_match' => 'Only alphabets, space and underscore are allowed for %s.'));
        $this->form_validation->set_rules('lname', 'Last Name', 'trim|required', array('required' => 'Please fill the field' . ' %s.'));
        if ($this->input->post('email'))
            $this->form_validation->set_rules('email', 'email', 'trim|required|valid_email' . $email_unique_str, array('required' => 'Please fill the field' . ' %s.', 'valid_email' => 'Please enter valid E-mail.', 'check_user' => 'Email Already Exists.'));
        $this->form_validation->set_rules('phone_no', 'Contact Number', 'trim|regex_match[/^[0-9]{9}$/]', array('regex_match' => 'Please enter valid %s.'));
        $this->form_validation->set_rules('address', 'Address', 'trim|required');
        if ($this->form_validation->run() == FALSE) {
            $this->data['heading'] = 'Edit Profile';
            $this->template->load('front_main', 'company/profile_edit', $this->data);
        } else {
            $user_id = $this->session_data['id'];
            //update_user_data
            $upd_data = $this->input->post(null);
//            pr($upd_data, 1);
            $upd_data['company_name'] = $this->input->post('company_name') != '' ? htmlentities($this->input->post('company_name')) : NULL;
            unset($upd_data['hidden_profile_picture']);
            if ($_FILES['profile_picture']['error'] == 0) {
                $img_name_arr = explode('.', $_FILES['profile_picture']['name']);
                $config['upload_path'] = './public/user_profile';
                $config['allowed_types'] = 'gif|jpg|png|jpeg';
                $config['max_size'] = '20000';
                $config['overwrite'] = TRUE;
                $image_name = date('Ymdhis') . '.' . $img_name_arr[(count($img_name_arr) - 1)];
                $_FILES['profile_picture']['name'] = $image_name;
                $this->load->library('upload', $config);
                if ($this->upload->do_upload('profile_picture')) {
                    $upd_data['profile_picture'] = $image_name;
                } else {
                    $error = $this->upload->display_errors();
                    $this->session->set_flashdata('success', $error);
                    redirect('profile');
                }
            } else {
                $upd_data['profile_picture'] = $this->input->post('hidden_profile_picture');
            }

            $this->Users_model->update_user_data($user_id, $upd_data);
            $user_data = $this->Users_model->check_if_user_exist(['id' => $this->session_data['id'], 'role_id' => '2'], false, true);
            $this->CMS_model->log_activity($this->user_name . ' has updated Profile!');
            $this->session->set_userdata(['users' => $user_data]);
            $this->session->set_flashdata('success', 'Profile updated successfully.');
            redirect('profile');
        }
    }

    /**
     * This function is used to Change password for company.
     * @author : HPA
     * @return boolean
     */
    public function change_password() {
        if ($this->data['user_data']['role_id'] != 5) {
            $sess_pass = $this->data['user_data']['password'];
            $decode_pass = $this->encrypt->decode($sess_pass);
        } else {
            $decode_pass = $this->data['user_data']['password'];
        }
        $user_id = $this->session_data['id'];
        $this->form_validation->set_rules('curr_pass', 'current password', 'trim|required|callback_check_current_password', ['check_current_password' => 'Please enter valid %s.', 'required' => 'Please fill the field %s.']);
        $this->form_validation->set_rules('pass', 'new password', 'trim|required|min_length[6]|matches[re_pass]', array('required' => 'Please fill the %s.', 'min_length' => 'Please enter password min 6 letter.'));
        $this->form_validation->set_rules('re_pass', 'repeat password', 'trim|required|matches[pass]', array('required' => 'Please fill the %s.', 'matches' => 'Please enter %s same as new password.'));
        if ($this->form_validation->run() == FALSE) {
            $this->data['heading'] = 'Change Password';
            $this->template->load('front_main', 'company/change_password', $this->data);
        } else {
            $password = htmlentities($this->input->post('pass'));

            if (($password == $this->encrypt->decode($this->data['user_data']['password']) || ( md5($password) == $this->data['user_data']['password']))) {
                $this->session->set_flashdata('error', 'Please do not use existing password.');
                redirect('change_password');
            }

            if ($this->data['user_data']['role_id'] != 5) {
                $encode_pass = $this->encrypt->encode($password);
            } else {
                $encode_pass = md5($password);
            }
//            pr($encode_pass, 1);
            $this->Users_model->update_user_data($user_id, ['password' => $encode_pass]);
            $this->CMS_model->log_activity($this->user_name . ' has changed password!');
            $this->session->set_flashdata('success', 'Password has been set Successfully.');
            redirect('dashboard');
        }
    }

    /**
     * This function is used to Check email already exists.
     * @author : HPA
     * @return boolean
     */
    public function check_user() {
        $email = htmlentities($this->input->post('email')); // get last name
        $this->db->select('email');
        $this->db->from('users');
        $this->db->where('email', $email);
        $this->db->where('is_deleted', '0');
        $query = $this->db->get();
        $num = $query->num_rows();
        if ($num > 0) {
            return FALSE;
        } else {
            return TRUE;
        }
    }

    /**
     * This function is used to Check current password is correct or not.
     * @author : HPA
     * @return boolean
     */
    public function check_current_password($value) {
//        if ($this->data['user_data']['role_id'] != 5) {
//            $sess_pass = $this->data['user_data']['password'];
//            $decode_pass = $this->encrypt->decode($sess_pass);
//            $password = $value;
//        } else {
//            $decode_pass = $this->data['user_data']['password'];
//            $password = md5($value);
//        }
        if ((md5($value) == $this->data['user_data']['password']) || ($value == $this->encrypt->decode($this->data['user_data']['password']) )) {
            return TRUE;
        } else {
            return FALSE;
        }
    }

    public function disclaimer_settings() {
        $this->data['title'] = $this->data['page_header'] = 'Disclaimer Settings';
        $disc_details = $this->CMS_model->get_disclaimer_details();
        $this->data['disc_settings'] = $disc_details;
        $this->form_validation->set_rules('disclaimer', 'Disclaimer', 'trim|required', array('required' => 'Please Enter Disclaimer.'));
        $this->template->load('front_main', 'company/Disclaimer/manage', $this->data);
        if ($this->form_validation->run() == TRUE) {
            if ($this->input->post()) {
                $disc_data['disclaimer'] = htmlentities($this->input->post('disclaimer'));
                if (!empty($disc_details)) {
                    if ($this->CMS_model->update_record(TBL_DISCLAIMER, ['id' => $disc_details['id']], $disc_data)) {
                        $this->CMS_model->log_activity($this->user_name . ' has updated Disclaimer Text!');
                        $this->session->set_flashdata('success', 'Successfully Updated Disclaimer Details');
                    } else {
                        $this->session->set_flashdata('error', 'Unable to update Disclaimer Details.');
                    }
                } else {
                    $disc_data['company_id'] = MY_Controller::$company_id;
                    $disc_data['created'] = date('Y-m-d H:i:s');
                    if ($this->CMS_model->insert_data(TBL_DISCLAIMER, $disc_data)) {
                        $this->CMS_model->log_activity($this->user_name . ' has added Disclaimer Text!');
                        $this->session->set_flashdata('success', 'Successfully added Disclaimer Details');
                    } else {
                        $this->session->set_flashdata('error', 'Unable to add Disclaimer Details.');
                    }
                }
                redirect('disclaimer');
            }
        }
    }

    public function cron_settings() {
        $this->data['title'] = $this->data['page_header'] = 'Reminder Settings';
        $this->data['cron_settings'] = $this->CMS_model->get_result(TBL_CRON_SETTINGS, ['company_id' => MY_Controller::$company_id], null, 1);
        if (empty($this->data['cron_settings'])) {
            $this->CMS_model->insert_data(TBL_CRON_SETTINGS, ['company_id' => MY_Controller::$company_id, 'created' => date('Y-m-d H:i:s')]);
            redirect('reminder');
        }
        $this->template->load('front_main', 'company/Cron/manage', $this->data);
        if ($this->input->post()) {
            $cron_data = $this->input->post(null);
            if ($this->CMS_model->update_record(TBL_CRON_SETTINGS, ['company_id' => MY_Controller::$company_id], $cron_data)) {
                $this->CMS_model->log_activity($this->user_name . ' has updated Cron Settings!');
                $this->session->set_flashdata('success', 'Successfully Updated Cron Details');
            } else {
                $this->session->set_flashdata('error', 'Unable to update Reminder Details.');
            }
            redirect('reminder');
        }
    }

    public function activity_log() {
        $this->template->load('front_main', 'company/Logs/index', $this->data);
    }

    /**
     * Function is used to get result based on datatable in user list page
     */
    public function list_logs() {
        $final['recordsTotal'] = $this->CMS_model->get_logs_count();
//        pr($final['recordsTotal']);
        $final['redraw'] = 1;
        // $final['recordsFiltered'] = $this->admin_users_model->get_users_result(TBL_USER,$select,'count');
        $final['recordsFiltered'] = $this->CMS_model->get_logs_count();
        $final['data'] = $this->CMS_model->get_all_logs();
        echo json_encode($final);
    }

}


text:
<?php
session_start();
require_once ('dbconfig.php');
require_once('class.user.php');

$auth_user = new USER();

if(isset($_GET['email']) && !empty($_GET['email']) AND isset($_GET['hash']) && !empty($_GET['hash'])){

    $email = ($_GET['email']); // Set email variable
    $hash = ($_GET['hash']);

    $search = mysqli_query($connection, "SELECT user_email, hash, active FROM users WHERE user_email='".$email."' AND hash='".$hash."' AND active='0'") or die('Error: ' . mysqli_error($connection));
    $match  = mysqli_num_rows($search);

    if($match > 0){
        mysqli_query($connection, "UPDATE users SET active='1' WHERE user_email='".$email."' AND hash='".$hash."' AND active='0'") or die('Error: ' . mysqli_error($connection));
        echo '
Your account has been activated, you can now login
';
    }else{
        // No match -> invalid url or account has already been activated.
        echo '
The url is either invalid or you already have activated your account.
';
    }

}else{
   echo 'you have no valid link';
}


text:
using System.Collections.Generic;

namespace RegTesting.Mvc.Models
{
	/// <summary>
	/// A Testsuite
	/// </summary>
	public class CreateTestsuiteModel
	{
		/// <summary>
		/// The id
		/// </summary>
		public virtual int ID { get; set; }

		/// <summary>
		/// The name
		/// </summary>
		public virtual string Name { get; set; }

		/// <summary>
		/// The description for the testsuite
		/// </summary>
		public virtual string Description { get; set; }

		/// <summary>
		/// A id for an testsuite to copy the settings from
		/// </summary>
		public virtual int CopyTestsuiteSettings { get; set; }

	}
}


text:
  <title>busICT</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

      Routes

        {{#each routes}}

              {{name}}

        {{/each}}

      <button type="button" class="navbar-toggle" data-toggle="offcanvas" data-target="#menu" data-canvas="body">

      </button>

      #busICT

Select a Route:

    {{#each routes}}
      {{name}}
    {{/each}}

    {{> map}}

<template name="map">

</template>


text:
var async = require('async'),
  express = require('express'),
  fs = require('fs'),
  jsonfile = require('jsonfile'),
  path = require('path'),
  mkdirp = require('mkdirp'),
  config = require('../config/app'),
  Category = require('../models/category'),
  Post = require('../models/post'),
  User = require('../models/user'),
  nodeZip = require('node-zip'),
  router = express.Router(),
  compressCategories = function(req, zip, settings, cb) {
    var params = JSON.parse(req.query.categories),
      filters = {
        $or: []
      };

    if (params.sections || params.categories || params.tags) {
      if (params.sections == true) {
        filters.$or.push({
          type: 'SECTION'
        });
      }
      if (params.categories == true) {
        filters.$or.push({
          type: 'CATEGORY'
        });
      }
      if (params.tags == true) {
        filters.$or.push({
          type: 'TAG'
        });
      }

      Category.find(filters, function(err, categories) {
        if (err || !categories) {
          cb(true);
        } else {
          var categoriesFile = path.join(config.uploads_tmp_path, 'categories.json');

          jsonfile.writeFile(categoriesFile, categories, {
            spaces: 2
          }, function() {
            zip.file('data/categories.json', fs.readFileSync(categoriesFile));

            for (var i = 0; i < categories.length; i++) {
              if (categories[i].type == 'TAG') {
                if (categories[i].cover_photo && categories[i].cover_photo.path) {
                  zip.file(path.join('data/images/', categories[i].id, categories[i].cover_photo.name), fs.readFileSync(categories[i].cover_photo.path));
                }

                if (categories[i].grid_photo && categories[i].grid_photo.path) {
                  zip.file(path.join('data/images/', categories[i].id, categories[i].grid_photo.name), fs.readFileSync(categories[i].grid_photo.path));
                }
              }
            }

            fs.unlinkSync(categoriesFile);
            cb(null, settings, zip);
          });
        }
      });
    } else {
      settings.categories = false;
      cb(null, settings, zip);
    }
  },
  compressPosts = function(req, zip, settings, cb) {
    var params = JSON.parse(req.query.posts),
      filters = {
        $or: []
      };

    if (params.archived || params.drafts || params.published) {
      if (params.archived == true) {
        filters.$or.push({
          status: 'ARCHIVED'
        });
      }
      if (params.drafts == true) {
        filters.$or.push({
          status: 'DRAFT'
        });
      }
      if (params.published == true) {
        filters.$or.push({
          status: 'PUBLISHED'
        });
      }

      Post.find(filters, function(err, posts) {
        if (err || !posts) {
          cb(true);
        } else {
          var postsFile = path.join(config.uploads_tmp_path, 'posts.json');

          jsonfile.writeFile(postsFile, posts, {
            spaces: 2
          }, function() {
            zip.file('data/posts.json', fs.readFileSync(postsFile));

            for (var i = 0; i < posts.length; i++) {
              if (posts[i].cover_photo && posts[i].cover_photo.path) {
                zip.file(path.join('data/images/', posts[i].id, posts[i].cover_photo.name), fs.readFileSync(posts[i].cover_photo.path));
              }

              if (posts[i].grid_photo && posts[i].grid_photo.path) {
                zip.file(path.join('data/images/', posts[i].id, posts[i].grid_photo.name), fs.readFileSync(posts[i].grid_photo.path));
              }

              if (posts[i].slider_photos && Array.isArray(posts[i].slider_photos)) {
                for (var j = 0; j < posts[i].slider_photos.length; j++) {
                  if (posts[i].slider_photos[j] && posts[i].slider_photos[j].path) {
                    zip.file(path.join('data/images/', posts[i].id, posts[i].slider_photos[j].name), fs.readFileSync(posts[i].slider_photos[j].path));
                  }
                }
              }
            }

            fs.unlinkSync(postsFile);
            cb(null, settings, zip);
          });
        }
      });
    } else {
      settings.posts = false;
      cb(null, settings, zip);
    }
  },
  compressUsers = function(req, zip, settings, cb) {
    var params = JSON.parse(req.query.users),
      filters = {
        $or: []
      };

    if (params.admin || params.author || params.editor || params.super) {
      if (params.admin == true) {
        filters.$or.push({
          type: 1
        });
      }
      if (params.author == true) {
        filters.$or.push({
          type: 3
        });
      }
      if (params.editor == true) {
        filters.$or.push({
          type: 2
        });
      }
      if (params.super == true) {
        filters.$or.push({
          type: 0
        });
      }

      User.find(filters, function(err, users) {
        if (err || !users) {
          cb(true);
        } else {
          var usersFile = path.join(config.uploads_tmp_path, 'users.json');

          jsonfile.writeFile(usersFile, users, {
            spaces: 2
          }, function() {
            zip.file('data/users.json', fs.readFileSync(usersFile));

            fs.unlinkSync(usersFile);
            cb(null, settings, zip);
          });
        }
      });
    } else {
      settings.users = false;
      cb(null, settings, zip);
    }
  },
  loadCategories = function(req, zip, cb) {
    var filePath = path.join(config.uploads_tmp_path, 'categories_import.json'),
      file = fs.writeFileSync(filePath, zip.files['data/categories.json']._data, 'binary'),
      categories = jsonfile.readFileSync(filePath),
      ids = Array(),
      photos = Array();
    fs.unlinkSync(filePath);

    for (var i = 0; i < categories.length; i++) {
      ids.push({
        original: categories[i]._id
      });

      photos.push({
        cover_photo: categories[i].cover_photo,
        grid_photo: categories[i].grid_photo
      });

      delete categories[i]._id;
      delete categories[i].cover_photo;
      delete categories[i].grid_photo;
    }

    Category.create(categories, function(err, records) {
      if (err) {
        err = new Error('Invalid categories data');
        err.status = 403;

        cb(err);
      } else {
        for (var j = 0; j < records.length; j++) {
          ids[j].created = records[j].id;
        }

        var k = 0;
        async.each(records, function(category, done) {
          if (category.type == 'TAG') {
            var dir = path.join(config.uploads_path, category.id);
            mkdirp.sync(dir);

            if (photos[k].cover_photo != undefined) {
              fs.writeFileSync(path.join(dir, photos[k].cover_photo.name), zip.files['data/images/' + ids[k].original + '/' + photos[k].cover_photo.name]._data, 'binary');
              category.cover_photo = {
                path: path.join(dir, photos[k].cover_photo.name),
                name: photos[k].cover_photo.name
              };
            }

            if (photos[k].grid_photo != undefined) {
              fs.writeFileSync(path.join(dir, photos[k].grid_photo.name), zip.files['data/images/' + ids[k].original + '/' + photos[k].grid_photo.name]._data, 'binary');
              category.grid_photo = {
                path: path.join(dir, photos[k].grid_photo.name),
                name: photos[k].grid_photo.name
              };
            }

            k++;
            category.save(function() {
              done(null);
            });
          } else {
            k++;
            done(null);
          }
        }, function(err) {
          cb(null, ids);
        });
      }
    });
  },
  loadPosts = function(req, zip, usersIds, categoriesIds, cb) {
    var filePath = path.join(config.uploads_tmp_path, 'posts_import.json'),
      file = fs.writeFileSync(filePath, zip.files['data/posts.json']._data, 'binary'),
      posts = jsonfile.readFileSync(filePath),
      ids = Array(),
      photos = Array();
    fs.unlinkSync(filePath);

    for (var i = 0; i < posts.length; i++) {
      var author = false,
        category = false,
        editor = false,
        publisher = false,
        section = false,
        tag = false;

      ids.push(posts[i]._id);
      photos.push({
        cover_photo: posts[i].cover_photo,
        grid_photo: posts[i].grid_photo,
        slider_photos: posts[i].slider_photos
      });

      delete posts[i]._id;
      delete posts[i].cover_photo;
      delete posts[i].grid_photo;
      delete posts[i].slider_photos;

      if (usersIds) {
        for (var j = 0; j < usersIds.length; j++) {
          if (!author && (posts[i].created_by && posts[i].created_by == usersIds[j].original)) {
            posts[i].created_by = usersIds[j].created;
            author = true;
          }

          if (!editor && (posts[i].edited_by && posts[i].edited_by == usersIds[j].original)) {
            posts[i].edited_by = usersIds[j].created;
            editor = true;
          }

          if (!publisher && (posts[i].published_by && posts[i].published_by == usersIds[j].original)) {
            posts[i].published_by = usersIds[j].created;
            publisher = true;
          }

          if (author && editor && publisher) {
            break;
          }
        }
      }

      if (categoriesIds) {
        for (var k = 0; k < categoriesIds.length; k++) {
          if (!category && posts[i].category == categoriesIds[k].original) {
            posts[i].category = categoriesIds[k].created;
            category = true;
          }

          if (!section && posts[i].section == categoriesIds[k].original) {
            posts[i].section = categoriesIds[k].created;
            section = true;
          }

          if (!tag && posts[i].tag == categoriesIds[k].original) {
            posts[i].tag = categoriesIds[k].created;
            tag = true;
          }

          if (category && section && tag) {
            break;
          }
        }
      }
    }

    Post.create(posts, function(err, records) {
      if (err) {
        err = new Error('Invalid posts data');
        err.status = 403;

        cb(err);
      } else {
        var i = 0;
        async.each(records, function(post, done) {
          var dir = path.join(config.uploads_path, post.id);

          mkdirp.sync(dir);

          if (photos[i].cover_photo != undefined) {
            fs.writeFileSync(path.join(dir, photos[i].cover_photo.name), zip.files['data/images/' + ids[i] + '/' + photos[i].cover_photo.name]._data, 'binary');
            post.cover_photo = {
              path: path.join(dir, photos[i].cover_photo.name),
              name: photos[i].cover_photo.name
            };
          }

          if (photos[i].grid_photo != undefined) {
            fs.writeFileSync(path.join(dir, photos[i].grid_photo.name), zip.files['data/images/' + ids[i] + '/' + photos[i].grid_photo.name]._data, 'binary');
            post.grid_photo = {
              path: path.join(dir, photos[i].grid_photo.name),
              name: photos[i].grid_photo.name
            };
          }

          if (photos[i].slider_photos != undefined && Array.isArray(photos[i].slider_photos)) {
            post.slider_photos = Array();
            for (var j = 0; j < photos[i].slider_photos.length; j++) {
              fs.writeFileSync(path.join(dir, photos[i].slider_photos[j].name), zip.files['data/images/' + ids[i] + '/' + photos[i].slider_photos[j].name]._data, 'binary');
              post.slider_photos.push({
                path: path.join(dir, photos[i].slider_photos[j].name),
                name: photos[i].slider_photos[j].name
              });
            }
          }

          i++;
          post.save(function() {
            done(null);
          });
        }, function(err) {
          cb(null);
        });
      }
    });
  },
  loadUsers = function(req, zip, cb) {
    var filePath = path.join(config.uploads_tmp_path, 'users_import.json'),
      file = fs.writeFileSync(filePath, zip.files['data/users.json']._data, 'binary'),
      users = jsonfile.readFileSync(filePath),
      ids = Array();
    fs.unlinkSync(filePath);

    for (var i = 0; i < users.length; i++) {
      ids.push({
        original: users[i]._id
      });
      delete users[i]._id;
    }

    User.create(users, function(err, records) {
      if (err) {
        err = new Error('Invalid users data');
        err.status = 403;

        cb(err);
      } else {
        for (var i = 0; i < records.length; i++) {
          ids[i].created = records[i].id;
        }

        cb(null, ids);
      }
    });
  };

router.get('/', function(req, res, next) {
  var zip = new nodeZip(),
    settings = {
      categories: true,
      posts: true,
      users: true
    };

  async.waterfall([
    function(cb) {
      compressCategories(req, zip, settings, function(err, settings, zip) {
        if (err) {
          cb(true);
        } else {
          cb(null, settings, zip);
        }
      });
    },
    function(settings, zip, cb) {
      compressPosts(req, zip, settings, function(err, settings, zip) {
        if (err) {
          cb(true);
        } else {
          cb(null, settings, zip);
        }
      });
    },
    function(settings, zip, cb) {
      compressUsers(req, zip, settings, function(err, settings, zip) {
        if (err) {
          cb(true);
        } else {
          cb(null, {
            settings: settings,
            zip: zip
          });
        }
      });
    }
  ], function(err, result) {
    if (err) {
      err = new Error('Invalid query');
      err.status = 401;

      cb(err);
    } else {
      var zipFile = path.join(config.uploads_tmp_path, 'data.zip'),
        settingsFile = path.join(config.uploads_tmp_path, 'settings.json');

      jsonfile.writeFileSync(settingsFile, settings, {
        spaces: 2
      });
      zip.file('data/settings.json', fs.readFileSync(settingsFile));

      fs.unlinkSync(settingsFile);
      fs.writeFileSync(zipFile, result.zip.generate({
        base64: false,
        compression: 'DEFLATE'
      }), 'binary');

      var filename = path.basename(zipFile),
        stats = fs.statSync(zipFile);

      res.setHeader('Content-Disposition', 'attachment; filename=' + filename);
      res.setHeader('Content-Length', stats.size);
      res.setHeader('Content-Type', 'application/zip');

      var filestream = fs.createReadStream(zipFile),
        stream = filestream.pipe(res);

      stream.on('finish', function() {
        fs.unlinkSync(zipFile);
      });
    }
  });
});

router.post('/', function(req, res, next) {
  if (!req.uploading || !req.body.files.data) {
    var err = new Error('Invalid request');
    err.status = 400;

    next(err);
  } else {
    var zipFile = fs.readFileSync(req.body.files.data[0].path),
      zip = new nodeZip(zipFile, {
        base64: false,
        checkCRC32: true
      }),
      settings = JSON.parse(zip.files['data/settings.json']._data);
    fs.unlinkSync(req.body.files.data[0].path);

    async.waterfall([
      function(cb) {
        if (settings.users) {
          loadUsers(req, zip, function(err, usersIds) {
            if (err) {
              cb(err);
            } else {
              cb(null, usersIds);
            }
          });
        } else {
          cb(null, null);
        }
      },
      function(usersIds, cb) {
        if (settings.categories) {
          loadCategories(req, zip, function(err, categoriesIds) {
            if (err) {
              cb(err);
            } else {
              cb(null, usersIds, categoriesIds);
            }
          });
        } else {
          cb(null, usersIds, null);
        }
      },
      function(usersIds, categoriesIds, cb) {
        if (settings.posts) {
          loadPosts(req, zip, usersIds, categoriesIds, function(err) {
            if (err) {
              cb(err);
            } else {
              cb();
            }
          });
        } else {
          cb();
        }
      }
    ], function(err, result) {
      if (err) {
        next(err);
      } else {
        res.json({
          message: 'Import complete'
        });
      }
    });
  }
});

module.exports = router;


text:
using System;
using System.Collections.Generic;

using Chiro.Gap.Domain;
using Chiro.Gap.Poco.Model;

namespace Chiro.Gap.WorkerInterfaces
{
    public interface IGelieerdePersonenManager
    {
        /// <summary>
        /// Zoekt naar gelieerde personen die gelijkaardig zijn aan een gegeven
        /// <paramref name="persoon"/>.
        /// </summary>
        /// <param name="persoon">
        /// Persoon waarmee vergeleken moet worden
        /// </param>
        /// <param name="groep">
        /// groep waarin te zoeken
        /// </param>
        /// <returns>
        /// Lijstje met gelijkaardige personen
        /// </returns>
        List<GelieerdePersoon> ZoekGelijkaardig(Persoon persoon, Groep groep);

        /// <summary>
        /// Koppelt het gegeven Adres via nieuwe PersoonsAdresObjecten
        /// aan de Personen gekoppeld aan de gelieerde personen <paramref name="gelieerdePersonen"/>.
        /// Persisteert niet.
        /// </summary>
        /// <param name="gelieerdePersonen">
        ///     Gelieerde  die er een adres bij krijgen, met daaraan gekoppeld hun huidige
        ///     adressen, en de gelieerde personen waarop de gebruiker GAV-rechten heeft.
        /// </param>
        /// <param name="adres">
        ///     Toe te voegen adres
        /// </param>
        /// <param name="adrestype">
        ///     Het adrestype (thuis, kot, enz.)
        /// </param>
        /// <param name="voorkeur">
        ///     Indien true, wordt het nieuwe adres voorkeursadres van de gegeven gelieerde personen
        /// </param>
        /// <returns>
        /// De nieuwe koppelingen tussen de <paramref name="gelieerdePersonen"/> en
        /// <paramref name="adres"/>.
        /// </returns>
        List<PersoonsAdres> AdresToevoegen(IList<GelieerdePersoon> gelieerdePersonen,
                                            Adres adres,
                                            AdresTypeEnum adrestype,
                                            bool voorkeur);

        /// <summary>
        /// Voegt een <paramref name="nieuwePersoon"/> toe aan de gegegeven <paramref name="groep"/>. Als
        /// <paramref name="forceer"/> niet is gezet, wordt een exception opgegooid als er al een gelijkaardige
        /// persoon aan de groep gekoppeld is.
        /// </summary>
        /// <param name="nieuwePersoon">Nieuwe toe te voegen persoon</param>
        /// <param name="groep">Groep waaraan de persoon gelieerd/gekoppeld moet worden</param>
        /// <param name="chiroLeeftijd">Chiroleeftijd van de persoon</param>
        /// <param name="forceer">Als <c>false</c>, dan wordt een exception opgegooid als er al een gelijkaardige
        /// persoon aan de groep gekoppeld is.</param>
        /// <returns>De gelieerde persoon na het koppelen van <paramref name="nieuwePersoon"/> aan <paramref name="groep"/>.</returns>
        GelieerdePersoon Toevoegen(Persoon nieuwePersoon, Groep groep, int chiroLeeftijd, bool forceer);

        /// <summary>
        /// Levert het contact-e-mailadres op van een gelieerde persoon
        /// </summary>
        /// <param name="gelieerdePersoon">Gelieerde persoon waarvan contact-e-mailadres opgeleverd moet worden</param>
        /// <returns>Het betreffende e-mailadres</returns>
        /// <remarks>Als er geen e-mailadres de voorkeur heeft, wordt gewoon een willekeurig opgeleverd. Of
        /// <c>null</c>, als er geen e-mailadressen zijn</remarks>
        string ContactEmail(GelieerdePersoon gelieerdePersoon);

        /// <summary>
        /// Levert alle gelieerde personen op uit dezelfde persoon als <paramref name="gelieerdePersoon"/>, die minstens
        /// een adres gemeenschappelijk hebben met die <paramref name="gelieerdePersoon"/>.
        /// </summary>
        /// <param name="gelieerdePersoon">Eem gelieerde persoon</param>
        /// <returns>Alle gelieerde personen uit dezelfde persoon als <paramref name="gelieerdePersoon"/>, die minstens
        /// een adres gemeenschappelijk hebben met die <paramref name="gelieerdePersoon"/>.</returns>
        GelieerdePersoon[] AdresGenotenUitZelfdeGroep(GelieerdePersoon gelieerdePersoon);
    }
}