This file is indexed.

/usr/lib/Wt/examples/codeview/CodeSession.C is in witty-examples 3.3.0-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
 * Copyright (C) 2010 Emweb bvba, Heverlee, Belgium.
 *
 * See the LICENSE file for terms of use.
 */

#include <Wt/WApplication>
#include <Wt/WServer>
#include <Wt/WRandom>

#include "CodeSession.h"

boost::recursive_mutex CodeSession::mutex_;
std::vector<CodeSession *> CodeSession::sessions_;

CodeSession::CodeSession(const CoderCallback& coderCallback)
{
  generateId();

  coder_ = new Coder();
  coder_->sessionId = Wt::WApplication::instance()->sessionId();
  coder_->callback = coderCallback;

  Lock lock(mutex_);
  sessions_.push_back(this);
}

CodeSession::~CodeSession()
{
  delete coder_;
}

CodeSession * CodeSession::addObserver(const std::string& id,
				       const BufferCallback& bufferCallback)
{
  Lock lock(mutex_);

  for (unsigned i = 0; i < sessions_.size(); ++i) {
    CodeSession *session = sessions_[i];
    if (session->id() == id) {
      Observer observer;
      observer.sessionId = Wt::WApplication::instance()->sessionId();
      observer.callback = bufferCallback;

      session->observers_.push_back(observer);
      session->postSessionChanged();

      return session;
    }
  }

  return 0;
}

void CodeSession::removeObserver()
{
  Lock lock(mutex_);

  std::string sessionId = Wt::WApplication::instance()->sessionId();

  for (unsigned i = 0; i < observers_.size(); ++i) {
    if (observers_[i].sessionId == sessionId) {
      observers_.erase(observers_.begin() + i);

      postSessionChanged();

      deleteIfEmpty();
      return;
    }
  }
}

void CodeSession::removeCoder()
{
  Lock lock(mutex_);

  delete coder_;
  coder_ = 0;

  deleteIfEmpty();
}

void CodeSession::insertBuffer(int index)
{
  Lock lock(mutex_);

  buffers_.insert(buffers_.begin() + index, Buffer());

  postBufferChanged(index, Inserted);
}

void CodeSession::updateBuffer(int buffer, const Wt::WString& name,
			       const Wt::WString& text)
{
  Lock lock(mutex_);

  buffers_[buffer].name = name;
  buffers_[buffer].text = text;

  postBufferChanged(buffer, Changed);
}

std::vector<CodeSession::Buffer> CodeSession::buffers() const
{
  Lock lock(mutex_);

  return buffers_;
}

CodeSession::Buffer CodeSession::buffer(int buffer) const
{
  Lock lock(mutex_);

  return buffers_[buffer];
}

void CodeSession::deleteIfEmpty()
{
  if (observers_.size() == 0 && !coder_) {
    sessions_.erase(std::find(sessions_.begin(), sessions_.end(), this));

    delete this;
  }
}

void CodeSession::generateId()
{
  id_ = Wt::WRandom::generateId(32);
}

void CodeSession::postSessionChanged()
{
  if (coder_)
    Wt::WServer::instance()->post(coder_->sessionId, coder_->callback);
}

void CodeSession::postBufferChanged(int buffer, BufferUpdate update)
{
  for (unsigned i = 0; i < observers_.size(); ++i) {
    Observer& observer = observers_[i];
    Wt::WServer::instance()
      ->post(observer.sessionId,
	     boost::bind(observer.callback, buffer, update));
  }
}