LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   webdav c++ programming (https://www.linuxquestions.org/questions/programming-9/webdav-c-programming-676201/)

SPF 10-14-2008 02:43 AM

webdav c++ programming
 
For testing purposes, I was given the task to create an appointment for every user on a microsoft 2007 exchange server.

I started out with a simple program under linux, but after the first message I send I got an "HTTP/1.1 401 Unauthorized" message back.
Looking at traces from other programs I discovered a challenge code has to be send after this message ( you get the same scenario when you use lynx sometimes ).

I searched a while on the internet, found some open source projects that have webdav included, but the code is very unreadable.

An existing tool/program could also be a solution so if anyone has suggestions?

SPF 10-14-2008 08:29 AM

After 6 hours of searching the internet. I found a website with a php script that could generate for example emails:
http://www.troywolf.com/articles/php...v_examples.php

I modified the script and now it can add appointments. Here's the code:

Code:

<?php

// Modify the path to this class file as needed.
require_once("class_http.php");

// Change these values for your Exchange Server.
$exchange_server = "http://192.168.0.40";
$exchange_username = "test";
$exchange_password = "123!test";

// We use Troy's http class object to send the XML-formatted WebDAV request
// to the Exchange Server and to receive the response from the Exchange Server.
// The response is also XML-formatted.
$h = new http();
$h->headers["Content-Type"] = 'text/xml; charset="UTF-8"';
$h->headers["Depth"] = "0";
$h->headers["Translate"] = "f";

$subject = "a" . rand();

// Build the XML request.
// This section must be against the left margin.

$h->xmlrequest = '<?xml version="1.0" encoding="utf-8"?>';
$h->xmlrequest .= <<<END
<D:propertyupdate  xmlns:ns0="http://schemas.microsoft.com/exchange/"
                    xmlns:ns1="http://schemas.microsoft.com/mapi/"
                    xmlns:ns2="http://schemas.microsoft.com/mapi/proptag/"
                    xmlns:ns3="urn:schemas:calendar:" xmlns:D="DAV:">
    <D:set>
          <D:prop>
              <ns0:outlookmessageclass>IPM.Appointment</ns0:outlookmessageclass>
              <ns1:subject>My New Appointment</ns1:subject>
              <ns2:x1000001e>Test</ns2:x1000001e>
              <ns3:dtend>2008-10-28T09:55:18.142Z</ns3:dtend>
              <ns3:dtstart>2008-10-26T07:55:17.909Z</ns3:dtstart>
          </D:prop>
    </D:set>
</D:propertyupdate>
END;

// IMPORTANT -- The END line above must be completely left-aligned. No white-space.

// The http object's 'fetch' method does the work of sending and receiving the
// request. We use the WebDAV PROPPATCH method to create or update Exchange items.
$url = $exchange_server."/Exchange/test/calendar/".urlencode($subject).".EML";
if (!$h->fetch($url, 0, null, $exchange_username, $exchange_password, "PROPPATCH")) {
  echo "<h2>There is a problem with the http request!</h2>";
  echo $h->log;
  exit();
}

// You can print out the response to help troubleshoot.
echo "<pre>".$h->header."</pre><hr />\n";
echo "<pre>".$h->body."</pre><hr />\n";

// Bonus tip! You can automatically open this new draft message for your user by
// formulating an outlook URL. Then either redirect to the URL by uncommenting the
// header line below, or pop the URL in client-side javascript using window.open.
#header("Location: outlook:drafts/~".urlencode($subject));

?>


SPF 11-11-2008 02:09 AM

It is also possible to set a location by adding:

Code:

$h->xmlrequest .= "              <ns3:location>patio</ns3:location>";
Note that ns3 refers to the schema ns3 (xmlns ns3)


All times are GMT -5. The time now is 02:07 PM.