LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-14-2008, 02:43 AM   #1
SPF
Member
 
Registered: Jul 2007
Location: /home
Distribution: Debian
Posts: 36

Rep: Reputation: 15
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?
 
Old 10-14-2008, 08:29 AM   #2
SPF
Member
 
Registered: Jul 2007
Location: /home
Distribution: Debian
Posts: 36

Original Poster
Rep: Reputation: 15
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));

?>
 
Old 11-11-2008, 02:09 AM   #3
SPF
Member
 
Registered: Jul 2007
Location: /home
Distribution: Debian
Posts: 36

Original Poster
Rep: Reputation: 15
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)
 
  


Reply

Tags
exchange, webdav


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
webdav tszhim Linux - Software 1 05-10-2005 10:02 PM
webdav dummyagain Linux - Software 0 10-14-2004 12:56 AM
WebDAV Questions wolftechmn Linux - Networking 1 04-21-2004 06:06 AM
webdav b_usa Linux - General 1 04-04-2003 05:00 PM


All times are GMT -5. The time now is 05:15 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration